-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 1286-add-clickable-links-to-tabs #1286
Reference: #1286 Signed-off-by: John M. Horan <[email protected]>
- Loading branch information
Showing
6 changed files
with
263 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# | ||
# Copyright (c) nexB Inc. and others. All rights reserved. | ||
# VulnerableCode is a trademark of nexB Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text. | ||
# See https://github.com/nexB/vulnerablecode for support or download. | ||
# See https://aboutcode.org for more information about nexB OSS projects. | ||
# | ||
|
||
import pytest | ||
|
||
from vulnerabilities.importer import AdvisoryData | ||
from vulnerabilities.importer import Reference | ||
from vulnerabilities.improver import MAX_CONFIDENCE | ||
from vulnerabilities.improver import Inference | ||
from vulnerabilities.improver import PackageURL | ||
|
||
|
||
def test_empty_inference_raises_exception(): | ||
with pytest.raises(AssertionError): | ||
Inference() | ||
|
||
|
||
def test_inference_to_dict_method_with_vulnerability_id(): | ||
inference = Inference(vulnerability_id="vulcoid-1337") | ||
expected = { | ||
"vulnerability_id": "vulcoid-1337", | ||
"aliases": [], | ||
"confidence": MAX_CONFIDENCE, | ||
"summary": "", | ||
"affected_purls": [], | ||
"fixed_purl": None, | ||
"references": [], | ||
"weaknesses": [], | ||
} | ||
assert expected == inference.to_dict() | ||
|
||
|
||
def test_inference_to_dict_method_with_purls(): | ||
purl = PackageURL(type="dummy", namespace="rick", name="jalebi", version="1") | ||
inference = Inference(affected_purls=[purl], fixed_purl=purl) | ||
expected = { | ||
"vulnerability_id": None, | ||
"aliases": [], | ||
"confidence": MAX_CONFIDENCE, | ||
"summary": "", | ||
"affected_purls": [purl.to_dict()], | ||
"fixed_purl": purl.to_dict(), | ||
"references": [], | ||
"weaknesses": [], | ||
} | ||
assert expected == inference.to_dict() | ||
|
||
|
||
def test_inference_to_dict_method_with_versionless_purls_raises_exception(): | ||
versionless_purl = PackageURL(type="dummy", namespace="rick", name="gulabjamun") | ||
with pytest.raises(AssertionError): | ||
Inference(affected_purls=[versionless_purl], fixed_purl=versionless_purl) | ||
|
||
|
||
def test_inference_from_advisory_data(): | ||
aliases = ["lalmohan", "gulabjamun"] | ||
summary = "really tasty sweets" | ||
references = [Reference(url="http://localhost")] | ||
advisory_data = AdvisoryData(aliases=aliases, summary=summary, references=references) | ||
fixed_purl = PackageURL(name="mithai", version="1", type="sweets") | ||
inference = Inference.from_advisory_data( | ||
advisory_data=advisory_data, fixed_purl=fixed_purl, confidence=MAX_CONFIDENCE | ||
) | ||
assert inference == Inference( | ||
aliases=aliases, summary=summary, references=references, fixed_purl=fixed_purl | ||
) |
Oops, something went wrong.