Skip to content

Commit 4c0adc9

Browse files
committed
added get version for docker
1 parent ecd4a99 commit 4c0adc9

File tree

1 file changed

+2
-76
lines changed

1 file changed

+2
-76
lines changed

commands/curation/curationaudit_test.go

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ import (
1616
"sync"
1717
"testing"
1818

19-
"github.com/jfrog/jfrog-cli-security/sca/bom/buildinfo/technologies/docker"
2019
"github.com/jfrog/jfrog-cli-security/sca/bom/buildinfo/technologies/java"
2120
"github.com/jfrog/jfrog-cli-security/utils/formats"
2221

2322
biutils "github.com/jfrog/build-info-go/utils"
2423
"github.com/jfrog/gofrog/datastructures"
25-
rtUtils "github.com/jfrog/jfrog-cli-core/v2/artifactory/utils"
2624
coreCommonTests "github.com/jfrog/jfrog-cli-core/v2/common/tests"
2725
"github.com/jfrog/jfrog-cli-core/v2/utils/config"
2826
"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
@@ -429,7 +427,7 @@ func TestDoCurationAudit(t *testing.T) {
429427
cleanUp := createCurationTestEnv(t, basePathToTests, tt, config)
430428
defer cleanUp()
431429
// Create audit command, and run it
432-
results, err := createCurationCmdAndRun(tt, config)
430+
results, err := createCurationCmdAndRun(tt)
433431
// Validate the results
434432
if tt.requestToError == nil {
435433
assert.NoError(t, err)
@@ -507,52 +505,19 @@ func runPreTestExec(t *testing.T, basePathToTests string, testCase testCase) {
507505
callbackPreTest()
508506
}
509507

510-
func createCurationCmdAndRun(tt testCase, serverDetails *config.ServerDetails) (cmdResults map[string]*CurationReport, err error) {
511-
// For Docker, building dep tree manually (since its not possible to do docker pull )
512-
if tt.tech == techutils.Docker {
513-
return runDockerCurationTest(tt, serverDetails)
514-
}
508+
func createCurationCmdAndRun(tt testCase) (cmdResults map[string]*CurationReport, err error) {
515509
curationCmd := NewCurationAuditCommand()
516510
curationCmd.SetIsCurationCmd(true)
517511
curationCmd.parallelRequests = 3
518512
// For tests, we use localhost http server (nuget have issues without setting insecureTls)
519513
curationCmd.SetInsecureTls(true)
520514
curationCmd.SetIgnoreConfigFile(tt.shouldIgnoreConfigFile)
521515
curationCmd.SetInsecureTls(tt.allowInsecureTls)
522-
curationCmd.SetDockerImageName(tt.dockerImageName)
523516
cmdResults = map[string]*CurationReport{}
524517
err = curationCmd.doCurateAudit(cmdResults)
525518
return
526519
}
527520

528-
func runDockerCurationTest(tt testCase, serverDetails *config.ServerDetails) (map[string]*CurationReport, error) {
529-
imageInfo, _ := docker.ParseDockerImage(tt.dockerImageName)
530-
rootId := imageInfo.Image + ":" + imageInfo.Tag
531-
532-
rtManager, _ := rtUtils.CreateServiceManager(serverDetails, 2, 0, false)
533-
rtAuth, _ := serverDetails.CreateArtAuthConfig()
534-
535-
analyzer := treeAnalyzer{
536-
rtManager: rtManager,
537-
extractPoliciesRegex: regexp.MustCompile(extractPoliciesRegexTemplate),
538-
rtAuth: rtAuth,
539-
httpClientDetails: rtAuth.CreateHttpClientDetails(),
540-
url: rtAuth.GetUrl(),
541-
repo: imageInfo.Repo,
542-
tech: techutils.Docker,
543-
parallelRequests: 3,
544-
}
545-
546-
tree := []*xrayUtils.GraphNode{{Id: rootId, Nodes: []*xrayUtils.GraphNode{{Id: "docker://" + rootId}}}}
547-
statusMap := sync.Map{}
548-
var status []*PackageStatus
549-
550-
_ = analyzer.fetchNodesStatus(tree[0], &statusMap, map[string]struct{}{rootId: {}})
551-
analyzer.GraphsRelations(tree, &statusMap, &status)
552-
553-
return map[string]*CurationReport{rootId: {packagesStatus: status, totalNumberOfPackages: 1}}, nil
554-
}
555-
556521
func validateCurationResults(t *testing.T, testCase testCase, results map[string]*CurationReport, config *config.ServerDetails) {
557522
// Add the mock server to the expected blocked message url
558523
for key := range testCase.expectedResp {
@@ -603,7 +568,6 @@ type testCase struct {
603568
tech techutils.Technology
604569
createServerWithoutCreds bool
605570
allowInsecureTls bool
606-
dockerImageName string
607571
}
608572

609573
func (tc testCase) getPathToTests() string {
@@ -1021,43 +985,6 @@ func getTestCasesForDoCurationAudit() []testCase {
1021985
},
1022986
allowInsecureTls: true,
1023987
},
1024-
{
1025-
name: "docker tree - one blocked package",
1026-
tech: techutils.Docker,
1027-
pathToProject: filepath.Join("projects", "package-managers", "docker", "curation-project"),
1028-
dockerImageName: "repo-test-docker/dweomer/nginx-auth-ldap:1.13.5-on-alpine-3.5",
1029-
requestToFail: map[string]bool{
1030-
"/api/docker/dweomer/v2/nginx-auth-ldap/manifests/1.13.5-on-alpine-3.5": true,
1031-
},
1032-
expectedRequest: map[string]bool{
1033-
"/api/docker/dweomer/v2/nginx-auth-ldap/manifests/1.13.5-on-alpine-3.5": false,
1034-
},
1035-
expectedResp: map[string]*CurationReport{
1036-
"nginx-auth-ldap:1.13.5-on-alpine-3.5": {
1037-
packagesStatus: []*PackageStatus{
1038-
{
1039-
Action: "blocked",
1040-
ParentName: "nginx-auth-ldap",
1041-
ParentVersion: "1.13.5-on-alpine-3.5",
1042-
BlockedPackageUrl: "/api/docker/dweomer/v2/nginx-auth-ldap/manifests/1.13.5-on-alpine-3.5",
1043-
PackageName: "nginx-auth-ldap",
1044-
PackageVersion: "1.13.5-on-alpine-3.5",
1045-
DepRelation: "direct",
1046-
PkgType: "docker",
1047-
BlockingReason: "Policy violations",
1048-
Policy: []Policy{
1049-
{
1050-
Policy: "pol1",
1051-
Condition: "cond1",
1052-
},
1053-
},
1054-
},
1055-
},
1056-
totalNumberOfPackages: 1,
1057-
},
1058-
},
1059-
allowInsecureTls: true,
1060-
},
1061988
}
1062989
return tests
1063990
}
@@ -1322,7 +1249,6 @@ func Test_getDockerNameScopeAndVersion(t *testing.T) {
13221249
})
13231250
}
13241251
}
1325-
13261252
func Test_getNugetNameScopeAndVersion(t *testing.T) {
13271253
tests := []struct {
13281254
name string

0 commit comments

Comments
 (0)