1515 update_sbom ,
1616 verify_sbom ,
1717)
18- from mobster .cmd .augment .handlers import get_purl_digest
18+ from mobster .cmd .augment .handlers import CycloneDXVersion1 , get_purl_digest
1919from mobster .error import SBOMError , SBOMVerificationError
2020from mobster .image import Image , IndexImage
2121from mobster .oci .artifact import SBOM , Provenance02
2222from mobster .oci .cosign import Cosign
2323from mobster .release import Component , Snapshot
24+ from mobster .sbom import cyclonedx
25+ from tests .conftest import assert_spdx_sbom
2426
2527TESTDATA_PATH = Path (__file__ ).parent .parent .joinpath ("data/component" )
2628
@@ -158,7 +160,7 @@ async def test_augment_execute_singlearch(
158160 expected = prepare_sbom (reference ).doc
159161
160162 assert len (cmd .sboms ) == 1
161- assert cmd .sboms [0 ].doc == expected
163+ assert_spdx_sbom ( cmd .sboms [0 ].doc , expected )
162164
163165 @pytest .mark .asyncio
164166 async def test_augment_execute_multiarch (
@@ -206,8 +208,9 @@ async def test_augment_execute_multiarch(
206208 ]
207209
208210 assert len (expected_sboms ) == len (cmd .sboms )
209- for expected , actual in zip (cmd .sboms , expected_sboms , strict = False ):
210- assert expected .doc == actual .doc
211+
212+ for actual , expected in zip (cmd .sboms , expected_sboms , strict = False ):
213+ assert_spdx_sbom (actual .doc , expected .doc )
211214
212215 @pytest .mark .asyncio
213216 async def test_augment_execute_cdx_singlearch (
@@ -404,6 +407,14 @@ def verify_component_updated(
404407 if verify_tags :
405408 VerifyCycloneDX .verify_tags (kflx_component , cdx_component )
406409
410+ @staticmethod
411+ def verify_mobster_version_info (sbom : Any ) -> None :
412+ """
413+ Verify that the mobster version info is added to the SBOM metadata.
414+ """
415+ components = sbom ["metadata" ]["tools" ]["components" ]
416+ assert cyclonedx .get_tools_component_dict () in components
417+
407418 @staticmethod
408419 def verify_components_updated (snapshot : Snapshot , sbom : Any ) -> None :
409420 """
@@ -413,6 +424,7 @@ def verify_components_updated(snapshot: Snapshot, sbom: Any) -> None:
413424 VerifyCycloneDX .verify_component_updated (
414425 snapshot , sbom ["metadata" ]["component" ], verify_tags = False
415426 )
427+ VerifyCycloneDX .verify_mobster_version_info (sbom )
416428
417429 for component in sbom .get ("components" , []):
418430 VerifyCycloneDX .verify_component_updated (
@@ -435,3 +447,12 @@ def test_get_purl_digest(purl_str: str, expected: str | BaseException) -> None:
435447 else :
436448 with pytest .raises (expected ): # type: ignore
437449 get_purl_digest (purl_str )
450+
451+
452+ def test_cdx_augment_metadata_tools_components_empty_metadata () -> None :
453+ metadata : dict [str , Any ] = {}
454+ CycloneDXVersion1 ()._augment_metadata_tools_components (metadata )
455+
456+ assert "tools" in metadata
457+ assert "components" in metadata ["tools" ]
458+ assert len (metadata ["tools" ]["components" ]) == 1
0 commit comments