Skip to content
Merged
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
39 changes: 39 additions & 0 deletions artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6563,6 +6563,45 @@ func TestRefreshableArtifactoryTokens(t *testing.T) {
cleanArtifactoryTest()
}

// TestBasicAuthRefreshTokenAndPing verifies the username/password (basic auth) flow end to end:
// configuring a server with user + password arms deferred refreshable-token creation, and the first
// command (ping) authenticates successfully and triggers creation of the refreshable Artifactory token.
func TestBasicAuthRefreshTokenAndPing(t *testing.T) {
initArtifactoryTest(t, "")

// This flow is only relevant for username/password authentication.
if *tests.JfrogAccessToken != "" {
t.Skip("Test only with username and password, skipping...")
}

// Configure a server with username + password. No token is created at this point
_, err := createServerConfigAndReturnPassphrase(t)
defer deleteServerConfig(t)
assert.NoError(t, err)

// Right after 'config add' there is no refreshable token yet, only the armed refresh interval.
preDetails, err := config.GetSpecificConfig(tests.ServerId, false, false)
assert.NoError(t, err)
assert.Empty(t, preDetails.AccessToken, "no access token should exist before the first command")
assert.Empty(t, preDetails.ArtifactoryRefreshToken, "no refresh token should exist before the first command")
assert.Equal(t, coreutils.TokenRefreshDefaultInterval, preDetails.ArtifactoryTokenRefreshInterval,
"the refresh interval should be armed so the token is created on the first command")

// Run ping using only the stored server-id (no inline credentials), so the CLI authenticates with
// the configured username/password and creates the refreshable token as part of the command.
err = coretests.NewJfrogCli(execMain, "jfrog rt", "--server-id="+tests.ServerId).Exec("ping")
assert.NoError(t, err, "ping should succeed using the configured username/password")

// Assert the refreshable Artifactory token was generated by the basic-auth flow.
curAccessToken, curRefreshToken, curArtifactoryRefreshToken, err := getTokensFromConfig(t)
assert.NoError(t, err)
assert.NotEmpty(t, curAccessToken, "an access token should be created after the first command")
assert.NotEmpty(t, curArtifactoryRefreshToken, "an Artifactory refresh token should be created after the first command")
assert.Empty(t, curRefreshToken, "the access refresh token must remain empty for the Artifactory-API flow")

cleanArtifactoryTest()
}

func setArtifactoryRefreshTokenInConfig(t *testing.T, serverId, token string) error {
details, err := config.GetAllServersConfigs()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/jfrog/gofrog v1.7.6
github.com/jfrog/jfrog-cli-application v1.0.2-0.20260608074325-4de652aef752
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260605085015-2102264e1ddd
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260601130310-8d52a530da18
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260608181453-edba164ca573
github.com/jfrog/jfrog-cli-evidence v0.9.5-0.20260601141509-8df6c9a4bc9b
github.com/jfrog/jfrog-cli-platform-services v1.10.1-0.20260601140139-4cefb6add7b7
github.com/jfrog/jfrog-cli-security v1.29.4-0.20260604062621-664f5215d30a
Expand Down Expand Up @@ -250,6 +250,6 @@ require (

// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.13.1-0.20260428071432-1e9d9a1991ad

// 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-cli-core/v2 => github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260608101344-b28be1f61ab7

//replace github.com/jfrog/jfrog-client-go => github.com/jfrog/jfrog-client-go v1.54.2-0.20251007084958-5eeaa42c31a6
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ github.com/jfrog/jfrog-cli-application v1.0.2-0.20260608074325-4de652aef752 h1:F
github.com/jfrog/jfrog-cli-application v1.0.2-0.20260608074325-4de652aef752/go.mod h1:EeLKgLeJfKcS7671H52bfCgj1xK8wyJJGBRD5a+vJMc=
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260605085015-2102264e1ddd h1:szLRYfFwFkVo1j3uSfKRdKfWzzq+QZP6ktMcBtCkq4Y=
github.com/jfrog/jfrog-cli-artifactory v0.8.1-0.20260605085015-2102264e1ddd/go.mod h1:7ynat5Vo0feKa4hQ2q+eUOaik9i1WDxqobGkD+oYTLg=
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260601130310-8d52a530da18 h1:tPv7XscDFAZaijVwMQNb+HmuucUMYQdjuA5frdGzhF0=
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260601130310-8d52a530da18/go.mod h1:9R90mhbczGXwW5EGlDs7F08ejQU/xdoDhYHMvzBiqgE=
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260608181453-edba164ca573 h1:04OOWU1PRShmy5AffB81v9Zo94MZ+Ffp5Z2YSo+185U=
github.com/jfrog/jfrog-cli-core/v2 v2.60.1-0.20260608181453-edba164ca573/go.mod h1:9R90mhbczGXwW5EGlDs7F08ejQU/xdoDhYHMvzBiqgE=
github.com/jfrog/jfrog-cli-evidence v0.9.5-0.20260601141509-8df6c9a4bc9b h1:V0FxnU3xh29y8yJHWymm6rPr1MrjG1DdPQlr3ckImwk=
github.com/jfrog/jfrog-cli-evidence v0.9.5-0.20260601141509-8df6c9a4bc9b/go.mod h1:t2luv7YHtrKe/Yf1xLZgLOkkiPtk1DsKj0OLXL2GwYo=
github.com/jfrog/jfrog-cli-platform-services v1.10.1-0.20260601140139-4cefb6add7b7 h1:wqOk6luH2NFVhK+3p7DyHCa0e5Prie4QQpo5hPyCFwI=
Expand Down
Loading