Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrog-ecosystem committed Oct 23, 2024
2 parents 53b9d04 + c363f1c commit e420c36
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 1,719 deletions.
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
1 change: 0 additions & 1 deletion .github/workflows/cla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
types: [ created ]
pull_request_target:
types: [ opened, synchronize ]

jobs:
CLAssistant:
runs-on: ubuntu-latest
Expand Down
5 changes: 3 additions & 2 deletions .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 All @@ -55,8 +55,9 @@ jobs:
- name: Install local Artifactory
uses: jfrog/.github/actions/install-local-artifactory@main
with:
RTLIC: ${{ secrets.RTLIC }}
RTLIC: ${{ secrets.RTLIC_V6 }}
JFROG_HOME: ${{ runner.temp }}
VERSION: 6.23.21

- 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-6
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 build/npm/v2-jf/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/npm/v2-jf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jfrog-cli-v2-jf",
"version": "2.71.0",
"version": "2.71.1",
"description": "🐸 Command-line interface for JFrog Artifactory, Xray, Distribution, Pipelines and Mission Control 🐸",
"homepage": "https://github.com/jfrog/jfrog-cli",
"preferGlobal": true,
Expand Down
2 changes: 1 addition & 1 deletion build/npm/v2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build/npm/v2/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jfrog-cli-v2",
"version": "2.71.0",
"version": "2.71.1",
"description": "🐸 Command-line interface for JFrog Artifactory, Xray, Distribution, Pipelines and Mission Control 🐸",
"homepage": "https://github.com/jfrog/jfrog-cli",
"preferGlobal": true,
Expand Down
Loading

0 comments on commit e420c36

Please sign in to comment.