Commit 4fdf086c authored by Johan Bloemberg's avatar Johan Bloemberg

Refactor rebuild ratings to new scheme.

parent 794bb225
Pipeline #16135969 passed with stage
in 9 minutes and 43 seconds
......@@ -5,7 +5,7 @@ from django.shortcuts import redirect
from django.urls import reverse
from jet.dashboard import dashboard
from failmap.map.rating import rebuild_ratings as rebuild_ratings_task
from failmap.map import rating
from ..celery import PRIO_HIGH, status
from .models import Job
......@@ -31,7 +31,7 @@ def rebuild_ratings(request):
name = 'Rebuild ratings'
# create a Task signature for rebuilding ratings, wrap this inside a Job
# to have it trackable by the user in the admin interface
task = rebuild_ratings_task.s()
task = rating.create_task.s()
job = Job.create(task, name, request, priority=PRIO_HIGH)
# tell the user where to find the Job that was just created
......
import logging
from failmap.app.management.commands._private import TaskCommand
from ...rating import rebuild_ratings_async
log = logging.getLogger(__name__)
from ...rating import create_task
class Command(TaskCommand):
......@@ -12,6 +8,4 @@ class Command(TaskCommand):
help = __doc__
# 6.5 minutes
# original: 1 hour
task = rebuild_ratings_async
task = create_task()
This diff is collapsed.
......@@ -127,18 +127,18 @@ class TlsQualysScanAdmin(admin.ModelAdmin):
self.message_user(request, "URL(s) have been rated")
def scan_url(self, request, queryset):
urls_to_scan = []
for tlsqualysscan in queryset:
urls_to_scan.append(tlsqualysscan.endpoint.url.url)
scan(urls_to_scan)
self.message_user(request, "URL(s) have been scanned")
# def scan_url(self, request, queryset):
#
# urls_to_scan = []
# for tlsqualysscan in queryset:
# urls_to_scan.append(tlsqualysscan.endpoint.url.url)
#
# scan(urls_to_scan)
#
# self.message_user(request, "URL(s) have been scanned")
rate_url.short_description = "Rate (url)"
scan_url.short_description = "Scan (url)"
# scan_url.short_description = "Scan (url)"
class TlsQualysScratchpadAdmin(admin.ModelAdmin):
......
......@@ -12,4 +12,3 @@ class Command(ScannerTaskCommand):
help = __doc__
scanner_module = scanner_tls_qualys
......@@ -16,8 +16,8 @@ from colorama import Fore, Style, init
from freezegun import freeze_time
from httmock import HTTMock, response
from failmap.scanners import scanner_tls_qualys
from failmap.scanners.models import Endpoint, TlsQualysScan
from failmap.scanners.scanner_tls_qualys import scan
try:
# Python 3
......@@ -144,7 +144,7 @@ def test_tls_scan_qualys_sample_result(db):
announce_testcase(1, "Creating a new scan, where everything has to go right.")
with freeze_time('2000-1-1', tick=True, tz_offset=1):
with HTTMock(qualys_mock_a):
scan(["www.faalkaart.nl"])
scanner_tls_qualys.create_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
assert Endpoint.objects.filter(domain="www.faalkaart.nl").count() == 2 # ipv4 + ipv6
assert TlsQualysScan.objects.filter(qualys_rating="A").count() == 2
......@@ -152,7 +152,7 @@ def test_tls_scan_qualys_sample_result(db):
"or scan results. Scan results would only be updated after 24h.")
with freeze_time('2000-1-3', tick=True, tz_offset=1):
with HTTMock(qualys_mock_a):
scan(["www.faalkaart.nl"])
scanner_tls_qualys.create_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
assert Endpoint.objects.filter(domain="www.faalkaart.nl").count() == 2
assert TlsQualysScan.objects.filter(qualys_rating="A").count() == 2
......@@ -161,7 +161,7 @@ def test_tls_scan_qualys_sample_result(db):
"should increase as only changes are recorded.")
with freeze_time('2000-1-5', tick=True, tz_offset=1):
with HTTMock(qualys_mock_b):
scan(["www.faalkaart.nl"])
scanner_tls_qualys.create_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
assert Endpoint.objects.filter(domain="www.faalkaart.nl").count() == 2
assert TlsQualysScan.objects.filter(qualys_rating="A").count() == 2
assert TlsQualysScan.objects.filter(qualys_rating="B").count() == 2
......@@ -170,7 +170,7 @@ def test_tls_scan_qualys_sample_result(db):
"scan is dismissed")
with freeze_time('2000-1-5', tick=True, tz_offset=1):
with HTTMock(qualys_mock_c):
scan(["www.faalkaart.nl"])
scanner_tls_qualys.create_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
assert Endpoint.objects.filter(domain="www.faalkaart.nl").count() == 2
assert TlsQualysScan.objects.filter(qualys_rating="A").count() == 2
assert TlsQualysScan.objects.filter(qualys_rating="B").count() == 2
......@@ -179,7 +179,12 @@ def test_tls_scan_qualys_sample_result(db):
announce_testcase(5, "Verify that it's possible to scan multiple domains.")
with freeze_time('2000-1-7', tick=True, tz_offset=1):
with HTTMock(qualys_mirror):
scan(["www.faalkaart.nl", "www.elgerjonker.nl", "www.nu.nl"])
scanner_tls_qualys.create_task()(
urls_filter={
'name__in': [
"www.faalkaart.nl",
"www.elgerjonker.nl",
"www.nu.nl"]})
assert Endpoint.objects.filter(domain="www.faalkaart.nl").count() == 2
assert Endpoint.objects.filter(domain="www.elgerjonker.nl").count() == 2
......@@ -195,7 +200,7 @@ def test_tls_scan_qualys_sample_result(db):
Counter().reset()
with freeze_time('2000-1-9', tick=True, tz_offset=1):
with HTTMock(qualys_realistic_scan):
scan(["www.faalkaart.nl"])
scanner_tls_qualys.create_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
# no update on the rating, so no new scans.
assert TlsQualysScan.objects.filter(qualys_rating="A").count() == 8
......@@ -206,7 +211,7 @@ def test_tls_scan_qualys_sample_result(db):
Counter().reset()
with freeze_time('2000-1-11', tick=True, tz_offset=1):
with HTTMock(qualys_error_scan):
scan(["www.faalkaart.nl"])
scanner_tls_qualys.create_task()(urls_filter={'name__in': ["www.faalkaart.nl"]})
# no update on the rating, so no new scan.
# the endpoints should now be set to dead...
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment