|
| 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 | +}) |
0 commit comments