Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Upcoming changes...

## [1.17.2] - 2024-10-29
## [1.17.2] - 2024-11-01
### Fixed
- Fixed parsing of dependencies in Policy Checks
- Fixed legacy SBOM.json support
### Added
- Added supplier to SPDX packages
### Changed
- Changed undeclared summary output

## [1.17.1] - 2024-10-24
### Fixed
Expand Down
16 changes: 11 additions & 5 deletions src/scanoss/inspection/undeclared_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,20 +115,26 @@ def _markdown(self, components: list) -> Dict[str,Any]:
'summary': self._get_summary(components),
}

def _generate_sbom_file(self, components: list) -> list:
def _generate_sbom_file(self, components: list) -> dict[str, list[dict[str, str]]]:
"""
Generate a list of PURLs for the SBOM file.

:param components: List of undeclared components
:return: List of dictionaries containing PURLs
:return: SBOM Dictionary with components
"""
sbom = {}

unique_components = {}
if components is None:
self.print_stderr(f'WARNING: No components provided!')
else:
for component in components:
sbom[component['purl']] = { 'purl': component['purl'] }
return list(sbom.values())
unique_components[component['purl']] = { 'purl': component['purl'] }

sbom = {
'components': list(unique_components.values())
}

return sbom

def run(self):
"""
Expand Down
62 changes: 34 additions & 28 deletions tests/policy-inspect-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,22 @@ def test_undeclared_policy(self):
expected_summary_output = """5 undeclared component(s) were found.
Add the following snippet into your `sbom.json` file
```json
[
{
"purl": "pkg:github/scanoss/scanner.c"
},
{
"purl": "pkg:github/scanoss/wfp"
},
{
"purl": "pkg:npm/%40electron/rebuild"
},
{
"purl": "pkg:npm/%40emotion/react"
}
]```
{
"components":[
{
"purl": "pkg:github/scanoss/scanner.c"
},
{
"purl": "pkg:github/scanoss/wfp"
},
{
"purl": "pkg:npm/%40electron/rebuild"
},
{
"purl": "pkg:npm/%40emotion/react"
}
]
}```
"""
self.assertEqual(len(details['components']), 5)
self.assertEqual(re.sub(r'\s|\\(?!`)|\\(?=`)', '', summary), re.sub(r'\s|\\(?!`)|\\(?=`)',
Expand Down Expand Up @@ -215,21 +217,25 @@ def test_undeclared_policy_markdown(self):
expected_summary_output = """5 undeclared component(s) were found.
Add the following snippet into your `sbom.json` file
```json
[
{
"purl": "pkg:github/scanoss/scanner.c"
},
{
"purl": "pkg:github/scanoss/wfp"
},
{
"purl": "pkg:npm/%40electron/rebuild"
},
{
"purl": "pkg:npm/%40emotion/react"
}
]```
{
"components":[
{
"purl": "pkg:github/scanoss/scanner.c"
},
{
"purl": "pkg:github/scanoss/wfp"
},
{
"purl": "pkg:npm/%40electron/rebuild"
},
{
"purl": "pkg:npm/%40emotion/react"
}
]
}```
"""

print(summary)
self.assertEqual(status, 0)
self.assertEqual(re.sub(r'\s|\\(?!`)|\\(?=`)', '', details), re.sub(r'\s|\\(?!`)|\\(?=`)',
'', expected_details_output))
Expand Down