Skip to content

Commit 74c9a47

Browse files
committed
Improve repositores code
Signed-off-by: Michael Sverdlov <[email protected]>
1 parent 633d8a0 commit 74c9a47

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

artifactory/commands/buildtoollogin/buildtoollogin_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
88
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
99
"github.com/jfrog/jfrog-cli-core/v2/utils/ioutils"
10+
"github.com/jfrog/jfrog-client-go/auth"
1011
"github.com/stretchr/testify/assert"
1112
"os"
1213
"path/filepath"
@@ -119,7 +120,7 @@ func TestBuildToolLoginCommand_Yarn(t *testing.T) {
119120
}{
120121
{
121122
name: "Token Authentication",
122-
accessToken: "test-token",
123+
accessToken: dummyToken,
123124
},
124125
{
125126
name: "Basic Authentication",
@@ -201,7 +202,7 @@ func TestBuildToolLoginCommand_Pip(t *testing.T) {
201202
}{
202203
{
203204
name: "Token Authentication",
204-
accessToken: "test-token",
205+
accessToken: dummyToken,
205206
},
206207
{
207208
name: "Basic Authentication",
@@ -233,15 +234,16 @@ func TestBuildToolLoginCommand_Pip(t *testing.T) {
233234
assert.NoError(t, err)
234235
pipConfigContent := string(pipConfigContentBytes)
235236

236-
// Validate that the index URL was set correctly in pip.conf.
237-
assert.Contains(t, pipConfigContent, fmt.Sprintf("index-url = https://%s:%[email protected]/artifactory/api/pypi/test-repo/simple", testCase.user, testCase.password))
238-
239-
// Validate token-based authentication.
240-
if testCase.accessToken != "" {
241-
assert.Contains(t, pipConfigContent, fmt.Sprintf("index-url = https://%[email protected]/artifactory/api/pypi/test-repo/simple", "test-token"))
242-
} else if testCase.user != "" && testCase.password != "" {
237+
switch {
238+
case testCase.accessToken != "":
239+
// Validate token-based authentication.
240+
assert.Contains(t, pipConfigContent, fmt.Sprintf("index-url = https://%s:%[email protected]/artifactory/api/pypi/test-repo/simple", auth.ExtractUsernameFromAccessToken(testCase.accessToken), testCase.accessToken))
241+
case testCase.user != "" && testCase.password != "":
243242
// Validate basic authentication with user and password.
244243
assert.Contains(t, pipConfigContent, fmt.Sprintf("index-url = https://%s:%[email protected]/artifactory/api/pypi/test-repo/simple", "myUser", "myPassword"))
244+
default:
245+
// Validate anonymous access.
246+
assert.Contains(t, pipConfigContent, "index-url = https://acme.jfrog.io/artifactory/api/pypi/test-repo/simple")
245247
}
246248
})
247249
}

artifactory/commands/python/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func GetPypiRemoteRegistryFlag(tool pythonutils.PythonTool) string {
5252
return pipenvRemoteRegistryFlag
5353
}
5454

55-
// Get the pypi repository embedded credentials URL (https://<user>:<token>@<your-artifactory-url>/artifactory/api/pypi/<repo-name>/simple)
55+
// Get the pypi repository embedded credentials URL (https://<user>:<password/token>@<your-artifactory-url>/artifactory/api/pypi/<repo-name>/simple)
5656
func GetPypiRepoUrl(serverDetails *config.ServerDetails, repository string, isCurationCmd bool) (string, error) {
5757
rtUrl, username, password, err := GetPypiRepoUrlWithCredentials(serverDetails, repository, isCurationCmd)
5858
if err != nil {

0 commit comments

Comments
 (0)