@@ -705,6 +705,53 @@ func TestEncoder_Encode(t *testing.T) {
705
705
},
706
706
wantVulns : make (map [uuid.UUID ][]core.Vulnerability ),
707
707
},
708
+ {
709
+ name : "SBOM file without root component" ,
710
+ report : types.Report {
711
+ SchemaVersion : 2 ,
712
+ ArtifactName : "report.cdx.json" ,
713
+ ArtifactType : artifact .TypeCycloneDX ,
714
+ Results : []types.Result {
715
+ {
716
+ Target : "Java" ,
717
+ Type : ftypes .Jar ,
718
+ Class : types .ClassLangPkg ,
719
+ Packages : []ftypes.Package {
720
+ {
721
+ ID : "org.apache.logging.log4j:log4j-core:2.23.1" ,
722
+ Name : "org.apache.logging.log4j:log4j-core" ,
723
+ Version : "2.23.1" ,
724
+ Identifier : ftypes.PkgIdentifier {
725
+ UID : "6C0AE96901617503" ,
726
+ PURL : & packageurl.PackageURL {
727
+ Type : packageurl .TypeMaven ,
728
+ Namespace : "org.apache.logging.log4j" ,
729
+ Name : "log4j-core" ,
730
+ Version : "2.23.1" ,
731
+ },
732
+ },
733
+ FilePath : "log4j-core-2.23.1.jar" ,
734
+ },
735
+ },
736
+ },
737
+ },
738
+ BOM : newTestBOM2 (t ),
739
+ },
740
+ wantComponents : map [uuid.UUID ]* core.Component {
741
+ uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000001" ): fsComponent ,
742
+ uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000002" ): libComponent ,
743
+ },
744
+ wantRels : map [uuid.UUID ][]core.Relationship {
745
+ uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000001" ): {
746
+ {
747
+ Dependency : uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000002" ),
748
+ Type : core .RelationshipContains ,
749
+ },
750
+ },
751
+ uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000002" ): nil ,
752
+ },
753
+ wantVulns : make (map [uuid.UUID ][]core.Vulnerability ),
754
+ },
708
755
{
709
756
name : "json file created from SBOM file (BOM is empty)" ,
710
757
report : types.Report {
@@ -860,3 +907,11 @@ func newTestBOM(t *testing.T) *core.BOM {
860
907
bom .AddComponent (appComponent )
861
908
return bom
862
909
}
910
+
911
+ // BOM without root component
912
+ func newTestBOM2 (t * testing.T ) * core.BOM {
913
+ uuid .SetFakeUUID (t , "2ff14136-e09f-4df9-80ea-%012d" )
914
+ bom := core .NewBOM (core.Options {})
915
+ bom .AddComponent (libComponent )
916
+ return bom
917
+ }
0 commit comments