@@ -535,6 +535,97 @@ func TestEncoder_Encode(t *testing.T) {
535
535
},
536
536
wantVulns : make (map [uuid.UUID ][]core.Vulnerability ),
537
537
},
538
+ {
539
+ name : "SBOM file" ,
540
+ report : types.Report {
541
+ SchemaVersion : 2 ,
542
+ ArtifactName : "report.cdx.json" ,
543
+ ArtifactType : artifact .TypeCycloneDX ,
544
+ Results : []types.Result {
545
+ {
546
+ Target : "Java" ,
547
+ Type : ftypes .Jar ,
548
+ Class : types .ClassLangPkg ,
549
+ Packages : []ftypes.Package {
550
+ {
551
+ ID : "org.apache.logging.log4j:log4j-core:2.23.1" ,
552
+ Name : "org.apache.logging.log4j:log4j-core" ,
553
+ Version : "2.23.1" ,
554
+ Identifier : ftypes.PkgIdentifier {
555
+ PURL : & packageurl.PackageURL {
556
+ Type : packageurl .TypeMaven ,
557
+ Namespace : "org.apache.logging.log4j" ,
558
+ Name : "log4j-core" ,
559
+ Version : "2.23.1" ,
560
+ },
561
+ },
562
+ FilePath : "log4j-core-2.23.1.jar" ,
563
+ },
564
+ },
565
+ },
566
+ },
567
+ BOM : newTestBOM (t ),
568
+ },
569
+ wantComponents : map [uuid.UUID ]* core.Component {
570
+ uuid .MustParse ("2ff14136-e09f-4df9-80ea-000000000001" ): appComponent ,
571
+ uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000001" ): libComponent ,
572
+ },
573
+ wantRels : map [uuid.UUID ][]core.Relationship {
574
+ uuid .MustParse ("2ff14136-e09f-4df9-80ea-000000000001" ): {
575
+ {
576
+ Dependency : uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000001" ),
577
+ Type : core .RelationshipContains ,
578
+ },
579
+ },
580
+ uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000001" ): nil ,
581
+ },
582
+ wantVulns : make (map [uuid.UUID ][]core.Vulnerability ),
583
+ },
584
+ {
585
+ name : "json file created from SBOM file (BOM is empty)" ,
586
+ report : types.Report {
587
+ SchemaVersion : 2 ,
588
+ ArtifactName : "report.cdx.json" ,
589
+ ArtifactType : artifact .TypeCycloneDX ,
590
+ Results : []types.Result {
591
+ {
592
+ Target : "Java" ,
593
+ Type : ftypes .Jar ,
594
+ Class : types .ClassLangPkg ,
595
+ Packages : []ftypes.Package {
596
+ {
597
+ ID : "org.apache.logging.log4j:log4j-core:2.23.1" ,
598
+ Name : "org.apache.logging.log4j:log4j-core" ,
599
+ Version : "2.23.1" ,
600
+ Identifier : ftypes.PkgIdentifier {
601
+ PURL : & packageurl.PackageURL {
602
+ Type : packageurl .TypeMaven ,
603
+ Namespace : "org.apache.logging.log4j" ,
604
+ Name : "log4j-core" ,
605
+ Version : "2.23.1" ,
606
+ },
607
+ },
608
+ FilePath : "log4j-core-2.23.1.jar" ,
609
+ },
610
+ },
611
+ },
612
+ },
613
+ },
614
+ wantComponents : map [uuid.UUID ]* core.Component {
615
+ uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000001" ): fsComponent ,
616
+ uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000002" ): libComponent ,
617
+ },
618
+ wantRels : map [uuid.UUID ][]core.Relationship {
619
+ uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000001" ): {
620
+ {
621
+ Dependency : uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000002" ),
622
+ Type : core .RelationshipContains ,
623
+ },
624
+ },
625
+ uuid .MustParse ("3ff14136-e09f-4df9-80ea-000000000002" ): nil ,
626
+ },
627
+ wantVulns : make (map [uuid.UUID ][]core.Vulnerability ),
628
+ },
538
629
{
539
630
name : "invalid digest" ,
540
631
report : types.Report {
@@ -580,3 +671,66 @@ func TestEncoder_Encode(t *testing.T) {
580
671
})
581
672
}
582
673
}
674
+
675
+ var (
676
+ appComponent = & core.Component {
677
+ Root : true ,
678
+ Type : core .TypeApplication ,
679
+ Name : "log4j-core-2.23.1.jar" ,
680
+ }
681
+ fsComponent = & core.Component {
682
+ Root : true ,
683
+ Type : core .TypeFilesystem ,
684
+ Name : "report.cdx.json" ,
685
+ PkgIdentifier : ftypes.PkgIdentifier {
686
+ BOMRef : "3ff14136-e09f-4df9-80ea-000000000001" ,
687
+ },
688
+ Properties : core.Properties {
689
+ {
690
+ Name : "SchemaVersion" ,
691
+ Value : "2" ,
692
+ },
693
+ },
694
+ }
695
+ libComponent = & core.Component {
696
+ Type : core .TypeLibrary ,
697
+ Name : "log4j-core" ,
698
+ Group : "org.apache.logging.log4j" ,
699
+ Version : "2.23.1" ,
700
+ PkgIdentifier : ftypes.PkgIdentifier {
701
+ BOMRef : "pkg:maven/org.apache.logging.log4j/log4j-core@2.23.1" ,
702
+ PURL : & packageurl.PackageURL {
703
+ Type : packageurl .TypeMaven ,
704
+ Namespace : "org.apache.logging.log4j" ,
705
+ Name : "log4j-core" ,
706
+ Version : "2.23.1" ,
707
+ },
708
+ },
709
+ Files : []core.File {
710
+ {
711
+ Path : "log4j-core-2.23.1.jar" ,
712
+ },
713
+ },
714
+ Properties : core.Properties {
715
+ {
716
+ Name : "FilePath" ,
717
+ Value : "log4j-core-2.23.1.jar" ,
718
+ },
719
+ {
720
+ Name : "PkgID" ,
721
+ Value : "org.apache.logging.log4j:log4j-core:2.23.1" ,
722
+ },
723
+ {
724
+ Name : "PkgType" ,
725
+ Value : "jar" ,
726
+ },
727
+ },
728
+ }
729
+ )
730
+
731
+ func newTestBOM (t * testing.T ) * core.BOM {
732
+ uuid .SetFakeUUID (t , "2ff14136-e09f-4df9-80ea-%012d" )
733
+ bom := core .NewBOM (core.Options {})
734
+ bom .AddComponent (appComponent )
735
+ return bom
736
+ }
0 commit comments