-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Shivam Sandbhor <[email protected]>
- Loading branch information
Showing
3 changed files
with
117 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
# Visit https://github.com/nexB/vulnerablecode/ for support and download. | ||
|
||
import os | ||
from collections import OrderedDict | ||
from random import choices | ||
from unittest.mock import MagicMock | ||
from urllib.parse import quote | ||
|
@@ -31,6 +32,8 @@ | |
|
||
from vulnerabilities.api import PackageSerializer | ||
from vulnerabilities.models import Package | ||
from rest_framework.test import APIRequestFactory | ||
from rest_framework.test import APIClient | ||
|
||
|
||
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
@@ -188,3 +191,110 @@ def test_package_serializer(self): | |
purls = {r["purl"] for r in response} | ||
self.assertIn("pkg:deb/debian/[email protected]?distro=jessie", purls) | ||
self.assertIn("pkg:deb/debian/[email protected]?distro=jessie", purls) | ||
|
||
|
||
class TestBulkAPIResponse(TestCase): | ||
fixtures = ["debian.json"] | ||
|
||
def test_bulk_vulnerabilities_api(self): | ||
request_body = {"vulnerabilities": ["CVE-2009-1382", "CVE-2014-8242", "RANDOM-CVE"]} | ||
expected_response = { | ||
"CVE-2009-1382": { | ||
"url": "http://testserver/api/vulnerabilities/2/", | ||
"references": [], | ||
"resolved_packages": [ | ||
OrderedDict( | ||
[ | ||
("url", "http://testserver/api/packages/2/"), | ||
("purl", "pkg:deb/debian/[email protected]?distro=jessie"), | ||
] | ||
), | ||
OrderedDict( | ||
[ | ||
("url", "http://testserver/api/packages/3/"), | ||
("purl", "pkg:deb/debian/[email protected]?distro=jessie"), | ||
] | ||
), | ||
], | ||
"unresolved_packages": [], | ||
"cve_id": "CVE-2009-1382", | ||
"summary": "", | ||
"cvss": None, | ||
}, | ||
"CVE-2014-8242": { | ||
"url": "http://testserver/api/vulnerabilities/1/", | ||
"references": [], | ||
"resolved_packages": [], | ||
"unresolved_packages": [ | ||
OrderedDict( | ||
[ | ||
("url", "http://testserver/api/packages/1/"), | ||
("purl", "pkg:deb/debian/[email protected]?distro=jessie"), | ||
] | ||
) | ||
], | ||
"cve_id": "CVE-2014-8242", | ||
"summary": "", | ||
"cvss": None, | ||
}, | ||
"RANDOM-CVE": {}, | ||
} | ||
response = self.client.post("/api/vulnerabilities/bulk_search/", request_body).data | ||
assert response == expected_response | ||
|
||
def test_bulk_packages_api(self): | ||
request_body = { | ||
"packages": [ | ||
"pkg:deb/debian/[email protected]?distro=jessie", | ||
"pkg:deb/debian/[email protected]?distro=jessie", | ||
] | ||
} | ||
response = self.client.post("/api/packages/bulk_search/", request_body).data | ||
expected_response = { | ||
"pkg:deb/debian/[email protected]?distro=jessie": { | ||
"url": "http://testserver/api/packages/1/", | ||
"type": "deb", | ||
"namespace": "debian", | ||
"name": "librsync", | ||
"version": "0.9.7-10", | ||
"qualifiers": {"distro": "jessie"}, | ||
"subpath": "", | ||
"purl": "pkg:deb/debian/[email protected]?distro=jessie", | ||
"resolved_vulnerabilities": [], | ||
"unresolved_vulnerabilities": [ | ||
OrderedDict( | ||
[ | ||
("url", "http://testserver/api/vulnerabilities/1/"), | ||
("vulnerability_id", "CVE-2014-8242"), | ||
] | ||
) | ||
], | ||
}, | ||
"pkg:deb/debian/[email protected]?distro=jessie": { | ||
"url": "http://testserver/api/packages/3/", | ||
"type": "deb", | ||
"namespace": "debian", | ||
"name": "mimetex", | ||
"version": "1.50-1.1", | ||
"qualifiers": {"distro": "jessie"}, | ||
"subpath": "", | ||
"purl": "pkg:deb/debian/[email protected]?distro=jessie", | ||
"resolved_vulnerabilities": [ | ||
OrderedDict( | ||
[ | ||
("url", "http://testserver/api/vulnerabilities/2/"), | ||
("vulnerability_id", "CVE-2009-1382"), | ||
] | ||
), | ||
OrderedDict( | ||
[ | ||
("url", "http://testserver/api/vulnerabilities/3/"), | ||
("vulnerability_id", "CVE-2009-2459"), | ||
] | ||
), | ||
], | ||
"unresolved_vulnerabilities": [], | ||
}, | ||
} | ||
|
||
assert response == expected_response |