@@ -239,7 +239,9 @@ def test_bulk_vulnerabilities_api(self):
239239 },
240240 "RANDOM-CVE" : {},
241241 }
242- response = self .client .post ("/api/vulnerabilities/bulk_search/" , request_body ).data
242+ response = self .client .post (
243+ "/api/vulnerabilities/bulk_search/" , data = request_body , content_type = "application/json"
244+ ).data
243245 assert response == expected_response
244246
245247 def test_bulk_packages_api (self ):
@@ -249,7 +251,9 @@ def test_bulk_packages_api(self):
249251 "pkg:deb/debian/mimetex@1.50-1.1?distro=jessie" ,
250252 ]
251253 }
252- response = self .client .post ("/api/packages/bulk_search/" , request_body ).data
254+ response = self .client .post (
255+ "/api/packages/bulk_search/" , data = request_body , content_type = "application/json"
256+ ).data
253257 expected_response = {
254258 "pkg:deb/debian/librsync@0.9.7-10?distro=jessie" : {
255259 "url" : "http://testserver/api/packages/1/" ,
@@ -298,3 +302,60 @@ def test_bulk_packages_api(self):
298302 }
299303
300304 assert response == expected_response
305+
306+ def test_invalid_request_bulk_packages (self ):
307+ error_response = {
308+ "Error" : "Request needs to contain a key 'packages' which has the value of a list of package urls" # nopep8
309+ }
310+ invalid_key_request_data = {"pkg" : []}
311+ response = self .client .post (
312+ "/api/packages/bulk_search/" ,
313+ data = invalid_key_request_data ,
314+ content_type = "application/json" ,
315+ ).data
316+ assert response == error_response
317+
318+ valid_key_invalid_datatype_request_data = {"packages" : {}}
319+ response = self .client .post (
320+ "/api/packages/bulk_search/" ,
321+ data = valid_key_invalid_datatype_request_data ,
322+ content_type = "application/json" ,
323+ ).data
324+ assert response == error_response
325+
326+ invalid_purl_request_data = {
327+ "packages" : [
328+ "pkg:deb/debian/librsync@0.9.7-10?distro=jessie" ,
329+ "pg:deb/debian/mimetex@1.50-1.1?distro=jessie" ,
330+ ]
331+ }
332+ response = self .client .post (
333+ "/api/packages/bulk_search/" ,
334+ data = invalid_purl_request_data ,
335+ content_type = "application/json" ,
336+ ).data
337+ purl_error_respones = {
338+ "Error" : "purl is missing the required \" pkg\" scheme component: 'pg:deb/debian/mimetex@1.50-1.1?distro=jessie'." # nopep8
339+ }
340+ assert response == purl_error_respones
341+
342+ def test_invalid_request_bulk_vulnerabilities (self ):
343+ error_response = {
344+ "Error" : "Request needs to contain a key 'vulnerabilities' which has the value of a list of vulnerability ids" # nopep8
345+ }
346+
347+ wrong_key_data = {"xyz" : []}
348+ response = self .client .post (
349+ "/api/vulnerabilities/bulk_search/" ,
350+ data = wrong_key_data ,
351+ content_type = "application/json" ,
352+ ).data
353+ assert response == error_response
354+
355+ wrong_type_data = {"vulnerabilities" : {}}
356+ response = self .client .post (
357+ "/api/vulnerabilities/bulk_search/" ,
358+ data = wrong_key_data ,
359+ content_type = "application/json" ,
360+ ).data
361+ assert response == error_response
0 commit comments