Skip to content

Commit

Permalink
work to get deserialization tests passing
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Horton <paul.horton@owasp.org>
  • Loading branch information
madpah committed Apr 3, 2024
1 parent af7b92b commit fdece59
Show file tree
Hide file tree
Showing 76 changed files with 5,804 additions and 24 deletions.
3 changes: 3 additions & 0 deletions cyclonedx/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class _HashTypeRepositorySerializationHelper(serializable.helpers.BaseHelper):
__CASES[SchemaVersion1Dot3] = __CASES[SchemaVersion1Dot2]
__CASES[SchemaVersion1Dot4] = __CASES[SchemaVersion1Dot3]
__CASES[SchemaVersion1Dot5] = __CASES[SchemaVersion1Dot4]
__CASES[SchemaVersion1Dot6] = __CASES[SchemaVersion1Dot5]

@classmethod
def __prep(cls, hts: Iterable['HashType'], view: Type[serializable.ViewType]) -> Generator['HashType', None, None]:
Expand Down Expand Up @@ -793,6 +794,7 @@ def type(self, type: ExternalReferenceType) -> None:
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.type_mapping(_HashTypeRepositorySerializationHelper)
def hashes(self) -> 'SortedSet[HashType]':
"""
Expand Down Expand Up @@ -1325,6 +1327,7 @@ def hashes(self, hashes: Iterable[HashType]) -> None:
@property
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'reference')
@serializable.xml_sequence(5)
def external_references(self) -> 'SortedSet[ExternalReference]':
Expand Down
5 changes: 5 additions & 0 deletions cyclonedx/model/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def component(self, component: Component) -> None:
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_sequence(6)
def manufacture(self) -> Optional[OrganizationalEntity]:
"""
Expand Down Expand Up @@ -402,6 +403,7 @@ def components(self, components: Iterable[Component]) -> None:
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'service')
@serializable.xml_sequence(3)
def services(self) -> 'SortedSet[Service]':
Expand All @@ -423,6 +425,7 @@ def services(self, services: Iterable[Service]) -> None:
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'reference')
@serializable.xml_sequence(4)
def external_references(self) -> 'SortedSet[ExternalReference]':
Expand All @@ -443,6 +446,7 @@ def external_references(self, external_references: Iterable[ExternalReference])
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'dependency')
@serializable.xml_sequence(5)
def dependencies(self) -> 'SortedSet[Dependency]':
Expand Down Expand Up @@ -481,6 +485,7 @@ def dependencies(self, dependencies: Iterable[Dependency]) -> None:
@property
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'vulnerability')
@serializable.xml_sequence(8)
def vulnerabilities(self) -> 'SortedSet[Vulnerability]':
Expand Down
34 changes: 22 additions & 12 deletions cyclonedx/model/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class _ComponentScopeSerializationHelper(serializable.helpers.BaseHelper):
__CASES[SchemaVersion1Dot3] = __CASES[SchemaVersion1Dot2]
__CASES[SchemaVersion1Dot4] = __CASES[SchemaVersion1Dot3]
__CASES[SchemaVersion1Dot5] = __CASES[SchemaVersion1Dot4]
__CASES[SchemaVersion1Dot6] = __CASES[SchemaVersion1Dot5]

@classmethod
def __normalize(cls, cs: ComponentScope, view: Type[serializable.ViewType]) -> Optional[str]:
Expand Down Expand Up @@ -689,6 +690,7 @@ def commits(self, commits: Iterable[Commit]) -> None:
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'patch')
@serializable.xml_sequence(5)
def patches(self) -> 'SortedSet[Patch]':
Expand Down Expand Up @@ -880,18 +882,18 @@ class OmniBorId(serializable.helpers.BaseHelper):

_VALID_OMNIBOR_ID_REGEX = re.compile(r'^gitoid:(blob|tree|commit|tag):sha(1|256):([a-z0-9]+)$')

def __init__(self, omnibor_id: str) -> None:
if OmniBorId._VALID_OMNIBOR_ID_REGEX.match(omnibor_id) is None:
def __init__(self, id: str) -> None:
if OmniBorId._VALID_OMNIBOR_ID_REGEX.match(id) is None:
raise InvalidOmniBorIdException(
f'Supplied value "{omnibor_id} does not meet format specification.'
f'Supplied value "{id} does not meet format specification.'
)
self._omnibor_id = omnibor_id
self._id = id

@property
@serializable.json_name('.')
@serializable.xml_name('.')
def omnibor_id(self) -> str:
return self._omnibor_id
def id(self) -> str:
return self._id

