Skip to content

Commit 542a380

Browse files
committed
test(bom): add test for multimodule project
1 parent 745bc9c commit 542a380

File tree

1 file changed

+356
-0
lines changed

1 file changed

+356
-0
lines changed

pkg/sbom/io/encode_test.go

+356
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,362 @@ func TestEncoder_Encode(t *testing.T) {
764764
},
765765
wantVulns: make(map[uuid.UUID][]core.Vulnerability),
766766
},
767+
{
768+
name: "multimodule maven project",
769+
report: types.Report{
770+
SchemaVersion: 2,
771+
ArtifactName: "pom.xml",
772+
ArtifactType: artifact.TypeFilesystem,
773+
Results: []types.Result{
774+
{
775+
Target: "pom.xml",
776+
Type: ftypes.Pom,
777+
Class: types.ClassLangPkg,
778+
Packages: []ftypes.Package{
779+
{
780+
ID: "com.example:root:1.0.0",
781+
Name: "com.example:root",
782+
Version: "1.0.0",
783+
Identifier: ftypes.PkgIdentifier{
784+
UID: "f684ec661900abbf",
785+
PURL: &packageurl.PackageURL{
786+
Type: packageurl.TypeMaven,
787+
Namespace: "com.example",
788+
Name: "root",
789+
Version: "1.0.0",
790+
},
791+
},
792+
Relationship: ftypes.RelationshipRoot,
793+
},
794+
{
795+
ID: "com.example:module1:1.0.0",
796+
Name: "com.example:module1",
797+
Version: "1.0.0",
798+
Identifier: ftypes.PkgIdentifier{
799+
UID: "ce0d29336874c431",
800+
PURL: &packageurl.PackageURL{
801+
Type: packageurl.TypeMaven,
802+
Namespace: "com.example",
803+
Name: "module1",
804+
Version: "1.0.0",
805+
},
806+
},
807+
Relationship: ftypes.RelationshipWorkspace,
808+
DependsOn: []string{
809+
"org.example:example-api:1.1.1",
810+
},
811+
},
812+
{
813+
ID: "com.example:module2:2.0.0",
814+
Name: "com.example:module2",
815+
Version: "2.0.0",
816+
Identifier: ftypes.PkgIdentifier{
817+
UID: "387238ffef6dfa9d",
818+
PURL: &packageurl.PackageURL{
819+
Type: packageurl.TypeMaven,
820+
Namespace: "com.example",
821+
Name: "module2",
822+
Version: "2.0.0",
823+
},
824+
},
825+
Relationship: ftypes.RelationshipWorkspace,
826+
DependsOn: []string{
827+
"org.example:example-dependency:1.2.3",
828+
},
829+
},
830+
{
831+
ID: "org.example:example-api:1.1.1",
832+
Name: "org.example:example-api",
833+
Version: "1.1.1",
834+
Identifier: ftypes.PkgIdentifier{
835+
UID: "45cdc62618708bb7",
836+
PURL: &packageurl.PackageURL{
837+
Type: packageurl.TypeMaven,
838+
Namespace: "org.example",
839+
Name: "example-api",
840+
Version: "1.1.1",
841+
},
842+
},
843+
Relationship: ftypes.RelationshipDirect,
844+
},
845+
{
846+
ID: "org.example:example-dependency:1.2.3",
847+
Name: "org.example:example-dependency",
848+
Version: "1.2.3",
849+
Identifier: ftypes.PkgIdentifier{
850+
UID: "52fbe353a46651",
851+
PURL: &packageurl.PackageURL{
852+
Type: packageurl.TypeMaven,
853+
Namespace: "org.example",
854+
Name: "example-dependency",
855+
Version: "1.2.3",
856+
},
857+
},
858+
Relationship: ftypes.RelationshipDirect,
859+
DependsOn: []string{
860+
"org.example:example-api:2.0.0",
861+
},
862+
},
863+
{
864+
ID: "org.example:example-api:2.0.0",
865+
Name: "org.example:example-api",
866+
Version: "2.0.0",
867+
Identifier: ftypes.PkgIdentifier{
868+
UID: "f71d14b6d2bd8810",
869+
PURL: &packageurl.PackageURL{
870+
Type: packageurl.TypeMaven,
871+
Namespace: "org.example",
872+
Name: "example-api",
873+
Version: "2.0.0",
874+
},
875+
},
876+
Relationship: ftypes.RelationshipIndirect,
877+
},
878+
},
879+
},
880+
},
881+
},
882+
wantComponents: map[uuid.UUID]*core.Component{
883+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000001"): {
884+
Type: core.TypeFilesystem,
885+
Name: "pom.xml",
886+
Root: true,
887+
Properties: []core.Property{
888+
{
889+
Name: core.PropertySchemaVersion,
890+
Value: "2",
891+
},
892+
},
893+
PkgIdentifier: ftypes.PkgIdentifier{
894+
BOMRef: "3ff14136-e09f-4df9-80ea-000000000001",
895+
},
896+
},
897+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000002"): {
898+
Type: core.TypeApplication,
899+
Name: "pom.xml",
900+
Properties: []core.Property{
901+
{
902+
Name: core.PropertyClass,
903+
Value: "lang-pkgs",
904+
},
905+
{
906+
Name: core.PropertyType,
907+
Value: "pom",
908+
},
909+
},
910+
PkgIdentifier: ftypes.PkgIdentifier{
911+
BOMRef: "3ff14136-e09f-4df9-80ea-000000000002",
912+
},
913+
},
914+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000003"): {
915+
Type: core.TypeLibrary,
916+
Group: "com.example",
917+
Name: "root",
918+
Version: "1.0.0",
919+
SrcFile: "pom.xml",
920+
Properties: []core.Property{
921+
{
922+
Name: core.PropertyPkgID,
923+
Value: "com.example:root:1.0.0",
924+
},
925+
{
926+
Name: core.PropertyPkgType,
927+
Value: "pom",
928+
},
929+
},
930+
PkgIdentifier: ftypes.PkgIdentifier{
931+
UID: "f684ec661900abbf",
932+
PURL: &packageurl.PackageURL{
933+
Type: packageurl.TypeMaven,
934+
Namespace: "com.example",
935+
Name: "root",
936+
Version: "1.0.0",
937+
},
938+
BOMRef: "pkg:maven/com.example/[email protected]",
939+
},
940+
},
941+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000004"): {
942+
Type: core.TypeLibrary,
943+
Group: "com.example",
944+
Name: "module1",
945+
Version: "1.0.0",
946+
SrcFile: "pom.xml",
947+
Properties: []core.Property{
948+
{
949+
Name: core.PropertyPkgID,
950+
Value: "com.example:module1:1.0.0",
951+
},
952+
{
953+
Name: core.PropertyPkgType,
954+
Value: "pom",
955+
},
956+
},
957+
PkgIdentifier: ftypes.PkgIdentifier{
958+
UID: "ce0d29336874c431",
959+
PURL: &packageurl.PackageURL{
960+
Type: packageurl.TypeMaven,
961+
Namespace: "com.example",
962+
Name: "module1",
963+
Version: "1.0.0",
964+
},
965+
BOMRef: "pkg:maven/com.example/[email protected]",
966+
},
967+
},
968+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000005"): {
969+
Type: core.TypeLibrary,
970+
Group: "com.example",
971+
Name: "module2",
972+
Version: "2.0.0",
973+
SrcFile: "pom.xml",
974+
Properties: []core.Property{
975+
{
976+
Name: core.PropertyPkgID,
977+
Value: "com.example:module2:2.0.0",
978+
},
979+
{
980+
Name: core.PropertyPkgType,
981+
Value: "pom",
982+
},
983+
},
984+
PkgIdentifier: ftypes.PkgIdentifier{
985+
UID: "387238ffef6dfa9d",
986+
PURL: &packageurl.PackageURL{
987+
Type: packageurl.TypeMaven,
988+
Namespace: "com.example",
989+
Name: "module2",
990+
Version: "2.0.0",
991+
},
992+
BOMRef: "pkg:maven/com.example/[email protected]",
993+
},
994+
},
995+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000006"): {
996+
Type: core.TypeLibrary,
997+
Group: "org.example",
998+
Name: "example-api",
999+
Version: "1.1.1",
1000+
SrcFile: "pom.xml",
1001+
Properties: []core.Property{
1002+
{
1003+
Name: core.PropertyPkgID,
1004+
Value: "org.example:example-api:1.1.1",
1005+
},
1006+
{
1007+
Name: core.PropertyPkgType,
1008+
Value: "pom",
1009+
},
1010+
},
1011+
PkgIdentifier: ftypes.PkgIdentifier{
1012+
UID: "45cdc62618708bb7",
1013+
PURL: &packageurl.PackageURL{
1014+
Type: packageurl.TypeMaven,
1015+
Namespace: "org.example",
1016+
Name: "example-api",
1017+
Version: "1.1.1",
1018+
},
1019+
BOMRef: "pkg:maven/org.example/[email protected]",
1020+
},
1021+
},
1022+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000007"): {
1023+
Type: core.TypeLibrary,
1024+
Group: "org.example",
1025+
Name: "example-dependency",
1026+
Version: "1.2.3",
1027+
SrcFile: "pom.xml",
1028+
Properties: []core.Property{
1029+
{
1030+
Name: core.PropertyPkgID,
1031+
Value: "org.example:example-dependency:1.2.3",
1032+
},
1033+
{
1034+
Name: core.PropertyPkgType,
1035+
Value: "pom",
1036+
},
1037+
},
1038+
PkgIdentifier: ftypes.PkgIdentifier{
1039+
UID: "52fbe353a46651",
1040+
PURL: &packageurl.PackageURL{
1041+
Type: packageurl.TypeMaven,
1042+
Namespace: "org.example",
1043+
Name: "example-dependency",
1044+
Version: "1.2.3",
1045+
},
1046+
BOMRef: "pkg:maven/org.example/[email protected]",
1047+
},
1048+
},
1049+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000008"): {
1050+
Type: core.TypeLibrary,
1051+
Group: "org.example",
1052+
Name: "example-api",
1053+
Version: "2.0.0",
1054+
SrcFile: "pom.xml",
1055+
Properties: []core.Property{
1056+
{
1057+
Name: core.PropertyPkgID,
1058+
Value: "org.example:example-api:2.0.0",
1059+
},
1060+
{
1061+
Name: core.PropertyPkgType,
1062+
Value: "pom",
1063+
},
1064+
},
1065+
PkgIdentifier: ftypes.PkgIdentifier{
1066+
UID: "f71d14b6d2bd8810",
1067+
PURL: &packageurl.PackageURL{
1068+
Type: packageurl.TypeMaven,
1069+
Namespace: "org.example",
1070+
Name: "example-api",
1071+
Version: "2.0.0",
1072+
},
1073+
BOMRef: "pkg:maven/org.example/[email protected]",
1074+
},
1075+
},
1076+
},
1077+
wantRels: map[uuid.UUID][]core.Relationship{
1078+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000001"): {
1079+
{
1080+
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000002"),
1081+
Type: core.RelationshipContains,
1082+
},
1083+
},
1084+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000002"): {
1085+
{
1086+
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000003"),
1087+
Type: core.RelationshipContains,
1088+
},
1089+
},
1090+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000003"): {
1091+
{
1092+
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000004"),
1093+
Type: core.RelationshipDependsOn,
1094+
},
1095+
{
1096+
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000005"),
1097+
Type: core.RelationshipDependsOn,
1098+
},
1099+
},
1100+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000004"): {
1101+
{
1102+
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000006"),
1103+
Type: core.RelationshipDependsOn,
1104+
},
1105+
},
1106+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000005"): {
1107+
{
1108+
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000007"),
1109+
Type: core.RelationshipDependsOn,
1110+
},
1111+
},
1112+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000006"): nil,
1113+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000007"): {
1114+
{
1115+
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000008"),
1116+
Type: core.RelationshipDependsOn,
1117+
},
1118+
},
1119+
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000008"): nil,
1120+
},
1121+
wantVulns: make(map[uuid.UUID][]core.Vulnerability),
1122+
},
7671123
{
7681124
name: "json file created from SBOM file (BOM is empty)",
7691125
report: types.Report{

0 commit comments

Comments
 (0)