|
| 1 | +/*! |
| 2 | +This file is part of CycloneDX JavaScript Library. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +
|
| 16 | +SPDX-License-Identifier: Apache-2.0 |
| 17 | +Copyright (c) OWASP Foundation. All Rights Reserved. |
| 18 | +*/ |
| 19 | + |
| 20 | +const assert = require('assert') |
| 21 | +const { suite, test } = require('mocha') |
| 22 | + |
| 23 | +const { |
| 24 | + Factories: { FromNodePackageJson: { PackageUrlFactory } }, |
| 25 | + Enums: { ComponentType, ExternalReferenceType }, |
| 26 | + Models: { Component, ExternalReference, ExternalReferenceRepository } |
| 27 | +} = require('../../') |
| 28 | + |
| 29 | +suite('Factories.FromNodePackageJson.PackageUrlFactory', () => { |
| 30 | + suite('makeFromComponent()', () => { |
| 31 | + test('plain', () => { |
| 32 | + const component = new Component(ComponentType.Library, 'testing') |
| 33 | + const purlFac = new PackageUrlFactory('npm') |
| 34 | + const actual = purlFac.makeFromComponent(component) |
| 35 | + assert.deepEqual(actual, 'TODO') |
| 36 | + }) |
| 37 | + |
| 38 | + test('strips default repo', () => { |
| 39 | + // see https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#npm |
| 40 | + const component = new Component(ComponentType.Library, 'testing', { |
| 41 | + externalReferences: new ExternalReferenceRepository([ |
| 42 | + new ExternalReference( |
| 43 | + 'https://registry.npmjs.org/@cyclonedx/cyclonedx-library/-/cyclonedx-library-1.0.0-beta.2.tgz', |
| 44 | + ExternalReferenceType.Distribution |
| 45 | + ) |
| 46 | + ]) |
| 47 | + }) |
| 48 | + const purlFac = new PackageUrlFactory('npm') |
| 49 | + const actual = purlFac.makeFromComponent(component) |
| 50 | + assert.deepEqual(actual, { |
| 51 | + type: 'npm', |
| 52 | + name: 'testing', |
| 53 | + namespace: undefined, |
| 54 | + version: undefined, |
| 55 | + qualifiers: undefined, |
| 56 | + subpath: undefined |
| 57 | + }) |
| 58 | + }) |
| 59 | + |
| 60 | + test('dont strip BA repo', () => { |
| 61 | + // regression test for https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1073 |
| 62 | + const component = new Component(ComponentType.Library, 'testing', { |
| 63 | + externalReferences: new ExternalReferenceRepository([ |
| 64 | + new ExternalReference( |
| 65 | + 'https://registry.npmjs.org.badactor.net/@cyclonedx/cyclonedx-library/-/cyclonedx-library-1.0.0-beta.2.tgz', |
| 66 | + ExternalReferenceType.Distribution |
| 67 | + ) |
| 68 | + ]) |
| 69 | + }) |
| 70 | + const purlFac = new PackageUrlFactory('npm') |
| 71 | + const actual = purlFac.makeFromComponent(component) |
| 72 | + assert.deepEqual(actual, |
| 73 | + { |
| 74 | + type: 'npm', |
| 75 | + name: 'testing', |
| 76 | + namespace: undefined, |
| 77 | + version: undefined, |
| 78 | + qualifiers: { |
| 79 | + download_url: 'https://registry.npmjs.org.badactor.net/@cyclonedx/cyclonedx-library/-/cyclonedx-library-1.0.0-beta.2.tgz' |
| 80 | + }, |
| 81 | + subpath: undefined |
| 82 | + }) |
| 83 | + }) |
| 84 | + }) |
| 85 | +}) |
0 commit comments