Skip to content

Commit 663ef16

Browse files
authored
bug: Fix inspection of undeclared components with empty licenses
* bug:SP-2804 Fix inspection of undeclared components with empty licenses * chore:Upgrades version to v1.26.2 * chore:Updates CHANGELOG.md file
1 parent 116a3b1 commit 663ef16

File tree

6 files changed

+93
-22
lines changed

6 files changed

+93
-22
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Added
1010
- Upcoming changes...
1111

12-
## [1.26.1] - 2025-06-23
12+
## [1.26.2] - 2025-06-24
13+
### Fixed
14+
- Fixed inspection of undeclared components with empty licenses
1315

16+
## [1.26.1] - 2025-06-23
1417
### Added
1518
- Added component count to inspect license summary
1619
### Changed
@@ -560,4 +563,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
560563
[1.25.1]: https://github.com/scanoss/scanoss.py/compare/v1.25.0...v1.25.1
561564
[1.25.2]: https://github.com/scanoss/scanoss.py/compare/v1.25.1...v1.25.2
562565
[1.26.0]: https://github.com/scanoss/scanoss.py/compare/v1.25.2...v1.26.0
563-
[1.26.1]: https://github.com/scanoss/scanoss.py/compare/v1.26.0...v1.26.1
566+
[1.26.1]: https://github.com/scanoss/scanoss.py/compare/v1.26.0...v1.26.1
567+
[1.26.2]: https://github.com/scanoss/scanoss.py/compare/v1.26.1...v1.26.2

src/scanoss/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
THE SOFTWARE.
2323
"""
2424

25-
__version__ = '1.26.1'
25+
__version__ = '1.26.2'

src/scanoss/inspection/inspect_base.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,14 +393,31 @@ def _group_components_by_license(self,components):
393393
"""
394394
component_licenses: dict = {}
395395
for component in components:
396-
for lic in component['licenses']:
397-
spdxid = lic.get('spdxid', 'Unknown')
396+
purl = component.get('purl', '')
397+
status = component.get('status', '')
398+
licenses = component.get('licenses', [])
399+
400+
# Component without license
401+
if not licenses:
402+
key = f'{purl}-unknown'
403+
component_licenses[key] = {
404+
'purl': purl,
405+
'spdxid': 'unknown',
406+
'status': status,
407+
'copyleft': False,
408+
'url': '-',
409+
}
410+
continue
411+
412+
# Iterate over licenses component licenses
413+
for lic in licenses:
414+
spdxid = lic.get('spdxid', 'unknown')
398415
if spdxid not in component_licenses:
399-
key = f'{component["purl"]}-{spdxid}'
416+
key = f'{purl}-{spdxid}'
400417
component_licenses[key] = {
401-
'purl': component['purl'],
418+
'purl': purl,
402419
'spdxid': spdxid,
403-
'status': component['status'],
420+
'status': status,
404421
'copyleft': lic['copyleft'],
405422
'url': lic['url'],
406423
}

