@@ -358,6 +358,19 @@ def setUp(self):
358358 attrs = {k : v for k , v in purl .to_dict ().items () if v }
359359 Package .objects .create (** attrs )
360360
361+ vulnerable_packages = [
362+ "pkg:nginx/nginx@1.0.15?foo=bar" ,
363+ "pkg:nginx/nginx@1.0.15?foo=baz" ,
364+ ]
365+
366+ vuln = Vulnerability .objects .create (summary = "test" )
367+
368+ for package in vulnerable_packages :
369+ purl = PackageURL .from_string (package )
370+ attrs = {k : v for k , v in purl .to_dict ().items () if v }
371+ pkg = Package .objects .create (** attrs )
372+ PackageRelatedVulnerability .objects .create (package = pkg , vulnerability = vuln )
373+
361374 def test_bulk_api_response (self ):
362375 request_body = {
363376 "purls" : self .packages ,
@@ -370,9 +383,7 @@ def test_bulk_api_response(self):
370383 assert len (response ) == 13
371384
372385 def test_bulk_api_response_with_ignoring_qualifiers (self ):
373- request_body = {
374- "purls" : ["pkg:nginx/nginx@1.0.15?qualifiers=dev" ],
375- }
386+ request_body = {"purls" : ["pkg:nginx/nginx@1.0.15?qualifiers=dev" ], "plain_purl" : True }
376387 response = self .csrf_client .post (
377388 "/api/packages/bulk_search" ,
378389 data = json .dumps (request_body ),
@@ -382,16 +393,28 @@ def test_bulk_api_response_with_ignoring_qualifiers(self):
382393 assert response [0 ]["purl" ] == "pkg:nginx/nginx@1.0.15"
383394
384395 def test_bulk_api_response_with_ignoring_subpath (self ):
396+ request_body = {"purls" : ["pkg:nginx/nginx@1.0.15#dev/subpath" ], "plain_purl" : True }
397+ response = self .csrf_client .post (
398+ "/api/packages/bulk_search" ,
399+ data = json .dumps (request_body ),
400+ content_type = "application/json" ,
401+ ).json ()
402+ assert len (response ) == 1
403+ assert response [0 ]["purl" ] == "pkg:nginx/nginx@1.0.15"
404+
405+ def test_bulk_api_with_purl_only_option (self ):
385406 request_body = {
386407 "purls" : ["pkg:nginx/nginx@1.0.15#dev/subpath" ],
408+ "purl_only" : True ,
409+ "plain_purl" : True ,
387410 }
388411 response = self .csrf_client .post (
389412 "/api/packages/bulk_search" ,
390413 data = json .dumps (request_body ),
391414 content_type = "application/json" ,
392415 ).json ()
393416 assert len (response ) == 1
394- assert response [0 ][ "purl" ] == "pkg:nginx/nginx@1.0.15"
417+ assert response [0 ] == "pkg:nginx/nginx@1.0.15"
395418
396419
397420class BulkSearchAPICPE (TestCase ):
0 commit comments