@@ -16,6 +16,7 @@ import (
1616 "sync"
1717 "testing"
1818
19+ "github.com/jfrog/jfrog-cli-security/sca/bom/buildinfo/technologies/docker"
1920 "github.com/jfrog/jfrog-cli-security/sca/bom/buildinfo/technologies/java"
2021 "github.com/jfrog/jfrog-cli-security/utils/formats"
2122
@@ -507,8 +508,9 @@ func runPreTestExec(t *testing.T, basePathToTests string, testCase testCase) {
507508}
508509
509510func createCurationCmdAndRun (tt testCase , serverDetails * config.ServerDetails ) (cmdResults map [string ]* CurationReport , err error ) {
510- if tt .tech == techutils .Docker && tt .mockDepTree != nil {
511- return runDockerCurationWithMockTree (tt , serverDetails )
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 )
512514 }
513515 curationCmd := NewCurationAuditCommand ()
514516 curationCmd .SetIsCurationCmd (true )
@@ -517,44 +519,38 @@ func createCurationCmdAndRun(tt testCase, serverDetails *config.ServerDetails) (
517519 curationCmd .SetInsecureTls (true )
518520 curationCmd .SetIgnoreConfigFile (tt .shouldIgnoreConfigFile )
519521 curationCmd .SetInsecureTls (tt .allowInsecureTls )
520- if tt .dockerImageName != "" {
521- curationCmd .SetDockerImageName (tt .dockerImageName )
522- // Docker requires server details to be set explicitly
523- curationCmd .SetServerDetails (serverDetails )
524- }
522+ curationCmd .SetDockerImageName (tt .dockerImageName )
525523 cmdResults = map [string ]* CurationReport {}
526524 err = curationCmd .doCurateAudit (cmdResults )
527525 return
528526}
529527
530- func runDockerCurationWithMockTree (tt testCase , serverDetails * config.ServerDetails ) (map [string ]* CurationReport , error ) {
531- rtAuth , _ := serverDetails .CreateArtAuthConfig ()
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+
532532 rtManager , _ := rtUtils .CreateServiceManager (serverDetails , 2 , 0 , false )
533+ rtAuth , _ := serverDetails .CreateArtAuthConfig ()
533534
534535 analyzer := treeAnalyzer {
535536 rtManager : rtManager ,
536537 extractPoliciesRegex : regexp .MustCompile (extractPoliciesRegexTemplate ),
537538 rtAuth : rtAuth ,
538539 httpClientDetails : rtAuth .CreateHttpClientDetails (),
539540 url : rtAuth .GetUrl (),
540- repo : strings . SplitN ( tt . dockerImageName , "/" , 2 )[ 0 ] ,
541+ repo : imageInfo . Repo ,
541542 tech : techutils .Docker ,
542543 parallelRequests : 3 ,
543544 }
544545
545- packagesStatusMap := sync. Map { }
546- rootNodes := map [ string ] struct {}{ tt . mockDepTree . Id : {} }
547- _ = analyzer . fetchNodesStatus ( tt . mockDepTree , & packagesStatusMap , rootNodes )
546+ tree := [] * xrayUtils. GraphNode {{ Id : rootId , Nodes : [] * xrayUtils. GraphNode {{ Id : "docker://" + rootId }}} }
547+ statusMap := sync. Map { }
548+ var status [] * PackageStatus
548549
549- var packagesStatus [] * PackageStatus
550- analyzer .GraphsRelations ([] * xrayUtils. GraphNode { tt . mockDepTree } , & packagesStatusMap , & packagesStatus )
550+ analyzer . fetchNodesStatus ( tree [ 0 ], & statusMap , map [ string ] struct {}{ rootId : {}})
551+ analyzer .GraphsRelations (tree , & statusMap , & status )
551552
552- return map [string ]* CurationReport {
553- tt .mockDepTree .Id : {
554- packagesStatus : packagesStatus ,
555- totalNumberOfPackages : len (tt .mockDepTree .Nodes ),
556- },
557- }, nil
553+ return map [string ]* CurationReport {rootId : {packagesStatus : status , totalNumberOfPackages : 1 }}, nil
558554}
559555
560556func validateCurationResults (t * testing.T , testCase testCase , results map [string ]* CurationReport , config * config.ServerDetails ) {
@@ -608,8 +604,6 @@ type testCase struct {
608604 createServerWithoutCreds bool
609605 allowInsecureTls bool
610606 dockerImageName string
611- // mockDepTree is used for Docker tests to bypass docker pull
612- mockDepTree * xrayUtils.GraphNode
613607}
614608
615609func (tc testCase ) getPathToTests () string {
@@ -1028,26 +1022,26 @@ func getTestCasesForDoCurationAudit() []testCase {
10281022 allowInsecureTls : true ,
10291023 },
10301024 {
1031- name : "docker tree - malicious package blocked" ,
1025+ name : "docker tree - one blocked package " ,
10321026 tech : techutils .Docker ,
10331027 pathToProject : filepath .Join ("projects" , "package-managers" , "docker" , "curation-project" ),
1034- dockerImageName : "docker-curation/ganodndentcom/drupal:latest " ,
1028+ dockerImageName : "repo-test-docker/dweomer/nginx-auth-ldap:1.13.5-on-alpine-3.5 " ,
10351029 requestToFail : map [string ]bool {
1036- "/api/docker/docker-curation /v2/ganodndentcom/drupal/ manifests/latest " : true ,
1030+ "/api/docker/dweomer /v2/nginx-auth-ldap/ manifests/1.13.5-on-alpine-3.5 " : true ,
10371031 },
10381032 expectedRequest : map [string ]bool {
1039- "/api/docker/docker-curation /v2/ganodndentcom/drupal/ manifests/latest " : false ,
1033+ "/api/docker/dweomer /v2/nginx-auth-ldap/ manifests/1.13.5-on-alpine-3.5 " : false ,
10401034 },
10411035 expectedResp : map [string ]* CurationReport {
1042- "ganodndentcom/drupal:latest " : {
1036+ "nginx-auth-ldap:1.13.5-on-alpine-3.5 " : {
10431037 packagesStatus : []* PackageStatus {
10441038 {
10451039 Action : "blocked" ,
1046- ParentName : "ganodndentcom/drupal " ,
1047- ParentVersion : "latest " ,
1048- BlockedPackageUrl : "/api/docker/docker-curation /v2/ganodndentcom/drupal/ manifests/latest " ,
1049- PackageName : "ganodndentcom/drupal " ,
1050- PackageVersion : "latest " ,
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 " ,
10511045 DepRelation : "direct" ,
10521046 PkgType : "docker" ,
10531047 BlockingReason : "Policy violations" ,
@@ -1063,13 +1057,6 @@ func getTestCasesForDoCurationAudit() []testCase {
10631057 },
10641058 },
10651059 allowInsecureTls : true ,
1066- // Mock dependency tree to bypass docker pull
1067- mockDepTree : & xrayUtils.GraphNode {
1068- Id : "ganodndentcom/drupal:latest" ,
1069- Nodes : []* xrayUtils.GraphNode {
1070- {Id : "docker://ganodndentcom/drupal:latest" },
1071- },
1072- },
10731060 },
10741061 }
10751062 return tests
0 commit comments