renamed commands, fixed django1.11 because of Django-Jet

parent 6be5ba40
......@@ -141,13 +141,13 @@ The setup script performs the following steps:
failmap-admin migrate
# create a user to view the admin interface
failmap-admin load-dataset development
failmap-admin load_dataset development
# loads a series of sample data into the database
failmap-admin load-dataset testdata
failmap-admin load_dataset testdata
# calculate the scores that should be displayed on the map
failmap-admin rebuild-ratings
failmap-admin rebuild_ratings
# Scanning services (beta)
......@@ -168,13 +168,13 @@ These services help fill the database with accurate up to date information. Run
a separate command line window and keep them running.
# handles all new urls with an initial (fast) scan
failmap-admin onboard-service
failmap-admin onboard_service
# slowly gets results from qualys
failmap-admin scan-tls-qualys-service
failmap-admin scan_tls_qualys_service
# makes many gigabytes of screenshots
failmap-admin screenshot-service
failmap-admin screenshot_service
# Using the software
......
......@@ -115,7 +115,7 @@ services:
DJANGO_DATABASE: production
# django decides what to log based on type of console
TERM: xterm-color
command: [ "load-dataset", "development", "testdata" ]
command: [ "load_dataset", "development", "testdata" ]
# retry if action failes (ie: database container is not ready yet)
restart: on-failure
......
......@@ -24,7 +24,10 @@ class Job(models.Model):
created_on = models.DateTimeField(auto_now_add=True, blank=True, null=True, help_text="when task was created")
finished_on = models.DateTimeField(blank=True, null=True, help_text="when task ended")
created_by = models.ForeignKey(User, blank=True, null=True)
# TypeError: __init__() missing 1 required positional argument: 'on_delete'
# probably because of blank and/or default.
created_by = models.ForeignKey(User, blank=True, null=True, on_delete=models.CASCADE,)
@classmethod
def create(cls, task: celery.Task, name: str, request, *args, **kwargs) -> 'Job':
......
......@@ -28,7 +28,7 @@ class OrganizationRating(models.Model):
Also this should not know too much about different scanners. In OO fashion, it should ask a
scanner to explain why something is the way it is (over time).
"""
organization = models.ForeignKey(Organization, on_delete=models.PROTECT,)
organization = models.ForeignKey(Organization, on_delete=models.CASCADE)
rating = models.IntegerField(
help_text="Amount of points scored by the organization based on a sum of all URL ratings at"
" this moment. Rating -1 is used as a default first rating, which are displayed "
......@@ -56,7 +56,7 @@ class UrlRating(models.Model):
"""
Aggregrates the results of many scanners to determine a rating for a URL.
"""
url = models.ForeignKey(Url)
url = models.ForeignKey(Url, on_delete=models.CASCADE)
rating = models.IntegerField(
help_text="Amount of points scored after rating the URL. Ratings are usually positive, yet "
"this is not a positive integerfield because we might use -1 as an 'unknown' "
......
......@@ -85,7 +85,7 @@ class Coordinate(models.Model):
class Url(models.Model):
organization_old = models.ForeignKey(Organization, null=True) # on_delete=models.PROTECT
organization_old = models.ForeignKey(Organization, null=True, on_delete=models.PROTECT)
organization = models.ManyToManyField(Organization, related_name="u_many_o_upgrade")
......@@ -162,7 +162,7 @@ class Url(models.Model):
return False
def add_subdomain(self, subdomain):
# import here to prevent circular/cyclic imports
# import here to prevent circular/cyclic imports, this module imports Url.
from failmap_admin.scanners.scanner_http import resolves
new_url = (subdomain + "." + self.url).lower()
......
# coding=UTF-8
from django.db import models
# from failmap_admin.organizations.models import Url
from failmap_admin.organizations.models import Url
class Endpoint(models.Model):
......@@ -32,9 +32,10 @@ class Endpoint(models.Model):
# imported using a string, to avoid circular imports, which happens in complexer models
# https://stackoverflow.com/questions/4379042/django-circular-model-import-issue
url = models.ForeignKey(
'organizations.Url',
Url,
null=True,
blank=True
blank=True,
on_delete=models.CASCADE
)
ip_version = models.IntegerField(
......@@ -118,9 +119,11 @@ class UrlIp(models.Model):
"""
url = models.ForeignKey(
'organizations.Url',
Url,
blank=True,
null=True)
null=True,
on_delete=models.CASCADE
)
ip = models.CharField(
max_length=255,
......@@ -154,7 +157,7 @@ class TlsQualysScan(models.Model):
"""
Model for scanner tls qualys
"""
endpoint = models.ForeignKey(Endpoint)
endpoint = models.ForeignKey(Endpoint, on_delete=models.CASCADE)
# result from the API
qualys_rating = models.CharField(max_length=3, default=0) # 0, F, D, C, B, A-, A, A+
......@@ -196,9 +199,10 @@ class EndpointGenericScan(models.Model):
"scan, this label separates the scans.")
endpoint = models.ForeignKey(
Endpoint,
on_delete=models.PROTECT,
on_delete=models.CASCADE,
null=True,
blank=True)
blank=True,
)
domain = models.CharField(
max_length=255,
help_text="Used when there is no known endpoint.")
......@@ -252,7 +256,7 @@ class EndpointGenericScanScratchpad(models.Model):
class Screenshot(models.Model):
endpoint = models.ForeignKey(
Endpoint, null=True, blank=True)
Endpoint, null=True, blank=True, on_delete=models.CASCADE)
domain = models.CharField(max_length=255, help_text="Used when there is no known URL.")
filename = models.CharField(max_length=255)
width_pixels = models.IntegerField(default=0)
......
......@@ -35,8 +35,8 @@ from requests import ConnectTimeout, HTTPError, ReadTimeout, Timeout
from requests.exceptions import ConnectionError
from failmap_admin.celery import app
from failmap_admin.scanners.models import Endpoint, UrlIp
from failmap_admin.organizations.models import Url
from failmap_admin.scanners.models import Endpoint, UrlIp
from .timeout import timeout
......@@ -186,7 +186,7 @@ def can_connect(protocol: str, url: Url, port: int, ip: str):
Any status code is enough to verify that there is an endpoint.
Some servers don't return a status code, that will trigger an exception (AttributeError?)
https://stackoverflow.com/questions/43156023/what-is-http-host-header#43156094
"""
r = requests.get(uri, timeout=(5, 8), allow_redirects=False, headers={'Host': url.url})
......
# django admin
django
# Django jet is blocking migration to 2.0
# error: from django.views.i18n import javascript_catalog
# ImportError: cannot import name 'javascript_catalog'
django==1.11
django-jet
django-countries
django-jsonfield
......
......@@ -18,7 +18,7 @@ def test_security_headers(responses, db, faalonië):
responses.add(responses.GET, 'https://' + faalonië['url'].url + ':443/', headers=SECURITY_HEADERS)
result = json.loads(call_command('scan-security-headers', '-v3', '-o', TEST_ORGANIZATION))
result = json.loads(call_command('scan_security_headers', '-v3', '-o', TEST_ORGANIZATION))
assert result[0]['status'] == 'success'
......@@ -28,7 +28,7 @@ def test_security_headers_all(responses, db, faalonië):
responses.add(responses.GET, 'https://' + faalonië['url'].url + ':443/', headers=SECURITY_HEADERS)
result = json.loads(call_command('scan-security-headers', '-v3'))
result = json.loads(call_command('scan_security_headers', '-v3'))
assert result[0]['status'] == 'success'
......@@ -37,7 +37,7 @@ def test_security_headers_notfound(responses, db, faalonië):
"""Test invalid organization."""
with pytest.raises(Exception):
call_command('scan-security-headers', '-v3', '-o', NON_EXISTING_ORGANIZATION)
call_command('scan_security_headers', '-v3', '-o', NON_EXISTING_ORGANIZATION)
# todo: could do a redirect test
......@@ -46,6 +46,6 @@ def test_security_headers_failure(responses, db, faalonië):
responses.add(responses.GET, 'https://' + faalonië['url'].url + ':443/', status=500)
result = json.loads(call_command('scan-security-headers', '-v3', '-o', TEST_ORGANIZATION))
result = json.loads(call_command('scan_security_headers', '-v3', '-o', TEST_ORGANIZATION))
assert result[0]['status'] == 'success'
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