Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integration tests #2730

Merged
merged 2 commits into from
Oct 22, 2024
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
7 changes: 6 additions & 1 deletion .github/workflows/accessTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ jobs:
- name: Setup Go with cache
uses: jfrog/.github/actions/install-go-with-cache@main

- name: Install local Artifactory
uses: jfrog/.github/actions/install-local-artifactory@main
with:
RTLIC: ${{ secrets.RTLIC }}

- name: Run Access tests
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
run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.access --jfrog.url=http://127.0.0.1:8082 --jfrog.adminToken=${{ env.JFROG_TESTS_LOCAL_ACCESS_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/artifactoryTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
RTLIC: ${{ secrets.RTLIC }}

- name: Run Artifactory tests
run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.artifactory
run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.artifactory --jfrog.url=http://127.0.0.1:8082 --jfrog.adminToken=${{ env.JFROG_TESTS_LOCAL_ACCESS_TOKEN }}
if: ${{ matrix.suite == 'artifactory' }}

- name: Run Artifactory projects tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/transferTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
JFROG_HOME: ${{ runner.temp }}

- name: Run transfer tests
run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.transfer --test.installDataTransferPlugin --jfrog.targetUrl=${{ secrets.PLATFORM_URL }} --jfrog.targetAdminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --jfrog.home=${{ runner.temp }} --ci.runId=${{ runner.os }}-transfer-7
run: go test -v github.com/jfrog/jfrog-cli --timeout 0 --test.transfer --test.installDataTransferPlugin --jfrog.url=http://127.0.0.1:8082 --jfrog.targetUrl=${{ secrets.PLATFORM_URL }} --jfrog.targetAdminToken=${{ secrets.PLATFORM_ADMIN_TOKEN }} --jfrog.home=${{ runner.temp }} --ci.runId=${{ runner.os }}-transfer-7

