Skip to content

Commit a30629c

Browse files
committed
Fixed issues with invalid test structures for field enum
1 parent 2c0d5ba commit a30629c

15 files changed

+319
-48
lines changed

cyclonedx/exception/serialization.py

+9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ class SerializationOfUnsupportedComponentTypeException(CycloneDxSerializationExc
4444
"""
4545

4646

47+
class SerializationOfUnsupportedComponentIdentityEvidenceFieldException(CycloneDxSerializationException):
48+
"""
49+
Raised when attempting serializing/normalizing a :py:class:`cyclonedx.model.component.Component`
50+
to a :py:class:`cyclonedx.schema.schema.BaseSchemaVersion`
51+
which does not support that :py:class:`cyclonedx.model.component.ComponentIdentityEvidenceField`
52+
.
53+
"""
54+
55+
4756
class SerializationOfUnexpectedValueException(CycloneDxSerializationException, ValueError):
4857
"""
4958
Raised when attempting serializing/normalizing a type that is not expected there.

cyclonedx/model/component.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from ..exception.serialization import (
3939
CycloneDxDeserializationException,
4040
SerializationOfUnexpectedValueException,
41+
SerializationOfUnsupportedComponentIdentityEvidenceFieldException,
4142
SerializationOfUnsupportedComponentTypeException,
4243
)
4344
from ..schema.schema import (
@@ -237,10 +238,11 @@ class _ComponentIdentityEvidenceFieldSerializationHelper(serializable.helpers.Ba
237238
}
238239

239240
@classmethod
240-
def __normalize(cls, cs: ComponentIdentityEvidenceField, view: Type[serializable.ViewType]) -> Optional[str]:
241-
return cs.value \
242-
if cs in cls.__CASES.get(view, ()) \
243-
else None
241+
def __normalize(cls, cief: ComponentIdentityEvidenceField, view: Type[serializable.ViewType]) -> Optional[str]:
242+
if cief in cls.__CASES.get(view, ()):
243+
return cief.value
244+
raise SerializationOfUnsupportedComponentIdentityEvidenceFieldException(
245+
f'unsupported {cief!r} for view {view!r}')
244246

245247
@classmethod
246248
def json_normalize(cls, o: Any, *,
@@ -492,7 +494,7 @@ def confidence(self, confidence: Optional[float]) -> None:
492494
self._confidence = confidence
493495

494496
@property
495-
@serializable.type_mapping(ComponentIdentityEvidenceMethod)
497+
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'method')
496498
@serializable.xml_sequence(3)
497499
def methods(self) -> 'SortedSet[ComponentIdentityEvidenceMethod]':
498500
"""
@@ -572,7 +574,7 @@ def __init__(
572574
@property
573575
@serializable.view(SchemaVersion1Dot5)
574576
@serializable.view(SchemaVersion1Dot6)
575-
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'identity')
577+
@serializable.xml_array(serializable.XmlArraySerializationType.FLAT, 'identity')
576578
@serializable.xml_sequence(1)
577579
def identity(self) -> 'SortedSet[ComponentIdentityEvidence]':
578580
"""
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
<?xml version="1.0" ?>
22
<bom xmlns="http://cyclonedx.org/schema/bom/1.0" version="1">
3-
<components/>
3+
<components>
4+
<component type="library">
5+
<name>dummy</name>
6+
<version/>
7+
<modified>false</modified>
8+
</component>
9+
</components>
410
</bom>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
<?xml version="1.0" ?>
22
<bom xmlns="http://cyclonedx.org/schema/bom/1.1" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3-
<components/>
3+
<components>
4+
<component type="library" bom-ref="dummy">
5+
<name>dummy</name>
6+
<version/>
7+
</component>
8+
</components>
49
</bom>

tests/_data/snapshots/enum_ComponentIdentityEvidenceField-1.2.json.bin

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
{
2+
"components": [
3+
{
4+
"bom-ref": "dummy",
5+
"name": "dummy",
6+
"type": "library",
7+
"version": ""
8+
}
9+
],
10+
"dependencies": [
11+
{
12+
"ref": "dummy"
13+
}
14+
],
215
"metadata": {
316
"timestamp": "2023-01-07T13:44:32.312678+00:00",
417
"tools": [
@@ -14,4 +27,4 @@
1427
"$schema": "http://cyclonedx.org/schema/bom-1.2b.schema.json",
1528
"bomFormat": "CycloneDX",
1629
"specVersion": "1.2"
17-
}
30+
}

tests/_data/snapshots/enum_ComponentIdentityEvidenceField-1.2.xml.bin

+9
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@
1010
</tool>
1111
</tools>
1212
</metadata>
13+
<components>
14+
<component type="library" bom-ref="dummy">
15+
<name>dummy</name>
16+
<version/>
17+
</component>
18+
</components>
19+
<dependencies>
20+
<dependency ref="dummy"/>
21+
</dependencies>
1322
</bom>

tests/_data/snapshots/enum_ComponentIdentityEvidenceField-1.3.json.bin

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
{
2+
"components": [
3+
{
4+
"bom-ref": "dummy",
5+
"evidence": {
6+
"copyright": [
7+
{
8+
"text": "Dummy"
9+
}
10+
]
11+
},
12+
"name": "dummy",
13+
"type": "library",
14+
"version": ""
15+
}
16+
],
17+
"dependencies": [
18+
{
19+
"ref": "dummy"
20+
}
21+
],
222
"metadata": {
323
"timestamp": "2023-01-07T13:44:32.312678+00:00",
424
"tools": [
@@ -14,4 +34,4 @@
1434
"$schema": "http://cyclonedx.org/schema/bom-1.3a.schema.json",
1535
"bomFormat": "CycloneDX",
1636
"specVersion": "1.3"
17-
}
37+
}

tests/_data/snapshots/enum_ComponentIdentityEvidenceField-1.3.xml.bin

+14
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,18 @@
1010
</tool>
1111
</tools>
1212
</metadata>
13+
<components>
14+
<component type="library" bom-ref="dummy">
15+
<name>dummy</name>
16+
<version/>
17+
<evidence>
18+
<copyright>
19+
<text>Dummy</text>
20+
</copyright>
21+
</evidence>
22+
</component>
23+
</components>
24+
<dependencies>
25+
<dependency ref="dummy"/>
26+
</dependencies>
1327
</bom>

tests/_data/snapshots/enum_ComponentIdentityEvidenceField-1.4.json.bin

+54-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,61 @@
11
{
2+
"components": [
3+
{
4+
"bom-ref": "dummy",
5+
"evidence": {
6+
"copyright": [
7+
{
8+
"text": "Dummy"
9+
}
10+
]
11+
},
12+
"name": "dummy",
13+
"type": "library"
14+
}
15+
],
16+
"dependencies": [
17+
{
18+
"ref": "dummy"
19+
}
20+
],
221
"metadata": {
322
"timestamp": "2023-01-07T13:44:32.312678+00:00",
423
"tools": [
524
{
25+
"externalReferences": [
26+
{
27+
"type": "build-system",
28+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/actions"
29+
},
30+
{
31+
"type": "distribution",
32+
"url": "https://pypi.org/project/cyclonedx-python-lib/"
33+
},
34+
{
35+
"type": "documentation",
36+
"url": "https://cyclonedx-python-library.readthedocs.io/"
37+
},
38+
{
39+
"type": "issue-tracker",
40+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/issues"
41+
},
42+
{
43+
"type": "license",
44+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE"
45+
},
46+
{
47+
"type": "release-notes",
48+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md"
49+
},
50+
{
51+
"type": "vcs",
52+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib"
53+
},
54+
{
55+
"type": "website",
56+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/#readme"
57+
}
58+
],
659
"name": "cyclonedx-python-lib",
760
"vendor": "CycloneDX",
861
"version": "TESTING"
@@ -14,4 +67,4 @@
1467
"$schema": "http://cyclonedx.org/schema/bom-1.4.schema.json",
1568
"bomFormat": "CycloneDX",
1669
"specVersion": "1.4"
17-
}
70+
}

tests/_data/snapshots/enum_ComponentIdentityEvidenceField-1.4.xml.bin

+39-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<?xml version="1.0" ?>
32
<bom xmlns="http://cyclonedx.org/schema/bom/1.4" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
43
<metadata>
@@ -8,7 +7,46 @@
87
<vendor>CycloneDX</vendor>
98
<name>cyclonedx-python-lib</name>
109
<version>TESTING</version>
10+
<externalReferences>
11+
<reference type="build-system">
12+
<url>https://github.com/CycloneDX/cyclonedx-python-lib/actions</url>
13+
</reference>
14+
<reference type="distribution">
15+
<url>https://pypi.org/project/cyclonedx-python-lib/</url>
16+
</reference>
17+
<reference type="documentation">
18+
<url>https://cyclonedx-python-library.readthedocs.io/</url>
19+
</reference>
20+
<reference type="issue-tracker">
21+
<url>https://github.com/CycloneDX/cyclonedx-python-lib/issues</url>
22+
</reference>
23+
<reference type="license">
24+
<url>https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE</url>
25+
</reference>
26+
<reference type="release-notes">
27+
<url>https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md</url>
28+
</reference>
29+
<reference type="vcs">
30+
<url>https://github.com/CycloneDX/cyclonedx-python-lib</url>
31+
</reference>
32+
<reference type="website">
33+
<url>https://github.com/CycloneDX/cyclonedx-python-lib/#readme</url>
34+
</reference>
35+
</externalReferences>
1136
</tool>
1237
</tools>
1338
</metadata>
39+
<components>
40+
<component type="library" bom-ref="dummy">
41+
<name>dummy</name>
42+
<evidence>
43+
<copyright>
44+
<text>Dummy</text>
45+
</copyright>
46+
</evidence>
47+
</component>
48+
</components>
49+
<dependencies>
50+
<dependency ref="dummy"/>
51+
</dependencies>
1452
</bom>

tests/_data/snapshots/enum_ComponentIdentityEvidenceField-1.5.json.bin

+14-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
"components": [
33
{
44
"bom-ref": "dummy",
5-
"name": "dummy",
6-
"type": "application",
75
"evidence": {
8-
"identity": {
9-
"field": "group"
10-
}
11-
}
6+
"copyright": [
7+
{
8+
"text": "Dummy"
9+
}
10+
]
11+
},
12+
"name": "dummy",
13+
"type": "library"
14+
}
15+
],
16+
"dependencies": [
17+
{
18+
"ref": "dummy"
1219
}
1320
],
1421
"metadata": {
@@ -70,4 +77,4 @@
7077
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
7178
"bomFormat": "CycloneDX",
7279
"specVersion": "1.5"
73-
}
80+
}

tests/_data/snapshots/enum_ComponentIdentityEvidenceField-1.5.xml.bin

+7-4
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@
3737
</tools>
3838
</metadata>
3939
<components>
40-
<component type="application" bom-ref="scoped">
40+
<component type="library" bom-ref="dummy">
4141
<name>dummy</name>
4242
<evidence>
43-
<identity>
44-
<field>group</field>
45-
</identity>
43+
<copyright>
44+
<text>Dummy</text>
45+
</copyright>
4646
</evidence>
4747
</component>
4848
</components>
49+
<dependencies>
50+
<dependency ref="dummy"/>
51+
</dependencies>
4952
<properties>
5053
<property name="key1">val1</property>
5154
<property name="key2">val2</property>

0 commit comments

Comments
 (0)