Skip to content

Commit 14f699f

Browse files
committed
test filtering
Signed-off-by: Paul Horton <[email protected]>
1 parent b23df1f commit 14f699f

File tree

6 files changed

+224
-4
lines changed

6 files changed

+224
-4
lines changed

tests/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#
1515
# SPDX-License-Identifier: Apache-2.0
1616
# Copyright (c) OWASP Foundation. All Rights Reserved.
17-
17+
import re
1818
from os import getenv, path
1919
from os.path import join
2020
from typing import TYPE_CHECKING, Any, Generator, Iterable, List, Optional, TypeVar, Union
@@ -160,6 +160,19 @@ def _make_unique(self) -> str:
160160
}
161161

162162

163-
def mksname(purpose: Union[Any], sv: SchemaVersion, f: OutputFormat) -> str:
163+
_LIMIT_GET_BOM_BY_VERSION_REGEX = re.compile(r'^get_bom_(?P<sv>v(?P<major_version>1)_(?P<minor_version>[0-6]))?(.*)$')
164+
165+
def mksname(purpose: Union[Any], sv: SchemaVersion, f: OutputFormat) -> Optional[str]:
164166
purpose = purpose if isinstance(purpose, str) else purpose.__name__
167+
restrict_to_schema = _LIMIT_GET_BOM_BY_VERSION_REGEX.match(purpose)
168+
if restrict_to_schema:
169+
mg = restrict_to_schema.groupdict()
170+
if mg.get('sv') is not None:
171+
# Restrict only to the schema version in the purpose or greater
172+
restricted_to_sv = SchemaVersion.from_version(f'{mg.get("major_version")}.{mg.get("minor_version")}')
173+
if sv >= restricted_to_sv:
174+
return f'{purpose}-{sv.to_version()}.{_SNAME_EXT[f]}'
175+
else:
176+
return None
177+
165178
return f'{purpose}-{sv.to_version()}.{_SNAME_EXT[f]}'

tests/_data/models.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,11 @@ def get_component_crypto_asset_protocol_tls_v13(
301301
)
302302

303303

304-
def get_bom_v16_with_crypto() -> Bom:
305-
return _make_bom(components=[get_component_crypto_asset_protocol_tls_v13()])
304+
def get_bom_v1_6_with_crypto() -> Bom:
305+
c = get_component_crypto_asset_protocol_tls_v13()
306+
b = _make_bom(components=[c])
307+
b.register_dependency(c)
308+
return b
306309

307310

