From a664ea439478a734223b64000105654c657470d9 Mon Sep 17 00:00:00 2001 From: Omer Zidkoni <50792403+omerzi@users.noreply.github.com> Date: Wed, 5 Apr 2023 09:49:30 +0300 Subject: [PATCH 1/6] Promote version to 1.28.1 (#733) --- .github/workflows/analysis.yml | 4 +- .github/workflows/frogbot-fix.yml | 6 +- .github/workflows/frogbot-scan-pr.yml | 6 +- .github/workflows/tests.yml | 10 ++-- artifactory/services/createreplication.go | 5 +- artifactory/services/utils/aqlquerybuilder.go | 4 +- .../services/utils/aqlquerybuilder_test.go | 36 ++++++------ .../services/utils/artifactoryutils.go | 6 +- artifactory/services/utils/deleteutils.go | 2 +- .../services/utils/deleteutils_test.go | 34 +++++------ artifactory/services/utils/properties.go | 2 +- .../services/utils/releasebundleutils.go | 4 +- .../services/utils/repopathfile_test.go | 6 +- artifactory/services/utils/searchutil_test.go | 6 +- auth/cert/loader.go | 1 - .../services/utils/distributionutils_test.go | 2 +- go.mod | 6 +- go.sum | 11 +++- pipelines/services/run.go | 12 ++-- tests/artifactorypermissiontarget_test.go | 12 ++-- tests/artifactorysystem_test.go | 12 ++-- tests/utils_test.go | 2 +- tests/xrayscan_test.go | 2 +- tests/xraysummary_test.go | 4 +- utils/io/content/contentwriter.go | 2 +- utils/io/fileutils/files.go | 56 +++++++++++++------ utils/utils.go | 13 +++-- xray/services/scan.go | 20 +++++++ xray/services/scan_test.go | 31 ++++++++++ 29 files changed, 198 insertions(+), 119 deletions(-) diff --git a/.github/workflows/analysis.yml b/.github/workflows/analysis.yml index ec02d745f..d376be5c4 100644 --- a/.github/workflows/analysis.yml +++ b/.github/workflows/analysis.yml @@ -9,7 +9,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.19.x + go-version: 1.20.x - name: Static Code Analysis uses: dominikh/staticcheck-action@v1 with: @@ -23,7 +23,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.19.x + go-version: 1.20.x - name: Install gosec run: curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(go env GOPATH)/bin - name: Run gosec diff --git a/.github/workflows/frogbot-fix.yml b/.github/workflows/frogbot-fix.yml index 5782a988a..3a25fb26c 100644 --- a/.github/workflows/frogbot-fix.yml +++ b/.github/workflows/frogbot-fix.yml @@ -13,18 +13,18 @@ jobs: - name: Setup Go uses: actions/setup-go@v3 with: - go-version: 1.19.x + go-version: 1.20.x - uses: jfrog/frogbot@v2 env: # [Mandatory] # JFrog platform URL JF_URL: ${{ secrets.FROGBOT_URL }} - + # [Mandatory if JF_USER and JF_PASSWORD are not provided] # JFrog access token with 'read' permissions on Xray service JF_ACCESS_TOKEN: ${{ secrets.FROGBOT_ACCESS_TOKEN }} - + # [Mandatory] # The GitHub token automatically generated for the job JF_GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/frogbot-scan-pr.yml b/.github/workflows/frogbot-scan-pr.yml index b5f224aab..8b61e89d1 100644 --- a/.github/workflows/frogbot-scan-pr.yml +++ b/.github/workflows/frogbot-scan-pr.yml @@ -17,18 +17,18 @@ jobs: - name: Setup Go uses: actions/setup-go@v3 with: - go-version: 1.19.x + go-version: 1.20.x - uses: jfrog/frogbot@v2 env: # [Mandatory] # JFrog platform URL JF_URL: ${{ secrets.FROGBOT_URL }} - + # [Mandatory if JF_USER and JF_PASSWORD are not provided] # JFrog access token with 'read' permissions on Xray service JF_ACCESS_TOKEN: ${{ secrets.FROGBOT_ACCESS_TOKEN }} - + # [Mandatory] # The GitHub token automatically generated for the job JF_GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1fbbb98f5..88e0bb1f2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,7 +28,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.19.x + go-version: 1.20.x - name: Go Cache uses: actions/cache@v3 @@ -53,7 +53,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.19.x + go-version: 1.20.x - name: Checkout code uses: actions/checkout@v3 @@ -96,7 +96,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.19.x + go-version: 1.20.x - name: Go Cache uses: actions/cache@v3 @@ -121,7 +121,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.19.x + go-version: 1.20.x - name: Go Cache uses: actions/cache@v3 @@ -141,7 +141,7 @@ jobs: - name: Install Go uses: actions/setup-go@v3 with: - go-version: 1.19.x + go-version: 1.20.x - name: Checkout code uses: actions/checkout@v3 diff --git a/artifactory/services/createreplication.go b/artifactory/services/createreplication.go index ad91cb1f7..bec1b172b 100644 --- a/artifactory/services/createreplication.go +++ b/artifactory/services/createreplication.go @@ -32,8 +32,7 @@ func (rs *CreateReplicationService) performRequest(params *utils.UpdateReplicati httpClientsDetails := rs.ArtDetails.CreateHttpClientDetails() utils.SetContentType("application/vnd.org.jfrog.artifactory.replications.ReplicationConfigRequest+json", &httpClientsDetails.Headers) var url = rs.ArtDetails.GetUrl() + "api/replications/" + params.RepoKey - log.Info("Creating replication..") - operationString := "creating" + log.Info("Creating replication...") resp, body, err := rs.client.SendPut(url, content, &httpClientsDetails) if err != nil { return err @@ -42,7 +41,7 @@ func (rs *CreateReplicationService) performRequest(params *utils.UpdateReplicati return err } log.Debug("Artifactory response:", resp.Status) - log.Info("Done " + operationString + " repository.") + log.Info("Done creating replication.") return nil } diff --git a/artifactory/services/utils/aqlquerybuilder.go b/artifactory/services/utils/aqlquerybuilder.go index fb5ae0619..88e1c7a53 100644 --- a/artifactory/services/utils/aqlquerybuilder.go +++ b/artifactory/services/utils/aqlquerybuilder.go @@ -163,8 +163,8 @@ func CreateAqlQueryForLatestCreated(repo, path string) string { func prepareSearchPattern(pattern string, repositoryExists bool) string { addWildcardIfNeeded(&pattern, repositoryExists) // Remove parenthesis - pattern = strings.Replace(pattern, "(", "", -1) - pattern = strings.Replace(pattern, ")", "", -1) + pattern = strings.ReplaceAll(pattern, "(", "") + pattern = strings.ReplaceAll(pattern, ")", "") return pattern } diff --git a/artifactory/services/utils/aqlquerybuilder_test.go b/artifactory/services/utils/aqlquerybuilder_test.go index 916a8b2a6..62502ce52 100644 --- a/artifactory/services/utils/aqlquerybuilder_test.go +++ b/artifactory/services/utils/aqlquerybuilder_test.go @@ -47,26 +47,26 @@ func TestBuildAqlSearchQuery(t *testing.T) { func TestCommonParams(t *testing.T) { artifactoryParams := CommonParams{} - assertIsSortLimitSpecBool(!includePropertiesInAqlForSpec(&artifactoryParams), false, t) + assertIsSortLimitSpecBool(t, !includePropertiesInAqlForSpec(&artifactoryParams), false) artifactoryParams.SortBy = []string{"Vava", "Bubu"} - assertIsSortLimitSpecBool(!includePropertiesInAqlForSpec(&artifactoryParams), true, t) + assertIsSortLimitSpecBool(t, !includePropertiesInAqlForSpec(&artifactoryParams), true) artifactoryParams.SortBy = nil artifactoryParams.Limit = 0 - assertIsSortLimitSpecBool(!includePropertiesInAqlForSpec(&artifactoryParams), false, t) + assertIsSortLimitSpecBool(t, !includePropertiesInAqlForSpec(&artifactoryParams), false) artifactoryParams.Limit = -3 - assertIsSortLimitSpecBool(!includePropertiesInAqlForSpec(&artifactoryParams), false, t) + assertIsSortLimitSpecBool(t, !includePropertiesInAqlForSpec(&artifactoryParams), false) artifactoryParams.Limit = 3 - assertIsSortLimitSpecBool(!includePropertiesInAqlForSpec(&artifactoryParams), true, t) + assertIsSortLimitSpecBool(t, !includePropertiesInAqlForSpec(&artifactoryParams), true) artifactoryParams.SortBy = []string{"Vava", "Bubu"} - assertIsSortLimitSpecBool(!includePropertiesInAqlForSpec(&artifactoryParams), true, t) + assertIsSortLimitSpecBool(t, !includePropertiesInAqlForSpec(&artifactoryParams), true) } -func assertIsSortLimitSpecBool(actual, expected bool, t *testing.T) { +func assertIsSortLimitSpecBool(t *testing.T, actual, expected bool) { if actual != expected { t.Error("The function includePropertiesInAqlForSpec() expected to return " + strconv.FormatBool(expected) + " but returned " + strconv.FormatBool(actual) + ".") } @@ -76,20 +76,20 @@ func TestGetQueryReturnFields(t *testing.T) { artifactoryParams := CommonParams{} minimalFields := []string{"name", "repo", "path", "actual_md5", "actual_sha1", "sha256", "size", "type", "created", "modified"} - assertEqualFieldsList(getQueryReturnFields(&artifactoryParams, ALL), append(minimalFields, "property"), t) - assertEqualFieldsList(getQueryReturnFields(&artifactoryParams, SYMLINK), append(minimalFields, "property"), t) - assertEqualFieldsList(getQueryReturnFields(&artifactoryParams, NONE), minimalFields, t) + assertEqualFieldsList(t, getQueryReturnFields(&artifactoryParams, ALL), append(minimalFields, "property")) + assertEqualFieldsList(t, getQueryReturnFields(&artifactoryParams, SYMLINK), append(minimalFields, "property")) + assertEqualFieldsList(t, getQueryReturnFields(&artifactoryParams, NONE), minimalFields) artifactoryParams.SortBy = []string{"Vava"} - assertEqualFieldsList(getQueryReturnFields(&artifactoryParams, NONE), append(minimalFields, "Vava"), t) - assertEqualFieldsList(getQueryReturnFields(&artifactoryParams, ALL), append(minimalFields, "Vava"), t) - assertEqualFieldsList(getQueryReturnFields(&artifactoryParams, SYMLINK), append(minimalFields, "Vava"), t) + assertEqualFieldsList(t, getQueryReturnFields(&artifactoryParams, NONE), append(minimalFields, "Vava")) + assertEqualFieldsList(t, getQueryReturnFields(&artifactoryParams, ALL), append(minimalFields, "Vava")) + assertEqualFieldsList(t, getQueryReturnFields(&artifactoryParams, SYMLINK), append(minimalFields, "Vava")) artifactoryParams.SortBy = []string{"Vava", "Bubu"} - assertEqualFieldsList(getQueryReturnFields(&artifactoryParams, ALL), append(minimalFields, "Vava", "Bubu"), t) + assertEqualFieldsList(t, getQueryReturnFields(&artifactoryParams, ALL), append(minimalFields, "Vava", "Bubu")) } -func assertEqualFieldsList(actual, expected []string, t *testing.T) { +func assertEqualFieldsList(t *testing.T, actual, expected []string) { if len(actual) != len(expected) { t.Error("The function getQueryReturnFields() expected to return the array:\n" + strings.Join(expected[:], ",") + ".\nbut returned:\n" + strings.Join(actual[:], ",") + ".") } @@ -109,11 +109,11 @@ func assertEqualFieldsList(actual, expected []string, t *testing.T) { } func TestBuildSortBody(t *testing.T) { - assertSortBody(buildSortQueryPart([]string{"bubu"}, ""), `"$asc":["bubu"]`, t) - assertSortBody(buildSortQueryPart([]string{"bubu", "kuku"}, ""), `"$asc":["bubu","kuku"]`, t) + assertSortBody(t, buildSortQueryPart([]string{"bubu"}, ""), `"$asc":["bubu"]`) + assertSortBody(t, buildSortQueryPart([]string{"bubu", "kuku"}, ""), `"$asc":["bubu","kuku"]`) } -func assertSortBody(actual, expected string, t *testing.T) { +func assertSortBody(t *testing.T, actual, expected string) { if actual != expected { t.Error("The function buildSortQueryPart expected to return the string:\n'" + expected + "'.\nbut returned:\n'" + actual + "'.") } diff --git a/artifactory/services/utils/artifactoryutils.go b/artifactory/services/utils/artifactoryutils.go index a851f152c..6fa0c8b6f 100644 --- a/artifactory/services/utils/artifactoryutils.go +++ b/artifactory/services/utils/artifactoryutils.go @@ -107,7 +107,7 @@ func BuildArtifactoryUrl(baseUrl, path string, params map[string]string) (string parsedUrl.RawQuery = q.Encode() // Semicolons are reserved as separators in some Artifactory APIs, so they'd better be encoded when used for other purposes - encodedUrl := strings.Replace(parsedUrl.String(), ";", url.QueryEscape(";"), -1) + encodedUrl := strings.ReplaceAll(parsedUrl.String(), ";", url.QueryEscape(";")) return encodedUrl, nil } @@ -227,8 +227,8 @@ func ParseNameAndVersion(identifier string, useLatestPolicy bool) (string, strin } } // Remove escape chars. - name = strings.Replace(name, "\\/", "/", -1) - version = strings.Replace(version, "\\/", "/", -1) + name = strings.ReplaceAll(name, "\\/", "/") + version = strings.ReplaceAll(version, "\\/", "/") return name, version, nil } diff --git a/artifactory/services/utils/deleteutils.go b/artifactory/services/utils/deleteutils.go index 7d404e613..f19d6f537 100644 --- a/artifactory/services/utils/deleteutils.go +++ b/artifactory/services/utils/deleteutils.go @@ -15,7 +15,7 @@ func WildcardToDirsPath(deletePattern, searchResult string) (string, error) { return "", errors.New("delete pattern must end with \"/\"") } - regexpPattern := "^" + strings.Replace(deletePattern, "*", "([^/]*|.*)", -1) + regexpPattern := "^" + strings.ReplaceAll(deletePattern, "*", "([^/]*|.*)") r, err := regexp.Compile(regexpPattern) if err != nil { return "", errorutils.CheckError(err) diff --git a/artifactory/services/utils/deleteutils_test.go b/artifactory/services/utils/deleteutils_test.go index 65e5061f6..ce197ad15 100644 --- a/artifactory/services/utils/deleteutils_test.go +++ b/artifactory/services/utils/deleteutils_test.go @@ -14,44 +14,44 @@ import ( func TestMatchingDelete(t *testing.T) { var actual string actual, _ = WildcardToDirsPath("s/*/path/", "s/a/path/b.zip") - assertDeletePattern("s/a/path/", actual, t) + assertDeletePattern(t, "s/a/path/", actual) actual, _ = WildcardToDirsPath("s/*/path/", "s/a/b/c/path/b.zip") - assertDeletePattern("s/a/b/c/path/", actual, t) + assertDeletePattern(t, "s/a/b/c/path/", actual) actual, _ = WildcardToDirsPath("s/a/*/", "s/a/b/path/b.zip") - assertDeletePattern("s/a/b/", actual, t) + assertDeletePattern(t, "s/a/b/", actual) actual, _ = WildcardToDirsPath("s/*/path/*/", "s/a/path/a/b.zip") - assertDeletePattern("s/a/path/a/", actual, t) + assertDeletePattern(t, "s/a/path/a/", actual) actual, _ = WildcardToDirsPath("s/*/path/*/", "s/a/a/path/a/b/c/d/b.zip") - assertDeletePattern("s/a/a/path/a/", actual, t) + assertDeletePattern(t, "s/a/a/path/a/", actual) actual, _ = WildcardToDirsPath("s/*/", "s/a/a/path/a/b/c/d/b.zip") - assertDeletePattern("s/a/", actual, t) + assertDeletePattern(t, "s/a/", actual) actual, _ = WildcardToDirsPath("s/*/a/*/", "s/a/a/path/k/b/c/d/b.zip") - assertDeletePattern("s/a/a/path/", actual, t) + assertDeletePattern(t, "s/a/a/path/", actual) actual, _ = WildcardToDirsPath("s/*/a/*/*/", "s/a/a/path/k/b/c/d/b.zip") - assertDeletePattern("s/a/a/path/k/", actual, t) + assertDeletePattern(t, "s/a/a/path/k/", actual) actual, _ = WildcardToDirsPath("s/*/*l*/*/*/", "s/a/l/path/k/b/c/d/b.zip") - assertDeletePattern("s/a/l/path/k/", actual, t) + assertDeletePattern(t, "s/a/l/path/k/", actual) actual, _ = WildcardToDirsPath("s/*/a*/", "s/a/a/path/k/b/c/d/b.zip") - assertDeletePattern("s/a/a/", actual, t) + assertDeletePattern(t, "s/a/a/", actual) actual, _ = WildcardToDirsPath("s/a*/", "s/a/a/path/k/b/c/d/b.zip") - assertDeletePattern("s/a/", actual, t) + assertDeletePattern(t, "s/a/", actual) actual, _ = WildcardToDirsPath("s/*/", "s/a/a/path/k/b/c/d/b.zip") - assertDeletePattern("s/a/", actual, t) + assertDeletePattern(t, "s/a/", actual) actual, _ = WildcardToDirsPath("s/*/*path*/", "s/a/h/path/k/b/c/d/b.zip") - assertDeletePattern("s/a/h/path/", actual, t) + assertDeletePattern(t, "s/a/h/path/", actual) actual, _ = WildcardToDirsPath("a/b/*********/*******/", "a/b/c/d/e.zip") - assertDeletePattern("a/b/c/d/", actual, t) + assertDeletePattern(t, "a/b/c/d/", actual) _, err := WildcardToDirsPath("s/*/a/*/*", "s/a/a/path/k/b/c/d/b.zip") - assertDeletePatternErr("delete pattern must end with \"/\"", err.Error(), t) + assertDeletePatternErr(t, "delete pattern must end with \"/\"", err.Error()) } -func assertDeletePattern(expected, actual string, t *testing.T) { +func assertDeletePattern(t *testing.T, expected, actual string) { if expected != actual { t.Error("Wrong matching expected: `" + expected + "` Got `" + actual + "`") } } -func assertDeletePatternErr(expected, actual string, t *testing.T) { +func assertDeletePatternErr(t *testing.T, expected, actual string) { if expected != actual { t.Error("Wrong err message expected: `" + expected + "` Got `" + actual + "`") } diff --git a/artifactory/services/utils/properties.go b/artifactory/services/utils/properties.go index bfc682b33..f91724916 100644 --- a/artifactory/services/utils/properties.go +++ b/artifactory/services/utils/properties.go @@ -121,7 +121,7 @@ func (props *Properties) ToEncodedString(concatValues bool) string { } for _, value := range values { if concatValues { - propValue := strings.Replace(value, multiValuesSeparator, fmt.Sprintf("\\%s", multiValuesSeparator), -1) + propValue := strings.ReplaceAll(value, multiValuesSeparator, fmt.Sprintf("\\%s", multiValuesSeparator)) jointProp = fmt.Sprintf("%s%s%s", jointProp, url.QueryEscape(propValue), url.QueryEscape(multiValuesSeparator)) } else { jointProp = fmt.Sprintf("%s%s=%s%s", jointProp, url.QueryEscape(key), url.QueryEscape(value), propsSeparator) diff --git a/artifactory/services/utils/releasebundleutils.go b/artifactory/services/utils/releasebundleutils.go index 72ce49f04..7097876f3 100644 --- a/artifactory/services/utils/releasebundleutils.go +++ b/artifactory/services/utils/releasebundleutils.go @@ -2,11 +2,11 @@ package utils import ( "fmt" - jwt "github.com/golang-jwt/jwt/v4" + "github.com/ProtonMail/go-crypto/openpgp" + "github.com/golang-jwt/jwt/v4" "github.com/jfrog/jfrog-client-go/auth" "github.com/jfrog/jfrog-client-go/http/jfroghttpclient" "github.com/jfrog/jfrog-client-go/utils/errorutils" - "golang.org/x/crypto/openpgp" "os" "path/filepath" "strings" diff --git a/artifactory/services/utils/repopathfile_test.go b/artifactory/services/utils/repopathfile_test.go index 51ca4699d..de9d30719 100644 --- a/artifactory/services/utils/repopathfile_test.go +++ b/artifactory/services/utils/repopathfile_test.go @@ -90,7 +90,7 @@ var repoPathFilesDataProvider = []createRepoPathFileTriplesTest{ func TestCreatePathFilePairs(t *testing.T) { for _, sample := range pathFilesDataProvider { t.Run(sample.pattern+"_recursive_"+strconv.FormatBool(sample.recursive), func(t *testing.T) { - validateRepoPathFile(createPathFilePairs("r", sample.pattern, sample.recursive), sample.expectedTriples, sample.pattern, t) + validateRepoPathFile(t, createPathFilePairs("r", sample.pattern, sample.recursive), sample.expectedTriples, sample.pattern) }) } } @@ -101,12 +101,12 @@ func TestCreateRepoPathFileTriples(t *testing.T) { repoPathFileTriples, singleRepo, err := createRepoPathFileTriples(sample.pattern, sample.recursive) assert.NoError(t, err) assert.Equal(t, sample.expectedSingleRepo, singleRepo) - validateRepoPathFile(repoPathFileTriples, sample.expectedTriples, sample.pattern, t) + validateRepoPathFile(t, repoPathFileTriples, sample.expectedTriples, sample.pattern) }) } } -func validateRepoPathFile(actual, expected []RepoPathFile, pattern string, t *testing.T) { +func validateRepoPathFile(t *testing.T, actual, expected []RepoPathFile, pattern string) { if len(actual) != len(expected) { t.Errorf("Wrong triple.\nPattern: %v\nExpected: %v\nActual: %v", pattern, expected, actual) } diff --git a/artifactory/services/utils/searchutil_test.go b/artifactory/services/utils/searchutil_test.go index 987309b48..637a6b310 100644 --- a/artifactory/services/utils/searchutil_test.go +++ b/artifactory/services/utils/searchutil_test.go @@ -68,7 +68,7 @@ func TestReduceTopChainDirResult(t *testing.T) { oldMaxSize := utils.MaxBufferSize defer func() { utils.MaxBufferSize = oldMaxSize }() - //Test buffer + sort + // Test buffer + sort utils.MaxBufferSize = 3 reader = content.NewContentReader(filepath.Join(testDataPath, "reduce_top_chain_step4.json"), content.DefaultKey) resultReader, err = ReduceTopChainDirResult(ResultItem{}, reader) @@ -79,7 +79,7 @@ func TestReduceTopChainDirResult(t *testing.T) { assert.True(t, isMatch) readerCloseAndAssert(t, resultReader) - //Two files in the same folder and one is a prefix to another. + // Two files in the same folder and one is a prefix to another. reader = content.NewContentReader(filepath.Join(testDataPath, "reduce_top_chain_step5.json"), content.DefaultKey) resultReader, err = ReduceTopChainDirResult(ResultItem{}, reader) assert.NoError(t, err) @@ -89,7 +89,7 @@ func TestReduceTopChainDirResult(t *testing.T) { assert.True(t, isMatch) readerCloseAndAssert(t, resultReader) - //Two files in the same folder and one is a prefix to another and their folder. + // Two files in the same folder and one is a prefix to another and their folder. reader = content.NewContentReader(filepath.Join(testDataPath, "reduce_top_chain_step6.json"), content.DefaultKey) resultReader, err = ReduceTopChainDirResult(ResultItem{}, reader) assert.NoError(t, err) diff --git a/auth/cert/loader.go b/auth/cert/loader.go index c12eebdad..b8afcd915 100644 --- a/auth/cert/loader.go +++ b/auth/cert/loader.go @@ -60,7 +60,6 @@ func GetTransportWithLoadedCert(certificatesDirPath string, insecureTls bool, tr ClientSessionCache: tls.NewLRUClientSessionCache(1), InsecureSkipVerify: insecureTls, } - transport.TLSClientConfig.BuildNameToCertificate() return transport, nil } diff --git a/distribution/services/utils/distributionutils_test.go b/distribution/services/utils/distributionutils_test.go index ae4adab3f..c99d1ae2c 100644 --- a/distribution/services/utils/distributionutils_test.go +++ b/distribution/services/utils/distributionutils_test.go @@ -24,7 +24,7 @@ func TestCreateBundleBody(t *testing.T) { assert.Equal(t, "storing-repo", releaseBundleBody.StoringRepository) assert.Equal(t, "Release bundle description", releaseBundleBody.Description) assert.Equal(t, "Release notes", releaseBundleBody.ReleaseNotes.Content) - assert.Equal(t, ReleaseNotesSyntax(Asciidoc), releaseBundleBody.ReleaseNotes.Syntax) + assert.Equal(t, Asciidoc, releaseBundleBody.ReleaseNotes.Syntax) assert.Len(t, releaseBundleBody.BundleSpec.Queries, 0) } diff --git a/go.mod b/go.mod index c6c0ad6dc..63aa633af 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,9 @@ module github.com/jfrog/jfrog-client-go -go 1.19 +go 1.20 require ( + github.com/ProtonMail/go-crypto v0.0.0-20230331115716-d34776aa93ec github.com/buger/jsonparser v1.1.1 github.com/forPelevin/gomoji v1.1.8 github.com/go-git/go-git/v5 v5.6.1 @@ -21,7 +22,6 @@ require ( require ( github.com/CycloneDX/cyclonedx-go v0.7.0 // indirect github.com/Microsoft/go-winio v0.5.2 // indirect - github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect github.com/acomagu/bufpipe v1.0.4 // indirect github.com/andybalholm/brotli v1.0.1 // indirect github.com/cloudflare/circl v1.1.0 // indirect @@ -55,6 +55,6 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -// replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230330091550-a452f54ba1cc +replace github.com/jfrog/build-info-go => github.com/jfrog/build-info-go v1.8.9-0.20230403064815-ea83b399ac8e // replace github.com/jfrog/gofrog => github.com/jfrog/gofrog v1.2.5-0.20221107113836-a4c9225c690e diff --git a/go.sum b/go.sum index 82a562a02..05c435ea6 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,9 @@ github.com/CycloneDX/cyclonedx-go v0.7.0 h1:jNxp8hL7UpcvPDFXjY+Y1ibFtsW+e5zyF9Qo github.com/CycloneDX/cyclonedx-go v0.7.0/go.mod h1:W5Z9w8pTTL+t+yG3PCiFRGlr8PUlE0pGWzKSJbsyXkg= github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= -github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA= github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g= +github.com/ProtonMail/go-crypto v0.0.0-20230331115716-d34776aa93ec h1:eQusauqzE1cAFR5hGnwkuSmFxKoy3+j9/cVaDeYfjjs= +github.com/ProtonMail/go-crypto v0.0.0-20230331115716-d34776aa93ec/go.mod h1:8TI4H3IbrackdNgv+92dI+rhpCaLqM0IfpgCgenFvRE= github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ= github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc= @@ -54,8 +55,8 @@ github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= -github.com/jfrog/build-info-go v1.9.0 h1:gLxBfp4C6pVz+bKTmsqwFGZAueVMuzGw+/M9HZgtGG4= -github.com/jfrog/build-info-go v1.9.0/go.mod h1:dQ8OKddrbgtO3jK9uLYoqmRGNEjuDuNXV0bSRdpeTCI= +github.com/jfrog/build-info-go v1.8.9-0.20230403064815-ea83b399ac8e h1:MB5u0Kbq9IIDIlnpDYUq+SHTZ+/ossTOCK7z/t8S0l8= +github.com/jfrog/build-info-go v1.8.9-0.20230403064815-ea83b399ac8e/go.mod h1:HIrpwf4p4XHpAx+N+rb8SX9yrWYWs7X4rT/s0GOJfW8= github.com/jfrog/gofrog v1.2.5 h1:jCgJC0iGQ8bU7jCC+YEFJTNINyngApIrhd8BjZAVRIE= github.com/jfrog/gofrog v1.2.5/go.mod h1:o00tSRff6IapTgaCMuX1Cs9MH08Y1JqnsKgRtx91Gc4= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= @@ -135,6 +136,7 @@ golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAb golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.6.0/go.mod h1:4mET923SAdbXp2ki8ey+zGs1SLqsuM2Y0uvdZR/fUNI= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -147,6 +149,7 @@ golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -180,10 +183,12 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= +golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.2.0/go.mod h1:y4OqIKeOV/fWJetJ8bXPU1sEVniLMIyDAZWeHdV+NTA= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/pipelines/services/run.go b/pipelines/services/run.go index 8eae4c2d7..fe766a844 100644 --- a/pipelines/services/run.go +++ b/pipelines/services/run.go @@ -25,13 +25,11 @@ func NewRunService(client *jfroghttpclient.JfrogHttpClient) *RunService { } const ( - runStatus = "api/v1/search/pipelines/" - triggerpipeline = "api/v1/pipelines/trigger" - pipelineSyncStatus = "api/v1/pipelineSyncStatuses" - pipelineResources = "api/v1/pipelineSources" - cancelRunPath = "api/v1/runs/:runId/cancel" - syncPipelineResource = "api/v1/pipelineSources" - resourceVersions = "api/v1/resourceVersions" + runStatus = "api/v1/search/pipelines/" + triggerpipeline = "api/v1/pipelines/trigger" + pipelineSyncStatus = "api/v1/pipelineSyncStatuses" + pipelineResources = "api/v1/pipelineSources" + cancelRunPath = "api/v1/runs/:runId/cancel" ) func (rs *RunService) GetRunStatus(branch, pipeName string, isMultiBranch bool) (*PipelineRunStatusResponse, error) { diff --git a/tests/artifactorypermissiontarget_test.go b/tests/artifactorypermissiontarget_test.go index 7ad1246d4..74ea398e9 100644 --- a/tests/artifactorypermissiontarget_test.go +++ b/tests/artifactorypermissiontarget_test.go @@ -159,7 +159,7 @@ func TestDocumentationExampleCreateUpdateAndDeletePermissionTarget(t *testing.T) } func createRandomUser(t *testing.T) string { - name := fmt.Sprintf("test-%s-%s", timestampStr, randomString(16)) + name := fmt.Sprintf("test-%s-%s", timestampStr, randomString(t, 16)) userDetails := services.User{ Name: name, Email: name + "@jfrog.com", @@ -186,20 +186,19 @@ func createRandomUser(t *testing.T) string { } func createRandomRepo(t *testing.T) string { - repoKey := fmt.Sprintf("test-%s-%s", timestampStr, randomString(16)) + repoKey := fmt.Sprintf("test-%s-%s", timestampStr, randomString(t, 16)) glp := services.NewGenericLocalRepositoryParams() glp.Key = repoKey setLocalRepositoryBaseParams(&glp.LocalRepositoryBaseParams, false) err := testsCreateLocalRepositoryService.Generic(glp) - assert.NoError(t, err) return repoKey } func createRandomGroup(t *testing.T) string { - name := fmt.Sprintf("test-%s-%s", timestampStr, randomString(16)) + name := fmt.Sprintf("test-%s-%s", timestampStr, randomString(t, 16)) groupDetails := services.Group{ Name: name, @@ -221,8 +220,9 @@ func createRandomGroup(t *testing.T) string { return name } -func randomString(length int) string { +func randomString(t *testing.T, length int) string { b := make([]byte, length) - rand.Read(b) + _, err := rand.Read(b) + assert.NoError(t, err) return fmt.Sprintf("%x", b)[:length] } diff --git a/tests/artifactorysystem_test.go b/tests/artifactorysystem_test.go index 2cc2fdece..c31b20303 100644 --- a/tests/artifactorysystem_test.go +++ b/tests/artifactorysystem_test.go @@ -50,7 +50,8 @@ func testGetConfigDescriptor(t *testing.T) { // Send response 200 OK w.WriteHeader(http.StatusOK) - w.Write([]byte("")) + _, err := w.Write([]byte("")) + assert.NoError(t, err) }) ts := httptest.NewServer(handler) defer ts.Close() @@ -71,7 +72,8 @@ func testActivateKeyEncryption(t *testing.T) { // Send response 200 OK w.WriteHeader(http.StatusOK) - w.Write([]byte("Done")) + _, err := w.Write([]byte("Done")) + assert.NoError(t, err) }) ts := httptest.NewServer(handler) defer ts.Close() @@ -90,7 +92,8 @@ func testDeactivateKeyEncryption(t *testing.T) { // Send response 200 OK w.WriteHeader(http.StatusOK) - w.Write([]byte("Done")) + _, err := w.Write([]byte("Done")) + assert.NoError(t, err) }) ts := httptest.NewServer(handler) defer ts.Close() @@ -111,7 +114,8 @@ func testDeactivateKeyEncryptionNotEncrypted(t *testing.T) { // Send response 200 OK w.WriteHeader(http.StatusConflict) - w.Write([]byte("Cannot decrypt without artifactory key file")) + _, err := w.Write([]byte("Cannot decrypt without artifactory key file")) + assert.NoError(t, err) }) ts := httptest.NewServer(handler) defer ts.Close() diff --git a/tests/utils_test.go b/tests/utils_test.go index 837dd5649..9c6d006bb 100644 --- a/tests/utils_test.go +++ b/tests/utils_test.go @@ -678,7 +678,7 @@ func teardownIntegrationTests() { repo := getRtTargetRepoKey() err := testsDeleteRepositoryService.Delete(repo) if err != nil { - fmt.Printf("teardownIntegrationTests failed for:" + err.Error()) + fmt.Print("teardownIntegrationTests failed for:" + err.Error()) os.Exit(1) } } diff --git a/tests/xrayscan_test.go b/tests/xrayscan_test.go index e14131e67..687f75057 100644 --- a/tests/xrayscan_test.go +++ b/tests/xrayscan_test.go @@ -55,7 +55,7 @@ func scanBuild(t *testing.T, buildName, buildNumber, expected string) { t.Error(err) } - expected = strings.Replace(expected, "\n", "", -1) + expected = strings.ReplaceAll(expected, "\n", "") if string(result) != expected { t.Error("Expected:", string(result), "Got: ", expected) } diff --git a/tests/xraysummary_test.go b/tests/xraysummary_test.go index 72b96a3c2..f5d7ea4f3 100644 --- a/tests/xraysummary_test.go +++ b/tests/xraysummary_test.go @@ -3,6 +3,7 @@ package tests import ( "bytes" "encoding/json" + "github.com/stretchr/testify/assert" "strconv" "strings" "testing" @@ -63,7 +64,8 @@ func artifactSummary(t *testing.T, checksums []string, paths []string, expected } buf := bytes.NewBuffer([]byte{}) - json.Compact(buf, []byte(expected)) + err = json.Compact(buf, []byte(expected)) + assert.NoError(t, err) expected = buf.String() expected = strings.ReplaceAll(expected, "\n", "") diff --git a/utils/io/content/contentwriter.go b/utils/io/content/contentwriter.go index 3eaaaea62..4918dc8c7 100644 --- a/utils/io/content/contentwriter.go +++ b/utils/io/content/contentwriter.go @@ -149,7 +149,7 @@ func (rw *ContentWriter) run() { firstRecord = false } } - closeString = closeString + jsonArraySuffix + closeString += jsonArraySuffix if rw.isCompleteFile { closeString += "}\n" } diff --git a/utils/io/fileutils/files.go b/utils/io/fileutils/files.go index 2e8e3d105..b85be9b0f 100644 --- a/utils/io/fileutils/files.go +++ b/utils/io/fileutils/files.go @@ -77,13 +77,13 @@ func GetFileInfo(path string, preserveSymLink bool) (fileInfo os.FileInfo, err e fileInfo, err = os.Stat(path) } // We should not do CheckError here, because the error is checked by the calling functions. - return fileInfo, err + return } func IsDirEmpty(path string) (isEmpty bool, err error) { dir, err := os.Open(path) - if err != nil { - return false, errorutils.CheckError(err) + if errorutils.CheckError(err) != nil { + return } defer func() { e := dir.Close() @@ -94,9 +94,12 @@ func IsDirEmpty(path string) (isEmpty bool, err error) { _, err = dir.Readdirnames(1) if err == io.EOF { - return true, nil + isEmpty = true + err = nil + return } - return false, errorutils.CheckError(err) + err = errorutils.CheckError(err) + return } func IsPathSymlink(path string) bool { @@ -282,16 +285,17 @@ func CreateDirIfNotExist(path string) error { // Reads the content of the file in the source path and appends it to // the file in the destination path. -func AppendFile(srcPath string, destFile *os.File) error { +func AppendFile(srcPath string, destFile *os.File) (err error) { srcFile, err := os.Open(srcPath) - err = errorutils.CheckError(err) - if err != nil { - return err + if errorutils.CheckError(err) != nil { + return } - defer func() error { - err := srcFile.Close() - return errorutils.CheckError(err) + defer func() { + e := srcFile.Close() + if err == nil { + err = e + } }() reader := bufio.NewReader(srcFile) @@ -299,7 +303,8 @@ func AppendFile(srcPath string, destFile *os.File) error { writer := bufio.NewWriter(destFile) buf := make([]byte, 1024000) for { - n, err := reader.Read(buf) + var n int + n, err = reader.Read(buf) if err != io.EOF { err = errorutils.CheckError(err) if err != nil { @@ -397,10 +402,20 @@ func GetFileDetailsFromReader(reader io.Reader, includeChecksums bool) (*FileDet details := new(FileDetails) pr, pw := io.Pipe() - defer pr.Close() + defer func() { + e := pr.Close() + if err == nil { + err = errorutils.CheckError(e) + } + }() go func() { - defer pw.Close() + defer func() { + e := pw.Close() + if err == nil { + err = errorutils.CheckError(e) + } + }() details.Size, err = io.Copy(pw, reader) }() @@ -529,8 +544,13 @@ func FindUpstream(itemToFInd string, itemType ItemType) (wd string, exists bool, if err != nil { return } - defer os.Chdir(wd) - + origWd := wd + defer func() { + e := os.Chdir(origWd) + if err == nil { + err = e + } + }() // Get the OS root. osRoot := os.Getenv("SYSTEMDRIVE") if osRoot != "" { @@ -567,7 +587,7 @@ func FindUpstream(itemToFInd string, itemType ItemType) (wd string, exists bool, visitedPaths[wd] = true // CD to the parent directory. wd = filepath.Dir(wd) - err := os.Chdir(wd) + err = os.Chdir(wd) if err != nil { return "", false, err } diff --git a/utils/utils.go b/utils/utils.go index f69e5a71c..b84e6dc40 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -26,7 +26,7 @@ import ( const ( Development = "development" Agent = "jfrog-client-go" - Version = "1.28.0" + Version = "1.28.1" ) // In order to limit the number of items loaded from a reader into the memory, we use a buffers with this size limit. @@ -205,6 +205,7 @@ func cleanPath(path string) string { if io.IsWindows() { // Since filepath.Clean replaces \\ with \, we revert this action. path = strings.ReplaceAll(path, `\`, `\\`) + path = strings.ReplaceAll(path, `\\\\`, `\\`) } return path } @@ -316,10 +317,10 @@ func GetLogMsgPrefix(threadId int, dryRun bool) string { } func TrimPath(path string) string { - path = strings.Replace(path, "\\", "/", -1) - path = strings.Replace(path, "//", "/", -1) - path = strings.Replace(path, "../", "", -1) - path = strings.Replace(path, "./", "", -1) + path = strings.ReplaceAll(path, "\\", "/") + path = strings.ReplaceAll(path, "//", "/") + path = strings.ReplaceAll(path, "../", "") + path = strings.ReplaceAll(path, "./", "") return path } @@ -343,7 +344,7 @@ func GetUserHomeDir() string { if home == "" { home = os.Getenv("USERPROFILE") } - return strings.Replace(home, "\\", "\\\\", -1) + return strings.ReplaceAll(home, "\\", "\\\\") } return os.Getenv("HOME") } diff --git a/xray/services/scan.go b/xray/services/scan.go index 60cb495c5..91f77bb22 100644 --- a/xray/services/scan.go +++ b/xray/services/scan.go @@ -3,6 +3,7 @@ package services import ( "encoding/json" "github.com/jfrog/jfrog-client-go/utils/log" + "golang.org/x/exp/maps" "net/http" "strings" "time" @@ -189,6 +190,25 @@ type GraphNode struct { Parent *GraphNode `json:"-"` } +// FlattenGraph creates a map of dependencies from the given graph, and returns a flat graph of dependencies with one level. +func FlattenGraph(graph []*GraphNode) []*GraphNode { + allDependencies := map[string]*GraphNode{} + for _, node := range graph { + populateUniqueDependencies(node, allDependencies) + } + return []*GraphNode{{Id: "root", Nodes: maps.Values(allDependencies)}} +} + +func populateUniqueDependencies(node *GraphNode, allDependencies map[string]*GraphNode) { + if _, exist := allDependencies[node.Id]; exist { + return + } + allDependencies[node.Id] = &GraphNode{Id: node.Id} + for _, dependency := range node.Nodes { + populateUniqueDependencies(dependency, allDependencies) + } +} + type OtherComponentIds struct { Id string `json:"component_id,omitempty"` Origin int `json:"origin,omitempty"` diff --git a/xray/services/scan_test.go b/xray/services/scan_test.go index 1eafe2a21..9f793460b 100644 --- a/xray/services/scan_test.go +++ b/xray/services/scan_test.go @@ -2,6 +2,8 @@ package services import ( "fmt" + "github.com/jfrog/gofrog/datastructures" + "github.com/stretchr/testify/assert" "testing" ) @@ -47,3 +49,32 @@ func TestCreateScanGraphQueryParams(t *testing.T) { }) } } + +func TestFlattenGraph(t *testing.T) { + nodeA := &GraphNode{Id: "A"} + nodeB := &GraphNode{Id: "B"} + nodeC := &GraphNode{Id: "C"} + nodeD := &GraphNode{Id: "D"} + nodeE := &GraphNode{Id: "E"} + nodeF := &GraphNode{Id: "F"} + + // Set dependencies + nodeA.Nodes = []*GraphNode{nodeB, nodeC} + nodeB.Nodes = []*GraphNode{nodeC, nodeD} + nodeC.Nodes = []*GraphNode{nodeD} + nodeD.Nodes = []*GraphNode{nodeE, nodeF} + nodeF.Nodes = []*GraphNode{nodeA, nodeB, nodeC} + + // Create graph + graph := []*GraphNode{nodeA, nodeB, nodeC} + flatGraph := FlattenGraph(graph) + + // Check that the graph has been flattened correctly + assert.Equal(t, len(flatGraph[0].Nodes), 6) + set := datastructures.MakeSet[string]() + for _, node := range flatGraph[0].Nodes { + assert.Len(t, node.Nodes, 0) + assert.False(t, set.Exists(node.Id)) + set.Add(node.Id) + } +} From 0b22cb3773a5db8107db220b02d1e6301b8c7eda Mon Sep 17 00:00:00 2001 From: Eyal Ben Moshe Date: Thu, 13 Apr 2023 12:48:44 +0300 Subject: [PATCH 2/6] Added the Frogbot badge to the README (#740) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 70f93b276..d07831f42 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ # JFrog Go Client +[![Scanned by Frogbot](https://raw.github.com/jfrog/frogbot/master/images/frogbot-badge.svg)](https://github.com/jfrog/frogbot#readme) + | Branch | Status | From b71c2803fbdf80504f4b4bce0450cb13477db1ea Mon Sep 17 00:00:00 2001 From: yahavi Date: Tue, 23 May 2023 18:44:41 +0300 Subject: [PATCH 3/6] Promoted version to 1.29.1 --- utils/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index 7e8932389..1e09afead 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -26,7 +26,7 @@ import ( const ( Development = "development" Agent = "jfrog-client-go" - Version = "1.29.0" + Version = "1.29.1" ) // In order to limit the number of items loaded from a reader into the memory, we use a buffers with this size limit. From f75002534808ee349c90adefcee62b267ee54f9b Mon Sep 17 00:00:00 2001 From: Omer Zidkoni Date: Wed, 12 Jul 2023 14:18:28 +0300 Subject: [PATCH 4/6] Promoted version to 1.31.1 --- utils/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index d30dfd5ce..7328edef6 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -26,7 +26,7 @@ import ( const ( Development = "development" Agent = "jfrog-client-go" - Version = "1.31.0" + Version = "1.31.1" ) // In order to limit the number of items loaded from a reader into the memory, we use a buffers with this size limit. From b1ae83639655298e5dd149a0b3d3f7e4c0a3511e Mon Sep 17 00:00:00 2001 From: eyalbe4 Date: Mon, 31 Jul 2023 21:00:52 +0300 Subject: [PATCH 5/6] Promoted version to 1.31.3 --- utils/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index 9c1d7246f..654bf095f 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -26,7 +26,7 @@ import ( const ( Development = "development" Agent = "jfrog-client-go" - Version = "1.31.2" + Version = "1.31.3" ) // In order to limit the number of items loaded from a reader into the memory, we use a buffers with this size limit. From 3edc13fe31ecd4c9bc7cfc942c2a5e4c0b09de24 Mon Sep 17 00:00:00 2001 From: eyalbe4 Date: Mon, 18 Dec 2023 17:12:50 +0200 Subject: [PATCH 6/6] Promote to v1.35.2 --- utils/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index d464a0bd9..a0ecd4fa7 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -27,7 +27,7 @@ import ( const ( Development = "development" Agent = "jfrog-client-go" - Version = "1.35.1" + Version = "1.35.2" ) type MinVersionProduct string