Skip to content

Commit cbf1348

Browse files
Fix d2d pipeline bugs from ecosytem configurations (#1716)
* Fix d2d pipeline bugs from ecosytem configurations Reference: #1715 Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com> * Fix license exception compliance parsing bug Reference: #1719 Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com> * Add tests for leading d2d configurations Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com> --------- Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 0ecd1e8 commit cbf1348

File tree

8 files changed

+65
-5
lines changed

8 files changed

+65
-5
lines changed

scanpipe/models.py

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

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

25922592
alerts = [
25932593
self.get_alert_for_symbol(license_policy_index, symbol)

scanpipe/pipelines/deploy_to_develop.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def match_archives_to_purldb(self):
158158

159159
d2d.match_purldb_resources(
160160
project=self.project,
161-
extensions=self.matchable_package_extensions,
161+
extensions=self.ecosystem_config.matchable_package_extensions,
162162
matcher_func=d2d.match_purldb_package,
163163
logger=self.log,
164164
)
@@ -249,7 +249,7 @@ def match_resources_to_purldb(self):
249249

250250
d2d.match_purldb_resources(
251251
project=self.project,
252-
extensions=self.matchable_resource_extensions,
252+
extensions=self.ecosystem_config.matchable_resource_extensions,
253253
matcher_func=d2d.match_purldb_resource,
254254
logger=self.log,
255255
)

scanpipe/pipes/d2d_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,5 @@ def add_ecosystem_config(pipeline_ecosystem_config, ecosystem_config):
184184
if not pipeline_config_value:
185185
new_config_value = config_value
186186
else:
187-
new_config_value = pipeline_config_value.extend(config_value)
188-
187+
new_config_value = config_value + pipeline_config_value
189188
setattr(pipeline_ecosystem_config, config_name, new_config_value)

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",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"ecosystem_option": "Default",
3+
"matchable_package_extensions": [".jar", ".war", ".gem", ".zip", ".tar.gz", ".tar.xz"],
4+
"matchable_resource_extensions": [".map", ".js", ".mjs", ".ts", ".d.ts", ".jsx", ".tsx", ".css", ".scss", ".less", ".sass", ".soy",".class", ".rb"],
5+
"doc_extensions": [".pdf", ".doc", ".docx", ".ppt", ".pptx", ".tex", ".odt", ".odp"],
6+
"deployed_resource_path_exclusions": ["*checksums.yaml.gz*", "*metadata.gz*"],
7+
"devel_resource_path_exclusions": ["*/tests/*"],
8+
"standard_symbols_to_exclude": [],
9+
"source_symbol_extensions": []
10+
}

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/pipes/test_d2d.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
# Visit https://github.com/nexB/scancode.io for support and download.
2222

2323
import io
24+
import json
2425
import sys
2526
import tempfile
2627
import uuid
28+
from dataclasses import asdict
2729
from pathlib import Path
2830
from unittest import mock
2931
from unittest import skipIf
@@ -1864,3 +1866,21 @@ def test_scanpipe_pipes_d2d_map_javascript_strings(self):
18641866
map_type="javascript_strings",
18651867
).count(),
18661868
)
1869+
1870+
def test_scanpipe_d2d_load_ecosystem_config(self):
1871+
pipeline_name = "map_deploy_to_develop"
1872+
selected_groups = ["Ruby", "Java", "JavaScript"]
1873+
1874+
run = self.project1.add_pipeline(
1875+
pipeline_name=pipeline_name, selected_groups=selected_groups
1876+
)
1877+
pipeline = run.make_pipeline_instance()
1878+
d2d_config.load_ecosystem_config(pipeline=pipeline, options=selected_groups)
1879+
1880+
expected_ecosystem_config = (
1881+
self.data / "d2d" / "config" / "ecosystem_config.json"
1882+
)
1883+
with open(expected_ecosystem_config) as f:
1884+
expected_extra_data = json.load(f)
1885+
1886+
self.assertEqual(expected_extra_data, asdict(pipeline.ecosystem_config))

scanpipe/tests/test_models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,6 +1637,14 @@ def test_scanpipe_codebase_resource_model_compliance_alert_update_fields(self):
16371637
resource.refresh_from_db()
16381638
self.assertEqual("ok", resource.compliance_alert)
16391639

1640+
@patch.object(scanpipe_app, "policies", new=global_policies)
1641+
def test_scanpipe_can_compute_compliance_alert_for_license_exceptions(self):
1642+
scanpipe_app.license_policies_index = license_policies_index
1643+
resource = CodebaseResource.objects.create(project=self.project1, path="file")
1644+
license_expression = "gpl-2.0-plus WITH font-exception-gpl"
1645+
resource.update(detected_license_expression=license_expression)
1646+
self.assertEqual("warning", resource.compute_compliance_alert())
1647+
16401648
def test_scanpipe_scan_fields_model_mixin_methods(self):
16411649
expected = [
16421650
"detected_license_expression",

0 commit comments

Comments
 (0)