diff options
| author | Ed Morley <emorley@mozilla.com> | 2016-07-28 17:48:07 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-08-10 20:23:54 -0400 |
| commit | 3c2447dd13e495d57700ca8447896acd85044444 (patch) | |
| tree | 26ad18a7df9ff5b0d9e35723164baa4587747e4b /tests | |
| parent | c412aaca735c7cc1c766b85c1512f9ff434ce63a (diff) | |
Fixed #26947 -- Added an option to enable the HSTS header preload directive.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/middleware/test_security.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/middleware/test_security.py b/tests/middleware/test_security.py index f671600c49..b8e77f76e4 100644 --- a/tests/middleware/test_security.py +++ b/tests/middleware/test_security.py @@ -99,6 +99,37 @@ class SecurityMiddlewareTest(SimpleTestCase): response = self.process_response(secure=True) self.assertEqual(response["strict-transport-security"], "max-age=600") + @override_settings(SECURE_HSTS_SECONDS=10886400, SECURE_HSTS_PRELOAD=True) + def test_sts_preload(self): + """ + With HSTS_SECONDS non-zero and SECURE_HSTS_PRELOAD True, the middleware + adds a "strict-transport-security" header with the "preload" directive + to the response. + """ + response = self.process_response(secure=True) + self.assertEqual(response["strict-transport-security"], "max-age=10886400; preload") + + @override_settings(SECURE_HSTS_SECONDS=10886400, SECURE_HSTS_INCLUDE_SUBDOMAINS=True, SECURE_HSTS_PRELOAD=True) + def test_sts_subdomains_and_preload(self): + """ + With HSTS_SECONDS non-zero, SECURE_HSTS_INCLUDE_SUBDOMAINS and + SECURE_HSTS_PRELOAD True, the middleware adds a "strict-transport-security" + header containing both the "includeSubDomains" and "preload" directives + to the response. + """ + response = self.process_response(secure=True) + self.assertEqual(response["strict-transport-security"], "max-age=10886400; includeSubDomains; preload") + + @override_settings(SECURE_HSTS_SECONDS=10886400, SECURE_HSTS_PRELOAD=False) + def test_sts_no_preload(self): + """ + With HSTS_SECONDS non-zero and SECURE_HSTS_PRELOAD + False, the middleware adds a "strict-transport-security" header without + the "preload" directive to the response. + """ + response = self.process_response(secure=True) + self.assertEqual(response["strict-transport-security"], "max-age=10886400") + @override_settings(SECURE_CONTENT_TYPE_NOSNIFF=True) def test_content_type_on(self): """ |
