-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1844 from uktrade/dev
UAT deployment
- Loading branch information
Showing
13 changed files
with
305 additions
and
180 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,9 +100,7 @@ EXPORTER_USERS='[{"email"=>"[email protected]"}]' ./manage.py seedexporterusers | |
``` | ||
|
||
## Running background tasks | ||
|
||
We currently have two mechanisms for background tasks in LITE; | ||
- django-background-tasks: `pipenv run ./manage.py process_tasks` will run all background tasks | ||
We currently use celery for async tasks and scheduling in LITE; | ||
- celery: a celery container is running by default when using docker-compose. If a working copy | ||
"on the metal" without docker, run celery with `watchmedo auto-restart -d . -R -p '*.py' -- celery -A api.conf worker -l info` | ||
- celery-scheduler: a celery container is running by default when using docker-compose. This is to monitor any scheduled tasks If a working copy | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Mock Virus Scan | ||
|
||
The purpose of mock virus scan is to give us the ability to swap out the external third party virus scan services that we use. | ||
|
||
Swapping this out is useful when: | ||
|
||
- we are running end-to-end tests and we don't want to rely on external services | ||
- we want to develop locally without an internet connection | ||
|
||
This mock replaces the virus scanning of documents that are uploaded. It's a dummy and not intented to provide any of the functionaity. It supports a postive scan using the ECIR pattern. | ||
|
||
To enable set MOCK_VIRUS_SCAN_ACTIVATE_ENDPOINTS = True |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from django.urls import reverse | ||
from django.test import Client | ||
from django.core.files.uploadedfile import SimpleUploadedFile | ||
|
||
from rest_framework.test import APITestCase, override_settings | ||
from test_helpers.helpers import reload_urlconf | ||
|
||
|
||
@override_settings(MOCK_VIRUS_SCAN_ACTIVATE_ENDPOINTS=True) | ||
class TestMockVirusScan(APITestCase): | ||
def setUp(self): | ||
super().setUp() | ||
|
||
reload_urlconf() | ||
self.url = reverse("mock_virus_scan:scan") | ||
self.client = Client() | ||
|
||
def test_mock_scan_virus_file(self): | ||
|
||
# eicar standard industry pattern used to test positive virus | ||
eicar_content = b"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*" | ||
|
||
response = self.client.post( | ||
self.url, | ||
{ | ||
"file": [ | ||
SimpleUploadedFile("file 1", eicar_content), | ||
] | ||
}, | ||
) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json(), {"malware": True}) | ||
|
||
def test_mock_scan_no_virus_file(self): | ||
|
||
response = self.client.post( | ||
self.url, | ||
{ | ||
"file": [ | ||
SimpleUploadedFile("file 1", b"no virus"), | ||
] | ||
}, | ||
) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.json(), {"malware": False}) | ||
|
||
def test_mock_scan_no_file(self): | ||
|
||
response = self.client.post( | ||
self.url, | ||
data={}, | ||
) | ||
|
||
self.assertEqual(response.status_code, 400) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.urls import path | ||
from mock_virus_scan import views | ||
|
||
app_name = "mock_virus_scan" | ||
|
||
urlpatterns = [ | ||
path("scan", views.Scan.as_view(), name="scan"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from rest_framework.views import APIView | ||
from rest_framework.parsers import MultiPartParser | ||
|
||
from django.http import JsonResponse, HttpResponseBadRequest | ||
|
||
|
||
class Scan(APIView): | ||
parser_classes = (MultiPartParser,) | ||
EICAR_TEST = b"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*" # noqa | ||
|
||
def post(self, request): | ||
if len(request.FILES) != 1: | ||
return HttpResponseBadRequest("Provide a single file") | ||
|
||
uploaded_file = request.FILES["file"] | ||
|
||
if uploaded_file.file.read() == self.EICAR_TEST: | ||
return JsonResponse({"malware": True}) | ||
|
||
return JsonResponse({"malware": False}) |