@@ -1121,9 +1121,9 @@ func TestExclude(t *testing.T) {
11211121 bom := cyclonedx .NewBOM ()
11221122 bom .Components = & []cyclonedx.Component {
11231123 {BOMRef : "root" , Type : cyclonedx .ComponentTypeLibrary },
1124- {BOMRef : "comp1" , Type : cyclonedx .ComponentTypeLibrary },
1125- {BOMRef : "comp2" , Type : cyclonedx .ComponentTypeLibrary },
1126- {BOMRef : "comp3" , Type : cyclonedx .ComponentTypeLibrary },
1124+ {BOMRef : "comp1" , PackageURL : "pkg:comp1" , Type : cyclonedx .ComponentTypeLibrary },
1125+ {BOMRef : "comp2" , PackageURL : "pkg:comp2" , Type : cyclonedx .ComponentTypeLibrary },
1126+ {BOMRef : "comp3" , PackageURL : "pkg:comp3" , Type : cyclonedx .ComponentTypeLibrary },
11271127 }
11281128 bom .Dependencies = & []cyclonedx.Dependency {
11291129 {Ref : "root" , Dependencies : & []string {"comp1" , "comp3" }},
@@ -1152,9 +1152,9 @@ func TestExclude(t *testing.T) {
11521152 expected : & cyclonedx.BOM {
11531153 Components : & []cyclonedx.Component {
11541154 {BOMRef : "root" , Type : cyclonedx .ComponentTypeLibrary },
1155- {BOMRef : "comp1" , Type : cyclonedx .ComponentTypeLibrary },
1156- {BOMRef : "comp2" , Type : cyclonedx .ComponentTypeLibrary },
1157- {BOMRef : "comp3" , Type : cyclonedx .ComponentTypeLibrary },
1155+ {BOMRef : "comp1" , PackageURL : "pkg:comp1" , Type : cyclonedx .ComponentTypeLibrary },
1156+ {BOMRef : "comp2" , PackageURL : "pkg:comp2" , Type : cyclonedx .ComponentTypeLibrary },
1157+ {BOMRef : "comp3" , PackageURL : "pkg:comp3" , Type : cyclonedx .ComponentTypeLibrary },
11581158 },
11591159 Dependencies : & []cyclonedx.Dependency {
11601160 {Ref : "root" , Dependencies : & []string {"comp1" , "comp3" }},
@@ -1164,25 +1164,25 @@ func TestExclude(t *testing.T) {
11641164 },
11651165 {
11661166 name : "Exclude single component with transitive dependencies" ,
1167- exclude : []cyclonedx.Component {{BOMRef : "comp1" }},
1167+ exclude : []cyclonedx.Component {{BOMRef : "comp1" , PackageURL : "pkg:comp1" }},
11681168 bom : * bom ,
11691169 expected : & cyclonedx.BOM {
11701170 Components : & []cyclonedx.Component {
11711171 {BOMRef : "root" , Type : cyclonedx .ComponentTypeLibrary },
1172- {BOMRef : "comp3" , Type : cyclonedx .ComponentTypeLibrary },
1172+ {BOMRef : "comp3" , PackageURL : "pkg:comp3" , Type : cyclonedx .ComponentTypeLibrary },
11731173 },
11741174 Dependencies : & []cyclonedx.Dependency {{Ref : "root" , Dependencies : & []string {"comp3" }}},
11751175 },
11761176 },
11771177 {
11781178 name : "Exclude single component existing both directly and transitively" ,
1179- exclude : []cyclonedx.Component {{BOMRef : "comp3" }},
1179+ exclude : []cyclonedx.Component {{BOMRef : "comp3" , PackageURL : "pkg:comp3" }},
11801180 bom : * bom ,
11811181 expected : & cyclonedx.BOM {
11821182 Components : & []cyclonedx.Component {
11831183 {BOMRef : "root" , Type : cyclonedx .ComponentTypeLibrary },
1184- {BOMRef : "comp1" , Type : cyclonedx .ComponentTypeLibrary },
1185- {BOMRef : "comp2" , Type : cyclonedx .ComponentTypeLibrary },
1184+ {BOMRef : "comp1" , PackageURL : "pkg:comp1" , Type : cyclonedx .ComponentTypeLibrary },
1185+ {BOMRef : "comp2" , PackageURL : "pkg:comp2" , Type : cyclonedx .ComponentTypeLibrary },
11861186 },
11871187 Dependencies : & []cyclonedx.Dependency {
11881188 {Ref : "root" , Dependencies : & []string {"comp1" }},
@@ -1192,18 +1192,44 @@ func TestExclude(t *testing.T) {
11921192 },
11931193 {
11941194 name : "Exclude multiple components" ,
1195- exclude : []cyclonedx.Component {{BOMRef : "comp2" }, {BOMRef : "comp3" }, {BOMRef : "exclude-me" }},
1195+ exclude : []cyclonedx.Component {{BOMRef : "comp2" , PackageURL : "pkg:comp2" }, {BOMRef : "comp3" , PackageURL : "pkg:comp3" }, {BOMRef : "exclude-me" , PackageURL : "pkg: exclude-me" }},
11961196 bom : * bom ,
11971197 expected : & cyclonedx.BOM {
11981198 Components : & []cyclonedx.Component {
11991199 {BOMRef : "root" , Type : cyclonedx .ComponentTypeLibrary },
1200- {BOMRef : "comp1" , Type : cyclonedx .ComponentTypeLibrary },
1200+ {BOMRef : "comp1" , PackageURL : "pkg:comp1" , Type : cyclonedx .ComponentTypeLibrary },
12011201 },
12021202 Dependencies : & []cyclonedx.Dependency {
12031203 {Ref : "root" , Dependencies : & []string {"comp1" }},
12041204 },
12051205 },
12061206 },
1207+ {
1208+ name : "Exclude by same name+version while ignoring hash" ,
1209+ bom : cyclonedx.BOM {
1210+ Components : & []cyclonedx.Component {
1211+ {BOMRef : "root" , Type : cyclonedx .ComponentTypeLibrary },
1212+ {
BOMRef :
"comp1" ,
PackageURL :
"pkg:npm/[email protected] ?hash=4321" ,
Type :
cyclonedx .
ComponentTypeLibrary },
1213+ {
BOMRef :
"comp2" ,
PackageURL :
"pkg:npm/[email protected] " ,
Type :
cyclonedx .
ComponentTypeLibrary },
1214+ {
BOMRef :
"comp3" ,
PackageURL :
"pkg:npm/[email protected] " ,
Type :
cyclonedx .
ComponentTypeLibrary },
1215+ },
1216+ Dependencies : & []cyclonedx.Dependency {
1217+ {Ref : "root" , Dependencies : & []string {"comp1" , "comp3" }},
1218+ {Ref : "comp1" , Dependencies : & []string {"comp2" , "comp3" }},
1219+ },
1220+ },
1221+ // Exclude the same name+version, with a hash that should be ignored
1222+ exclude : []cyclonedx.
Component {{
BOMRef :
"comp1" ,
PackageURL :
"pkg:npm/[email protected] ?hash=1234" }},
1223+ expected : & cyclonedx.BOM {
1224+ Components : & []cyclonedx.Component {
1225+ {BOMRef : "root" , Type : cyclonedx .ComponentTypeLibrary },
1226+ {
BOMRef :
"comp3" ,
PackageURL :
"pkg:npm/[email protected] " ,
Type :
cyclonedx .
ComponentTypeLibrary },
1227+ },
1228+ Dependencies : & []cyclonedx.Dependency {
1229+ {Ref : "root" , Dependencies : & []string {"comp3" }},
1230+ },
1231+ },
1232+ },
12071233 }
12081234
12091235 for _ , tt := range tests {
0 commit comments