@@ -66,10 +66,12 @@ def test_api_with_single_vulnerability(self):
6666 {
6767 "url" : f"http://testserver/api/packages/{ self .pkg1 .id } " ,
6868 "purl" :
"pkg:pypi/[email protected] " ,
69+ "is_vulnerable" : False ,
6970 },
7071 {
7172 "url" : f"http://testserver/api/packages/{ self .pkg2 .id } " ,
7273 "purl" :
"pkg:debian/[email protected] " ,
74+ "is_vulnerable" : False ,
7375 },
7476 ],
7577 "affected_packages" : [],
@@ -89,6 +91,7 @@ def test_api_with_single_vulnerability_with_filters(self):
8991 {
9092 "url" : f"http://testserver/api/packages/{ self .pkg1 .id } " ,
9193 "purl" :
"pkg:pypi/[email protected] " ,
94+ "is_vulnerable" : False ,
9295 },
9396 ],
9497 "affected_packages" : [],
@@ -136,6 +139,18 @@ def setUp(self):
136139 vulnerability = vuln ,
137140 fix = True ,
138141 )
142+ vuln1 = Vulnerability .objects .create (
143+ summary = "test-vuln1" ,
144+ )
145+ self .vuln1 = vuln1
146+ PackageRelatedVulnerability .objects .create (
147+ package = self .package ,
148+ vulnerability = vuln1 ,
149+ fix = False ,
150+ )
151+
152+ def test_is_vulnerable_attribute (self ):
153+ self .assertTrue (self .package .is_vulnerable )
139154
140155 def test_api_status (self ):
141156 response = self .csrf_client .get ("/api/packages/" , format = "json" )
@@ -156,7 +171,15 @@ def test_api_with_single_vulnerability_and_fixed_package(self):
156171 "version" : "11" ,
157172 "qualifiers" : {},
158173 "subpath" : "" ,
159- "affected_by_vulnerabilities" : [],
174+ "affected_by_vulnerabilities" : [
175+ {
176+ "url" : f"http://testserver/api/vulnerabilities/{ self .vuln1 .id } " ,
177+ "vulnerability_id" : f"VULCOID-{ int_to_base36 (self .vuln1 .id ).upper ()} " ,
178+ "summary" : "test-vuln1" ,
179+ "references" : [],
180+ "fixed_packages" : [],
181+ }
182+ ],
160183 "fixing_vulnerabilities" : [
161184 {
162185 "url" : f"http://testserver/api/vulnerabilities/{ self .vuln .id } " ,
@@ -167,11 +190,20 @@ def test_api_with_single_vulnerability_and_fixed_package(self):
167190 {
168191 "url" : f"http://testserver/api/packages/{ self .package .id } " ,
169192 "purl" : "pkg:generic/nginx/test@11" ,
193+ "is_vulnerable" : True ,
170194 }
171195 ],
172196 },
173197 ],
174- "unresolved_vulnerabilities" : [],
198+ "unresolved_vulnerabilities" : [
199+ {
200+ "url" : f"http://testserver/api/vulnerabilities/{ self .vuln1 .id } " ,
201+ "vulnerability_id" : f"VULCOID-{ int_to_base36 (self .vuln1 .id ).upper ()} " ,
202+ "summary" : "test-vuln1" ,
203+ "references" : [],
204+ "fixed_packages" : [],
205+ }
206+ ],
175207 }
176208
177209 def test_api_with_single_vulnerability_and_vulnerable_package (self ):
@@ -195,6 +227,7 @@ def test_api_with_single_vulnerability_and_vulnerable_package(self):
195227 {
196228 "url" : f"http://testserver/api/packages/{ self .package .id } " ,
197229 "purl" : "pkg:generic/nginx/test@11" ,
230+ "is_vulnerable" : True ,
198231 }
199232 ],
200233 }
@@ -210,6 +243,7 @@ def test_api_with_single_vulnerability_and_vulnerable_package(self):
210243 {
211244 "url" : f"http://testserver/api/packages/{ self .package .id } " ,
212245 "purl" : "pkg:generic/nginx/test@11" ,
246+ "is_vulnerable" : True ,
213247 }
214248 ],
215249 }
0 commit comments