Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
feaf0b5
Expose Advisory details in API
ykodwani01 Apr 10, 2024
486d803
Updated Code Style
ykodwani01 Apr 10, 2024
f72c75a
Updated advisory data API response
ykodwani01 Apr 12, 2024
0b9b7f2
Updated response of API
ykodwani01 Apr 12, 2024
2807339
Updated response of API
ykodwani01 Apr 12, 2024
d4354df
Update test_api.py
ykodwani01 Apr 12, 2024
18df6dd
Updated API.py for DCO
ykodwani01 Apr 12, 2024
76ce9dd
Prepare for release v34.0.0rc4 (#1441)
TG1999 Mar 18, 2024
4e5d8db
Expose Advisory details in API
ykodwani01 Apr 10, 2024
b4d790c
Updated Code Style
ykodwani01 Apr 10, 2024
74b24cf
Updated response of API
ykodwani01 Apr 12, 2024
366aa5e
Updated API.py for DCO
ykodwani01 Apr 12, 2024
fdef1d5
Merge branch 'expose' of https://github.com/ykodwani01/vulnerablecode…
ykodwani01 Apr 12, 2024
84a494b
Add a test for cvss_printer (#1312)
ziadhany Feb 13, 2024
71ff402
Add support for all osv ecosystems (#926)
ziadhany Feb 13, 2024
c3bee0d
Add CVE support to Snyk datasource (#1405)
shravankshenoy Feb 23, 2024
e0e5276
Add resource URL to the vulnerability and package details view in the…
TG1999 Feb 23, 2024
baefb16
Bump cryptography from 42.0.0 to 42.0.4 (#1424)
dependabot[bot] Feb 26, 2024
6e20383
Prepare for release v34.0.0rc3 (#1426)
TG1999 Feb 26, 2024
202d76c
Revert 1400-fix_dupe_changelog (#1440)
TG1999 Mar 18, 2024
35f724b
Prepare for release v34.0.0rc4 (#1441)
TG1999 Mar 18, 2024
590fd92
Expose Advisory details in API
ykodwani01 Apr 10, 2024
e33a17c
Updated Code Style
ykodwani01 Apr 10, 2024
c0760fb
Updated response of API
ykodwani01 Apr 12, 2024
c97fd5f
Updated API.py for DCO
ykodwani01 Apr 12, 2024
76829db
Expose Advisory details in API
ykodwani01 Apr 10, 2024
e3e8a41
Updated Code Style
ykodwani01 Apr 10, 2024
7092cda
Updated response of API
ykodwani01 Apr 12, 2024
2a158fa
Merge branch 'expose' of https://github.com/ykodwani01/vulnerablecode…
ykodwani01 Apr 13, 2024
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
16 changes: 16 additions & 0 deletions vulnerabilities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from rest_framework.throttling import AnonRateThrottle
from rest_framework.throttling import UserRateThrottle

from vulnerabilities.models import Advisory
from vulnerabilities.models import Alias
from vulnerabilities.models import Package
from vulnerabilities.models import Vulnerability
Expand Down Expand Up @@ -182,6 +183,21 @@ def to_representation(self, instance):

weaknesses = data.get("weaknesses", [])
data["weaknesses"] = [weakness for weakness in weaknesses if weakness is not None]
alias_queryset = instance.aliases.all()
data["advisory"] = []
for itr in alias_queryset:
advisory_objects = Advisory.objects.filter(aliases=[itr.alias])
for advisory_object in advisory_objects:
data["advisory"].append(
{
"unique_content_id": advisory_object.unique_content_id,
"url": advisory_object.url,
"summary": advisory_object.summary,
"date_collected": advisory_object.date_collected,
"created_by": advisory_object.created_by,
}
)


return data

Expand Down
38 changes: 36 additions & 2 deletions vulnerabilities/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# See https://aboutcode.org for more information about nexB OSS projects.
#

import datetime
import json
import os
from collections import OrderedDict
Expand All @@ -21,6 +22,7 @@

from vulnerabilities.api import MinimalPackageSerializer
from vulnerabilities.api import PackageSerializer
from vulnerabilities.models import Advisory
from vulnerabilities.models import Alias
from vulnerabilities.models import ApiUser
from vulnerabilities.models import Package
Expand Down Expand Up @@ -193,13 +195,23 @@ def setUp(self):
summary=str(i),
)
self.vulnerability = Vulnerability.objects.create(summary="test")
self.alias = Alias.objects.create(alias="CORE-2010-0121", vulnerability=self.vulnerability)
self.pkg1 = Package.objects.create(name="flask", type="pypi", version="0.1.2")
self.pkg2 = Package.objects.create(name="flask", type="deb", version="0.1.2")
for pkg in [self.pkg1, self.pkg2]:
PackageRelatedVulnerability.objects.create(
package=pkg, vulnerability=self.vulnerability, fix=True
)
self.weaknesses = Weakness.objects.create(cwe_id=119)
self.advisory = Advisory.objects.create(
unique_content_id="6b7d417a552b19f26a5c2267ba7876c2",
aliases=["CORE-2010-0121"],
summary="Vulnerabilities with Windows 8.3 filename pseudonyms",
affected_packages=[],
url="https://nginx.org/en/security_advisories.html",
date_collected="2024-04-12T00:00:00",
created_by="vulnerabilities.importers.nginx.NginxImporter",
)
self.weaknesses.vulnerabilities.add(self.vulnerability)
self.invalid_weaknesses = Weakness.objects.create(
cwe_id=10000
Expand All @@ -223,7 +235,7 @@ def test_api_with_single_vulnerability(self):
"url": f"http://testserver/api/vulnerabilities/{self.vulnerability.id}",
"vulnerability_id": self.vulnerability.vulnerability_id,
"summary": "test",
"aliases": [],
"aliases": [OrderedDict([("alias", "CORE-2010-0121")])],
"resource_url": f"http://testserver/vulnerabilities/{self.vulnerability.vulnerability_id}",
"fixed_packages": [
{
Expand All @@ -250,6 +262,17 @@ def test_api_with_single_vulnerability(self):
"description": "The software performs operations on a memory buffer, but it can read from or write to a memory location that is outside of the intended boundary of the buffer.",
},
],
"advisory": [
{
"unique_content_id": "6b7d417a552b19f26a5c2267ba7876c2",
"url": "https://nginx.org/en/security_advisories.html",
"summary": "Vulnerabilities with Windows 8.3 filename pseudonyms",
"date_collected": datetime.datetime(
2024, 4, 12, 0, 0, tzinfo=datetime.timezone.utc
),
"created_by": "vulnerabilities.importers.nginx.NginxImporter",
}
],
}

def test_api_with_single_vulnerability_with_filters(self):
Expand All @@ -260,7 +283,7 @@ def test_api_with_single_vulnerability_with_filters(self):
"url": f"http://testserver/api/vulnerabilities/{self.vulnerability.id}",
"vulnerability_id": self.vulnerability.vulnerability_id,
"summary": "test",
"aliases": [],
"aliases": [OrderedDict([("alias", "CORE-2010-0121")])],
"resource_url": f"http://testserver/vulnerabilities/{self.vulnerability.vulnerability_id}",
"fixed_packages": [
{
Expand All @@ -280,6 +303,17 @@ def test_api_with_single_vulnerability_with_filters(self):
"description": "The software performs operations on a memory buffer, but it can read from or write to a memory location that is outside of the intended boundary of the buffer.",
},
],
"advisory": [
{
"unique_content_id": "6b7d417a552b19f26a5c2267ba7876c2",
"url": "https://nginx.org/en/security_advisories.html",
"summary": "Vulnerabilities with Windows 8.3 filename pseudonyms",
"date_collected": datetime.datetime(
2024, 4, 12, 0, 0, tzinfo=datetime.timezone.utc
),
"created_by": "vulnerabilities.importers.nginx.NginxImporter",
}
],
}


Expand Down