@@ -11,6 +11,56 @@ import Javascript_pnpm from '../../src/providers/javascript_pnpm.js'
1111import Javascript_yarn from '../../src/providers/javascript_yarn.js'
1212import pythonPipProvider from '../../src/providers/python_pip.js'
1313import rustCargoProvider from '../../src/providers/rust_cargo.js'
14+ import { normalizeLicensesResponse } from '../../src/license/licenses_api.js'
15+
16+ suite ( 'normalizeLicensesResponse' , ( ) => {
17+ const lgpl = { id : 'LGPL-2.1' , name : 'GNU Lesser General Public License v2.1 only' , category : 'WEAK_COPYLEFT' }
18+ const apache = { id : 'Apache-2.0' , name : 'Apache License 2.0' , category : 'PERMISSIVE' }
19+
20+ const backendResponse = [
21+ {
22+ status : { ok : true , name : 'deps.dev' } ,
23+ packages : {
24+ // backend returns purls with ?scope=compile qualifier
25+ 'pkg:maven/org.mariadb.jdbc/mariadb-java-client@3.1.4?scope=compile' : {
26+ concluded : { identifiers : [ lgpl ] , expression : 'LGPL-2.1' , category : 'WEAK_COPYLEFT' }
27+ } ,
28+ 'pkg:maven/javassist/javassist@3.12.1.GA?scope=compile' : {
29+ concluded : { identifiers : [ lgpl ] , expression : 'LGPL-2.1' , category : 'WEAK_COPYLEFT' }
30+ } ,
31+ 'pkg:maven/commons-collections/commons-collections@3.2.1' : {
32+ concluded : { identifiers : [ apache ] , expression : 'Apache-2.0' , category : 'PERMISSIVE' }
33+ }
34+ }
35+ }
36+ ]
37+
38+ // SBOM purls have no qualifier
39+ const sbomPurls = [
40+ 'pkg:maven/org.mariadb.jdbc/mariadb-java-client@3.1.4' ,
41+ 'pkg:maven/javassist/javassist@3.12.1.GA' ,
42+ 'pkg:maven/commons-collections/commons-collections@3.2.1'
43+ ]
44+
45+ test ( 'matches backend purls with ?scope=compile qualifier against plain SBOM purls' , ( ) => {
46+ const map = normalizeLicensesResponse ( backendResponse , sbomPurls )
47+ expect ( map . size ) . to . equal ( 3 )
48+ } )
49+
50+ test ( 'stores purl without qualifier as map key' , ( ) => {
51+ const map = normalizeLicensesResponse ( backendResponse , sbomPurls )
52+ expect ( map . has ( 'pkg:maven/org.mariadb.jdbc/mariadb-java-client@3.1.4' ) ) . to . be . true
53+ expect ( map . has ( 'pkg:maven/javassist/javassist@3.12.1.GA' ) ) . to . be . true
54+ expect ( map . has ( 'pkg:maven/org.mariadb.jdbc/mariadb-java-client@3.1.4?scope=compile' ) ) . to . be . false
55+ } )
56+
57+ test ( 'preserves correct license category for qualifier-stripped purls' , ( ) => {
58+ const map = normalizeLicensesResponse ( backendResponse , sbomPurls )
59+ expect ( map . get ( 'pkg:maven/org.mariadb.jdbc/mariadb-java-client@3.1.4' ) . category ) . to . equal ( 'WEAK_COPYLEFT' )
60+ expect ( map . get ( 'pkg:maven/javassist/javassist@3.12.1.GA' ) . category ) . to . equal ( 'WEAK_COPYLEFT' )
61+ expect ( map . get ( 'pkg:maven/commons-collections/commons-collections@3.2.1' ) . category ) . to . equal ( 'PERMISSIVE' )
62+ } )
63+ } )
1464
1565suite ( 'testing readLicenseFromManifest with existing test manifests' , ( ) => {
1666
0 commit comments