Skip to content

Commit 100dd51

Browse files
committed
complete tests in XML for #155
Signed-off-by: Paul Horton <[email protected]>
1 parent d2f8ebe commit 100dd51

File tree

7 files changed

+357
-24
lines changed

7 files changed

+357
-24
lines changed

cyclonedx/output/schema.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ def component_supports_swid(self) -> bool:
7777
def component_supports_pedigree(self) -> bool:
7878
return True
7979

80+
def pedigree_supports_patches(self) -> bool:
81+
return True
82+
8083
def component_supports_external_references(self) -> bool:
8184
return True
8285

@@ -184,6 +187,9 @@ def bom_supports_services(self) -> bool:
184187
def services_supports_properties(self) -> bool:
185188
return False
186189

190+
def pedigree_supports_patches(self) -> bool:
191+
return False
192+
187193
def services_supports_release_notes(self) -> bool:
188194
return False
189195

cyclonedx/output/xml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def _add_component_element(self, component: Component) -> ElementTree.Element:
267267
))
268268
if commit.message:
269269
ElementTree.SubElement(commit_element, 'message').text = commit.message
270-
if component.pedigree.patches:
270+
if self.pedigree_supports_patches() and component.pedigree.patches:
271271
patches_element = ElementTree.SubElement(pedigree_element, 'patches')
272272
for patch in component.pedigree.patches:
273273
patches_element.append(Xml.add_patch_element(patch=patch))
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.0" version="1">
3+
<components>
4+
<component type="library">
5+
<name>setuptools</name>
6+
<version>50.3.2</version>
7+
<cpe>cpe:2.3:a:python:setuptools:50.3.2:*:*:*:*:*:*:*</cpe>
8+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
9+
<modified>false</modified>
10+
</component>
11+
</components>
12+
</bom>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.1" version="1">
3+
<components>
4+
<component type="library" bom-ref="pkg:pypi/[email protected]?extension=tar.gz">
5+
<name>setuptools</name>
6+
<version>50.3.2</version>
7+
<licenses>
8+
<expression>MIT License</expression>
9+
</licenses>
10+
<cpe>cpe:2.3:a:python:setuptools:50.3.2:*:*:*:*:*:*:*</cpe>
11+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
12+
<pedigree>
13+
<ancestors>
14+
<component type="library" bom-ref="ccc8d7ee-4b9c-4750-aee0-a72585152291">
15+
<name>setuptools</name>
16+
<version>50.3.2</version>
17+
<licenses>
18+
<expression>MIT License</expression>
19+
</licenses>
20+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
21+
</component>
22+
<component type="library" bom-ref="8a3893b3-9923-4adb-a1d3-47456636ba0a">
23+
<name>setuptools</name>
24+
<version />
25+
<licenses>
26+
<expression>MIT License</expression>
27+
</licenses>
28+
<purl>pkg:pypi/setuptools?extension=tar.gz</purl>
29+
</component>
30+
</ancestors>
31+
<descendants>
32+
<component type="library" bom-ref="28b2d8ce-def0-446f-a221-58dee0b44acc">
33+
<name>setuptools</name>
34+
<version />
35+
<licenses>
36+
<expression>MIT License</expression>
37+
</licenses>
38+
<purl>pkg:pypi/setuptools?extension=tar.gz</purl>
39+
</component>
40+
<component type="library" bom-ref="555ca729-93c6-48f3-956e-bdaa4a2f0bfa">
41+
<name>toml</name>
42+
<version>0.10.2</version>
43+
<hashes>
44+
<hash alg="SHA-256">806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b</hash>
45+
</hashes>
46+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
47+
<externalReferences>
48+
<reference type="distribution">
49+
<url>https://cyclonedx.org</url>
50+
<comment>No comment</comment>
51+
</reference>
52+
</externalReferences>
53+
</component>
54+
</descendants>
55+
<variants>
56+
<component type="library" bom-ref="e7abdcca-5ba2-4f29-b2cf-b1e1ef788e66">
57+
<name>toml</name>
58+
<version>0.10.2</version>
59+
<hashes>
60+
<hash alg="SHA-256">806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b</hash>
61+
</hashes>
62+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
63+
<externalReferences>
64+
<reference type="distribution">
65+
<url>https://cyclonedx.org</url>
66+
<comment>No comment</comment>
67+
</reference>
68+
</externalReferences>
69+
</component>
70+
<component type="library" bom-ref="ded1d73e-1fca-4302-b520-f1bc53979958">
71+
<name>setuptools</name>
72+
<version>50.3.2</version>
73+
<licenses>
74+
<expression>MIT License</expression>
75+
</licenses>
76+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
77+
</component>
78+
</variants>
79+
<commits>
80+
<commit>
81+
<uid>a-random-uid</uid>
82+
<message>A commit message</message>
83+
</commit>
84+
</commits>
85+
<notes>Some notes here please</notes>
86+
</pedigree>
87+
</component>
88+
</components>
89+
</bom>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.2" version="1">
3+
<metadata>
4+
<timestamp>2021-09-01T10:50:42.051979+00:00</timestamp>
5+
<tools>
6+
<tool>
7+
<vendor>CycloneDX</vendor>
8+
<name>cyclonedx-python-lib</name>
9+
<version>VERSION</version>
10+
</tool>
11+
</tools>
12+
</metadata>
13+
<components>
14+
<component type="library" bom-ref="pkg:pypi/[email protected]?extension=tar.gz">
15+
<author>Test Author</author>
16+
<name>setuptools</name>
17+
<version>50.3.2</version>
18+
<licenses>
19+
<expression>MIT License</expression>
20+
</licenses>
21+
<cpe>cpe:2.3:a:python:setuptools:50.3.2:*:*:*:*:*:*:*</cpe>
22+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
23+
<swid tagId="swidgen-242eb18a-503e-ca37-393b-cf156ef09691_9.1.1" name="Test Application" version="3.4.5">
24+
<text content-type="text/xml" encoding="base64">PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiID8+CjxTb2Z0d2FyZUlkZW50aXR5IHhtbDpsYW5nPSJFTiIgbmFtZT0iQWNtZSBBcHBsaWNhdGlvbiIgdmVyc2lvbj0iOS4xLjEiIAogdmVyc2lvblNjaGVtZT0ibXVsdGlwYXJ0bnVtZXJpYyIgCiB0YWdJZD0ic3dpZGdlbi1iNTk1MWFjOS00MmMwLWYzODItM2YxZS1iYzdhMmE0NDk3Y2JfOS4xLjEiIAogeG1sbnM9Imh0dHA6Ly9zdGFuZGFyZHMuaXNvLm9yZy9pc28vMTk3NzAvLTIvMjAxNS9zY2hlbWEueHNkIj4gCiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiAKIHhzaTpzY2hlbWFMb2NhdGlvbj0iaHR0cDovL3N0YW5kYXJkcy5pc28ub3JnL2lzby8xOTc3MC8tMi8yMDE1LWN1cnJlbnQvc2NoZW1hLnhzZCBzY2hlbWEueHNkIiA+CiAgPE1ldGEgZ2VuZXJhdG9yPSJTV0lEIFRhZyBPbmxpbmUgR2VuZXJhdG9yIHYwLjEiIC8+IAogIDxFbnRpdHkgbmFtZT0iQWNtZSwgSW5jLiIgcmVnaWQ9ImV4YW1wbGUuY29tIiByb2xlPSJ0YWdDcmVhdG9yIiAvPiAKPC9Tb2Z0d2FyZUlkZW50aXR5Pg==</text>
25+
</swid>
26+
<pedigree>
27+
<ancestors>
28+
<component type="library" bom-ref="ccc8d7ee-4b9c-4750-aee0-a72585152291">
29+
<author>Test Author</author>
30+
<name>setuptools</name>
31+
<version>50.3.2</version>
32+
<licenses>
33+
<expression>MIT License</expression>
34+
</licenses>
35+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
36+
</component>
37+
<component type="library" bom-ref="8a3893b3-9923-4adb-a1d3-47456636ba0a">
38+
<author>Test Author</author>
39+
<name>setuptools</name>
40+
<version />
41+
<licenses>
42+
<expression>MIT License</expression>
43+
</licenses>
44+
<purl>pkg:pypi/setuptools?extension=tar.gz</purl>
45+
</component>
46+
</ancestors>
47+
<descendants>
48+
<component type="library" bom-ref="28b2d8ce-def0-446f-a221-58dee0b44acc">
49+
<author>Test Author</author>
50+
<name>setuptools</name>
51+
<version />
52+
<licenses>
53+
<expression>MIT License</expression>
54+
</licenses>
55+
<purl>pkg:pypi/setuptools?extension=tar.gz</purl>
56+
</component>
57+
<component type="library" bom-ref="555ca729-93c6-48f3-956e-bdaa4a2f0bfa">
58+
<name>toml</name>
59+
<version>0.10.2</version>
60+
<hashes>
61+
<hash alg="SHA-256">806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b</hash>
62+
</hashes>
63+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
64+
<externalReferences>
65+
<reference type="distribution">
66+
<url>https://cyclonedx.org</url>
67+
<comment>No comment</comment>
68+
</reference>
69+
</externalReferences>
70+
</component>
71+
</descendants>
72+
<variants>
73+
<component type="library" bom-ref="e7abdcca-5ba2-4f29-b2cf-b1e1ef788e66">
74+
<name>toml</name>
75+
<version>0.10.2</version>
76+
<hashes>
77+
<hash alg="SHA-256">806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b</hash>
78+
</hashes>
79+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
80+
<externalReferences>
81+
<reference type="distribution">
82+
<url>https://cyclonedx.org</url>
83+
<comment>No comment</comment>
84+
</reference>
85+
</externalReferences>
86+
</component>
87+
<component type="library" bom-ref="ded1d73e-1fca-4302-b520-f1bc53979958">
88+
<author>Test Author</author>
89+
<name>setuptools</name>
90+
<version>50.3.2</version>
91+
<licenses>
92+
<expression>MIT License</expression>
93+
</licenses>
94+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
95+
</component>
96+
</variants>
97+
<commits>
98+
<commit>
99+
<uid>a-random-uid</uid>
100+
<message>A commit message</message>
101+
</commit>
102+
</commits>
103+
<patches>
104+
<patch type="backport"></patch>
105+
</patches>
106+
<notes>Some notes here please</notes>
107+
</pedigree>
108+
</component>
109+
</components>
110+
</bom>
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<bom xmlns="http://cyclonedx.org/schema/bom/1.3" version="1">
3+
<metadata>
4+
<timestamp>2021-09-01T10:50:42.051979+00:00</timestamp>
5+
<tools>
6+
<tool>
7+
<vendor>CycloneDX</vendor>
8+
<name>cyclonedx-python-lib</name>
9+
<version>VERSION</version>
10+
</tool>
11+
</tools>
12+
</metadata>
13+
<components>
14+
<component type="library" bom-ref="pkg:pypi/[email protected]?extension=tar.gz">
15+
<author>Test Author</author>
16+
<name>setuptools</name>
17+
<version>50.3.2</version>
18+
<licenses>
19+
<expression>MIT License</expression>
20+
</licenses>
21+
<cpe>cpe:2.3:a:python:setuptools:50.3.2:*:*:*:*:*:*:*</cpe>
22+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
23+
<swid tagId="swidgen-242eb18a-503e-ca37-393b-cf156ef09691_9.1.1" name="Test Application" version="3.4.5">
24+
<text content-type="text/xml" encoding="base64">PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiID8+CjxTb2Z0d2FyZUlkZW50aXR5IHhtbDpsYW5nPSJFTiIgbmFtZT0iQWNtZSBBcHBsaWNhdGlvbiIgdmVyc2lvbj0iOS4xLjEiIAogdmVyc2lvblNjaGVtZT0ibXVsdGlwYXJ0bnVtZXJpYyIgCiB0YWdJZD0ic3dpZGdlbi1iNTk1MWFjOS00MmMwLWYzODItM2YxZS1iYzdhMmE0NDk3Y2JfOS4xLjEiIAogeG1sbnM9Imh0dHA6Ly9zdGFuZGFyZHMuaXNvLm9yZy9pc28vMTk3NzAvLTIvMjAxNS9zY2hlbWEueHNkIj4gCiB4bWxuczp4c2k9Imh0dHA6Ly93d3cudzMub3JnLzIwMDEvWE1MU2NoZW1hLWluc3RhbmNlIiAKIHhzaTpzY2hlbWFMb2NhdGlvbj0iaHR0cDovL3N0YW5kYXJkcy5pc28ub3JnL2lzby8xOTc3MC8tMi8yMDE1LWN1cnJlbnQvc2NoZW1hLnhzZCBzY2hlbWEueHNkIiA+CiAgPE1ldGEgZ2VuZXJhdG9yPSJTV0lEIFRhZyBPbmxpbmUgR2VuZXJhdG9yIHYwLjEiIC8+IAogIDxFbnRpdHkgbmFtZT0iQWNtZSwgSW5jLiIgcmVnaWQ9ImV4YW1wbGUuY29tIiByb2xlPSJ0YWdDcmVhdG9yIiAvPiAKPC9Tb2Z0d2FyZUlkZW50aXR5Pg==</text>
25+
</swid>
26+
<pedigree>
27+
<ancestors>
28+
<component type="library" bom-ref="ccc8d7ee-4b9c-4750-aee0-a72585152291">
29+
<author>Test Author</author>
30+
<name>setuptools</name>
31+
<version>50.3.2</version>
32+
<licenses>
33+
<expression>MIT License</expression>
34+
</licenses>
35+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
36+
</component>
37+
<component type="library" bom-ref="8a3893b3-9923-4adb-a1d3-47456636ba0a">
38+
<author>Test Author</author>
39+
<name>setuptools</name>
40+
<version />
41+
<licenses>
42+
<expression>MIT License</expression>
43+
</licenses>
44+
<purl>pkg:pypi/setuptools?extension=tar.gz</purl>
45+
</component>
46+
</ancestors>
47+
<descendants>
48+
<component type="library" bom-ref="28b2d8ce-def0-446f-a221-58dee0b44acc">
49+
<author>Test Author</author>
50+
<name>setuptools</name>
51+
<version />
52+
<licenses>
53+
<expression>MIT License</expression>
54+
</licenses>
55+
<purl>pkg:pypi/setuptools?extension=tar.gz</purl>
56+
</component>
57+
<component type="library" bom-ref="555ca729-93c6-48f3-956e-bdaa4a2f0bfa">
58+
<name>toml</name>
59+
<version>0.10.2</version>
60+
<hashes>
61+
<hash alg="SHA-256">806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b</hash>
62+
</hashes>
63+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
64+
<externalReferences>
65+
<reference type="distribution">
66+
<url>https://cyclonedx.org</url>
67+
<comment>No comment</comment>
68+
<hashes>
69+
<hash alg="SHA-256">806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b</hash>
70+
</hashes>
71+
</reference>
72+
</externalReferences>
73+
</component>
74+
</descendants>
75+
<variants>
76+
<component type="library" bom-ref="e7abdcca-5ba2-4f29-b2cf-b1e1ef788e66">
77+
<name>toml</name>
78+
<version>0.10.2</version>
79+
<hashes>
80+
<hash alg="SHA-256">806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b</hash>
81+
</hashes>
82+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
83+
<externalReferences>
84+
<reference type="distribution">
85+
<url>https://cyclonedx.org</url>
86+
<comment>No comment</comment>
87+
<hashes>
88+
<hash alg="SHA-256">806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b</hash>
89+
</hashes>
90+
</reference>
91+
</externalReferences>
92+
</component>
93+
<component type="library" bom-ref="ded1d73e-1fca-4302-b520-f1bc53979958">
94+
<author>Test Author</author>
95+
<name>setuptools</name>
96+
<version>50.3.2</version>
97+
<licenses>
98+
<expression>MIT License</expression>
99+
</licenses>
100+
<purl>pkg:pypi/[email protected]?extension=tar.gz</purl>
101+
</component>
102+
</variants>
103+
<commits>
104+
<commit>
105+
<uid>a-random-uid</uid>
106+
<message>A commit message</message>
107+
</commit>
108+
</commits>
109+
<patches>
110+
<patch type="backport"></patch>
111+
</patches>
112+
<notes>Some notes here please</notes>
113+
</pedigree>
114+
</component>
115+
</components>
116+
</bom>

0 commit comments

Comments
 (0)