1313
1414from vulnerabilities .models import Alias
1515from vulnerabilities .models import Package
16+ from vulnerabilities .models import PackageRelatedVulnerability
1617from vulnerabilities .models import Vulnerability
1718from vulnerabilities .models import VulnerabilityReference
1819from vulnerabilities .models import VulnerabilityRelatedReference
@@ -51,25 +52,40 @@ def test_api_with_single_vulnerability(self):
5152
5253class APITestCasePackage (TestCase ):
5354 def setUp (self ):
55+ vuln = Vulnerability .objects .create (
56+ summary = "test-vuln" ,
57+ )
58+ self .vuln = vuln
5459 for i in range (0 , 10 ):
5560 query_kwargs = dict (
5661 type = "generic" ,
5762 namespace = "nginx" ,
58- name = f "test- { i } " ,
63+ name = "test" ,
5964 version = str (i ),
6065 qualifiers = {},
6166 subpath = "" ,
6267 )
63- Package .objects .create (** query_kwargs )
68+ vuln_package = Package .objects .create (** query_kwargs )
69+ PackageRelatedVulnerability .objects .create (
70+ package = vuln_package ,
71+ vulnerability = vuln ,
72+ fix = False ,
73+ )
74+ self .vuln_package = vuln_package
6475 query_kwargs = dict (
6576 type = "generic" ,
6677 namespace = "nginx" ,
67- name = "test-vulnDB " ,
68- version = "1.0 " ,
78+ name = "test" ,
79+ version = "11 " ,
6980 qualifiers = {},
7081 subpath = "" ,
7182 )
7283 self .package = Package .objects .create (** query_kwargs )
84+ PackageRelatedVulnerability .objects .create (
85+ package = self .package ,
86+ vulnerability = vuln ,
87+ fix = True ,
88+ )
7389
7490 def test_api_status (self ):
7591 response = self .client .get ("/api/packages/" , format = "json" )
@@ -79,20 +95,80 @@ def test_api_response(self):
7995 response = self .client .get ("/api/packages/" , format = "json" ).data
8096 self .assertEqual (response ["count" ], 11 )
8197
82- def test_api_with_single_vulnerability (self ):
98+ def test_api_with_single_vulnerability_and_fixed_package (self ):
8399 response = self .client .get (f"/api/packages/{ self .package .id } " , format = "json" ).data
84100 assert response == {
85101 "url" : f"http://testserver/api/packages/{ self .package .id } " ,
86- "purl" :
"pkg:generic/nginx/test[email protected] " ,
102+ "purl" : "pkg:generic/nginx/test@11 " ,
87103 "type" : "generic" ,
88104 "namespace" : "nginx" ,
89- "name" : "test-vulnDB " ,
90- "version" : "1.0 " ,
105+ "name" : "test" ,
106+ "version" : "11 " ,
91107 "unresolved_vulnerabilities" : [],
92108 "qualifiers" : {},
93109 "subpath" : "" ,
94- "fixed_packages" : [],
110+ "fixed_packages" : [
111+ {
112+ "url" : f"http://testserver/api/packages/{ self .package .id } " ,
113+ "purl" : "pkg:generic/nginx/test@11" ,
114+ "fixing_vulnerabilities" : [
115+ {
116+ "url" : f"http://testserver/api/vulnerabilities/{ self .vuln .id } " ,
117+ "vulnerability_id" : f"VULCOID-{ int_to_base36 (self .vuln .id ).upper ()} " ,
118+ }
119+ ],
120+ }
121+ ],
95122 "affected_by_vulnerabilities" : [],
123+ "fixing_vulnerabilities" : [
124+ {
125+ "url" : f"http://testserver/api/vulnerabilities/{ self .vuln .id } " ,
126+ "vulnerability_id" : f"VULCOID-{ int_to_base36 (self .vuln .id ).upper ()} " ,
127+ "summary" : "test-vuln" ,
128+ "references" : [],
129+ }
130+ ],
131+ }
132+
133+ def test_api_with_single_vulnerability_and_vulnerable_package (self ):
134+ response = self .client .get (f"/api/packages/{ self .vuln_package .id } " , format = "json" ).data
135+ assert response == {
136+ "url" : f"http://testserver/api/packages/{ self .vuln_package .id } " ,
137+ "purl" : "pkg:generic/nginx/test@9" ,
138+ "type" : "generic" ,
139+ "namespace" : "nginx" ,
140+ "name" : "test" ,
141+ "version" : "9" ,
142+ "unresolved_vulnerabilities" : [
143+ {
144+ "url" : f"http://testserver/api/vulnerabilities/{ self .vuln .id } " ,
145+ "vulnerability_id" : f"VULCOID-{ int_to_base36 (self .vuln .id ).upper ()} " ,
146+ "summary" : "test-vuln" ,
147+ "references" : [],
148+ }
149+ ],
150+ "qualifiers" : {},
151+ "subpath" : "" ,
152+ "fixed_packages" : [
153+ {
154+ "url" : f"http://testserver/api/packages/{ self .package .id } " ,
155+ "purl" : "pkg:generic/nginx/test@11" ,
156+ "fixing_vulnerabilities" : [
157+ {
158+ "url" : f"http://testserver/api/vulnerabilities/{ self .vuln .id } " ,
159+ "vulnerability_id" : f"VULCOID-{ int_to_base36 (self .vuln .id ).upper ()} " ,
160+ }
161+ ],
162+ }
163+ ],
164+ "affected_by_vulnerabilities" : [
165+ {
166+ "url" : f"http://testserver/api/vulnerabilities/{ self .vuln .id } " ,
167+ "vulnerability_id" : f"VULCOID-{ int_to_base36 (self .vuln .id ).upper ()} " ,
168+ "summary" : "test-vuln" ,
169+ "references" : [],
170+ }
171+ ],
96172 "fixing_vulnerabilities" : [],
97173 }
98174
0 commit comments