Skip to content

Commit

Permalink
Improve Access tests (#1819)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 authored Jan 26, 2023
1 parent 61e3194 commit 0ab08e5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 58 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/accessTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,5 @@ jobs:
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Artifactory
run: |
go install github.com/jfrog/jfrog-testing-infra/local-rt-setup@latest
~/go/bin/local-rt-setup
env:
RTLIC: ${{secrets.RTLIC}}
GOPROXY: direct
- name: Run Access tests
run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.access --ci.runId=${{ runner.os }}-access
run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.access --jfrog.url=${{ secrets.PLATFORM_URL }} --jfrog.adminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --jfrog.user=${{ secrets.PLATFORM_USER }} --ci.runId=${{ runner.os }}-access
58 changes: 9 additions & 49 deletions access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,26 @@ package main
import (
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
coreenvsetup "github.com/jfrog/jfrog-cli-core/v2/general/envsetup"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
coretests "github.com/jfrog/jfrog-cli-core/v2/utils/tests"
"github.com/jfrog/jfrog-cli/utils/tests"
"github.com/jfrog/jfrog-client-go/auth"
clientUtils "github.com/jfrog/jfrog-client-go/utils"
clientTestUtils "github.com/jfrog/jfrog-client-go/utils/tests"
"github.com/stretchr/testify/assert"
"testing"
)

var (
accessDetails *config.ServerDetails
accessAuth auth.ServiceDetails
// JFrog CLI for Xray commands
accessCli *tests.JfrogCli
)

func InitAccessTests() {
initAccessCli()
}

func authenticateAccess() string {
*tests.JfrogUrl = clientUtils.AddTrailingSlashIfNeeded(*tests.JfrogUrl)
accessDetails = &config.ServerDetails{AccessUrl: *tests.JfrogUrl + tests.AccessEndpoint}
cred := fmt.Sprintf("--url=%s", accessDetails.AccessUrl)
if *tests.JfrogAccessToken == "" {
coreutils.ExitOnErr(errors.New("Failed while attempting to authenticate with Access: No access token was provided. "))
}
accessDetails.AccessToken = *tests.JfrogAccessToken
cred += fmt.Sprintf(" --access-token=%s", accessDetails.AccessToken)

var err error
if accessAuth, err = accessDetails.CreateAccessAuthConfig(); err != nil {
coreutils.ExitOnErr(errors.New("Failed while attempting to authenticate with Access: " + err.Error()))
}
accessDetails.AccessUrl = accessAuth.GetUrl()
return cred
}

func initAccessCli() {
if accessCli != nil {
return
}
cred := authenticateAccess()
xrayCli = tests.NewJfrogCli(execMain, "jfrog", cred)
}

func initAccessTest(t *testing.T, minVersion string) {
func initAccessTest(t *testing.T) {
if !*tests.TestAccess {
t.Skip("Skipping Access test. To run Access test add the '-test.access=true' option.")
}
}

func TestSetupInvitedUser(t *testing.T) {
initAccessTest(t, "")
initAccessTest(t)
tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t)
defer createTempDirCallback()
setEnvCallBack := clientTestUtils.SetEnvWithCallbackAndAssert(t, coreutils.HomeDir, tempDirPath)
Expand Down Expand Up @@ -91,7 +51,7 @@ func encodeConnectionDetails(serverDetails *config.ServerDetails, t *testing.T)
}

func TestRefreshableAccessTokens(t *testing.T) {
initAccessTest(t, "")
initAccessTest(t)

server := &config.ServerDetails{Url: *tests.JfrogUrl, AccessToken: *tests.JfrogAccessToken}
err := coreenvsetup.GenerateNewLongTermRefreshableAccessToken(server)
Expand All @@ -105,11 +65,11 @@ func TestRefreshableAccessTokens(t *testing.T) {
artifactoryCommandExecutor := tests.NewJfrogCli(execMain, "jfrog rt", "")
uploadedFiles := 1
err = uploadWithSpecificServerAndVerify(t, artifactoryCommandExecutor, tests.ServerId, "testdata/a/a1.in", uploadedFiles)
if err != nil {
if !assert.NoError(t, err) {
return
}
curAccessToken, curRefreshToken, err := getAccessTokensFromConfig(t, tests.ServerId)
if err != nil {
if !assert.NoError(t, err) {
return
}
assert.NotEmpty(t, curAccessToken)
Expand All @@ -121,23 +81,23 @@ func TestRefreshableAccessTokens(t *testing.T) {
// Upload a file and assert tokens were refreshed.
uploadedFiles++
err = uploadWithSpecificServerAndVerify(t, artifactoryCommandExecutor, tests.ServerId, "testdata/a/a2.in", uploadedFiles)
if err != nil {
if !assert.NoError(t, err) {
return
}
curAccessToken, curRefreshToken, err = assertTokensChanged(t, tests.ServerId, curAccessToken, curRefreshToken)
if err != nil {
if !assert.NoError(t, err) {
return
}

// Make the token not refresh. Verify Tokens did not refresh.
auth.InviteRefreshBeforeExpiryMinutes = 0
uploadedFiles++
err = uploadWithSpecificServerAndVerify(t, artifactoryCommandExecutor, tests.ServerId, "testdata/a/b/b2.in", uploadedFiles)
if err != nil {
if !assert.NoError(t, err) {
return
}
newAccessToken, newRefreshToken, err := getArtifactoryTokensFromConfig(t, tests.ServerId)
if err != nil {
if !assert.NoError(t, err) {
return
}
assert.Equal(t, curAccessToken, newAccessToken)
Expand Down
1 change: 0 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ func setupIntegrationTests() {
InitXrayTests()
}
if *tests.TestAccess {
InitAccessTests()
InitArtifactoryTests()
}
if *tests.TestTransfer {
Expand Down

0 comments on commit 0ab08e5

Please sign in to comment.