Skip to content

Commit 29510b0

Browse files
committed
fix uni tests
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent c92ce57 commit 29510b0

13 files changed

Lines changed: 133 additions & 447 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ shell:
3030
# make test - full suite
3131
# make test k=<pattern> - filter by name, e.g. make test k=test_name
3232
test:
33+
${EXEC} web pip install --find-links=thirdparty/dist/ --no-index --no-cache-dir '.[dev]'
3334
${MANAGE} test --noinput --parallel auto $(if $(k),-k $(k),)
3435

3536
migrations:

component_catalog/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ class PackageSerializer(
631631
many=True,
632632
fields=[
633633
"advisory_uid",
634+
"advisory_id",
634635
"api_url",
635636
"uuid",
636637
],

component_catalog/tests/test_views.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,34 +3056,34 @@ def test_vulnerablecode_get_vulnerable_purls(self):
30563056
with mock.patch(
30573057
"dejacode_toolkit.vulnerablecode.VulnerableCode.bulk_search_by_purl"
30583058
) as bulk_search:
3059-
bulk_search.return_value = []
3059+
bulk_search.return_value = {"count": 0, "results": []}
30603060
vulnerable_purls = vulnerablecode.get_vulnerable_purls(packages=[self.package1])
30613061
self.assertEqual([], vulnerable_purls)
30623062

3063-
bulk_search.return_value = ["pkg:pypi/django@2.1"]
3063+
bulk_search.return_value = {"count": 1, "results": ["pkg:pypi/django@2.1"]}
30643064
vulnerable_purls = vulnerablecode.get_vulnerable_purls(packages=[self.package1])
30653065
self.assertEqual(["pkg:pypi/django@2.1"], vulnerable_purls)
30663066

3067-
@mock.patch("dejacode_toolkit.vulnerablecode.VulnerableCode.request_get")
3068-
def test_vulnerablecode_get_vulnerabilities_cache(self, mock_request_get):
3067+
@mock.patch("dejacode_toolkit.vulnerablecode.VulnerableCode.bulk_search_by_purl")
3068+
def test_vulnerablecode_get_vulnerabilities_cache(self, mock_bulk_search):
30693069
vulnerablecode = VulnerableCode(self.dataspace)
30703070

30713071
self.package1.set_package_url("pkg:pypi/django@2.1")
30723072
self.package1.save()
30733073

3074-
mock_request_get.return_value = {
3074+
mock_bulk_search.return_value = {
30753075
"count": 1,
30763076
"results": True,
30773077
}
30783078

30793079
results = vulnerablecode.get_vulnerabilities_by_purl(self.package1.package_url)
3080-
self.assertEqual(1, mock_request_get.call_count)
3080+
self.assertEqual(1, mock_bulk_search.call_count)
30813081
self.assertTrue(results)
30823082

30833083
results = vulnerablecode.get_vulnerabilities_by_purl(self.package1.package_url)
3084-
# request.get was only called once since the results are returned from the cached
3084+
# bulk_search_by_purl was only called once since the results are returned from the cache
30853085
# on the second call of `get_vulnerabilities_by_purl`.
3086-
self.assertEqual(1, mock_request_get.call_count)
3086+
self.assertEqual(1, mock_bulk_search.call_count)
30873087
self.assertTrue(results)
30883088

30893089
def test_send_scan_notification(self):

dje/tests/testfiles/outputs/csaf_security_advisory.csaf.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"ids": [
5454
{
5555
"system_name": "VulnerableCode",
56-
"text": "VCID-0001"
56+
"text": "ID-0001"
5757
},
5858
{
5959
"system_name": "Common Vulnerabilities and Exposures",
@@ -85,7 +85,7 @@
8585
"ids": [
8686
{
8787
"system_name": "VulnerableCode",
88-
"text": "VCID-0002"
88+
"text": "ID-0002"
8989
}
9090
],
9191
"notes": [
@@ -113,7 +113,7 @@
113113
"ids": [
114114
{
115115
"system_name": "VulnerableCode",
116-
"text": "VCID-0003"
116+
"text": "ID-0003"
117117
}
118118
],
119119
"notes": [

dje/tests/testfiles/outputs/openvex_document.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"statements": [
88
{
99
"vulnerability": {
10-
"name": "VCID-0001",
11-
"@id": "https://public.vulnerablecode.io/vulnerabilities/VCID-0001",
10+
"name": "ID-0001",
11+
"@id": "https://public.vulnerablecode.io/vulnerabilities/ID-0001",
1212
"description": "",
1313
"aliases": [
1414
"CVE-1984-1010"
@@ -27,8 +27,8 @@
2727
},
2828
{
2929
"vulnerability": {
30-
"name": "VCID-0002",
31-
"@id": "https://public.vulnerablecode.io/vulnerabilities/VCID-0002",
30+
"name": "ID-0002",
31+
"@id": "https://public.vulnerablecode.io/vulnerabilities/ID-0002",
3232
"description": "",
3333
"aliases": []
3434
},
@@ -45,7 +45,7 @@
4545
},
4646
{
4747
"vulnerability": {
48-
"name": "VCID-0003",
48+
"name": "ID-0003",
4949
"@id": "",
5050
"description": "",
5151
"aliases": []

product_portfolio/tests/test_views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def test_product_portfolio_tab_vulnerability_view_packages_row_rendering(self):
330330
data-bs-target="#vulnerability-analysis-modal"
331331
data-vulnerability-id="{vulnerability1.advisory_id}"
332332
data-package-identifier="{p1}"
333-
data-edit-url="/products/vulnerability_analysis/{pp1.uuid}/{vulnerability1.advisory_id}/"
333+
data-edit-url="/products/vulnerability_analysis/{pp1.uuid}/{vulnerability1.advisory_uid}/"
334334
>
335335
<button type="button" data-bs-toggle="tooltip" title="Edit" class="btn btn-link p-0"
336336
aria-label="Edit">
@@ -3384,7 +3384,7 @@ def test_product_portfolio_vulnerability_analysis_form_view(self):
33843384

33853385
url = reverse(
33863386
"product_portfolio:vulnerability_analysis_form",
3387-
args=[pp1.uuid, vulnerability1.advisory_id],
3387+
args=[pp1.uuid, vulnerability1.advisory_uid],
33883388
)
33893389

33903390
response = self.client.get(url)

product_portfolio/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def product_path(path_segment, view):
117117
name="edit_productrelation_ajax",
118118
),
119119
path(
120-
"vulnerability_analysis/<uuid:productpackage_uuid>/<str:advisory_uid>/",
120+
"vulnerability_analysis/<uuid:productpackage_uuid>/<path:advisory_uid>/",
121121
vulnerability_analysis_form_view,
122122
name="vulnerability_analysis_form",
123123
),

product_portfolio/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3232,7 +3232,7 @@ class ProductSecurityComplianceExportView(
32323232

32333233
export_filename = "security_compliance"
32343234
export_fields = {
3235-
"advisory_uid": "Vulnerability ID",
3235+
"advisory_id": "Vulnerability ID",
32363236
"aliases": "Aliases",
32373237
"summary": "Summary",
32383238
"risk_level": "Risk level",

vulnerabilities/fetch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def fetch_for_packages(
9595
purl = PackageURL.from_string(vc_entry.get("purl"))
9696
affected_packages = queryset.filter(
9797
type=purl.type,
98-
namespace=purl.namespace,
98+
namespace=purl.namespace or "",
9999
name=purl.name,
100100
version=purl.version,
101101
)

vulnerabilities/tests/data/vulnerabilities/idna_3.6_as_cyclonedx.json

Lines changed: 4 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -4,132 +4,10 @@
44
"ref": "pkg:type/name@1.9.0"
55
}
66
],
7-
"description": "Internationalized Domain Names in Applications (IDNA) vulnerable to denial of service from specially crafted inputs to idna.encode",
8-
"id": "VCID-j3au-usaz-aaag",
9-
"references": [
10-
{
11-
"id": "",
12-
"source": {
13-
"url": "https://access.redhat.com/hydra/rest/securitydata/cve/CVE-2024-3651.json"
14-
}
15-
},
16-
{
17-
"id": "",
18-
"source": {
19-
"url": "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-3651"
20-
}
21-
},
22-
{
23-
"id": "",
24-
"source": {
25-
"url": "https://ftp.suse.com/pub/projects/security/yaml/suse-cvss-scores.yaml"
26-
}
27-
},
28-
{
29-
"id": "",
30-
"source": {
31-
"url": "https://github.com/kjd/idna"
32-
}
33-
},
34-
{
35-
"id": "",
36-
"source": {
37-
"url": "https://github.com/kjd/idna/commit/1d365e17e10d72d0b7876316fc7b9ca0eebdd38d"
38-
}
39-
},
40-
{
41-
"id": "",
42-
"source": {
43-
"url": "https://github.com/pypa/advisory-database/tree/main/vulns/idna/PYSEC-2024-60.yaml"
44-
}
45-
},
46-
{
47-
"id": "",
48-
"source": {
49-
"url": "https://huntr.com/bounties/93d78d07-d791-4b39-a845-cbfabc44aadb"
50-
}
51-
},
52-
{
53-
"id": "1069127",
54-
"source": {
55-
"url": "https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1069127"
56-
}
57-
},
58-
{
59-
"id": "2274779",
60-
"source": {
61-
"url": "https://bugzilla.redhat.com/show_bug.cgi?id=2274779"
62-
}
63-
},
64-
{
65-
"id": "CVE-2024-3651",
66-
"source": {
67-
"url": "https://nvd.nist.gov/vuln/detail/CVE-2024-3651"
68-
}
69-
},
70-
{
71-
"id": "GHSA-jjg7-2v4v-x38h",
72-
"source": {
73-
"url": "https://github.com/advisories/GHSA-jjg7-2v4v-x38h"
74-
}
75-
},
76-
{
77-
"id": "GHSA-jjg7-2v4v-x38h",
78-
"source": {
79-
"url": "https://github.com/kjd/idna/security/advisories/GHSA-jjg7-2v4v-x38h"
80-
}
81-
},
82-
{
83-
"id": "RHSA-2024:3466",
84-
"source": {
85-
"url": "https://access.redhat.com/errata/RHSA-2024:3466"
86-
}
87-
},
88-
{
89-
"id": "RHSA-2024:3543",
90-
"source": {
91-
"url": "https://access.redhat.com/errata/RHSA-2024:3543"
92-
}
93-
},
94-
{
95-
"id": "RHSA-2024:3552",
96-
"source": {
97-
"url": "https://access.redhat.com/errata/RHSA-2024:3552"
98-
}
99-
},
100-
{
101-
"id": "RHSA-2024:3781",
102-
"source": {
103-
"url": "https://access.redhat.com/errata/RHSA-2024:3781"
104-
}
105-
},
106-
{
107-
"id": "RHSA-2024:3846",
108-
"source": {
109-
"url": "https://access.redhat.com/errata/RHSA-2024:3846"
110-
}
111-
},
112-
{
113-
"id": "RHSA-2024:4260",
114-
"source": {
115-
"url": "https://access.redhat.com/errata/RHSA-2024:4260"
116-
}
117-
},
118-
{
119-
"id": "USN-6780-1",
120-
"source": {
121-
"url": "https://usn.ubuntu.com/6780-1/"
122-
}
123-
},
124-
{
125-
"id": "cpe:2.3:a:kjd:internationalized_domain_names_in_applications:3.6:*:*:*:*:*:*:*",
126-
"source": {
127-
"url": "https://nvd.nist.gov/vuln/search/results?adv_search=true&isCpeNameSearch=true&query=cpe:2.3:a:kjd:internationalized_domain_names_in_applications:3.6:*:*:*:*:*:*:*"
128-
}
129-
}
130-
],
7+
"description": "A vulnerability was identified in the kjd/idna library, specifically within the `idna.encode()` function, affecting version 3.6. The issue arises from the function's handling of crafted input strings, which can lead to quadratic complexity and consequently, a denial of service condition. This vulnerability is triggered by a crafted input that causes the `idna.encode()` function to process the input with considerable computational load, significantly increasing the processing time in a quadratic manner relative to the input size.",
8+
"id": "PYSEC-2024-60",
1319
"source": {
13210
"name": "VulnerableCode",
133-
"url": "http://public.vulnerablecode.io/vulnerabilities/VCID-j3au-usaz-aaag"
11+
"url": "http://public.vulnerablecode.io/advisories/pypa/idna/PYSEC-2024-60"
13412
}
135-
}
13+
}

0 commit comments

Comments
 (0)