From 8d626e2e43459cf373595af2192bf05ffef0124c Mon Sep 17 00:00:00 2001 From: Tushar Goel Date: Wed, 15 Jun 2022 23:17:46 +0530 Subject: [PATCH 1/2] Search from alias in UI Signed-off-by: Tushar Goel --- vulnerabilities/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vulnerabilities/views.py b/vulnerabilities/views.py index 54325074a..a920e155e 100644 --- a/vulnerabilities/views.py +++ b/vulnerabilities/views.py @@ -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) ), From 2fad684550c956c7a955957808aaa8322ad3f99e Mon Sep 17 00:00:00 2001 From: Tushar Goel Date: Wed, 15 Jun 2022 23:27:27 +0530 Subject: [PATCH 2/2] Add tests Signed-off-by: Tushar Goel --- vulnerabilities/tests/test_view.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/vulnerabilities/tests/test_view.py b/vulnerabilities/tests/test_view.py index 650f6ffe5..6421e3490 100644 --- a/vulnerabilities/tests/test_view.py +++ b/vulnerabilities/tests/test_view.py @@ -1,6 +1,7 @@ from django.test import Client from django.test import TestCase +from vulnerabilities.models import Alias from vulnerabilities.models import Vulnerability @@ -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() @@ -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)