@@ -22,6 +22,9 @@ const assert = require('node:assert')
2222const { suite, test } = require ( 'mocha' )
2323
2424const {
25+ Enums : {
26+ HashAlgorithm
27+ } ,
2528 Utils : {
2629 NpmjsUtility
2730 }
@@ -30,28 +33,65 @@ const {
3033suite ( 'unit: Utils.NpmjsUtility' , ( ) => {
3134 suite ( 'defaultRegistryMatcher' , ( ) => {
3235 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 )
3538 } )
3639 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 )
3942 } )
4043 suite ( 'not match unexpected' , ( ) => {
41- for ( const c in [
44+ for ( const c of [
4245 'https://my-own=registry.local' ,
4346 'https://registry.npmjs.org.uk' ,
4447 'https://registry.npmjs.org.uk/foo/bar'
4548 ] ) {
4649 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 )
4952 } )
5053 }
5154 } )
5255 } )
5356
5457 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+ } )
5696 } )
5797} )
0 commit comments