Skip to content

Commit b7a140a

Browse files
committed
Add namespace filter in packages api
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent e0731ad commit b7a140a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

vulnerabilities/api.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,15 @@ class PackageFilterSet(filters.FilterSet):
190190

191191
class Meta:
192192
model = Package
193-
fields = ["name", "type", "version", "subpath", "purl", "packagerelatedvulnerability__fix"]
193+
fields = [
194+
"name",
195+
"type",
196+
"version",
197+
"subpath",
198+
"purl",
199+
"namespace",
200+
"packagerelatedvulnerability__fix",
201+
]
194202

195203
def filter_purl(self, queryset, name, value):
196204
purl = unquote(value)

vulnerabilities/tests/test_fix_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ def test_api_response(self):
145145
response = self.csrf_client.get("/api/packages/", format="json").data
146146
self.assertEqual(response["count"], 11)
147147

148+
def test_api_with_namespace_filter(self):
149+
response = self.csrf_client.get("/api/packages/?namespace=nginx", format="json").data
150+
self.assertEqual(response["count"], 11)
151+
152+
def test_api_with_wrong_namespace_filter(self):
153+
response = self.csrf_client.get("/api/packages/?namespace=foo-bar", format="json").data
154+
self.assertEqual(response["count"], 0)
155+
148156
def test_api_with_single_vulnerability_and_fixed_package(self):
149157
response = self.csrf_client.get(f"/api/packages/{self.package.id}", format="json").data
150158
assert response == {

0 commit comments

Comments
 (0)