|
| 1 | +package lib.sbom_test |
| 2 | + |
| 3 | +import data.lib.assertions |
| 4 | +import data.lib.sbom |
| 5 | + |
| 6 | +test_cyclonedx_maven_extraction if { |
| 7 | + mock_components := [{ |
| 8 | + "name": "auth-lib", |
| 9 | + "purl": "pkg:maven/org.example/auth@1.0", |
| 10 | + "externalRefs": [{"type": "distribution", "url": "https://repo.maven.apache.org/maven2/"}], |
| 11 | + }] |
| 12 | + |
| 13 | + expected := {{ |
| 14 | + "name": "auth-lib", |
| 15 | + "purl": "pkg:maven/org.example/auth@1.0", |
| 16 | + "repository_url": "https://repo.maven.apache.org/maven2/", |
| 17 | + }} |
| 18 | + |
| 19 | + result := sbom.maven_packages with sbom.cyclonedx_sboms as [_cyclonedx_sbom(mock_components)] |
| 20 | + |
| 21 | + assertions.assert_equal(expected, result) |
| 22 | +} |
| 23 | + |
| 24 | +test_cyclonedx_ignores_non_maven if { |
| 25 | + mock_components := [{"name": "react", "purl": "pkg:npm/react@18.2.0"}] |
| 26 | + |
| 27 | + assertions.assert_empty(sbom.maven_packages) with sbom.cyclonedx_sboms as [_cyclonedx_sbom(mock_components)] |
| 28 | +} |
| 29 | + |
| 30 | +test_cyclonedx_empty_repo_url if { |
| 31 | + mock_components := [{ |
| 32 | + "name": "no-repo", |
| 33 | + "purl": "pkg:maven/org.example/no-repo@1.0", |
| 34 | + "externalRefs": [], |
| 35 | + }] |
| 36 | + |
| 37 | + expected := {{ |
| 38 | + "name": "no-repo", |
| 39 | + "purl": "pkg:maven/org.example/no-repo@1.0", |
| 40 | + "repository_url": "", |
| 41 | + }} |
| 42 | + |
| 43 | + result := sbom.maven_packages with sbom.cyclonedx_sboms as [_cyclonedx_sbom(mock_components)] |
| 44 | + |
| 45 | + assertions.assert_equal(expected, result) |
| 46 | +} |
| 47 | + |
| 48 | +test_spdx_maven_extraction if { |
| 49 | + mock_packages := [{ |
| 50 | + "name": "data-service", |
| 51 | + "purl": "pkg:maven/org.example/data@2.5", |
| 52 | + "externalRefs": [{ |
| 53 | + "referenceType": "repository", |
| 54 | + "referenceLocator": "https://internal.jfrog.io/artifactory", |
| 55 | + }], |
| 56 | + }] |
| 57 | + |
| 58 | + expected := {{ |
| 59 | + "name": "data-service", |
| 60 | + "purl": "pkg:maven/org.example/data@2.5", |
| 61 | + "repository_url": "https://internal.jfrog.io/artifactory", |
| 62 | + }} |
| 63 | + |
| 64 | + result := sbom.maven_packages with sbom.spdx_sboms as [_spdx_sbom(mock_packages)] |
| 65 | + |
| 66 | + assertions.assert_equal(expected, result) |
| 67 | +} |
| 68 | + |
| 69 | +test_combined_sources if { |
| 70 | + mock_cdx := [{ |
| 71 | + "name": "cdx-pkg", |
| 72 | + "purl": "pkg:maven/cdx/pkg@1", |
| 73 | + "externalRefs": [{"type": "distribution", "url": "url1"}], |
| 74 | + }] |
| 75 | + |
| 76 | + mock_spdx := [{ |
| 77 | + "name": "spdx-pkg", |
| 78 | + "purl": "pkg:maven/spdx/pkg@1", |
| 79 | + "externalRefs": [{ |
| 80 | + "referenceType": "repository", |
| 81 | + "referenceLocator": "url2", |
| 82 | + }], |
| 83 | + }] |
| 84 | + |
| 85 | + expected := { |
| 86 | + { |
| 87 | + "name": "cdx-pkg", |
| 88 | + "purl": "pkg:maven/cdx/pkg@1", |
| 89 | + "repository_url": "url1", |
| 90 | + }, |
| 91 | + { |
| 92 | + "name": "spdx-pkg", |
| 93 | + "purl": "pkg:maven/spdx/pkg@1", |
| 94 | + "repository_url": "url2", |
| 95 | + }, |
| 96 | + } |
| 97 | + |
| 98 | + result := sbom.maven_packages with sbom.cyclonedx_sboms as [_cyclonedx_sbom(mock_cdx)] |
| 99 | + with sbom.spdx_sboms as [_spdx_sbom(mock_spdx)] |
| 100 | + |
| 101 | + assertions.assert_equal(expected, result) |
| 102 | +} |
| 103 | + |
| 104 | +test_cyclonedx_multiple_repo_capture if { |
| 105 | + mock_components := [{ |
| 106 | + "name": "multi-repo-lib", |
| 107 | + "purl": "pkg:maven/org.example/multi@1.0", |
| 108 | + "externalRefs": [ |
| 109 | + {"type": "distribution", "url": "https://repo-a.com"}, |
| 110 | + {"type": "artifact-repository", "url": "https://repo-b.com"}, |
| 111 | + ], |
| 112 | + }] |
| 113 | + |
| 114 | + expected := { |
| 115 | + { |
| 116 | + "name": "multi-repo-lib", |
| 117 | + "purl": "pkg:maven/org.example/multi@1.0", |
| 118 | + "repository_url": "https://repo-a.com", |
| 119 | + }, |
| 120 | + { |
| 121 | + "name": "multi-repo-lib", |
| 122 | + "purl": "pkg:maven/org.example/multi@1.0", |
| 123 | + "repository_url": "https://repo-b.com", |
| 124 | + }, |
| 125 | + } |
| 126 | + |
| 127 | + result := sbom.maven_packages with sbom.cyclonedx_sboms as [_cyclonedx_sbom(mock_components)] |
| 128 | + |
| 129 | + assertions.assert_equal(expected, result) |
| 130 | +} |
| 131 | + |
| 132 | +_cyclonedx_sbom(components) := {"components": components} |
| 133 | + |
| 134 | +_spdx_sbom(packages) := {"packages": packages} |
0 commit comments