|
| 1 | +import datetime |
| 2 | + |
| 3 | +from django.test import TestCase |
| 4 | +from django.utils import timezone |
| 5 | + |
| 6 | +from dojo.filters import ApiFindingFilter, FindingFilterHelper |
| 7 | +from dojo.models import ( |
| 8 | + Engagement, |
| 9 | + Finding, |
| 10 | + Product, |
| 11 | + Product_Type, |
| 12 | + Test, |
| 13 | + Test_Type, |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +def _make_finding(title, mitigation, product): |
| 18 | + test_type, _ = Test_Type.objects.get_or_create(name="Unit Test") |
| 19 | + engagement = Engagement.objects.create( |
| 20 | + name="Test Engagement", |
| 21 | + product=product, |
| 22 | + target_start=timezone.now().date(), |
| 23 | + target_end=(timezone.now() + datetime.timedelta(days=1)).date(), |
| 24 | + ) |
| 25 | + test = Test.objects.create( |
| 26 | + engagement=engagement, |
| 27 | + test_type=test_type, |
| 28 | + target_start=timezone.now(), |
| 29 | + target_end=timezone.now() + datetime.timedelta(hours=1), |
| 30 | + ) |
| 31 | + return Finding.objects.create( |
| 32 | + title=title, |
| 33 | + test=test, |
| 34 | + severity="Medium", |
| 35 | + mitigation=mitigation, |
| 36 | + verified=True, |
| 37 | + active=True, |
| 38 | + ) |
| 39 | + |
| 40 | + |
| 41 | +class MitigationFilterTestCase(TestCase): |
| 42 | + @classmethod |
| 43 | + def setUpTestData(cls): |
| 44 | + prod_type = Product_Type.objects.create(name="Test Type") |
| 45 | + product = Product.objects.create( |
| 46 | + name="Test Product", |
| 47 | + prod_type=prod_type, |
| 48 | + ) |
| 49 | + cls.finding_with_mitigation = _make_finding("Finding A", "apply patch", product) |
| 50 | + cls.finding_null_mitigation = _make_finding("Finding B", None, product) |
| 51 | + cls.finding_empty_mitigation = _make_finding("Finding C", "", product) |
| 52 | + |
| 53 | + def _api_filter(self, params): |
| 54 | + qs = Finding.objects.all() |
| 55 | + f = ApiFindingFilter(params, queryset=qs) |
| 56 | + return set(f.qs.values_list("id", flat=True)) |
| 57 | + |
| 58 | + def test_mitigation_icontains(self): |
| 59 | + # Filtering by mitigation text returns only findings whose mitigation contains that substring |
| 60 | + pass |
| 61 | + |
| 62 | + def test_mitigation_available_true(self): |
| 63 | + # mitigation_available=true returns only findings with a non-null, non-empty mitigation |
| 64 | + pass |
| 65 | + |
| 66 | + def test_mitigation_available_false(self): |
| 67 | + # mitigation_available=false returns only findings with a null or empty mitigation |
| 68 | + pass |
| 69 | + |
| 70 | + def test_mitigation_available_false_handles_null(self): |
| 71 | + # mitigation_available=false includes findings where mitigation is NULL |
| 72 | + pass |
| 73 | + |
| 74 | + def test_mitigation_available_false_handles_empty_string(self): |
| 75 | + # mitigation_available=false includes findings where mitigation is an empty string |
| 76 | + pass |
| 77 | + |
| 78 | + |
| 79 | +class MitigationUIFilterTestCase(TestCase): |
| 80 | + @classmethod |
| 81 | + def setUpTestData(cls): |
| 82 | + prod_type = Product_Type.objects.create(name="UI Test Type") |
| 83 | + product = Product.objects.create( |
| 84 | + name="UI Test Product", |
| 85 | + prod_type=prod_type, |
| 86 | + ) |
| 87 | + cls.finding_with_mitigation = _make_finding("UI Finding A", "upgrade to v2", product) |
| 88 | + cls.finding_null_mitigation = _make_finding("UI Finding B", None, product) |
| 89 | + cls.finding_empty_mitigation = _make_finding("UI Finding C", "", product) |
| 90 | + |
| 91 | + def _ui_filter(self, params): |
| 92 | + qs = Finding.objects.all() |
| 93 | + f = FindingFilterHelper(params, queryset=qs) |
| 94 | + return set(f.qs.values_list("id", flat=True)) |
| 95 | + |
| 96 | + def test_mitigation_available_true(self): |
| 97 | + # mitigation_available=true returns only findings with a non-null, non-empty mitigation |
| 98 | + pass |
| 99 | + |
| 100 | + def test_mitigation_available_false(self): |
| 101 | + # mitigation_available=false returns only findings with a null or empty mitigation |
| 102 | + pass |
0 commit comments