@@ -21,6 +21,7 @@ const npmChange: Change = {
21
21
}
22
22
]
23
23
}
24
+
24
25
const rubyChange : Change = {
25
26
change_type : 'added' ,
26
27
manifest : 'Gemfile.lock' ,
@@ -73,6 +74,32 @@ const pipChange: Change = {
73
74
]
74
75
}
75
76
77
+ const complexLicenseChange : Change = {
78
+ change_type : 'added' ,
79
+ manifest : 'requirements.txt' ,
80
+ ecosystem : 'pip' ,
81
+ name : 'package-1' ,
82
+ version : '1.1.1' ,
83
+ package_url : 'pkg:pypi/package-1@1.1.1' ,
84
+ license : 'MIT AND Apache-2.0' ,
85
+ source_repository_url : 'github.com/some-repo' ,
86
+ scope : 'runtime' ,
87
+ vulnerabilities : [
88
+ {
89
+ severity : 'moderate' ,
90
+ advisory_ghsa_id : 'second-random_string' ,
91
+ advisory_summary : 'not so dangerous' ,
92
+ advisory_url : 'github.com/future-funk'
93
+ } ,
94
+ {
95
+ severity : 'low' ,
96
+ advisory_ghsa_id : 'third-random_string' ,
97
+ advisory_summary : 'dont page me' ,
98
+ advisory_url : 'github.com/future-funk'
99
+ }
100
+ ]
101
+ }
102
+
76
103
jest . mock ( '@actions/core' )
77
104
78
105
const mockOctokit = {
@@ -100,130 +127,55 @@ beforeEach(async () => {
100
127
jest . resetModules ( )
101
128
} )
102
129
103
- test ( 'it should handle SPDX expressions in allow-list that matches a single license project' , async ( ) => {
104
- const change : Change = getChangeWithLicense ( 'MIT' )
105
- const changes : Changes = [ change ]
106
-
107
- const { forbidden} = await getInvalidLicenseChanges ( changes , {
108
- allow : [ 'EPL-1.0 OR MIT' ]
109
- } )
110
-
111
- expect ( forbidden ) . toStrictEqual ( [ ] )
112
- } )
113
-
114
- test ( 'it should handle SPDX expressions in allow-list with operators and a valid triple licensed project' , async ( ) => {
115
- const change : Change = getChangeWithLicense (
116
- 'EPL-1.0 AND LGPL-2.1 AND LGPL-2.1-only'
117
- )
118
- const changes : Changes = [ change ]
119
-
120
- const { forbidden} = await getInvalidLicenseChanges ( changes , {
121
- allow : [ 'EPL-1.0 AND LGPL-2.1 AND LGPL-2.1-only' ]
122
- } )
123
-
124
- expect ( forbidden ) . toStrictEqual ( [ ] )
125
- } )
126
-
127
- test ( 'it should handle a valid triple licensed project that does not have a match in the allow-list' , async ( ) => {
128
- const change = getChangeWithLicense ( 'EPL-1.0 AND LGPL-2.1 AND LGPL-2.1-only' )
129
- const changes : Changes = [ change ]
130
-
131
- const { forbidden} = await getInvalidLicenseChanges ( changes , {
132
- allow : [ 'EPL-1.0' , 'LGPL-2.1' , 'LGPL-2.1-only' ]
133
- } )
134
-
135
- expect ( forbidden [ 0 ] ) . toBe ( change )
136
- expect ( forbidden . length ) . toEqual ( 1 )
137
- } )
138
-
139
- test ( 'it should handle license with OR SPDX expression and only match on one license in the allow-list' , async ( ) => {
140
- const change = getChangeWithLicense ( 'EPL-1.0 OR LGPL-2.1' )
141
- const changes : Changes = [ change ]
142
-
143
- for ( const allowedLicense of [ 'EPL-1.0' , 'LGPL-2.1' ] ) {
144
- const { forbidden} = await getInvalidLicenseChanges ( changes , {
145
- allow : [ allowedLicense ]
146
- } )
147
-
148
- expect ( forbidden ) . toStrictEqual ( [ ] )
149
- }
150
- } )
151
-
152
- test ( 'it should handle SPDX expressions in allow-list with operators when license matches' , async ( ) => {
153
- const changes : Changes = [
154
- npmChange // MIT license
155
- ]
156
-
157
- const { forbidden} = await getInvalidLicenseChanges ( changes , {
158
- allow : [ 'MIT OR Apache-2.0' , 'MIT' , 'BSD-3-Clause' ]
159
- } )
160
-
161
- expect ( forbidden ) . toStrictEqual ( [ ] )
162
- } )
163
-
164
- test ( 'it should handle SPDX expressions in allow-list with operators when license does not match' , async ( ) => {
130
+ test ( 'it adds license outside the allow list to forbidden changes' , async ( ) => {
165
131
const changes : Changes = [
166
- npmChange // MIT license
132
+ npmChange , // MIT license
133
+ rubyChange // BSD license
167
134
]
168
135
169
136
const { forbidden} = await getInvalidLicenseChanges ( changes , {
170
- allow : [ 'MIT AND Apache-2.0' , ' BSD-3-Clause']
137
+ allow : [ 'BSD-3-Clause' ]
171
138
} )
172
139
173
140
expect ( forbidden [ 0 ] ) . toBe ( npmChange )
174
141
expect ( forbidden . length ) . toEqual ( 1 )
175
142
} )
176
143
177
- test ( 'it should handle SPDX expressions in deny- list with operators when license matches deny list entry ' , async ( ) => {
144
+ test ( 'it adds license inside the deny list to forbidden changes ' , async ( ) => {
178
145
const changes : Changes = [
179
- npmChange // MIT license
146
+ npmChange , // MIT license
147
+ rubyChange // BSD license
180
148
]
181
149
182
150
const { forbidden} = await getInvalidLicenseChanges ( changes , {
183
- deny : [ 'MIT OR Apache-2.0' , ' BSD-3-Clause']
151
+ deny : [ 'BSD-3-Clause' ]
184
152
} )
185
153
186
- expect ( forbidden [ 0 ] ) . toBe ( npmChange )
154
+ expect ( forbidden [ 0 ] ) . toBe ( rubyChange )
187
155
expect ( forbidden . length ) . toEqual ( 1 )
188
156
} )
189
157
190
- test ( 'it should handle SPDX expressions in deny-list with operators when license does not match any deny list entry ' , async ( ) => {
158
+ test ( 'it handles allowed complex licenses ' , async ( ) => {
191
159
const changes : Changes = [
192
- npmChange // MIT license
160
+ complexLicenseChange // MIT AND Apache-2.0 license
193
161
]
194
162
195
163
const { forbidden} = await getInvalidLicenseChanges ( changes , {
196
- deny : [ 'MIT AND Apache-2.0' , 'BSD-3-Clause ']
164
+ allow : [ 'MIT' , ' Apache-2.0']
197
165
} )
198
166
199
- expect ( forbidden ) . toStrictEqual ( [ ] )
167
+ expect ( forbidden . length ) . toEqual ( 0 )
200
168
} )
201
169
202
- test ( 'it adds license outside the allow list to forbidden changes ' , async ( ) => {
170
+ test ( 'it handles complex licenses not all on the allow list ' , async ( ) => {
203
171
const changes : Changes = [
204
- npmChange , // MIT license
205
- rubyChange // BSD license
206
- ]
207
-
208
- const { forbidden} = await getInvalidLicenseChanges ( changes , {
209
- allow : [ 'BSD-3-Clause' ]
210
- } )
211
-
212
- expect ( forbidden [ 0 ] ) . toBe ( npmChange )
213
- expect ( forbidden . length ) . toEqual ( 1 )
214
- } )
215
-
216
- test ( 'it adds license inside the deny list to forbidden changes' , async ( ) => {
217
- const changes : Changes = [
218
- npmChange , // MIT license
219
- rubyChange // BSD license
172
+ complexLicenseChange // MIT AND Apache-2.0 license
220
173
]
221
174
222
175
const { forbidden} = await getInvalidLicenseChanges ( changes , {
223
- deny : [ 'BSD-3-Clause ' ]
176
+ allow : [ 'MIT ' ]
224
177
} )
225
178
226
- expect ( forbidden [ 0 ] ) . toBe ( rubyChange )
227
179
expect ( forbidden . length ) . toEqual ( 1 )
228
180
} )
229
181
@@ -362,25 +314,3 @@ describe('GH License API fallback', () => {
362
314
expect ( unlicensed . length ) . toEqual ( 0 )
363
315
} )
364
316
} )
365
-
366
- function getChangeWithLicense ( license : string ) : Change {
367
- return {
368
- manifest : 'pom.xml' ,
369
- change_type : 'added' ,
370
- ecosystem : 'maven' ,
371
- name : 'dummy-library' ,
372
- version : '1.0.0' ,
373
- package_url : 'pkg:org.something:sdummy-library@1.0.0' ,
374
- license,
375
- source_repository_url : 'github.com/some-repo' ,
376
- scope : 'runtime' ,
377
- vulnerabilities : [
378
- {
379
- severity : 'critical' ,
380
- advisory_ghsa_id : 'first-random_string' ,
381
- advisory_summary : 'very dangerous' ,
382
- advisory_url : 'github.com/future-funk'
383
- }
384
- ]
385
- }
386
- }
0 commit comments