Merge pull request #3218 from alphagov/dev-antivirus-setting

Antivirus off for development by default
This commit is contained in:
David McDonald
2019-12-06 11:49:48 +00:00
committed by GitHub
2 changed files with 7 additions and 3 deletions

View File

@@ -79,6 +79,7 @@ class Config(object):
ROUTE_SECRET_KEY_1 = os.environ.get('ROUTE_SECRET_KEY_1', '')
ROUTE_SECRET_KEY_2 = os.environ.get('ROUTE_SECRET_KEY_2', '')
CHECK_PROXY_HEADER = False
ANTIVIRUS_ENABLED = True
REDIS_URL = os.environ.get('REDIS_URL')
REDIS_ENABLED = os.environ.get('REDIS_ENABLED') == '1'
@@ -106,6 +107,7 @@ class Development(Config):
SECRET_KEY = 'dev-notify-secret-key'
ANTIVIRUS_API_HOST = 'http://localhost:6016'
ANTIVIRUS_API_KEY = 'test-key'
ANTIVIRUS_ENABLED = os.getenv('ANTIVIRUS_ENABLED') == '1'
ASSET_PATH = '/static/'
@@ -126,6 +128,7 @@ class Test(Development):
TEMPLATE_PREVIEW_API_HOST = 'http://localhost:9999'
ANTIVIRUS_API_HOST = 'https://test-antivirus'
ANTIVIRUS_API_KEY = 'test-antivirus-secret'
ANTIVIRUS_ENABLED = True
ASSET_DOMAIN = 'static.example.com'
ASSET_PATH = 'https://static.example.com/'

View File

@@ -52,9 +52,10 @@ def upload_letter(service_id):
pdf_file_bytes = form.file.data.read()
original_filename = form.file.data.filename
virus_free = antivirus_client.scan(BytesIO(pdf_file_bytes))
if not virus_free:
return invalid_upload_error('Your file contains a virus')
if current_app.config['ANTIVIRUS_ENABLED']:
virus_free = antivirus_client.scan(BytesIO(pdf_file_bytes))
if not virus_free:
return invalid_upload_error('Your file contains a virus')
if len(pdf_file_bytes) > MAX_FILE_UPLOAD_SIZE:
return invalid_upload_error('Your file is too big', 'Files must be smaller than 2MB.')