Skip to content

Commit

Permalink
Fix API errors
Browse files Browse the repository at this point in the history
Signed-off-by: Tushar Goel <[email protected]>
  • Loading branch information
TG1999 committed Nov 15, 2024
1 parent 297ab51 commit 1738194
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 24 deletions.
2 changes: 1 addition & 1 deletion vulnerabilities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def get_vulnerabilities_for_a_package(self, package, fix) -> dict:
otherwise return vulnerabilities fixed by the `package`.
"""
fixed_packages = self.get_fixed_packages(package=package)
if fix:
if not fix:
qs = package.affected_by_vulnerabilities.all()
else:
qs = package.fixing_vulnerabilities.all()
Expand Down
111 changes: 88 additions & 23 deletions vulnerabilities/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,65 @@ def setUp(self):
def test_api_with_lesser_and_greater_fixed_by_packages(self):
response = self.csrf_client.get(f"/api/packages/{self.pkg_2_13_1.id}", format="json").data

# expected = {
# "url": "http://testserver/api/packages/{0}".format(self.pkg_2_13_1.id),
# "purl": "pkg:maven/com.fasterxml.jackson.core/[email protected]",
# "type": "maven",
# "namespace": "com.fasterxml.jackson.core",
# "name": "jackson-databind",
# "version": "2.13.1",
# "qualifiers": {},
# "subpath": "",
# "is_vulnerable": True,
# "next_non_vulnerable_version": "2.14.0-rc1",
# "latest_non_vulnerable_version": "2.14.0-rc1",
# "affected_by_vulnerabilities": [
# {
# "url": "http://testserver/api/vulnerabilities/{0}".format(self.vul3.id),
# "vulnerability_id": "VCID-vul3-vul3-vul3",
# "summary": "This is VCID-vul3-vul3-vul3",
# "references": [],
# "fixed_packages": [],
# "aliases": ["CVE-2021-46877", "GHSA-3x8x-79m2-3w2w"],
# "resource_url": "http://testserver/vulnerabilities/VCID-vul3-vul3-vul3",
# }
# ],
# "fixing_vulnerabilities": [
# {
# "url": "http://testserver/api/vulnerabilities/{0}".format(self.vul1.id),
# "vulnerability_id": "VCID-vul1-vul1-vul1",
# "summary": "This is VCID-vul1-vul1-vul1",
# "references": [],
# "fixed_packages": [
# {
# "url": "http://testserver/api/packages/{0}".format(
# self.pkg_2_12_6_1.id
# ),
# "purl": "pkg:maven/com.fasterxml.jackson.core/[email protected]",
# "is_vulnerable": True,
# "affected_by_vulnerabilities": [
# {"vulnerability": "VCID-vul2-vul2-vul2"}
# ],
# "resource_url": "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected]",
# },
# {
# "url": "http://testserver/api/packages/{0}".format(self.pkg_2_13_2.id),
# "purl": "pkg:maven/com.fasterxml.jackson.core/[email protected]",
# "is_vulnerable": True,
# "affected_by_vulnerabilities": [
# {"vulnerability": "VCID-vul2-vul2-vul2"}
# ],
# "resource_url": "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected]",
# },
# ],
# "aliases": ["CVE-2020-36518", "GHSA-57j2-w4cx-62h2"],
# "resource_url": "http://testserver/vulnerabilities/VCID-vul1-vul1-vul1",
# }
# ],
# "resource_url": "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected]",
# "risk_score": None,
# }

expected = {
"url": "http://testserver/api/packages/{0}".format(self.pkg_2_13_1.id),
"purl": "pkg:maven/com.fasterxml.jackson.core/[email protected]",
Expand All @@ -583,50 +642,56 @@ def test_api_with_lesser_and_greater_fixed_by_packages(self):
"next_non_vulnerable_version": "2.14.0-rc1",
"latest_non_vulnerable_version": "2.14.0-rc1",
"affected_by_vulnerabilities": [
{
"url": "http://testserver/api/vulnerabilities/{0}".format(self.vul3.id),
"vulnerability_id": "VCID-vul3-vul3-vul3",
"summary": "This is VCID-vul3-vul3-vul3",
"references": [],
"fixed_packages": [],
"aliases": ["CVE-2021-46877", "GHSA-3x8x-79m2-3w2w"],
"resource_url": "http://testserver/vulnerabilities/VCID-vul3-vul3-vul3",
}
],
"fixing_vulnerabilities": [
{
"url": "http://testserver/api/vulnerabilities/{0}".format(self.vul1.id),
"vulnerability_id": "VCID-vul1-vul1-vul1",
"summary": "This is VCID-vul1-vul1-vul1",
"references": [],
"fixed_packages": [
{
"url": "http://testserver/api/packages/{0}".format(
self.pkg_2_12_6_1.id
),
"purl": "pkg:maven/com.fasterxml.jackson.core/[email protected]",
"url": "http://testserver/api/packages/{0}".format(self.pkg_2_13_2.id),
"purl": "pkg:maven/com.fasterxml.jackson.core/[email protected]",
"is_vulnerable": True,
"affected_by_vulnerabilities": [
{"vulnerability": "VCID-vul2-vul2-vul2"}
],
"resource_url": "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected]",
"resource_url": "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected]",
}
],
"aliases": ["CVE-2020-36518", "GHSA-57j2-w4cx-62h2"],
"resource_url": "http://testserver/vulnerabilities/VCID-vul1-vul1-vul1",
}
],
"fixing_vulnerabilities": [
{
"url": "http://testserver/api/vulnerabilities/{0}".format(self.vul3.id),
"vulnerability_id": "VCID-vul3-vul3-vul3",
"summary": "This is VCID-vul3-vul3-vul3",
"references": [],
"fixed_packages": [
{
"url": "http://testserver/api/packages/{0}".format(self.pkg_2_12_6.id),
"purl": "pkg:maven/com.fasterxml.jackson.core/[email protected]",
"is_vulnerable": False,
"affected_by_vulnerabilities": [],
"resource_url": "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected]",
},
{
"url": "http://testserver/api/packages/{0}".format(self.pkg_2_13_2.id),
"purl": "pkg:maven/com.fasterxml.jackson.core/[email protected].2",
"url": "http://testserver/api/packages/{0}".format(self.pkg_2_13_1.id),
"purl": "pkg:maven/com.fasterxml.jackson.core/[email protected].1",
"is_vulnerable": True,
"affected_by_vulnerabilities": [
{"vulnerability": "VCID-vul2-vul2-vul2"}
{"vulnerability": "VCID-vul1-vul1-vul1"}
],
"resource_url": "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected].2",
"resource_url": "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected].1",
},
],
"aliases": ["CVE-2020-36518", "GHSA-57j2-w4cx-62h2"],
"resource_url": "http://testserver/vulnerabilities/VCID-vul1-vul1-vul1",
"aliases": ["CVE-2021-46877", "GHSA-3x8x-79m2-3w2w"],
"resource_url": "http://testserver/vulnerabilities/VCID-vul3-vul3-vul3",
}
],
"resource_url": "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected]",
"risk_score": None,
"resource_url": "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected]",
}

assert response == expected
Expand Down

0 comments on commit 1738194

Please sign in to comment.