github.com/jfrog/jfrog-cli-core/v2@v2.52.0/utils/golang/utils_test.go (about)

     1  package goutils
     2  
     3  import (
     4  	"github.com/jfrog/jfrog-cli-core/v2/utils/config"
     5  	"github.com/jfrog/jfrog-client-go/artifactory/auth"
     6  	"github.com/stretchr/testify/assert"
     7  	"testing"
     8  )
     9  
    10  func TestGetArtifactoryRemoteRepoUrl(t *testing.T) {
    11  	server := &config.ServerDetails{
    12  		ArtifactoryUrl: "https://server.com/artifactory",
    13  		AccessToken:    "eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiJmYWtlXC91c2Vyc1wvdGVzdCJ9.MTIzNDU2Nzg5MA",
    14  	}
    15  	repoName := "test-repo"
    16  	repoUrl, err := GetArtifactoryRemoteRepoUrl(server, repoName)
    17  	assert.NoError(t, err)
    18  	assert.Equal(t, "https://test:eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiJmYWtlXC91c2Vyc1wvdGVzdCJ9.MTIzNDU2Nzg5MA@server.com/artifactory/api/go/test-repo", repoUrl)
    19  }
    20  
    21  func TestGetArtifactoryApiUrl(t *testing.T) {
    22  	details := auth.NewArtifactoryDetails()
    23  	details.SetUrl("https://test.com/artifactory/")
    24  
    25  	// Test username and password
    26  	details.SetUser("frog")
    27  	details.SetPassword("passfrog")
    28  	url, err := getArtifactoryApiUrl("test-repo", details)
    29  	assert.NoError(t, err)
    30  	assert.Equal(t, "https://frog:passfrog@test.com/artifactory/api/go/test-repo", url)
    31  
    32  	// Test access token
    33  	// Set fake access token with username "test"
    34  	details.SetUser("")
    35  	details.SetAccessToken("eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiJmYWtlXC91c2Vyc1wvdGVzdCJ9.MTIzNDU2Nzg5MA")
    36  	url, err = getArtifactoryApiUrl("test-repo", details)
    37  	assert.NoError(t, err)
    38  	assert.Equal(t, "https://test:eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiJmYWtlXC91c2Vyc1wvdGVzdCJ9.MTIzNDU2Nzg5MA@test.com/artifactory/api/go/test-repo", url)
    39  
    40  	// Test access token with username
    41  	// Set fake access token with username "test"
    42  	// Expect username to be "frog"
    43  	details.SetUser("frog")
    44  	details.SetAccessToken("eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiJmYWtlXC91c2Vyc1wvdGVzdCJ9.MTIzNDU2Nzg5MA")
    45  	url, err = getArtifactoryApiUrl("test-repo", details)
    46  	assert.NoError(t, err)
    47  	assert.Equal(t, "https://frog:eyJ0eXAiOiJKV1QifQ.eyJzdWIiOiJmYWtlXC91c2Vyc1wvdGVzdCJ9.MTIzNDU2Nzg5MA@test.com/artifactory/api/go/test-repo", url)
    48  }