Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Version v30.0.0

- Add is_vulnerable property in fixed and affected_packages.

- Add namespace filter in packages api endpoint.

Other:

- we dropped calver to use a plain semver.
Expand Down
10 changes: 9 additions & 1 deletion vulnerabilities/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,15 @@ class PackageFilterSet(filters.FilterSet):

class Meta:
model = Package
fields = ["name", "type", "version", "subpath", "purl", "packagerelatedvulnerability__fix"]
fields = [
"name",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list of fields should be ordered this way:

            "purl",
            "type",
            "namespace",
            "name",
            "version",
            "subpath",
            "packagerelatedvulnerability__fix",

"type",
"version",
"subpath",
"purl",
"namespace",
"packagerelatedvulnerability__fix",
]

def filter_purl(self, queryset, name, value):
purl = unquote(value)
Expand Down
8 changes: 8 additions & 0 deletions vulnerabilities/tests/test_fix_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ def test_api_response(self):
response = self.csrf_client.get("/api/packages/", format="json").data
self.assertEqual(response["count"], 11)

def test_api_with_namespace_filter(self):
response = self.csrf_client.get("/api/packages/?namespace=nginx", format="json").data
self.assertEqual(response["count"], 11)

def test_api_with_wrong_namespace_filter(self):
response = self.csrf_client.get("/api/packages/?namespace=foo-bar", format="json").data
self.assertEqual(response["count"], 0)

def test_api_with_single_vulnerability_and_fixed_package(self):
response = self.csrf_client.get(f"/api/packages/{self.package.id}", format="json").data
assert response == {
Expand Down