tests/data/result.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,38 @@
1111
}
1212
}
1313
],
14+
"inc/log.c": [
15+
{
16+
"component": "scanner.c",
17+
"file": "scanner.c-1.3.3/external/inc/json.h",
18+
"file_hash": "e91a03b850651dd56dd979ba92668a19",
19+
"file_url": "https://api.osskb.org/file_contents/e91a03b850651dd56dd979ba92668a19",
20+
"id": "file",
21+
"latest": "1.3.4",
22+
"licenses": [],
23+
"lines": "all",
24+
"matched": "100%",
25+
"oss_lines": "all",
26+
"purl": [
27+
"pkg:github/scanoss/jenkins-pipeline-example"
28+
],
29+
"release_date": "2021-05-26",
30+
"server": {
31+
"kb_version": {
32+
"daily": "24.08.16",
33+
"monthly": "24.07"
34+
},
35+
"version": "5.4.8"
36+
},
37+
"source_hash": "e91a03b850651dd56dd979ba92668a19",
38+
"status": "pending",
39+
"url": "https://github.com/scanoss/scanner.c",
40+
"url_hash": "2d1700ba496453d779d4987255feb5f2",
41+
"url_stats": {},
42+
"vendor": "scanoss",
43+
"version": "1.3.3"
44+
}
45+
],
1446
"inc/json.h": [
1547
{
1648
"component": "scanner.c",

tests/test_policy_inspect.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,14 @@ def test_undeclared_policy(self):
181181
status, results = undeclared.run()
182182
details = json.loads(results['details'])
183183
summary = results['summary']
184-
expected_summary_output = """2 undeclared component(s) were found.
184+
expected_summary_output = """3 undeclared component(s) were found.
185185
Add the following snippet into your `sbom.json` file
186186
```json
187187
{
188188
"components":[
189+
{
190+
"purl": "pkg:github/scanoss/jenkins-pipeline-example"
191+
},
189192
{
190193
"purl": "pkg:github/scanoss/scanner.c"
191194
},
@@ -195,7 +198,7 @@ def test_undeclared_policy(self):
195198
]
196199
}```
197200
"""
198-
self.assertEqual(len(details['components']), 3)
201+
self.assertEqual(len(details['components']), 4)
199202
self.assertEqual(
200203
re.sub(r'\s|\\(?!`)|\\(?=`)', '', summary), re.sub(r'\s|\\(?!`)|\\(?=`)', '', expected_summary_output)
201204
)
@@ -216,14 +219,18 @@ def test_undeclared_policy_markdown(self):
216219
expected_details_output = """ ### Undeclared components
217220
| Component | License |
218221
| - | - |
222+
| pkg:github/scanoss/jenkins-pipeline-example | unknown |
219223
| pkg:github/scanoss/scanner.c | GPL-2.0-only |
220224
| pkg:github/scanoss/wfp | GPL-2.0-only | """
221225

222-
expected_summary_output = """2 undeclared component(s) were found.
226+
expected_summary_output = """3 undeclared component(s) were found.
223227
Add the following snippet into your `sbom.json` file
224228
```json
225229
{
226230
"components":[
231+
{
232+
"purl": "pkg:github/scanoss/jenkins-pipeline-example"
233+
},
227234
{
228235
"purl": "pkg:github/scanoss/scanner.c"
229236
},
@@ -256,16 +263,20 @@ def test_undeclared_policy_markdown_scanoss_summary(self):
256263
expected_details_output = """ ### Undeclared components
257264
| Component | License |
258265
| - | - |
266+
| pkg:github/scanoss/jenkins-pipeline-example | unknown |
259267
| pkg:github/scanoss/scanner.c | GPL-2.0-only |
260268
| pkg:github/scanoss/wfp | GPL-2.0-only | """
261269

262-
expected_summary_output = """2 undeclared component(s) were found.
270+
expected_summary_output = """3 undeclared component(s) were found.
263271
Add the following snippet into your `scanoss.json` file
264272
265273
```json
266274
{
267275
"bom": {
268276
"include": [
277+
{
278+
"purl": "pkg:github/scanoss/jenkins-pipeline-example"
279+
},
269280
{
270281
"purl": "pkg:github/scanoss/scanner.c"
271282
},
@@ -296,13 +307,16 @@ def test_undeclared_policy_scanoss_summary(self):
296307
status, results = undeclared.run()
297308
details = json.loads(results['details'])
298309
summary = results['summary']
299-
expected_summary_output = """2 undeclared component(s) were found.
310+
expected_summary_output = """3 undeclared component(s) were found.
300311
Add the following snippet into your `scanoss.json` file
301312
302313
```json
303314
{
304315
"bom": {
305316
"include": [
317+
{
318+
"purl": "pkg:github/scanoss/jenkins-pipeline-example"
319+
},
306320
{
307321
"purl": "pkg:github/scanoss/scanner.c"
308322
},
@@ -314,7 +328,7 @@ def test_undeclared_policy_scanoss_summary(self):
314328
}
315329
```"""
316330
self.assertEqual(status, 0)
317-
self.assertEqual(len(details['components']), 3)
331+
self.assertEqual(len(details['components']), 4)
318332
self.assertEqual(
319333
re.sub(r'\s|\\(?!`)|\\(?=`)', '', summary), re.sub(r'\s|\\(?!`)|\\(?=`)', '', expected_summary_output)
320334
)
@@ -328,15 +342,19 @@ def test_undeclared_policy_jira_markdown_output(self):
328342
details = results['details']
329343
summary = results['summary']
330344
expected_details_output = """|*Component*|*License*|
345+
|pkg:github/scanoss/jenkins-pipeline-example|unknown|
331346
|pkg:github/scanoss/scanner.c|GPL-2.0-only|
332347
|pkg:github/scanoss/wfp|GPL-2.0-only|
333348
"""
334-
expected_summary_output = """2 undeclared component(s) were found.
349+
expected_summary_output = """3 undeclared component(s) were found.
335350
Add the following snippet into your `scanoss.json` file
336351
{code:json}
337352
{
338353
"bom": {
339354
"include": [
355+
{
356+
"purl": "pkg:github/scanoss/jenkins-pipeline-example"
357+
},
340358
{
341359
"purl": "pkg:github/scanoss/scanner.c"
342360
},
@@ -373,7 +391,7 @@ def test_inspect_license_summary(self):
373391
input_file_name = os.path.join(script_dir, 'data', file_name)
374392
i_license_summary = LicenseSummary(filepath=input_file_name)
375393
license_summary = i_license_summary.run()
376-
self.assertEqual(license_summary['detectedLicenses'], 2)
394+
self.assertEqual(license_summary['detectedLicenses'], 3)
377395
self.assertEqual(license_summary['detectedLicensesWithCopyleft'], 1)
378396

379397
def test_inspect_license_summary_with_empty_result(self):
@@ -393,11 +411,11 @@ def test_inspect_component_summary(self):
393411
i_component_summary = ComponentSummary(filepath=input_file_name)
394412
component_summary = i_component_summary.run()
395413
print(component_summary)
396-
self.assertEqual(component_summary['totalComponents'], 3)
397-
self.assertEqual(component_summary['undeclaredComponents'], 2)
414+
self.assertEqual(component_summary['totalComponents'], 4)
415+
self.assertEqual(component_summary['undeclaredComponents'], 3)
398416
self.assertEqual(component_summary['declaredComponents'], 1)
399-
self.assertEqual(component_summary['totalFilesDetected'], 7)
400-
self.assertEqual(component_summary['totalFilesUndeclared'], 5)
417+
self.assertEqual(component_summary['totalFilesDetected'], 8)
418+
self.assertEqual(component_summary['totalFilesUndeclared'], 6)
401419
self.assertEqual(component_summary['totalFilesDeclared'], 2)
402420

403421
def test_inspect_component_summary_empty_result(self):

tests/test_spdxlite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def testSpdxLite(self):
5858
self.assertEqual(name, "SCANOSS-SBOM")
5959
self.assertEqual(organization, "Organization: SCANOSS")
6060
self.assertEqual(creation_info_comment, "SBOM Build information - SBOM Type: Build")
61-
self.assertEqual(len(document_describes), 5)
62-
self.assertEqual(len(packages), 5)
61+
self.assertEqual(len(document_describes), 6)
62+
self.assertEqual(len(packages), 6)
6363

6464
for package in packages:
6565
for checksum in package.get("checksums", []):

0 commit comments

Comments
 (0)