Skip to content

Commit 3a02221

Browse files
authored
Merge pull request #197 from nokia/check-url-download-location
The option `--strict-url-check` now checks the PackageDownloadLocation instead of the PackageHomePage
2 parents fa78844 + 42fe49b commit 3a02221

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

tools/openchain_telco_sbom_validator/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ the [OpenChain Telco SBOM Guide](https://github.com/OpenChain-Project/Telco-WG/b
55

66
What is new in version 0.3.1:
77
* new option `--noassertion` will list fields that have value NOASSERTION,
8-
* implement the strict mode for tool name and version (presence of "-").
8+
* implement the strict mode for tool name and version (presence of "-"),
9+
* the option `--strict-url-check` now checks the PackageDownloadLocation instead of the PackageHomePage.
910

1011
What is new in version 0.3.0:
1112
* you can validate recursively SBOMs linked by SPDX Relationships,

tools/openchain_telco_sbom_validator/src/openchain_telco_sbom_validator/cli.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def main():
6767
args.guide_version,
6868
args.strict,
6969
args.noassertion,
70-
args.strict_purl_check)
70+
args.strict_purl_check,
71+
args.strict_url_check)
7172
sys.exit(exitCode)
7273
except KeyboardInterrupt:
7374
print(" Ctrl-C pressed. Terminating...")
@@ -117,7 +118,7 @@ def parseArguments(additionalArguments: AdditionalArguments = AdditionalArgument
117118
' run a non-strict purl check meaning that it is not checked if the'
118119
' purl is translating to a downloadable URL.')
119120
parser.add_argument('--strict-url-check', action="store_true",
120-
help='Runs a strict check on the URLs of the PackageHomepages. Strict check'
121+
help='Runs a strict check on the URLs of the PackageDowloadLocation. Strict check'
121122
' means that the validator checks also if the given URL can be accessed.'
122123
' The default behaviour is to run a non-strict URL check, meaning that'
123124
' it is not checked if the URL points to a valid page. Strict URL check'
@@ -162,7 +163,7 @@ def parseArguments(additionalArguments: AdditionalArguments = AdditionalArgument
162163
if args.strict_purl_check:
163164
logger.info("Running strict checks for purls, what means that it is tested if the purls can be translated to a downloadable url.")
164165
if args.strict_url_check:
165-
logger.info("Running strict checks for URL, what means that it is tested if the PackageHomePage fields are pointing to real pages.")
166+
logger.info("Running strict checks for URL, what means that it is tested if the PackageDowloadLocation fields are pointing to real pages.")
166167

167168
if args.guide_version:
168169
logger.info(f"Checking for the {args.guide_version} version of the OpenChain Telco Guide")

tools/openchain_telco_sbom_validator/src/openchain_telco_sbom_validator/reporter.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
logger = logging.getLogger(__name__)
1414
logger.propagate = True
1515

16-
def reportCli(result, problems, nr_of_errors, input, guide_version, strict, noassertion, strict_purl_check):
16+
def reportCli(result, problems, nr_of_errors, input, guide_version, strict, noassertion, strict_purl_check, strict_url_check):
1717
if len(problems):
1818

1919
errors = problems.get_errors()
@@ -38,6 +38,11 @@ def reportCli(result, problems, nr_of_errors, input, guide_version, strict, noas
3838
print("Fields with purl that cannot be converted to a downloadable URL:")
3939
printTable(warnings, problems.print_file)
4040

41+
if strict_url_check:
42+
if len(warnings):
43+
print("PackageDownloadLocation field points to a nonexisting page:")
44+
printTable(warnings, problems.print_file)
45+
4146
if not result:
4247
if len(problems.checked_files) == 1:
4348
if strict:

tools/openchain_telco_sbom_validator/src/openchain_telco_sbom_validator/validator.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def validate(self,
183183
""" Validates, returns a status and a list of problems.
184184
filePath: path to the SPDX file to validate.
185185
strict_purl_check: not only checks the syntax of the PURL, but also checks if the package can be downloaded.
186-
strict_url_check: checks if the given URLs in PackageHomepages can be accessed.
186+
strict_url_check: checks if the given URLs in PackageDownloadLocation can be accessed.
187187
strict: checks for both MANDATORY and RECOMMENDED fields.
188188
noassertion: lists fields with value NOASSERTION.
189189
functionRegistry: is an optionsl functionRegistry class to inject custom checks.
@@ -529,27 +529,27 @@ def validate(self,
529529
"ExternalRef field is missing (no Package URL)",
530530
Problem.SCOPE_OPEN_CHAIN,
531531
Problem.SEVERITY_ERROR, file)
532-
if isinstance(package.homepage, type(None)):
533-
logger.debug("Package homepage is missing")
532+
if isinstance(package.download_location, type(None)):
533+
logger.debug("PackageDownloadLocation is missing")
534534
else:
535-
logger.debug(f"Package homepage is ({package.homepage})")
536-
if not validators.url(package.homepage):
537-
logger.debug("Package homepage is not a valid URL")
535+
logger.debug(f"PackageDownloadLocation is ({package.download_location})")
536+
if not validators.url(package.download_location):
537+
logger.debug("PackageDownloadLocation not a valid URL")
538538
# Adding this to the problem list is not needed as the SPDX validator also adds it
539-
# problems.append(["Invalid field in Package", package.spdx_id, package.name, f"PackageHomePage is not a valid URL ({package.homepage})"])
539+
# problems.append(["Invalid field in Package", package.spdx_id, package.name, f"PackageDownloadLocation a valid URL ({package.download_location})"])
540540
else:
541541
if strict_url_check:
542542
try:
543-
logger.debug("Checking package homepage")
544-
page = requests.get(package.homepage)
543+
logger.debug("Checking PackageDownloadLocation")
544+
page = requests.get(package.download_location)
545545
except Exception as err:
546546
logger.debug(f"Exception received ({format(err)})")
547547
problems.append("Invalid field in Package",
548548
package.spdx_id,
549549
package.name,
550-
f"PackageHomePage field points to a nonexisting page ({package.homepage})",
550+
f"PackageDownloadLocation field points to a nonexisting page ({package.download_location})",
551551
Problem.SCOPE_OPEN_CHAIN,
552-
Problem.SEVERITY_ERROR,
552+
Problem.SEVERITY_WARNING,
553553
file)
554554
# Version specifics
555555
match guide_version:

tools/openchain_telco_sbom_validator/unittests/sboms/unittest-sbom-12.spdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ PackageVersion: 2.4.57+dfsg-3+deb11u1
4545
PackageOriginator: Person: Debian OpenLDAP Maintainers <pkg-openldap-devel@lists.alioth.debian.org>
4646
PackageSupplier: Person: Jane Doe (jane.doe@example.com)
4747
PackageChecksum: SHA256: e325881d738b1091d0105778523ad60eb61e62557b9dc15624e08144b3991d08
48-
PackageDownloadLocation: NOASSERTION
48+
PackageDownloadLocation: https://www.not-openldap.org/
4949
FilesAnalyzed: true
5050
PackageHomePage: https://www.not-openldap.org/
5151
PackageVerificationCode: 8360ca10f484b118d367165552d0b934835d128a
@@ -98,4 +98,4 @@ ExtractedText: Autoconf
9898

9999

100100
Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-Package-deb-nopurl-libldap-2.4-2-796a192b709a2a2b
101-
Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-Package-deb-badpurl-libldap-2.4-2-796a192b709a2a2b
101+
Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-Package-deb-badpurl-libldap-2.4-2-796a192b709a2a2b

tools/openchain_telco_sbom_validator/unittests/test_validator_package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ def test_nok_purls():
1818
assert result == False
1919
assert len(problems) == 1
2020
assert problems[0].ErrorType == "Invalid field in Package"
21-
assert problems[0].Reason == "PackageHomePage field points to a nonexisting page (https://www.not-openldap.org/)"
21+
assert problems[0].Reason == "PackageDownloadLocation field points to a nonexisting page (https://www.not-openldap.org/)"
2222
assert problems[0].SPDX_ID == "SPDXRef-Package-deb-badpurl-libldap-2.4-2-796a192b709a2a2b"
2323
assert problems[0].PackageName == "badpurl-libldap-2.4-2"

0 commit comments

Comments
 (0)