@classmethod
def serialize(cls, o: Any) -> str:
Expand All @@ -903,7 +905,7 @@ def serialize(cls, o: Any) -> str:
@classmethod
def deserialize(cls, o: Any) -> 'OmniBorId':
try:
return OmniBorId(omnibor_id=str(o))
return OmniBorId(id=str(o))
except ValueError as err:
raise CycloneDxDeserializationException(
f'OmniBorId string supplied does not parse: {o!r}'
Expand All @@ -916,17 +918,17 @@ def __eq__(self, other: Any) -> bool:

def __lt__(self, other: Any) -> bool:
if isinstance(other, OmniBorId):
return self._omnibor_id < other._omnibor_id
return self._id < other._id
return NotImplemented

def __hash__(self) -> int:
return hash(self._omnibor_id)
return hash(self._id)

def __repr__(self) -> str:
return f'<OmniBorId {self._omnibor_id}>'
return f'<OmniBorId {self._id}>'

def __str__(self) -> str:
return self._omnibor_id
return self._id


@serializable.serializable_class
Expand Down Expand Up @@ -1145,6 +1147,7 @@ def authors(self, authors: Iterable[OrganizationalContact]) -> None:
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6) # todo: this is deprecated in v1.6?
@serializable.xml_sequence(4)
def author(self) -> Optional[str]:
"""
Expand Down Expand Up @@ -1289,6 +1292,7 @@ def hashes(self, hashes: Iterable[HashType]) -> None:
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.type_mapping(LicenseRepositoryHelper)
@serializable.xml_sequence(12)
def licenses(self) -> LicenseRepository:
Expand Down Expand Up @@ -1399,6 +1403,7 @@ def omnibor_ids(self, omnibor_ids: Iterable[OmniBorId]) -> None:
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_sequence(18)
def swid(self) -> Optional[Swid]:
"""
Expand All @@ -1414,7 +1419,7 @@ def swid(self, swid: Optional[Swid]) -> None:
self._swid = swid

