Skip to content

Commit 1149b4a

Browse files
committed
test component.components normalizer/serializer tests
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent e69b7b3 commit 1149b4a

18 files changed

+422
-15
lines changed

HISTORY.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ All notable changes to this project will be documented in this file.
55
## unreleased
66

77
* Added
8+
* Implemented support for nested/bundled components via `bom.component.components`. (via [#136])
89
* CycloneDX spec version 1.4 made element `bom.component.version` optional.
910
Therefore, serialization/normalization with this spec version will no longer render this element,
1011
when its value is empty. (via [#137])
1112

13+
[#136]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/136
1214
[#137]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/137
1315

1416
## 1.0.3 - 2022-07-28

tests/_data/models.js

+23-3
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ module.exports.createComplexStructure = function () {
127127
component.scope = Enums.ComponentScope.Required
128128
component.supplier = new Models.OrganizationalEntity({ name: 'Component Supplier' })
129129
component.supplier.url.add(new URL('https://localhost/componentSupplier-B'))
130-
component.supplier.url.add(new URL('https://localhost/componentSupplier-A'))
130+
component.supplier.url.add('https://localhost/componentSupplier-A')
131131
component.supplier.contact.add(new Models.OrganizationalContact({ name: 'The quick brown fox' }))
132132
component.supplier.contact.add((function (contact) {
133133
contact.name = 'Franz'
@@ -149,17 +149,37 @@ module.exports.createComplexStructure = function () {
149149
return component
150150
})(new Models.Component(Enums.ComponentType.Library, 'dummy-component', { version: '1337-beta' })))
151151

152-
bom.components.add(function (component) {
152+
bom.components.add((function (component) {
153153
// interlink everywhere
154154
bom.metadata.component.dependencies.add(component.bomRef)
155155
bom.components.forEach(c => c.dependencies.add(component.bomRef))
156156
return component
157-
}(new Models.Component(Enums.ComponentType.Library, 'a-component', {
157+
})(new Models.Component(Enums.ComponentType.Library, 'a-component', {
158158
bomRef: 'a-component',
159159
dependencies: new Models.BomRefRepository([
160160
new Models.BomRef('unknown foreign ref that should not be rendered')
161161
])
162162
})))
163163

164+
bom.components.add((function (component) {
165+
// scenario:
166+
// * `subComponentA` is a bundled dependency, that itself depends on `subComponentB`.
167+
// * `subComponentB` is a transitive bundled dependency.
168+
const subComponentA = new Models.Component(Enums.ComponentType.Library, 'SubComponentA', {
169+
bomRef: `${component.bomRef.value}#SubComponentA`
170+
})
171+
component.dependencies.add(subComponentA.bomRef)
172+
component.components.add(subComponentA)
173+
const subComponentB = new Models.Component(Enums.ComponentType.Library, 'SubComponentB', {
174+
bomRef: `${component.bomRef.value}#SubComponentB`
175+
})
176+
subComponentA.dependencies.add(subComponentB.bomRef)
177+
component.components.add(subComponentB)
178+
return component
179+
})(new Models.Component(
180+
Enums.ComponentType.Framework, 'SomeFrameworkBundle', {
181+
bomRef: 'SomeFrameworkBundle'
182+
})))
183+
164184
return bom
165185
}

tests/_data/normalizeResults/json_sortedLists_spec1.2.json

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/normalizeResults/json_sortedLists_spec1.3.json

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/normalizeResults/json_sortedLists_spec1.4.json

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/normalizeResults/xml_sortedLists_spec1.2.json

+74
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/normalizeResults/xml_sortedLists_spec1.3.json

+74
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)