Repository navigation
Closed
Description
I've used this part of your code to validate user provided BOM files
import xmlschema # same as your used version
bom_schema = xmlschema.XMLSchema("http://cyclonedx.org/schema/bom/1.1")I've changed the version to 1.1 here and in my test code since I get this error when using 1.0:
File "/home/glozmantal/PycharmProjects/Android-iOS-Code-OSS-Report/venv/lib64/python3.8/site-packages/xmlschema/validators/schema.py", line 885, in get_schema
raise XMLSchemaKeyError('the namespace {!r} is not loaded'.format(namespace)) from None
xmlschema.exceptions.XMLSchemaKeyError: "the namespace 'http://cyclonedx.org/schema/bom/1.1' is not loaded"When I use
bom_schema.is_valid(bom.name): # I use pathlib so 'bom.name' is equivalent to 'bom' in your code.And when I try to validate this broken test bom.xml file that was created using the ORT tool which uses BOM schema 1.1 against "http://cyclonedx.org/schema/bom/1.1", I get a positive validation. I've changed the license text value, apart from distorting the XML format integrity for the validation test.
<?xml version="1.0" encoding="UTF-8"?>
<bom xmlns="http://cyclonedx.org/schema/bom/1.1" serialNumber="urn:uuid:1817d96f-20c1-41a6-b8fa-fdb16bdc97de" version="1">
<components>
<component type="library">
<group>androidx.annotation</group>
<name>annotation
<version>1.1.0</version>
<description>The Support Library is a static library that you can add to your Android application in order to use APIs that are either not available for older platform versions or utility APIs that aren't a part of the framework APIs.</description>
<scope>required</scope>
<hashes>
<hash alg="SHA-1">e3a6fb2f40e3a3842e6b7472628ba4ce416ea4c8</hash>
</hashes>
<licenses>
<license>
<id>Apache-2.0</id>
<text content-type="plain/text"><![CDATA[ TEST
LICENSE TEXT.
]]></text>
</license>
</licenses>
<purl>pkg:maven/androidx.annotation/[email protected]</purl>
</externalReferences>Metadata
Metadata
Assignees
Labels
No labels
Activity
coderpatros commentedon Mar 11, 2020
@CleanHit I wasn't able to reproduce this. I couldn't even parse that xml. Have you confirmed that
bom.nameis what you expect?And I suggest you do something like this...
That will read the schema url from the xml file. Saves you hard coding the schema version and should support validating BOMs of different versions without code changes.
CleanHit commentedon Mar 12, 2020
Thanks for pointing out the dynamic load of the schema URL. As it turns out I've made a little mistake.The
bom.namedoesn't do the trick if the file is not in the root folder of the project, so I had to usebomwhich is in my case the whole path with the file name.