@@ -41,7 +41,9 @@ suite('Factories.PackageUrlFactory', () => {
4141 ''
4242 )
4343 const expected = undefined
44+
4445 const actual = sut . makeFromComponent ( component )
46+
4547 assert . strictEqual ( actual , expected )
4648 } )
4749
@@ -58,38 +60,109 @@ suite('Factories.PackageUrlFactory', () => {
5860 }
5961 )
6062 const expected = new PackageURL ( 'testing' , `@group-${ salt } ` , `name-${ salt } ` , `v1+${ salt } ` , { } , undefined )
63+
64+ const actual = sut . makeFromComponent ( component )
65+
66+ assert . deepStrictEqual ( actual , expected )
67+ } )
68+
69+ test ( 'extRef[vcs] -> qualifiers.vcs-url without subpath' , ( ) => {
70+ const component = new Models . Component (
71+ Enums . ComponentType . Library ,
72+ `name-${ salt } ` ,
73+ {
74+ externalReferences : new Models . ExternalReferenceRepository ( [
75+ new Models . ExternalReference ( 'git+https://foo.bar/repo.git' , Enums . ExternalReferenceType . VCS )
76+ ] )
77+ }
78+ )
79+ const expected = new PackageURL ( 'testing' , undefined , `name-${ salt } ` , undefined , { vcs_url : 'git+https://foo.bar/repo.git' } , undefined )
80+
6181 const actual = sut . makeFromComponent ( component )
82+
6283 assert . deepStrictEqual ( actual , expected )
6384 } )
6485
65- test ( 'vcs- url without subpath' , ( ) => {
86+ test ( 'extRef[ vcs] -> qualifiers.vcs- url with subpath' , ( ) => {
6687 const component = new Models . Component (
6788 Enums . ComponentType . Library ,
6889 `name-${ salt } ` ,
6990 {
7091 externalReferences : new Models . ExternalReferenceRepository ( [
71- new Models . ExternalReference ( 'git://foo.bar' , Enums . ExternalReferenceType . VCS )
92+ new Models . ExternalReference ( 'git+https ://foo.bar/repo.git#sub/path ' , Enums . ExternalReferenceType . VCS )
7293 ] )
7394 }
7495 )
75- const expected = new PackageURL ( 'testing' , undefined , `name-${ salt } ` , undefined , { vcs_url : 'git://foo.bar' } , undefined )
96+ const expected = new PackageURL ( 'testing' , undefined , `name-${ salt } ` , undefined , { vcs_url : 'git+https://foo.bar/repo.git' } , 'sub/path' )
97+
7698 const actual = sut . makeFromComponent ( component )
99+
77100 assert . deepStrictEqual ( actual , expected )
78101 } )
79102
80- test ( 'vcs-url with subpath ' , ( ) => {
103+ test ( 'extRef[distribution] -> qualifiers.download_url ' , ( ) => {
81104 const component = new Models . Component (
82105 Enums . ComponentType . Library ,
83106 `name-${ salt } ` ,
84107 {
85108 externalReferences : new Models . ExternalReferenceRepository ( [
86- new Models . ExternalReference ( 'git ://foo.bar#sub/path ' , Enums . ExternalReferenceType . VCS )
109+ new Models . ExternalReference ( 'https ://foo.bar/download ' , Enums . ExternalReferenceType . Distribution )
87110 ] )
88111 }
89112 )
90- const expected = new PackageURL ( 'testing' , undefined , `name-${ salt } ` , undefined , { vcs_url : 'git://foo.bar' } , 'sub/path' )
113+ const expected = new PackageURL ( 'testing' , undefined , `name-${ salt } ` , undefined , { download_url : 'https://foo.bar/download' } , undefined )
114+
91115 const actual = sut . makeFromComponent ( component )
116+
92117 assert . deepStrictEqual ( actual , expected )
93118 } )
119+
120+ test ( 'hashes -> qualifiers.checksum' , ( ) => {
121+ const component = new Models . Component (
122+ Enums . ComponentType . Library ,
123+ `name-${ salt } ` ,
124+ {
125+ hashes : new Models . HashRepository ( [
126+ [ Enums . HashAlgorithm [ 'SHA-256' ] , 'C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2' ]
127+ ] )
128+ }
129+ )
130+ const expected = new PackageURL ( 'testing' , undefined , `name-${ salt } ` , undefined , { checksum : 'sha-256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2' } , undefined )
131+
132+ const actual = sut . makeFromComponent ( component )
133+
134+ assert . deepStrictEqual ( actual , expected )
135+ } )
136+
137+ test ( 'sorted' , ( ) => {
138+ const component = new Models . Component (
139+ Enums . ComponentType . Library ,
140+ 'name' ,
141+ {
142+ externalReferences : new Models . ExternalReferenceRepository ( [
143+ new Models . ExternalReference ( 'git+https://foo.bar/repo.git' , Enums . ExternalReferenceType . VCS ) ,
144+ new Models . ExternalReference ( 'https://foo.bar/download' , Enums . ExternalReferenceType . Distribution )
145+ ] ) ,
146+ hashes : new Models . HashRepository ( [
147+ [ Enums . HashAlgorithm [ 'SHA-256' ] , 'C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2' ] ,
148+ [ Enums . HashAlgorithm . BLAKE3 , 'aa51dcd43d5c6c5203ee16906fd6b35db298b9b2e1de3fce81811d4806b76b7d' ]
149+ ] )
150+ }
151+ )
152+ const expectedObject = new PackageURL ( 'testing' , undefined , 'name' , undefined ,
153+ {
154+ // expect sorted hash list
155+ checksum : 'blake3:aa51dcd43d5c6c5203ee16906fd6b35db298b9b2e1de3fce81811d4806b76b7d,sha-256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2' ,
156+ download_url : 'https://foo.bar/download' ,
157+ vcs_url : 'git+https://foo.bar/repo.git'
158+ } , undefined )
159+ // expect objet's keys in alphabetical oder, expect sorted hash list
160+ const expectedString = 'pkg:testing/name?checksum=blake3:aa51dcd43d5c6c5203ee16906fd6b35db298b9b2e1de3fce81811d4806b76b7d,sha-256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2&download_url=https://foo.bar/download&vcs_url=git+https://foo.bar/repo.git'
161+
162+ const actual = sut . makeFromComponent ( component , true )
163+
164+ assert . deepStrictEqual ( actual , expectedObject )
165+ assert . deepStrictEqual ( actual . toString ( ) , expectedString )
166+ } )
94167 } )
95168} )
0 commit comments