[elbe-devel] [PATCH v5 6/7] elbepack: tests: cyclonedx: add reference test

Eduard Krein eduard.krein at linutronix.de
Mon Jul 1 17:01:18 CEST 2024


Add reference test for cyclonedx which compares the generated
sbom with a reference sample for verification.

Signed-off-by: Eduard Krein <eduard.krein at linutronix.de>
---
 .../tests/cyclonedx/cyclonedx_reference.json  | 22 +++++++++++++++++++
 .../tests/cyclonedx/test_cyclonedx_sbom.py    | 10 +++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 elbepack/tests/cyclonedx/cyclonedx_reference.json

diff --git a/elbepack/tests/cyclonedx/cyclonedx_reference.json b/elbepack/tests/cyclonedx/cyclonedx_reference.json
new file mode 100644
index 00000000..35147b14
--- /dev/null
+++ b/elbepack/tests/cyclonedx/cyclonedx_reference.json
@@ -0,0 +1,22 @@
+{
+  "bomFormat": "CycloneDX",
+  "specVersion": "1.6",
+  "serialNumber": "INVALID",
+  "version": 1,
+  "metadata": {
+    "timestamp": "INVALID",
+    "tools": [
+      {
+        "vendor": "Linutronix",
+        "name": "Elbe",
+        "version": "INVALID"
+      }
+    ],
+    "component": {
+      "type": "operating-system",
+      "name": "cyclonedx-example",
+      "version": "1",
+      "description": "example for generation of cyclonedx sboms"
+    }
+  }
+}
diff --git a/elbepack/tests/cyclonedx/test_cyclonedx_sbom.py b/elbepack/tests/cyclonedx/test_cyclonedx_sbom.py
index 7fb43c9c..4bd911d3 100644
--- a/elbepack/tests/cyclonedx/test_cyclonedx_sbom.py
+++ b/elbepack/tests/cyclonedx/test_cyclonedx_sbom.py
@@ -25,3 +25,13 @@ def test_schema():
     with here.joinpath('bom-1.6.schema.json').open() as f:
         bom_schema = json.load(f)
     jsonschema.validate(test_bom, bom_schema)
+
+
+def test_reference_data():
+    test_bom = generate_test_bom()
+    test_bom['metadata']['timestamp'] = 'INVALID'
+    test_bom['serialNumber'] = 'INVALID'
+    test_bom['metadata']['tools'][0]['version'] = 'INVALID'
+    with here.joinpath('cyclonedx_reference.json').open() as f:
+        reference_data = json.load(f)
+    assert test_bom == reference_data
-- 
2.39.2



More information about the elbe-devel mailing list