@@ -22,6 +22,9 @@ const assert = require('node:assert')
22
22
const { suite, test } = require ( 'mocha' )
23
23
24
24
const {
25
+ Enums : {
26
+ HashAlgorithm
27
+ } ,
25
28
Utils : {
26
29
NpmjsUtility
27
30
}
@@ -30,28 +33,65 @@ const {
30
33
suite ( 'unit: Utils.NpmjsUtility' , ( ) => {
31
34
suite ( 'defaultRegistryMatcher' , ( ) => {
32
35
test ( 'matches pure domain' , ( ) => {
33
- const match = NpmjsUtility . defaultRegistryMatcher . test ( 'https://registry.npmjs.org' )
34
- assert . strictEqual ( match , true )
36
+ const actual = NpmjsUtility . defaultRegistryMatcher . test ( 'https://registry.npmjs.org' )
37
+ assert . strictEqual ( actual , true )
35
38
} )
36
39
test ( 'matches with path' , ( ) => {
37
- const match = NpmjsUtility . defaultRegistryMatcher . test ( 'https://registry.npmjs.org/foo/bar' )
38
- assert . strictEqual ( match , true )
40
+ const actual = NpmjsUtility . defaultRegistryMatcher . test ( 'https://registry.npmjs.org/foo/bar' )
41
+ assert . strictEqual ( actual , true )
39
42
} )
40
43
suite ( 'not match unexpected' , ( ) => {
41
- for ( const c in [
44
+ for ( const c of [
42
45
'https://my-own=registry.local' ,
43
46
'https://registry.npmjs.org.uk' ,
44
47
'https://registry.npmjs.org.uk/foo/bar'
45
48
] ) {
46
49
test ( c , ( ) => {
47
- const match = NpmjsUtility . defaultRegistryMatcher . test ( c )
48
- assert . strictEqual ( match , false )
50
+ const actual = NpmjsUtility . defaultRegistryMatcher . test ( c )
51
+ assert . strictEqual ( actual , false )
49
52
} )
50
53
}
51
54
} )
52
55
} )
53
56
54
57
suite ( 'parsePackageIntegrity' , ( ) => {
55
-
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
+ } )
93
+ } )
94
+ }
95
+ } )
56
96
} )
57
97
} )
0 commit comments