Replies: 3 comments
-
The problem is a lot more clear when merging multiple files, as it seems to compound in some manner. >>> with open('out2.json', mode="r") as testfile:
... json_bom = load(testfile)
...
>>> loaded_bom2 = Bom.from_json(json_bom)
>>>
>>> loaded_bom.metadata.component
<Component bom-ref=<BomRef 'root' id=140246182363600>, group=None, name=test, version=None, type=ComponentType.APPLICATION>
>>> loaded_bom2.metadata.component
<Component bom-ref=<BomRef 'root' id=140246180662288>, group=None, name=test2, version=None, type=ComponentType.APPLICATION>
>>>
>>> loaded_bom.metadata.component == loaded_bom2.metadata.component
False
>>> loaded_bom.metadata.component.bom_ref == loaded_bom2.metadata.component.bom_ref
True
>>>
>>> bom.components.add(loaded_bom2.metadata.component)
>>> bom.register_dependency(root_component, [loaded_bom2.metadata.component])
>>> bom.components |= loaded_bom2.components
>>> bom.dependencies |= loaded_bom2.dependencies
>>> bom.validate()
True
>>>
>>> len(bom.components)
10
>>> len(bom.dependencies)
12 This provides the following [
{"ref": "root", "dependsOn": ["BomRef.19783006151644178.9868708899859131"]},
{"ref": "root", "dependsOn": ["test11", "test21"]},
{"ref": "root", "dependsOn": ["test411", "test421"]},
{"ref": "test11", "dependsOn": ["test12"]},
{"ref": "test12"},
{"ref": "test21", "dependsOn": ["test22"]},
{"ref": "test22"},
{"ref": "test411", "dependsOn": ["test412"]},
{"ref": "test412"},
{"ref": "test421", "dependsOn": ["test422"]},
{"ref": "test422"}
] Because the first dependency object is the Note that the root >>> for dep in bom.dependencies:
... print(dep)
...
<Dependency ref=<BomRef 'root' id=140246198533136>, targets=1>
<Dependency ref=<BomRef 'root' id=140246182437328>, targets=2>
<Dependency ref=<BomRef 'root' id=140246180673744>, targets=2>
<Dependency ref=<BomRef 'test11' id=140246182406736>, targets=1>
<Dependency ref=<BomRef 'test12' id=140246182363664>, targets=0>
<Dependency ref=<BomRef 'test21' id=140246182440080>, targets=1>
<Dependency ref=<BomRef 'test22' id=140246182376016>, targets=0>
<Dependency ref=<BomRef 'test411' id=140246180704336>, targets=1>
<Dependency ref=<BomRef 'test412' id=140246180662352>, targets=0>
<Dependency ref=<BomRef 'test421' id=140246180721232>, targets=1>
<Dependency ref=<BomRef 'test422' id=140246180673616>, targets=0>
>>> bom.dependencies[0]._dependencies[0]._ref._value
'root' |
Beta Was this translation helpful? Give feedback.
-
Are you aware, that per CycloneDX specification, Bom-refs must be unique per document? Furthermore, since you are struggling with merging again, you maybe want to try out https://github.com/CycloneDX/cyclonedx-cli and read CycloneDX/specification#320 |
Beta Was this translation helpful? Give feedback.
-
Yes, I agree. The problem arises with merging of multiple documents, which are all valid on their own, but may contain duplicates. The examples above show that this library is not correctly assigning unique values, and doesn't throw warning/exception. However, every call to |
Beta Was this translation helpful? Give feedback.
-
NB: this is an extension of #540 and #677
Given the testdata in #677, set up a test for #540 but with clashing
bom_ref
s and unique names instead:Note that the Bom says it is valid, while it is actually not - although this is not apparent at a glance.
When outputting to json (e.g. with the reported
JsonV1Dot5
),dependencies
is shown to be as follows:This is actually invalid and would not validate when dumped to file and re-read by the library
Beta Was this translation helpful? Give feedback.
All reactions