File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -161,14 +161,22 @@ func (md *ScannerAdapterMetadata) GetCapability(mimeType string) *ScannerCapabil
161161// ConvertCapability converts the capability to map, used in get scanner API
162162func (md * ScannerAdapterMetadata ) ConvertCapability () map [string ]interface {} {
163163 capabilities := make (map [string ]interface {})
164+ oldScanner := true
164165 for _ , c := range md .Capabilities {
166+ if len (c .Type ) > 0 {
167+ oldScanner = false
168+ }
165169 if c .Type == ScanTypeVulnerability {
166170 capabilities [supportVulnerability ] = true
167- }
168- if c .Type == ScanTypeSbom {
171+ } else if c .Type == ScanTypeSbom {
169172 capabilities [supportSBOM ] = true
170173 }
171174 }
175+ if oldScanner && len (capabilities ) == 0 {
176+ // to compatible with old version scanner, suppose they should always support scan vulnerability when capability is empty
177+ capabilities [supportVulnerability ] = true
178+ capabilities [supportSBOM ] = false
179+ }
172180 return capabilities
173181}
174182
Original file line number Diff line number Diff line change @@ -13,3 +13,29 @@ func TestIsSupportedMimeType(t *testing.T) {
1313 // Test with an unsupported mime type
1414 assert .False (t , isSupportedMimeType ("unsupported/mime-type" ), "isSupportedMimeType should return false for unsupported mime types" )
1515}
16+
17+ func TestConvertCapability (t * testing.T ) {
18+ md := & ScannerAdapterMetadata {
19+ Capabilities : []* ScannerCapability {
20+ {Type : ScanTypeSbom },
21+ {Type : ScanTypeVulnerability },
22+ },
23+ }
24+ result := md .ConvertCapability ()
25+ assert .Equal (t , result [supportSBOM ], true )
26+ assert .Equal (t , result [supportVulnerability ], true )
27+ }
28+
29+ func TestConvertCapabilityOldScaner (t * testing.T ) {
30+ md := & ScannerAdapterMetadata {
31+ Capabilities : []* ScannerCapability {
32+ {
33+ ConsumesMimeTypes : []string {"application/vnd.oci.image.manifest.v1+json" , "application/vnd.docker.distribution.manifest.v2+json" },
34+ ProducesMimeTypes : []string {MimeTypeNativeReport },
35+ },
36+ },
37+ }
38+ result := md .ConvertCapability ()
39+ assert .Equal (t , result [supportSBOM ], false )
40+ assert .Equal (t , result [supportVulnerability ], true )
41+ }
You can’t perform that action at this time.
0 commit comments