Skip to content

Commit 1a47062

Browse files
committed
fix: `Component.supplier in constructor
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 29dc1c0 commit 1a47062

9 files changed

+118
-7
lines changed

src/models/component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class Component implements Comparable {
7979
this.#bomRef = new BomRef(op.bomRef)
8080
this.type = type
8181
this.name = name
82+
this.supplier = op.supplier
8283
this.author = op.author
8384
this.copyright = op.copyright
8485
this.externalReferences = op.externalReferences ?? new ExternalReferenceRepository()

tests/integration/Serialize.JsonNormalize.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const {
3333
Spec: { Spec1dot2, Spec1dot3, Spec1dot4 }
3434
} = require('../../')
3535

36-
describe('JSON normalize', function () {
36+
describe('Serialize.JsonNormalize', function () {
3737
this.timeout(60000);
3838

3939
[

tests/integration/Serialize.JsonSerialize.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const {
3434
Spec: { Spec1dot2, Spec1dot3, Spec1dot4 }
3535
} = require('../../')
3636

37-
describe('JSON serialize', function () {
37+
describe('Serialize.JsonSerialize', function () {
3838
this.timeout(60000);
3939

4040
[

tests/integration/Serialize.XmlNormalize.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const {
3333
Spec: { Spec1dot2, Spec1dot3, Spec1dot4 }
3434
} = require('../../')
3535

36-
describe('XML normalize', function () {
36+
describe('Serialize.XmlNormalize', function () {
3737
this.timeout(60000);
3838

3939
[

tests/integration/Serialize.XmlSerialize.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const {
3434
Spec: { Spec1dot2, Spec1dot3, Spec1dot4 }
3535
} = require('../../')
3636

37-
describe('XML serialize', function () {
37+
describe('Serialize.XmlSerialize', function () {
3838
this.timeout(60000);
3939

4040
[

tests/unit/Models.Bom.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const {
2525
Models: { Bom, ComponentRepository, Metadata }
2626
} = require('../../')
2727

28-
suite('BOM', () => {
28+
suite('Models.Bom', () => {
2929
test('construct with empty properties', () => {
3030
const bom = new Bom()
3131

tests/unit/Models.Component.spec.js

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
'use strict'
2+
3+
/*!
4+
This file is part of CycloneDX JavaScript Library.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
SPDX-License-Identifier: Apache-2.0
19+
Copyright (c) OWASP Foundation. All Rights Reserved.
20+
*/
21+
22+
const assert = require('assert')
23+
const { suite, test } = require('mocha')
24+
25+
const { PackageURL } = require('packageurl-js')
26+
27+
const {
28+
Models: {
29+
Component,
30+
BomRef, BomRefRepository,
31+
ExternalReferenceRepository, ExternalReference,
32+
HashRepository,
33+
LicenseRepository, NamedLicense,
34+
OrganizationalEntity,
35+
SWID
36+
}
37+
} = require('../../')
38+
39+
suite('Models.Component', () => {
40+
test('constructor', () => {
41+
const component = new Component('application', 'foobar')
42+
43+
assert.strictEqual(component.type, 'application')
44+
assert.strictEqual(component.name, 'foobar')
45+
assert.strictEqual(component.author, undefined)
46+
assert.strictEqual(component.bomRef.value, undefined)
47+
assert.strictEqual(component.copyright, undefined)
48+
assert.strictEqual(component.cpe, undefined)
49+
assert.strictEqual(component.dependencies.size, 0)
50+
assert.strictEqual(component.description, undefined)
51+
assert.strictEqual(component.externalReferences.size, 0)
52+
assert.strictEqual(component.group, undefined)
53+
assert.strictEqual(component.hashes.size, 0)
54+
assert.strictEqual(component.licenses.size, 0)
55+
assert.strictEqual(component.purl, undefined)
56+
assert.strictEqual(component.scope, undefined)
57+
assert.strictEqual(component.supplier, undefined)
58+
assert.strictEqual(component.swid, undefined)
59+
assert.strictEqual(component.version, undefined)
60+
})
61+
62+
test('constructor with OptionalProperties', () => {
63+
const dummnBomRef = new BomRef('testing')
64+
const dummyExtRef = new ExternalReference('../', 'other')
65+
const dummyLicense = new NamedLicense('mine')
66+
const dummyPurl = new PackageURL('npm', 'ns', 'app', '1.33.7', {}, undefined)
67+
const dummySupplier = new OrganizationalEntity({ name: 'dummySupplier' })
68+
const dummySWID = new SWID('my-fake-swid', 'foo-bar')
69+
70+
const component = new Component('application', 'foobar', {
71+
author: 'my author',
72+
bomRef: 'my-bomref',
73+
copyright: 'my copyright',
74+
cpe: 'cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*',
75+
dependencies: new BomRefRepository([dummnBomRef]),
76+
description: 'this is a test',
77+
externalReferences: new ExternalReferenceRepository([dummyExtRef]),
78+
group: 'the-crew',
79+
hashes: new HashRepository([['MD5', '59bcc3ad6775562f845953cf01624225']]),
80+
licenses: new LicenseRepository([dummyLicense]),
81+
purl: dummyPurl,
82+
scope: 'optional',
83+
supplier: dummySupplier,
84+
swid: dummySWID,
85+
version: '1.33.7'
86+
})
87+
88+
assert.strictEqual(component.type, 'application')
89+
assert.strictEqual(component.name, 'foobar')
90+
assert.strictEqual(component.author, 'my author')
91+
assert.strictEqual(component.bomRef.value, 'my-bomref')
92+
assert.strictEqual(component.copyright, 'my copyright')
93+
assert.strictEqual(component.cpe, 'cpe:2.3:a:microsoft:internet_explorer:8.0.6001:beta:*:*:*:*:*:*')
94+
assert.strictEqual(component.dependencies.size, 1)
95+
assert.strictEqual(Array.from(component.dependencies)[0], dummnBomRef)
96+
assert.strictEqual(component.description, 'this is a test')
97+
assert.strictEqual(component.externalReferences.size, 1)
98+
assert.strictEqual(Array.from(component.externalReferences)[0], dummyExtRef)
99+
assert.strictEqual(component.group, 'the-crew')
100+
assert.strictEqual(component.hashes.size, 1)
101+
assert.strictEqual(component.hashes.get('MD5'), '59bcc3ad6775562f845953cf01624225')
102+
assert.strictEqual(component.licenses.size, 1)
103+
assert.strictEqual(Array.from(component.licenses)[0], dummyLicense)
104+
assert.strictEqual(component.purl, dummyPurl)
105+
assert.strictEqual(component.scope, 'optional')
106+
assert.strictEqual(component.supplier, dummySupplier)
107+
assert.strictEqual(component.swid, dummySWID)
108+
assert.strictEqual(component.version, '1.33.7')
109+
})
110+
})

tests/unit/SPDX.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const {
2525
SPDX: { fixupSpdxId, isSupportedSpdxId }
2626
} = require('../../')
2727

28-
suite('isSupportedSpdxId()', () => {
28+
suite('SPDX.isSupportedSpdxId()', () => {
2929
const knownSpdxIds = Object.freeze(['MIT', 'Apache-2.0'])
3030

3131
suite('is true', () =>

tests/unit/Serialize.BomRefDiscriminator.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const {
2626
Serialize: { BomRefDiscriminator }
2727
} = require('../../')
2828

29-
suite('BomRefDiscriminator', () => {
29+
suite('Serialize.BomRefDiscriminator', () => {
3030
test('does not alter BomRef.value unintended', () => {
3131
const bomRef1 = new BomRef()
3232
const bomRef2 = new BomRef('foo')

0 commit comments

Comments
 (0)