Skip to content

Commit d6403f1

Browse files
Fix license exception compliance parsing bug
Reference: #1719 Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent 23d6724 commit d6403f1

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

scanpipe/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2585,7 +2585,7 @@ def compute_compliance_alert(self):
25852585
return ""
25862586

25872587
licensing = get_licensing()
2588-
parsed_symbols = licensing.parse(license_expression, simple=True).symbols
2588+
parsed_symbols = licensing.license_symbols(license_expression, simple=True)
25892589

25902590
alerts = [
25912591
self.get_alert_for_symbol(policy_index, symbol) for symbol in parsed_symbols

scanpipe/tests/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,14 @@ def make_mock_response(url, content=b"\x00", status_code=200, headers=None):
333333
"label": "Prohibited License",
334334
"compliance_alert": "error",
335335
},
336+
{
337+
"license_key": "gpl-2.0-plus",
338+
"compliance_alert": "warning",
339+
},
340+
{
341+
"license_key": "font-exception-gpl",
342+
"compliance_alert": "warning",
343+
},
336344
{
337345
"license_key": "OFL-1.1",
338346
"compliance_alert": "warning",
@@ -368,6 +376,14 @@ def make_mock_response(url, content=b"\x00", status_code=200, headers=None):
368376
"label": "Prohibited License",
369377
"compliance_alert": "error",
370378
},
379+
"gpl-2.0-plus": {
380+
"license_key": "gpl-2.0-plus",
381+
"compliance_alert": "warning",
382+
},
383+
"font-exception-gpl": {
384+
"license_key": "font-exception-gpl",
385+
"compliance_alert": "warning",
386+
},
371387
"OFL-1.1": {
372388
"license_key": "OFL-1.1",
373389
"compliance_alert": "warning",

scanpipe/tests/data/policies/policies.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ license_policies:
1212
label: Prohibited License
1313
compliance_alert: error
1414

15+
- license_key: gpl-2.0-plus
16+
compliance_alert: warning
17+
18+
# AboutCode license execption key
19+
- license_key: font-exception-gpl
20+
compliance_alert: warning
21+
1522
# SPDX license keys
1623
- license_key: OFL-1.1
1724
compliance_alert: warning

scanpipe/tests/test_models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,14 @@ def test_scanpipe_codebase_resource_model_compliance_alert_update_fields(self):
16011601
# Reset the index value
16021602
scanpipe_app.license_policies_index = None
16031603

1604+
def test_scanpipe_can_compute_compliance_alert_for_license_exceptions(self):
1605+
scanpipe_app.license_policies_index = license_policies_index
1606+
resource = CodebaseResource.objects.create(project=self.project1, path="file")
1607+
license_expression = "gpl-2.0-plus WITH font-exception-gpl"
1608+
resource.update(detected_license_expression=license_expression)
1609+
resource.compute_compliance_alert()
1610+
self.assertEqual("warning", resource.compliance_alert)
1611+
16041612
def test_scanpipe_scan_fields_model_mixin_methods(self):
16051613
expected = [
16061614
"detected_license_expression",

0 commit comments

Comments
 (0)