From 0442494a2fe0c75c450c882e59d9c86803800bbf Mon Sep 17 00:00:00 2001 From: Romain Kieffer Date: Wed, 24 Jul 2024 15:13:50 +0200 Subject: [PATCH] chg: [tp] Added model for storing test result Signed-off-by: Romain Kieffer --- testing/admin.py | 2 ++ testing/models.py | 9 +++++++++ testing/views.py | 9 +++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/testing/admin.py b/testing/admin.py index 531aab2b..5849f2fa 100644 --- a/testing/admin.py +++ b/testing/admin.py @@ -7,6 +7,7 @@ MailDomain, TlsScanHistory, UserDomain, + TestReport ) @@ -26,3 +27,4 @@ def get_username(self, obj): admin.site.register(DMARCRecord) admin.site.register(DMARCReport) admin.site.register(TlsScanHistory) +admin.site.register(TestReport) diff --git a/testing/models.py b/testing/models.py index db53fcbc..261d8ccd 100644 --- a/testing/models.py +++ b/testing/models.py @@ -94,3 +94,12 @@ class DMARCReport(models.Model): def __str__(self): return f"{self.dmarc_record}-{self.mail_from}-{self.timestamp}" + + +class TestReport(models.Model): + tested_site = models.CharField(max_length=200, blank=True, null=True) + test_ran = models.CharField(max_length=200, blank=True, null=True) + report = models.JSONField() + + def __str__(self): + return f"{self.test_ran}_{self.tested_site.replace('.', '-')}" diff --git a/testing/views.py b/testing/views.py index d2fd8fb5..7a0a7f24 100644 --- a/testing/views.py +++ b/testing/views.py @@ -47,7 +47,7 @@ from .zap import zap_scan -from .models import DMARCRecord, DMARCReport, MailDomain +from .models import DMARCRecord, DMARCReport, MailDomain, TestReport @login_required @@ -140,8 +140,13 @@ def zap_test(request): nb_tests += 1 context = json_report['site'][0] response = render(request, "check_zap.html", context) + test_report = TestReport( + tested_site=target, + test_ran="zap", + report=context + ) + test_report.save() response.set_cookie("nb_tests", nb_tests) - print("wat") return response # return HttpResponse(html_report) else: