Skip to content

Commit 36df3ee

Browse files
author
Peter Bengtsson
authored
fixes bug 1469898 - don't check security.W001 (mozilla-services#917)
1 parent 5287cea commit 36df3ee

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

.env-dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PYTHONUNBUFFERED=1
22
PYTHONDONTWRITEBYTECODE=1
33

44
# You must set this
5-
DJANGO_SECRET_KEY=dontusethisinprod
5+
DJANGO_SECRET_KEY=DontusethisinproductionbutitneedsbelongforCI1234567890
66

77
# Only override this if you need something different from the default
88
DJANGO_ALLOWED_HOSTS=web,localhost

tecken/cache_extra.py

+24
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@
77
from django.core.cache.backends.locmem import LocMemCache
88

99

10+
class MockClient:
11+
"""This exists to satisfy the ability to use get_redis_connection()
12+
in dockerflow checks even though the backend is actually a glorified
13+
LocMemCache instance.
14+
"""
15+
16+
def __init__(self):
17+
pass
18+
19+
def get_client(self, write=True):
20+
self.write = write
21+
return self
22+
23+
def ping(self):
24+
return "pong"
25+
26+
def info(self):
27+
raise NotImplementedError
28+
29+
1030
class RedisLocMemCache(LocMemCache):
1131
"""Expanding Django's LocMemCache with the methods that are expected
1232
beyond the default cache but as if it was backed by Redis"""
@@ -17,3 +37,7 @@ def iter_keys(self, search_term):
1737
if regex.findall(key):
1838
# the "raw key" will always be "<PREFIX>:<VERSION>:<KEY>"
1939
yield key.split(':', 2)[2]
40+
41+
@property
42+
def client(self):
43+
return MockClient()

tecken/settings.py

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class Core(AWS, Configuration, Celery, S3):
155155
# with confidence we do these good deeds in Nginx.
156156
# https://docs.djangoproject.com/en/1.11/ref/checks/#security
157157
SILENCED_SYSTEM_CHECKS = [
158+
'security.W001', # Dealt with using Nginx headers
158159
'security.W002', # Dealt with using Nginx headers
159160
'security.W003', # CSRF is explicit only on the views that need it
160161
# We can't set SECURE_HSTS_INCLUDE_SUBDOMAINS since this runs under a
@@ -685,6 +686,7 @@ class Test(Localdev):
685686
ENABLE_AUTH0_BLOCKED_CHECK = False
686687

687688
SECRET_KEY = values.Value('not-so-secret-after-all')
689+
SESSION_COOKIE_SECURE = True
688690

689691
OIDC_RP_CLIENT_ID = values.Value('not-so-secret-after-all')
690692
OIDC_RP_CLIENT_SECRET = values.Value('not-so-secret-after-all')

tests/test_views.py

+13
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,16 @@ def test_auth_debug(client):
162162
text = response.content.decode('utf-8')
163163
assert 'Cache works!' in text
164164
assert 'Session cookies work!' in text
165+
166+
167+
@pytest.mark.django_db
168+
def test_heartbeat_no_warnings(client, botomock, settings):
169+
170+
def mock_api_call(self, operation_name, api_params):
171+
assert operation_name == 'HeadBucket'
172+
return {}
173+
174+
with botomock(mock_api_call):
175+
response = client.get('/__heartbeat__')
176+
assert response.status_code == 200
177+
assert response.json()['status'] == 'ok'

0 commit comments

Comments
 (0)