Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search from alias in UI #765

Merged
merged 2 commits into from
Jun 15, 2022
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
12 changes: 11 additions & 1 deletion vulnerabilities/tests/test_view.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.test import Client
from django.test import TestCase

from vulnerabilities.models import Alias
from vulnerabilities.models import Vulnerability


Expand All @@ -26,6 +27,8 @@ class VulnerabilitySearchTestCase(TestCase):
def setUp(self):
vulnerability = Vulnerability(summary="test")
vulnerability.save()
alias = Alias(alias="TEST-2022", vulnerability=vulnerability)
alias.save()
self.id = vulnerability.id
self.client = Client()

Expand All @@ -36,9 +39,16 @@ def test_vulnerabilties(self):
response = self.client.get(f"/vulnerabilities/{self.id}")
self.assertEqual(response.status_code, 200)

def test_vulnerabilties(self):
def test_vulnerabilties_search(self):
"""
Test Vulnerability Search View
"""
response = self.client.get(f"/vulnerabilities/search")
self.assertEqual(response.status_code, 200)

def test_alias(self):
"""
Test Vulnerability Search View
"""
response = self.client.get(f"/vulnerabilities/search?vuln_id=TEST-2022")
self.assertEqual(response.status_code, 200)
4 changes: 3 additions & 1 deletion vulnerabilities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def get(self, request):
def request_to_vulnerabilities(request):
vuln_id = request.GET["vuln_id"]
return list(
models.Vulnerability.objects.filter(vulnerability_id=vuln_id).annotate(
models.Vulnerability.objects.filter(
Q(vulnerability_id=vuln_id) | Q(aliases__alias__icontains=vuln_id)
).annotate(
vulnerable_package_count=Count(
"packages", filter=Q(packagerelatedvulnerability__fix=False)
),
Expand Down