308311
def get_bom_with_component_setuptools_no_component_version() -> Bom:
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"components": [
3+
{
4+
"bom-ref": "26b1ce0f-bec6-4bfe-9db1-03b75a4ed1ec",
5+
"cryptoProperties": {
6+
"assetType": "protocol",
7+
"oid": "an-oid-here",
8+
"protocolProperties": {
9+
"cipherSuites": [
10+
{
11+
"identifiers": [
12+
"TLS_AES_128_CCM_8_SHA256"
13+
],
14+
"name": "TLS_AES_128_CCM_8_SHA256"
15+
},
16+
{
17+
"identifiers": [
18+
"TLS_AES_128_CCM_SHA256"
19+
],
20+
"name": "TLS_AES_128_CCM_SHA256"
21+
},
22+
{
23+
"identifiers": [
24+
"TLS_AES_128_GCM_SHA256"
25+
],
26+
"name": "TLS_AES_128_GCM_SHA256"
27+
},
28+
{
29+
"identifiers": [
30+
"TLS_AES_256_GCM_SHA384"
31+
],
32+
"name": "TLS_AES_256_GCM_SHA384"
33+
},
34+
{
35+
"identifiers": [
36+
"TLS_CHACHA20_POLY1305_SHA256"
37+
],
38+
"name": "TLS_CHACHA20_POLY1305_SHA256"
39+
}
40+
],
41+
"type": "tls",
42+
"version": "1.3"
43+
}
44+
},
45+
"name": "TLS",
46+
"tags": [
47+
"protocl",
48+
"tls"
49+
],
50+
"type": "cryptographic-asset",
51+
"version": "v1.3"
52+
}
53+
],
54+
"dependencies": [
55+
{
56+
"ref": "26b1ce0f-bec6-4bfe-9db1-03b75a4ed1ec"
57+
}
58+
],
59+
"metadata": {
60+
"timestamp": "2023-01-07T13:44:32.312678+00:00",
61+
"tools": [
62+
{
63+
"externalReferences": [
64+
{
65+
"type": "build-system",
66+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/actions"
67+
},
68+
{
69+
"type": "distribution",
70+
"url": "https://pypi.org/project/cyclonedx-python-lib/"
71+
},
72+
{
73+
"type": "documentation",
74+
"url": "https://cyclonedx-python-library.readthedocs.io/"
75+
},
76+
{
77+
"type": "issue-tracker",
78+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/issues"
79+
},
80+
{
81+
"type": "license",
82+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE"
83+
},
84+
{
85+
"type": "release-notes",
86+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md"
87+
},
88+
{
89+
"type": "vcs",
90+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib"
91+
},
92+
{
93+
"type": "website",
94+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/#readme"
95+
}
96+
],
97+
"name": "cyclonedx-python-lib",
98+
"vendor": "CycloneDX",
99+
"version": "TESTING"
100+
}
101+
]
102+
},
103+
"serialNumber": "urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac",
104+
"version": 1,
105+
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
106+
"bomFormat": "CycloneDX",
107+
"specVersion": "1.6"
108+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" ?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.6" serialNumber="urn:uuid:1441d33a-e0fc-45b5-af3b-61ee52a88bac" version="1">
3+
<metadata>
4+
<timestamp>2023-01-07T13:44:32.312678+00:00</timestamp>
5+
<tools>
6+
<tool>
7+
<vendor>CycloneDX</vendor>
8+
<name>cyclonedx-python-lib</name>
9+
<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>
36+
</tool>
37+
</tools>
38+
</metadata>
39+
<components>
40+
<component type="cryptographic-asset" bom-ref="26b1ce0f-bec6-4bfe-9db1-03b75a4ed1ec">
41+
<name>TLS</name>
42+
<version>v1.3</version>
43+
<cryptoProperties>
44+
<assetType>protocol</assetType>
45+
<protocolProperties>
46+
<type>tls</type>
47+
<version>1.3</version>
48+
<cipherSuites>
49+
<cipherSuite>
50+
<name>TLS_AES_128_CCM_8_SHA256</name>
51+
<identifiers>
52+
<identifier>TLS_AES_128_CCM_8_SHA256</identifier>
53+
</identifiers>
54+
</cipherSuite>
55+
<cipherSuite>
56+
<name>TLS_AES_128_CCM_SHA256</name>
57+
<identifiers>
58+
<identifier>TLS_AES_128_CCM_SHA256</identifier>
59+
</identifiers>
60+
</cipherSuite>
61+
<cipherSuite>
62+
<name>TLS_AES_128_GCM_SHA256</name>
63+
<identifiers>
64+
<identifier>TLS_AES_128_GCM_SHA256</identifier>
65+
</identifiers>
66+
</cipherSuite>
67+
<cipherSuite>
68+
<name>TLS_AES_256_GCM_SHA384</name>
69+
<identifiers>
70+
<identifier>TLS_AES_256_GCM_SHA384</identifier>
71+
</identifiers>
72+
</cipherSuite>
73+
<cipherSuite>
74+
<name>TLS_CHACHA20_POLY1305_SHA256</name>
75+
<identifiers>
76+
<identifier>TLS_CHACHA20_POLY1305_SHA256</identifier>
77+
</identifiers>
78+
</cipherSuite>
79+
</cipherSuites>
80+
</protocolProperties>
81+
<oid>an-oid-here</oid>
82+
</cryptoProperties>
83+
<tags>
84+
<tag>protocl</tag>
85+
<tag>tls</tag>
86+
</tags>
87+
</component>
88+
</components>
89+
<dependencies>
90+
<dependency ref="26b1ce0f-bec6-4bfe-9db1-03b75a4ed1ec"/>
91+
</dependencies>
92+
</bom>

tests/test_output_json.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def test_unsupported_schema_raises(self, sv: SchemaVersion) -> None:
5656
@patch('cyclonedx.model.ThisTool._version', 'TESTING')
5757
def test_valid(self, get_bom: Callable[[], Bom], sv: SchemaVersion, *_: Any, **__: Any) -> None:
5858
snapshot_name = mksname(get_bom, sv, OutputFormat.JSON)
59+
if snapshot_name is None:
60+
return
5961
bom = get_bom()
6062
json = BY_SCHEMA_VERSION[sv](bom).output_as_string(indent=2)
6163
try:

tests/test_output_xml.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class TestOutputXml(TestCase, SnapshotMixin):
4343
@patch('cyclonedx.model.ThisTool._version', 'TESTING')
4444
def test_valid(self, get_bom: Callable[[], Bom], sv: SchemaVersion, *_: Any, **__: Any) -> None:
4545
snapshot_name = mksname(get_bom, sv, OutputFormat.XML)
46+
if snapshot_name is None:
47+
return
4648
bom = get_bom()
4749
xml = BY_SCHEMA_VERSION[sv](bom).output_as_string(indent=2)
4850
try:

0 commit comments

Comments
 (0)