99
1010import json
1111import os
12+ from collections import OrderedDict
1213from urllib .parse import quote
1314
1415from django .test import TestCase
@@ -223,18 +224,21 @@ def test_api_with_single_vulnerability(self):
223224 "vulnerability_id" : self .vulnerability .vulnerability_id ,
224225 "summary" : "test" ,
225226 "aliases" : [],
227+ "resource_url" : f"http://testserver/vulnerabilities/{ self .vulnerability .vulnerability_id } " ,
226228 "fixed_packages" : [
227229 {
228230 "url" : f"http://testserver/api/packages/{ self .pkg2 .id } " ,
229231 "purl" :
"pkg:deb/[email protected] " ,
230232 "is_vulnerable" : False ,
231233 "affected_by_vulnerabilities" : [],
234+ "resource_url" : f"http://testserver/packages/{ self .pkg2 .purl } " ,
232235 },
233236 {
234237 "url" : f"http://testserver/api/packages/{ self .pkg1 .id } " ,
235238 "purl" :
"pkg:pypi/[email protected] " ,
236239 "is_vulnerable" : False ,
237240 "affected_by_vulnerabilities" : [],
241+ "resource_url" : f"http://testserver/packages/{ self .pkg1 .purl } " ,
238242 },
239243 ],
240244 "affected_packages" : [],
@@ -257,11 +261,13 @@ def test_api_with_single_vulnerability_with_filters(self):
257261 "vulnerability_id" : self .vulnerability .vulnerability_id ,
258262 "summary" : "test" ,
259263 "aliases" : [],
264+ "resource_url" : f"http://testserver/vulnerabilities/{ self .vulnerability .vulnerability_id } " ,
260265 "fixed_packages" : [
261266 {
262267 "url" : f"http://testserver/api/packages/{ self .pkg1 .id } " ,
263268 "purl" :
"pkg:pypi/[email protected] " ,
264269 "is_vulnerable" : False ,
270+ "resource_url" : f"http://testserver/packages/{ self .pkg1 .purl } " ,
265271 "affected_by_vulnerabilities" : [],
266272 },
267273 ],
@@ -443,49 +449,106 @@ def test_api_with_lesser_and_greater_fixed_by_packages(self):
443449 "next_non_vulnerable_version" : "2.14.0-rc1" ,
444450 "latest_non_vulnerable_version" : "2.14.0-rc1" ,
445451 "affected_by_vulnerabilities" : [
446- {
447- "url" : f"http://testserver/api/vulnerabilities/{ self .vuln_VCID_2nyb_8rwu_aaag .id } " ,
448- "vulnerability_id" : "VCID-2nyb-8rwu-aaag" ,
449- "summary" : "This is VCID-2nyb-8rwu-aaag" ,
450- "references" : [],
451- "fixed_packages" : [
452- {
453- "url" : f"http://testserver/api/packages/{ self .package_maven_jackson_databind_2_13_2 .id } " ,
454- "purl" :
"pkg:maven/com.fasterxml.jackson.core/[email protected] " ,
455- "is_vulnerable" : True ,
456- "affected_by_vulnerabilities" : [
457- {"vulnerability" : "VCID-gqhw-ngh8-aaap" }
452+ OrderedDict (
453+ [
454+ (
455+ "url" ,
456+ f"http://testserver/api/vulnerabilities/{ self .vuln_VCID_2nyb_8rwu_aaag .id } " ,
457+ ),
458+ ("vulnerability_id" , "VCID-2nyb-8rwu-aaag" ),
459+ ("summary" , "This is VCID-2nyb-8rwu-aaag" ),
460+ ("references" , []),
461+ (
462+ "fixed_packages" ,
463+ [
464+ OrderedDict (
465+ [
466+ (
467+ "url" ,
468+ f"http://testserver/api/packages/{ self .package_maven_jackson_databind_2_13_2 .id } " ,
469+ ),
470+ (
471+ "purl" ,
472+ "pkg:maven/com.fasterxml.jackson.core/[email protected] " ,
473+ ),
474+ ("is_vulnerable" , True ),
475+ (
476+ "affected_by_vulnerabilities" ,
477+ [{"vulnerability" : "VCID-gqhw-ngh8-aaap" }],
478+ ),
479+ (
480+ "resource_url" ,
481+ "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected] " ,
482+ ),
483+ ]
484+ )
458485 ],
459- }
460- ],
461- "aliases" : ["CVE-2020-36518" , "GHSA-57j2-w4cx-62h2" ],
462- }
486+ ),
487+ ("aliases" , ["CVE-2020-36518" , "GHSA-57j2-w4cx-62h2" ]),
488+ ("resource_url" , "http://testserver/vulnerabilities/VCID-2nyb-8rwu-aaag" ),
489+ ]
490+ )
463491 ],
464492 "fixing_vulnerabilities" : [
465- {
466- "url" : f"http://testserver/api/vulnerabilities/{ self .vuln_VCID_ftmk_wbwx_aaar .id } " ,
467- "vulnerability_id" : "VCID-ftmk-wbwx-aaar" ,
468- "summary" : "This is VCID-ftmk-wbwx-aaar" ,
469- "references" : [],
470- "fixed_packages" : [
471- {
472- "url" : f"http://testserver/api/packages/{ self .package_maven_jackson_databind_2_12_6 .id } " ,
473- "purl" :
"pkg:maven/com.fasterxml.jackson.core/[email protected] " ,
474- "is_vulnerable" : False ,
475- "affected_by_vulnerabilities" : [],
476- },
477- {
478- "url" : f"http://testserver/api/packages/{ self .package_maven_jackson_databind_2_13_1 .id } " ,
479- "purl" :
"pkg:maven/com.fasterxml.jackson.core/[email protected] " ,
480- "is_vulnerable" : True ,
481- "affected_by_vulnerabilities" : [
482- {"vulnerability" : "VCID-2nyb-8rwu-aaag" }
493+ OrderedDict (
494+ [
495+ (
496+ "url" ,
497+ f"http://testserver/api/vulnerabilities/{ self .vuln_VCID_ftmk_wbwx_aaar .id } " ,
498+ ),
499+ ("vulnerability_id" , "VCID-ftmk-wbwx-aaar" ),
500+ ("summary" , "This is VCID-ftmk-wbwx-aaar" ),
501+ ("references" , []),
502+ (
503+ "fixed_packages" ,
504+ [
505+ OrderedDict (
506+ [
507+ (
508+ "url" ,
509+ f"http://testserver/api/packages/{ self .package_maven_jackson_databind_2_12_6 .id } " ,
510+ ),
511+ (
512+ "purl" ,
513+ "pkg:maven/com.fasterxml.jackson.core/[email protected] " ,
514+ ),
515+ ("is_vulnerable" , False ),
516+ ("affected_by_vulnerabilities" , []),
517+ (
518+ "resource_url" ,
519+ "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected] " ,
520+ ),
521+ ]
522+ ),
523+ OrderedDict (
524+ [
525+ (
526+ "url" ,
527+ f"http://testserver/api/packages/{ self .package_maven_jackson_databind_2_13_1 .id } " ,
528+ ),
529+ (
530+ "purl" ,
531+ "pkg:maven/com.fasterxml.jackson.core/[email protected] " ,
532+ ),
533+ ("is_vulnerable" , True ),
534+ (
535+ "affected_by_vulnerabilities" ,
536+ [{"vulnerability" : "VCID-2nyb-8rwu-aaag" }],
537+ ),
538+ (
539+ "resource_url" ,
540+ "http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected] " ,
541+ ),
542+ ]
543+ ),
483544 ],
484- },
485- ],
486- "aliases" : ["CVE-2021-46877" , "GHSA-3x8x-79m2-3w2w" ],
487- },
545+ ),
546+ ("aliases" , ["CVE-2021-46877" , "GHSA-3x8x-79m2-3w2w" ]),
547+ ("resource_url" , "http://testserver/vulnerabilities/VCID-ftmk-wbwx-aaar" ),
548+ ]
549+ )
488550 ],
551+ "resource_url" :
"http://testserver/packages/pkg:maven/com.fasterxml.jackson.core/[email protected] " ,
489552 }
490553
491554 assert response == expected_response
0 commit comments