@property
@serializable.view(SchemaVersion1Dot0)
@serializable.view(SchemaVersion1Dot0) # todo: Deprecated in v1.3
@serializable.xml_sequence(19)
def modified(self) -> bool:
return self._modified
Expand All @@ -1429,6 +1434,7 @@ def modified(self, modified: bool) -> None:
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_sequence(20)
def pedigree(self) -> Optional[Pedigree]:
"""
Expand All @@ -1450,6 +1456,7 @@ def pedigree(self, pedigree: Optional[Pedigree]) -> None:
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'reference')
@serializable.xml_sequence(21)
def external_references(self) -> 'SortedSet[ExternalReference]':
Expand All @@ -1470,6 +1477,7 @@ def external_references(self, external_references: Iterable[ExternalReference])
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'property')
@serializable.xml_sequence(22)
def properties(self) -> 'SortedSet[Property]':
Expand Down Expand Up @@ -1508,6 +1516,7 @@ def components(self, components: Iterable['Component']) -> None:
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_sequence(24)
def evidence(self) -> Optional[ComponentEvidence]:
"""
Expand All @@ -1525,6 +1534,7 @@ def evidence(self, evidence: Optional[ComponentEvidence]) -> None:
@property
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_sequence(25)
def release_notes(self) -> Optional[ReleaseNotes]:
"""
Expand Down
6 changes: 4 additions & 2 deletions cyclonedx/model/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from cyclonedx.serialization import BomRefHelper, LicenseRepositoryHelper

from .._internal.compare import ComparableTuple as _ComparableTuple
from ..schema.schema import SchemaVersion1Dot3, SchemaVersion1Dot4, SchemaVersion1Dot5
from ..schema.schema import SchemaVersion1Dot3, SchemaVersion1Dot4, SchemaVersion1Dot5, SchemaVersion1Dot6
from . import DataClassification, ExternalReference, OrganizationalEntity, Property, XsUri
from .bom_ref import BomRef
from .dependency import Dependable
Expand Down Expand Up @@ -98,7 +98,7 @@ def bom_ref(self) -> BomRef:
@serializable.xml_sequence(1)
def provider(self) -> Optional[OrganizationalEntity]:
"""
Get the The organization that provides the service.
Get the organization that provides the service.
Returns:
`OrganizationalEntity` if set else `None`
Expand Down Expand Up @@ -289,6 +289,7 @@ def external_references(self, external_references: Iterable[ExternalReference])
@serializable.view(SchemaVersion1Dot3)
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_array(serializable.XmlArraySerializationType.NESTED, 'property')
@serializable.xml_sequence(13)
def properties(self) -> 'SortedSet[Property]':
Expand Down Expand Up @@ -328,6 +329,7 @@ def services(self, services: Iterable['Service']) -> None:
@property
@serializable.view(SchemaVersion1Dot4)
@serializable.view(SchemaVersion1Dot5)
@serializable.view(SchemaVersion1Dot6)
@serializable.xml_sequence(15)
def release_notes(self) -> Optional[ReleaseNotes]:
"""
Expand Down
5 changes: 3 additions & 2 deletions cyclonedx/model/vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

from .._internal.compare import ComparableTuple as _ComparableTuple
from ..exception.model import MutuallyExclusivePropertiesException, NoPropertiesProvidedException
from ..schema.schema import SchemaVersion1Dot4, SchemaVersion1Dot5
from ..schema.schema import SchemaVersion1Dot4, SchemaVersion1Dot5, SchemaVersion1Dot6
from ..serialization import BomRefHelper
from . import OrganizationalContact, OrganizationalEntity, Property, Tool, XsUri
from .bom_ref import BomRef
Expand Down Expand Up @@ -605,6 +605,7 @@ class _VulnerabilityScoreSourceSerializationHelper(serializable.helpers.BaseHelp
VulnerabilityScoreSource.CVSS_V4,
VulnerabilityScoreSource.SSVC
}
__CASES[SchemaVersion1Dot6] = __CASES[SchemaVersion1Dot5]

@classmethod
def __normalize(cls, vss: VulnerabilityScoreSource, view: Type[serializable.ViewType]) -> str:
Expand Down Expand Up @@ -697,7 +698,7 @@ class VulnerabilityRating:
.. warning::
As part of implementing support for CycloneDX schema version 1.4, the three score types defined in the schema
externsion used prior to 1.4 have been deprecated. The deprecated `score_base` should loosely be equivalent to
extension used prior to 1.4 have been deprecated. The deprecated `score_base` should loosely be equivalent to
the new `score` in 1.4 schema. Both `score_impact` and `score_exploitability` are deprecated and removed as
they are redundant if you have the vector (the vector allows you to calculate the scores).
"""
Expand Down
48 changes: 48 additions & 0 deletions tests/_data/snapshots/enum_ComponentScope-1.6.json.bin
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,71 @@
{
"bom-ref": "scoped-EXCLUDED",
"name": "dummy-EXCLUDED",
"scope": "excluded",
"type": "library"
},
{
"bom-ref": "scoped-OPTIONAL",
"name": "dummy-OPTIONAL",
"scope": "optional",
"type": "library"
},
{
"bom-ref": "scoped-REQUIRED",
"name": "dummy-REQUIRED",
"scope": "required",
"type": "library"
}
],
"dependencies": [
{
"ref": "scoped-EXCLUDED"
},
{
"ref": "scoped-OPTIONAL"
},
{
"ref": "scoped-REQUIRED"
}
],
"metadata": {
"timestamp": "2023-01-07T13:44:32.312678+00:00",
"tools": [
{
"externalReferences": [
{
"type": "build-system",
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/actions"
},
{
"type": "distribution",
"url": "https://pypi.org/project/cyclonedx-python-lib/"
},
{
"type": "documentation",
"url": "https://cyclonedx-python-library.readthedocs.io/"
},
{
"type": "issue-tracker",
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/issues"
},
{
"type": "license",
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE"
},
{
"type": "release-notes",
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md"
},
{
"type": "vcs",
"url": "https://github.com/CycloneDX/cyclonedx-python-lib"
},
{
"type": "website",
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/#readme"
}
],
"name": "cyclonedx-python-lib",
"vendor": "CycloneDX",
"version": "TESTING"
Expand Down
34 changes: 34 additions & 0 deletions tests/_data/snapshots/enum_ComponentScope-1.6.xml.bin
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,52 @@
<vendor>CycloneDX</vendor>
<name>cyclonedx-python-lib</name>
<version>TESTING</version>
<externalReferences>
<reference type="build-system">
<url>https://github.com/CycloneDX/cyclonedx-python-lib/actions</url>
</reference>
<reference type="distribution">
<url>https://pypi.org/project/cyclonedx-python-lib/</url>
</reference>
<reference type="documentation">
<url>https://cyclonedx-python-library.readthedocs.io/</url>
</reference>
<reference type="issue-tracker">
<url>https://github.com/CycloneDX/cyclonedx-python-lib/issues</url>
</reference>
<reference type="license">
<url>https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE</url>
</reference>
<reference type="release-notes">
<url>https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md</url>
</reference>
<reference type="vcs">
<url>https://github.com/CycloneDX/cyclonedx-python-lib</url>
</reference>
<reference type="website">
<url>https://github.com/CycloneDX/cyclonedx-python-lib/#readme</url>
</reference>
</externalReferences>
</tool>
</tools>
</metadata>
<components>
<component type="library" bom-ref="scoped-EXCLUDED">
<name>dummy-EXCLUDED</name>
<scope>excluded</scope>
</component>
<component type="library" bom-ref="scoped-OPTIONAL">
<name>dummy-OPTIONAL</name>
<scope>optional</scope>
</component>
<component type="library" bom-ref="scoped-REQUIRED">
<name>dummy-REQUIRED</name>
<scope>required</scope>
</component>
</components>
<dependencies>
<dependency ref="scoped-EXCLUDED"/>
<dependency ref="scoped-OPTIONAL"/>
<dependency ref="scoped-REQUIRED"/>
</dependencies>
</bom>
Loading

0 comments on commit fdece59

Please sign in to comment.