Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1573,3 +1573,71 @@ CMD ["echo", "Hello from CI VCS test"]`, baseImage)
}
assert.Greater(t, artifactCount, 0, "No artifacts in build info")
}

// TestSetupDockerCommand verifies `jf setup docker --url ...` end-to-end.
//
// Guards RTECO-1352: configureContainer (in jfrog-cli-artifactory) used to read
// ServerDetails.GetUrl(), which createServerDetailsFromFlags clears for the Rt
// command domain after copying it into ArtifactoryUrl. On the --url invocation
// path that left the registry host empty and routed `docker login ""` to Docker
// Hub, producing a misleading 401. The corresponding fix in jfrog-cli-artifactory
// derives the host from GetArtifactoryUrl() (with GetUrl() fallback for the
// --server-id path) and asserts a non-empty host.
//
// This e2e test exercises the *exact* failure path — `--url` + `--access-token`
// flags with no saved config — and verifies that the docker config file ends up
// with an auth entry keyed by the Artifactory registry hostname.
func TestSetupDockerCommand(t *testing.T) {
if !*tests.TestDocker {
t.Skip("Skipping setup docker test. To run it, add the '-test.docker=true' option.")
}

// Isolate the docker config to a temp dir so the test never touches the
// developer's ~/.docker/config.json. The docker CLI honors DOCKER_CONFIG
// as the config-file directory.
dockerConfigDir := t.TempDir()
t.Setenv("DOCKER_CONFIG", dockerConfigDir)

// Build credentials from the test globals. The --url path is what the bug
// hit, so pass it explicitly along with --access-token (or --user/--password)
// rather than relying on a saved server config.
artifactoryUrl := *tests.JfrogUrl + tests.ArtifactoryEndpoint
user := *tests.JfrogUser
credFlag := ""
switch {
case *tests.JfrogAccessToken != "":
credFlag = "--access-token=" + *tests.JfrogAccessToken
if user == "" {
user = auth.ExtractUsernameFromAccessToken(*tests.JfrogAccessToken)
}
case *tests.JfrogPassword != "":
credFlag = "--password=" + *tests.JfrogPassword
default:
t.Skip("Skipping setup docker test: no JFrog credentials available.")
}

jfrogCli := coreTests.NewJfrogCli(execMain, "jfrog", "")
require.NoError(t, jfrogCli.Exec(
"setup", "docker",
"--url="+artifactoryUrl,
"--user="+user,
credFlag,
"--repo="+tests.DockerVirtualRepo,
))

// Derive the expected registry host the same way the fix does: take the
// host component of the Artifactory URL.
parsedUrl, err := url.Parse(artifactoryUrl)
require.NoError(t, err)
expectedRegistryHost := parsedUrl.Host
require.NotEmpty(t, expectedRegistryHost, "Artifactory URL must have a host")

// Verify the docker config file was updated with an auth entry for the
// derived registry host. Before the fix the entry would have been keyed by
// an empty string (and the underlying `docker login` would have failed).
dockerConfigPath := filepath.Join(dockerConfigDir, "config.json")
contentBytes, err := os.ReadFile(dockerConfigPath)
require.NoError(t, err, "docker config file should be created by setup docker")
assert.Contains(t, string(contentBytes), expectedRegistryHost,
"docker config should contain the Artifactory registry host derived from --url")
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,5 @@ require (
// replace github.com/jfrog/jfrog-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260518123155-036d9195c4e9

//replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.54.2-0.20251007084958-5eeaa42c31a6

replace github.com/jfrog/jfrog-cli-artifactory => github.com/Edenb2131/jfrog-cli-artifactory v0.8.1-0.20260527121640-331df92da060
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk
github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/CycloneDX/cyclonedx-go v0.11.0 h1:GokP8FiRC+foiuwWhSSLpSD5H4hSWtGnR3wo7apkBFI=
github.com/CycloneDX/cyclonedx-go v0.11.0/go.mod h1:vUvbCXQsEm48OI6oOlanxstwNByXjCZ2wuleUlwGEO8=
github.com/Edenb2131/jfrog-cli-artifactory v0.8.1-0.20260527121640-331df92da060 h1:PmuUPkdOiX+17q9ZHozC6A8+cKJD4qsUTdO9TD6WdwI=
github.com/Edenb2131/jfrog-cli-artifactory v0.8.1-0.20260527121640-331df92da060/go.mod h1:T5HDtDxHlUZWF4LQnmF2kiyFyd8yLOf3K618BsG0CWk=
github.com/Masterminds/semver/v3 v3.5.0 h1:kQceYJfbupGfZOKZQg0kou0DgAKhzDg2NZPAwZ/2OOE=
github.com/Masterminds/semver/v3 v3.5.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
Expand Down Expand Up @@ -412,8 +414,6 @@ github.com/jfrog/jfrog-apps-config v1.0.1 h1:mtv6k7g8A8BVhlHGlSveapqf4mJfonwvXYL
github.com/jfrog/jfrog-apps-config v1.0.1/go.mod h1:8AIIr1oY9JuH5dylz2S6f8Ym2MaadPLR6noCBO4C22w=
github.com/jfrog/jfrog-cli-application v1.0.2-0.20260511133105-55a0ab56fd64 h1:bxcy1v1LXQV4T0kVU1duWQr3h7vKfHyMD1B+IuFLWUw=
github.com/jfrog/jfrog-cli-application v1.0.2-0.20260511133105-55a0ab56fd64/go.mod h1:cKqb/JgN+XuD4RhOxvSZnyGyXw3cJsTZfQT3rk9MCho=
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260527043943-fdf755c4f4c2 h1:acwlLYjjglecqjXXgj2JoM1bUhH/dDMpLpJXrBfvyqU=
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260527043943-fdf755c4f4c2/go.mod h1:T5HDtDxHlUZWF4LQnmF2kiyFyd8yLOf3K618BsG0CWk=
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260528061115-b41c87af0194 h1:cwppCKLitT0XBqYGQimW00qyx1ej88sY+rIjXAWNvAU=
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260528061115-b41c87af0194/go.mod h1:9R90mhbczGXwW5EGlDs7F08ejQU/xdoDhYHMvzBiqgE=
github.com/jfrog/jfrog-cli-evidence v0.9.4 h1:RAqZYaH2RrzmhW+bGA7dx/yTqa4X1fZ4/5V7VVMSJtc=
Expand Down
Loading