Transfer-Artifactory-6-Tests:
if: contains(github.event.pull_request.labels.*.name, 'safe to test') || github.event_name == 'push'
Expand Down
137 changes: 69 additions & 68 deletions access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package main
import (
"encoding/json"
"fmt"
"net/http"
"testing"

"github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
Expand All @@ -16,8 +19,6 @@ import (
"github.com/jfrog/jfrog-client-go/utils/errorutils"
"github.com/jfrog/jfrog-client-go/utils/io/httputils"
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)

var (
Expand Down Expand Up @@ -176,90 +177,90 @@ const (
userScope = "applied-permissions/user"
)

var atcTestCases = []struct {
name string
args []string
shouldExpire bool
// The expected expiry or -1 if we use the default expiry value
expectedExpiry int
expectedScope string
expectedRefreshable bool
expectedReference bool
}{
{
name: "default",
args: []string{"atc"},
shouldExpire: true,
expectedExpiry: -1,
expectedScope: userScope,
expectedRefreshable: false,
expectedReference: false,
},
{
name: "explicit user, no expiry",
args: []string{"atc", auth.ExtractUsernameFromAccessToken(*tests.JfrogAccessToken), "--expiry=0"},
shouldExpire: false,
expectedExpiry: 0,
expectedScope: userScope,
expectedRefreshable: false,
expectedReference: false,
},
{
name: "refreshable, admin",
args: []string{"atc", "--refreshable", "--grant-admin"},
shouldExpire: true,
expectedExpiry: -1,
expectedScope: "applied-permissions/admin",
expectedRefreshable: true,
expectedReference: false,
},
{
name: "reference, custom scope, custom expiry",
args: []string{"atc", "--reference", "--scope=system:metrics:r", "--expiry=123456"},
shouldExpire: true,
expectedExpiry: 123456,
expectedScope: "system:metrics:r",
expectedRefreshable: false,
expectedReference: true,
},
{
name: "groups, description",
args: []string{"atc", "--groups=group1,group2", "--description=description"},
shouldExpire: true,
expectedExpiry: -1,
expectedScope: "applied-permissions/groups:group1,group2",
expectedRefreshable: false,
expectedReference: false,
},
}

func TestAccessTokenCreate(t *testing.T) {
initAccessTest(t)
if *tests.JfrogAccessToken == "" {
t.Skip("access token create command only supports authorization with access token, but a token is not provided. Skipping...")
}

for _, test := range atcTestCases {
t.Run(test.name, func(t *testing.T) {
var testCases = []struct {
name string
args []string
shouldExpire bool
// The expected expiry or -1 if we use the default expiry value
expectedExpiry int
expectedScope string
expectedRefreshable bool
expectedReference bool
}{
{
name: "default",
args: []string{"atc"},
shouldExpire: true,
expectedExpiry: -1,
expectedScope: userScope,
expectedRefreshable: false,
expectedReference: false,
},
{
name: "explicit user, no expiry",
args: []string{"atc", auth.ExtractUsernameFromAccessToken(*tests.JfrogAccessToken), "--expiry=0"},
shouldExpire: false,
expectedExpiry: 0,
expectedScope: userScope,
expectedRefreshable: false,
expectedReference: false,
},
{
name: "refreshable, admin",
args: []string{"atc", "--refreshable", "--grant-admin"},
shouldExpire: true,
expectedExpiry: -1,
expectedScope: "applied-permissions/admin",
expectedRefreshable: true,
expectedReference: false,
},
{
name: "reference, custom scope, custom expiry",
args: []string{"atc", "--reference", "--scope=system:metrics:r", "--expiry=123456"},
shouldExpire: true,
expectedExpiry: 123456,
expectedScope: "system:metrics:r",
expectedRefreshable: false,
expectedReference: true,
},
{
name: "groups, description",
args: []string{"atc", "--groups=group1,group2", "--description=description"},
shouldExpire: true,
expectedExpiry: -1,
expectedScope: "applied-permissions/groups:group1,group2",
expectedRefreshable: false,
expectedReference: false,
},
}

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
var token auth.CreateTokenResponseData
output := accessCli.RunCliCmdWithOutput(t, test.args...)
output := accessCli.RunCliCmdWithOutput(t, testCase.args...)
assert.NoError(t, json.Unmarshal([]byte(output), &token))
defer revokeToken(t, token.TokenId)

if test.shouldExpire {
if test.expectedExpiry == -1 {
if testCase.shouldExpire {
if testCase.expectedExpiry == -1 {
// If expectedExpiry is -1, expect the default expiry
assert.Positive(t, *token.ExpiresIn)
} else {
assert.EqualValues(t, test.expectedExpiry, *token.ExpiresIn)
assert.EqualValues(t, testCase.expectedExpiry, *token.ExpiresIn)
}
} else {
assert.Nil(t, token.ExpiresIn)
}
assert.NotEmpty(t, token.AccessToken)
assert.Equal(t, test.expectedScope, token.Scope)
assertNotEmptyIfExpected(t, test.expectedRefreshable, token.RefreshToken)
assertNotEmptyIfExpected(t, test.expectedReference, token.ReferenceToken)
assert.Equal(t, testCase.expectedScope, token.Scope)
assertNotEmptyIfExpected(t, testCase.expectedRefreshable, token.RefreshToken)
assertNotEmptyIfExpected(t, testCase.expectedReference, token.ReferenceToken)

// Try pinging Artifactory with the new token.
assert.NoError(t, coreTests.NewJfrogCli(execMain, "jfrog rt",
Expand Down
108 changes: 0 additions & 108 deletions artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3439,114 +3439,6 @@ func TestArtifactoryDownloadByBuildNoPatternUsingSimpleDownload(t *testing.T) {
cleanArtifactoryTest()
}

func TestArtifactoryDownloadByArchiveEntriesCli(t *testing.T) {
initArtifactoryTest(t, "")
uploadSpecFile, err := tests.CreateSpec(tests.ArchiveEntriesUpload)
assert.NoError(t, err)

// Upload archives
runRt(t, "upload", "--spec="+uploadSpecFile)

// Trigger archive indexing on the repo.
triggerArchiveIndexing(t)

// Create executor for running with retries
retryExecutor := createRetryExecutorForArchiveEntries(tests.GetBuildArchiveEntriesDownloadCli(),
[]string{"dl", tests.RtRepo1, "out/", "--archive-entries=(*)c1.in", "--flat=true"})

// Perform download by archive-entries only the archives containing c1.in, and validate results
assert.NoError(t, retryExecutor.Execute())

// Cleanup
cleanArtifactoryTest()
}

func triggerArchiveIndexing(t *testing.T) {
client, err := httpclient.ClientBuilder().Build()
assert.NoError(t, err)
resp, _, err := client.SendPost(serverDetails.ArtifactoryUrl+"api/archiveIndex/"+tests.RtRepo1, []byte{}, artHttpDetails, "")
if err != nil {
assert.NoError(t, err, "archive indexing failed")
return
}
assert.Equal(t, http.StatusAccepted, resp.StatusCode, "archive indexing failed")
// Indexing buffer
time.Sleep(3 * time.Second)
}

func TestArtifactoryDownloadByArchiveEntriesSpecificPathCli(t *testing.T) {
initArtifactoryTest(t, "")
uploadSpecFile, err := tests.CreateSpec(tests.ArchiveEntriesUpload)
assert.NoError(t, err)

// Upload archives
runRt(t, "upload", "--spec="+uploadSpecFile)

// Trigger archive indexing on the repo.
triggerArchiveIndexing(t)

// Create executor for running with retries
retryExecutor := createRetryExecutorForArchiveEntries(tests.GetBuildArchiveEntriesSpecificPathDownload(),
[]string{"dl", tests.RtRepo1, "out/", "--archive-entries=b/c/c1.in", "--flat=true"})

// Perform download by archive-entries only the archives containing c1.in, and validate results
assert.NoError(t, retryExecutor.Execute())

// Cleanup
cleanArtifactoryTest()
}

func TestArtifactoryDownloadByArchiveEntriesSpec(t *testing.T) {
initArtifactoryTest(t, "")
uploadSpecFile, err := tests.CreateSpec(tests.ArchiveEntriesUpload)
assert.NoError(t, err)
downloadSpecFile, err := tests.CreateSpec(tests.ArchiveEntriesDownload)
assert.NoError(t, err)

// Upload archives
runRt(t, "upload", "--spec="+uploadSpecFile)

// Trigger archive indexing on the repo.
triggerArchiveIndexing(t)

// Create executor for running with retries
retryExecutor := createRetryExecutorForArchiveEntries(tests.GetBuildArchiveEntriesDownloadSpec(),
[]string{"dl", "--spec=" + downloadSpecFile})

// Perform download by archive-entries only the archives containing d1.in, and validate results
assert.NoError(t, retryExecutor.Execute())

// Cleanup
cleanArtifactoryTest()
}

func createRetryExecutorForArchiveEntries(expected []string, args []string) *clientutils.RetryExecutor {
return &clientutils.RetryExecutor{
MaxRetries: 120,
// RetriesIntervalMilliSecs in milliseconds
RetriesIntervalMilliSecs: 1 * 1000,
ErrorMessage: "Waiting for Artifactory to index archives...",
ExecutionHandler: func() (bool, error) {
// Execute the requested cli command
err := artifactoryCli.Exec(args...)
if err != nil {
return true, err
}
err = validateDownloadByArchiveEntries(expected)
if err != nil {
return false, err
}
return false, nil
},
}
}

func validateDownloadByArchiveEntries(expected []string) error {
// Validate files are downloaded as expected
paths, _ := fileutils.ListFilesRecursiveWalkIntoDirSymlink(tests.Out, false)
return tests.ValidateListsIdentical(expected, paths)
}

func TestArtifactoryDownloadExcludeByCli(t *testing.T) {
initArtifactoryTest(t, "")

Expand Down
2 changes: 1 addition & 1 deletion utils/cliutils/commandsflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ var flagsMap = map[string]cli.Flag{
},
archiveEntries: cli.StringFlag{
Name: archiveEntries,
Usage: "[Optional] If specified, only archive artifacts containing entries matching this pattern are matched. You can use wildcards to specify multiple artifacts.` `",
Usage: "[Optional] If specified, only archive artifacts containing entries matching this pattern are matched. You can use wildcards to specify multiple artifacts. This option stopped being supported since version 7.90.5 for Artifactory.` `",
},
detailedSummary: cli.BoolFlag{
Name: detailedSummary,
Expand Down
Loading