Skip to content

Commit 194b27a

Browse files
committed
tests
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent d2f227d commit 194b27a

File tree

2 files changed

+67
-63
lines changed

2 files changed

+67
-63
lines changed

tests/unit/Factories.FromNodePackageJson.PackageUrlFactory.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ const assert = require('node:assert')
2222
const { suite, test } = require('mocha')
2323

2424
const {
25-
Factories: { FromNodePackageJson: { PackageUrlFactory } },
25+
Factories: { FromNodePackageJson: {
26+
ExternalReferenceFactory, PackageUrlFactory
27+
}},
2628
Enums: { ComponentType, ExternalReferenceType },
2729
Models: { Component, ExternalReference, ExternalReferenceRepository }
2830
} = require('../../')
2931

32+
suite('unit: Factories.FromNodePackageJson.ExternalReferenceFactory', () => {
33+
// TODO
34+
})
35+
3036
suite('unit: Factories.FromNodePackageJson.PackageUrlFactory', () => {
3137
suite('makeFromComponent()', () => {
3238
test('plain', () => {
@@ -36,7 +42,7 @@ suite('unit: Factories.FromNodePackageJson.PackageUrlFactory', () => {
3642
assert.deepEqual(actual, 'TODO')
3743
})
3844

39-
test('strips default repo', () => {
45+
test('strips default registry from qualifiers', () => {
4046
// see https://github.com/package-url/purl-spec/blob/master/PURL-TYPES.rst#npm
4147
const component = new Component(ComponentType.Library, 'testing', {
4248
externalReferences: new ExternalReferenceRepository([
@@ -58,7 +64,7 @@ suite('unit: Factories.FromNodePackageJson.PackageUrlFactory', () => {
5864
})
5965
})
6066

61-
test('dont strip BA repo', () => {
67+
test('dont strip BA registry from qualifiers', () => {
6268
// regression test for https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1073
6369
const component = new Component(ComponentType.Library, 'testing', {
6470
externalReferences: new ExternalReferenceRepository([

tests/unit/Utils.NpmjsUtility.spec.js

Lines changed: 58 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -30,68 +30,66 @@ const {
3030
}
3131
} = require('../../')
3232

33-
suite('unit: Utils.NpmjsUtility', () => {
34-
suite('defaultRegistryMatcher', () => {
35-
test('matches pure domain', () => {
36-
const actual = NpmjsUtility.defaultRegistryMatcher.test('https://registry.npmjs.org')
37-
assert.strictEqual(actual, true)
38-
})
39-
test('matches with path', () => {
40-
const actual = NpmjsUtility.defaultRegistryMatcher.test('https://registry.npmjs.org/foo/bar')
41-
assert.strictEqual(actual, true)
42-
})
43-
suite('not match unexpected', () => {
44-
for (const c of [
45-
'https://my-own=registry.local',
46-
'https://registry.npmjs.org.uk',
47-
'https://registry.npmjs.org.uk/foo/bar'
48-
]) {
49-
test(c, () => {
50-
const actual = NpmjsUtility.defaultRegistryMatcher.test(c)
51-
assert.strictEqual(actual, false)
52-
})
53-
}
54-
})
33+
suite('unit: Utils.NpmjsUtility.defaultRegistryMatcher', () => {
34+
test('matches pure domain', () => {
35+
const actual = NpmjsUtility.defaultRegistryMatcher.test('https://registry.npmjs.org')
36+
assert.strictEqual(actual, true)
37+
})
38+
test('matches with path', () => {
39+
const actual = NpmjsUtility.defaultRegistryMatcher.test('https://registry.npmjs.org/foo/bar')
40+
assert.strictEqual(actual, true)
41+
})
42+
suite('not match unexpected', () => {
43+
for (const c of [
44+
'https://my-own=registry.local',
45+
'https://registry.npmjs.org.uk',
46+
'https://registry.npmjs.org.uk/foo/bar'
47+
]) {
48+
test(c, () => {
49+
const actual = NpmjsUtility.defaultRegistryMatcher.test(c)
50+
assert.strictEqual(actual, false)
51+
})
52+
}
5553
})
54+
})
5655

57-
suite('parsePackageIntegrity', () => {
58-
suite('as expected', () => {
59-
for (const [c, ...expected] of [
60-
['sha512-zvj65TkFeIt3i6aj5bIvJDzjjQQGs4o/sNoezg1F1kYap9Nu2jcUdpwzRSJTHMMzG0H7bZkn4rNQpImhuxWX2A==',
61-
HashAlgorithm['SHA-512'],
62-
'cef8fae53905788b778ba6a3e5b22f243ce38d0406b38a3fb0da1ece0d45d6461aa7d36eda3714769c334522531cc3331b41fb6d9927e2b350a489a1bb1597d8'
63-
],
64-
['sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0=',
65-
HashAlgorithm['SHA-1'],
66-
'2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'
67-
],
68-
['sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=',
69-
HashAlgorithm['SHA-256'],
70-
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
71-
],
72-
['sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC',
73-
HashAlgorithm['SHA-384'],
74-
'a2a56e01f5d129aa7b7dd81c098e6eca433af91f46a90f0afeec72f6bc7b1cd42519897590fcd0868d70c7827063cc02'
75-
],
76-
]) {
77-
test(c, () => {
78-
const actual = NpmjsUtility.parsePackageIntegrity(c)
79-
assert.deepStrictEqual(actual, expected)
80-
})
81-
}
82-
})
83-
suite('fails', () => {
84-
for (const c of [
85-
'sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0', // missing character
86-
'sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0==', // additional character
87-
'sha512-Kq5sNclPz7QV2+lfQIuc6R7oRu0=', // alg and hash dont match
88-
]) {
89-
test(c, () => {
90-
assert.throws(() => {
91-
NpmjsUtility.parsePackageIntegrity(c)
92-
})
56+
suite('unit: Utils.NpmjsUtility.parsePackageIntegrity', () => {
57+
suite('as expected', () => {
58+
for (const [c, ...expected] of [
59+
['sha512-zvj65TkFeIt3i6aj5bIvJDzjjQQGs4o/sNoezg1F1kYap9Nu2jcUdpwzRSJTHMMzG0H7bZkn4rNQpImhuxWX2A==',
60+
HashAlgorithm['SHA-512'],
61+
'cef8fae53905788b778ba6a3e5b22f243ce38d0406b38a3fb0da1ece0d45d6461aa7d36eda3714769c334522531cc3331b41fb6d9927e2b350a489a1bb1597d8'
62+
],
63+
['sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0=',
64+
HashAlgorithm['SHA-1'],
65+
'2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'
66+
],
67+
['sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=',
68+
HashAlgorithm['SHA-256'],
69+
'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
70+
],
71+
['sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC',
72+
HashAlgorithm['SHA-384'],
73+
'a2a56e01f5d129aa7b7dd81c098e6eca433af91f46a90f0afeec72f6bc7b1cd42519897590fcd0868d70c7827063cc02'
74+
],
75+
]) {
76+
test(c, () => {
77+
const actual = NpmjsUtility.parsePackageIntegrity(c)
78+
assert.deepStrictEqual(actual, expected)
79+
})
80+
}
81+
})
82+
suite('fails', () => {
83+
for (const c of [
84+
'sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0', // missing character
85+
'sha1-Kq5sNclPz7QV2+lfQIuc6R7oRu0==', // additional character
86+
'sha512-Kq5sNclPz7QV2+lfQIuc6R7oRu0=', // alg and hash dont match
87+
]) {
88+
test(c, () => {
89+
assert.throws(() => {
90+
NpmjsUtility.parsePackageIntegrity(c)
9391
})
94-
}
95-
})
92+
})
93+
}
9694
})
9795
})

0 commit comments

Comments
 (0)