@@ -14,6 +14,7 @@ import (
1414 "testing"
1515 "time"
1616
17+ urfavecli "github.com/urfave/cli"
1718 "github.com/jfrog/jfrog-client-go/utils/log"
1819
1920 tests2 "github.com/jfrog/jfrog-cli-artifactory/utils/tests"
@@ -1278,6 +1279,48 @@ CMD ["echo", "Hello from buildx"]`, baseImage)
12781279 inttestutils .ContainerTestCleanup (t , serverDetails , artHttpDetails , imageNameOnly , buildName , tests .OciLocalRepo )
12791280}
12801281
1282+ // TestDockerBuildxSkipLoginFails verifies that --skip-login actually skips login.
1283+ // After logging out, buildx --push with --skip-login should fail because no auth is available.
1284+ func TestDockerBuildxSkipLoginFails (t * testing.T ) {
1285+ cleanup := initDockerBuildTest (t )
1286+ defer cleanup ()
1287+
1288+ // Prevent urfave/cli from calling os.Exit on command errors
1289+ origOsExiter := urfavecli .OsExiter
1290+ urfavecli .OsExiter = func (code int ) {}
1291+ defer func () { urfavecli .OsExiter = origOsExiter }()
1292+
1293+ registryHost := * tests .ContainerRegistry
1294+ if parsedURL , err := url .Parse (registryHost ); err == nil && parsedURL .Host != "" {
1295+ registryHost = parsedURL .Host
1296+ }
1297+ imageName := path .Join (registryHost , tests .OciLocalRepo , "test-skip-login" )
1298+ imageTag := imageName + ":v1"
1299+
1300+ workspace , err := filepath .Abs (tests .Out )
1301+ assert .NoError (t , err )
1302+ assert .NoError (t , fileutils .CreateDirIfNotExist (workspace ))
1303+
1304+ baseImage := path .Join (registryHost , tests .OciRemoteRepo , "busybox:latest" )
1305+ dockerfileContent := fmt .Sprintf (`FROM %s
1306+ CMD ["echo", "skip-login test"]` , baseImage )
1307+ dockerfilePath := filepath .Join (workspace , "Dockerfile" )
1308+ assert .NoError (t , os .WriteFile (dockerfilePath , []byte (dockerfileContent ), 0644 )) //#nosec G703 -- test code
1309+
1310+ // Logout from registry so push requires fresh login
1311+ logoutCmd := exec .Command ("docker" , "logout" , registryHost )
1312+ assert .NoError (t , logoutCmd .Run ())
1313+
1314+ // With --skip-login, jf should NOT re-login, so push should fail
1315+ err = runJfrogCliWithoutAssertion ("docker" , "buildx" , "build" ,
1316+ "--platform" , "linux/amd64" ,
1317+ "-t" , imageTag , "-f" , dockerfilePath , "--push" , "--skip-login" , workspace )
1318+ assert .Error (t , err , "Expected failure: --skip-login should prevent auto-login, causing push to fail without auth" )
1319+
1320+ // Re-login for subsequent tests
1321+ runJfrogCli (t , "docker" , "login" , registryHost )
1322+ }
1323+
12811324// TestDockerBuildWithVirtualRepo tests docker build with virtual repository
12821325func TestDockerBuildWithVirtualRepo (t * testing.T ) {
12831326 cleanup := initDockerBuildTest (t )
0 commit comments