diff mbox series

[v5,3/3] oeqa/selftest: spdx: Test crate identity and output PURLs

Message ID 20261126230732.2708012-4-stondo@gmail.com
State New
Headers show
Series spdx30: identity and purls of dependency downloads | expand

Commit Message

Stefano Tondo Nov. 26, 2026, 11:07 p.m. UTC
From: Stefano Tondo <stefano.tondo.ext@siemens.com>

hello-rs from meta-selftest has a fixed SRCREV. It fetches its source
and one git dependency from github.com, and one crate, figlet-rs
0.1.5. The new tests check that:

- The crate download has its name, version and PURL.
- The output package gets the PURLs of the three downloads and keeps
  its own PURLs.
- A download PURL does not become the PURL of the package when
  SPDX_PACKAGE_URLS is empty.

Signed-off-by: Stefano Tondo <stefano.tondo.ext@siemens.com>
---
 meta/lib/oeqa/selftest/cases/spdx.py | 55 ++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/cases/spdx.py b/meta/lib/oeqa/selftest/cases/spdx.py
index ce9a8af4f6..17484df591 100644
--- a/meta/lib/oeqa/selftest/cases/spdx.py
+++ b/meta/lib/oeqa/selftest/cases/spdx.py
@@ -543,3 +543,58 @@  class SPDX30Check(SPDX3CheckBase, OESelftestTestCase):
 
         # Document should be fully linked
         self.check_objset_missing_ids(objset)
+
+    # hello-rs is a test recipe with a fixed SRCREV. It fetches its source
+    # and one git dependency from github.com, and one crate.
+    HELLO_RS_DOWNLOAD_PURLS = {
+        "pkg:github/akiernan/hello-bin@d3d096eda182644868f8e7458dcfa538ff637db3",
+        "pkg:github/akiernan/hello-lib@59c84574e844617043cf337bc8fa537cf87ad8ae",
+        "pkg:cargo/figlet-rs@0.1.5",
+    }
+
+    def test_crate_package_identity(self):
+        """Test that a crate download has its name, version and PURL."""
+        objset = self.check_recipe_spdx(
+            "hello-rs",
+            "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/builds/build-hello-rs.spdx.json",
+        )
+
+        crates = [
+            (pkg.name, pkg.software_packageVersion, pkg.software_packageUrl)
+            for pkg in objset.foreach_type(oe.spdx30.software_Package)
+            if (pkg.software_downloadLocation or "").startswith("https://static.crates.io/")
+        ]
+        self.assertEqual(crates, [("figlet-rs", "0.1.5", "pkg:cargo/figlet-rs@0.1.5")])
+
+    def get_package_purls(self, extraconf=""):
+        objset = self.check_recipe_spdx(
+            "hello-rs",
+            "{DEPLOY_DIR_SPDX}/{SSTATE_PKGARCH}/packages/package-hello-rs.spdx.json",
+            extraconf=extraconf,
+        )
+        package = next(
+            pkg
+            for pkg in objset.foreach_type(oe.spdx30.software_Package)
+            if pkg.name == "hello-rs"
+        )
+        purls = {
+            e.identifier
+            for e in package.externalIdentifier
+            if e.externalIdentifierType == oe.spdx30.ExternalIdentifierType.packageUrl
+        }
+        return package.software_packageUrl, purls
+
+    def test_download_purls_in_output_package(self):
+        """Test that the output package gets the PURLs of its downloads."""
+        package_purl, purls = self.get_package_purls()
+
+        own_purls = get_bb_var("SPDX_PACKAGE_URLS", "hello-rs").split()
+        self.assertEqual(package_purl, own_purls[0])
+        self.assertEqual(purls, set(own_purls) | self.HELLO_RS_DOWNLOAD_PURLS)
+
+    def test_download_purls_without_package_urls(self):
+        """Test that a download PURL does not become the package PURL."""
+        package_purl, purls = self.get_package_purls('SPDX_PACKAGE_URLS:pn-hello-rs = ""\n')
+
+        self.assertIsNone(package_purl)
+        self.assertEqual(purls, self.HELLO_RS_DOWNLOAD_PURLS)