Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
413d50b5
Kaydet (Commit)
413d50b5
authored
Mar 21, 2019
tarafından
Nick Pope
Kaydeden (comit)
Tim Graham
Mar 21, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Corrected settings names in SecurityMiddleware tests.
üst
0b70985f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
33 deletions
+26
-33
test_security.py
tests/middleware/test_security.py
+26
-33
No files found.
tests/middleware/test_security.py
Dosyayı görüntüle @
413d50b5
...
@@ -43,7 +43,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -43,7 +43,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
@override_settings
(
SECURE_HSTS_SECONDS
=
3600
)
@override_settings
(
SECURE_HSTS_SECONDS
=
3600
)
def
test_sts_on
(
self
):
def
test_sts_on
(
self
):
"""
"""
With HSTS_SECONDS=3600, the middleware adds
With
SECURE_
HSTS_SECONDS=3600, the middleware adds
"Strict-Transport-Security: max-age=3600" to the response.
"Strict-Transport-Security: max-age=3600" to the response.
"""
"""
self
.
assertEqual
(
self
.
assertEqual
(
...
@@ -62,7 +62,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -62,7 +62,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
headers
=
{
"Strict-Transport-Security"
:
"max-age=7200"
})
headers
=
{
"Strict-Transport-Security"
:
"max-age=7200"
})
self
.
assertEqual
(
response
[
"Strict-Transport-Security"
],
"max-age=7200"
)
self
.
assertEqual
(
response
[
"Strict-Transport-Security"
],
"max-age=7200"
)
@override_settings
(
HSTS_SECONDS
=
3600
)
@override_settings
(
SECURE_
HSTS_SECONDS
=
3600
)
def
test_sts_only_if_secure
(
self
):
def
test_sts_only_if_secure
(
self
):
"""
"""
The "Strict-Transport-Security" header is not added to responses going
The "Strict-Transport-Security" header is not added to responses going
...
@@ -70,30 +70,28 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -70,30 +70,28 @@ class SecurityMiddlewareTest(SimpleTestCase):
"""
"""
self
.
assertNotIn
(
"Strict-Transport-Security"
,
self
.
process_response
(
secure
=
False
))
self
.
assertNotIn
(
"Strict-Transport-Security"
,
self
.
process_response
(
secure
=
False
))
@override_settings
(
HSTS_SECONDS
=
0
)
@override_settings
(
SECURE_
HSTS_SECONDS
=
0
)
def
test_sts_off
(
self
):
def
test_sts_off
(
self
):
"""
"""
With
HSTS_SECONDS of
0, the middleware does not add a
With
SECURE_HSTS_SECONDS=
0, the middleware does not add a
"Strict-Transport-Security" header to the response.
"Strict-Transport-Security" header to the response.
"""
"""
self
.
assertNotIn
(
"Strict-Transport-Security"
,
self
.
process_response
(
secure
=
True
))
self
.
assertNotIn
(
"Strict-Transport-Security"
,
self
.
process_response
(
secure
=
True
))
@override_settings
(
@override_settings
(
SECURE_HSTS_SECONDS
=
600
,
SECURE_HSTS_INCLUDE_SUBDOMAINS
=
True
)
SECURE_HSTS_SECONDS
=
600
,
SECURE_HSTS_INCLUDE_SUBDOMAINS
=
True
)
def
test_sts_include_subdomains
(
self
):
def
test_sts_include_subdomains
(
self
):
"""
"""
With
HSTS_SECONDS non-zero and
HSTS_INCLUDE_SUBDOMAINS
With
SECURE_HSTS_SECONDS non-zero and SECURE_
HSTS_INCLUDE_SUBDOMAINS
True, the middleware adds a "Strict-Transport-Security" header with the
True, the middleware adds a "Strict-Transport-Security" header with the
"includeSubDomains" directive to the response.
"includeSubDomains" directive to the response.
"""
"""
response
=
self
.
process_response
(
secure
=
True
)
response
=
self
.
process_response
(
secure
=
True
)
self
.
assertEqual
(
response
[
"Strict-Transport-Security"
],
"max-age=600; includeSubDomains"
)
self
.
assertEqual
(
response
[
"Strict-Transport-Security"
],
"max-age=600; includeSubDomains"
)
@override_settings
(
@override_settings
(
SECURE_HSTS_SECONDS
=
600
,
SECURE_HSTS_INCLUDE_SUBDOMAINS
=
False
)
SECURE_HSTS_SECONDS
=
600
,
SECURE_HSTS_INCLUDE_SUBDOMAINS
=
False
)
def
test_sts_no_include_subdomains
(
self
):
def
test_sts_no_include_subdomains
(
self
):
"""
"""
With
HSTS_SECONDS non-zero and
HSTS_INCLUDE_SUBDOMAINS
With
SECURE_HSTS_SECONDS non-zero and SECURE_
HSTS_INCLUDE_SUBDOMAINS
False, the middleware adds a "Strict-Transport-Security" header without
False, the middleware adds a "Strict-Transport-Security" header without
the "includeSubDomains" directive to the response.
the "includeSubDomains" directive to the response.
"""
"""
...
@@ -103,9 +101,9 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -103,9 +101,9 @@ class SecurityMiddlewareTest(SimpleTestCase):
@override_settings
(
SECURE_HSTS_SECONDS
=
10886400
,
SECURE_HSTS_PRELOAD
=
True
)
@override_settings
(
SECURE_HSTS_SECONDS
=
10886400
,
SECURE_HSTS_PRELOAD
=
True
)
def
test_sts_preload
(
self
):
def
test_sts_preload
(
self
):
"""
"""
With
HSTS_SECONDS non-zero and SECURE_HSTS_PRELOAD True, the middlewar
e
With
SECURE_HSTS_SECONDS non-zero and SECURE_HSTS_PRELOAD True, th
e
adds a "Strict-Transport-Security" header with the "preload" directive
middleware adds a "Strict-Transport-Security" header with the "preload"
to the response.
directive
to the response.
"""
"""
response
=
self
.
process_response
(
secure
=
True
)
response
=
self
.
process_response
(
secure
=
True
)
self
.
assertEqual
(
response
[
"Strict-Transport-Security"
],
"max-age=10886400; preload"
)
self
.
assertEqual
(
response
[
"Strict-Transport-Security"
],
"max-age=10886400; preload"
)
...
@@ -113,7 +111,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -113,7 +111,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
@override_settings
(
SECURE_HSTS_SECONDS
=
10886400
,
SECURE_HSTS_INCLUDE_SUBDOMAINS
=
True
,
SECURE_HSTS_PRELOAD
=
True
)
@override_settings
(
SECURE_HSTS_SECONDS
=
10886400
,
SECURE_HSTS_INCLUDE_SUBDOMAINS
=
True
,
SECURE_HSTS_PRELOAD
=
True
)
def
test_sts_subdomains_and_preload
(
self
):
def
test_sts_subdomains_and_preload
(
self
):
"""
"""
With HSTS_SECONDS non-zero, SECURE_HSTS_INCLUDE_SUBDOMAINS and
With
SECURE_
HSTS_SECONDS non-zero, SECURE_HSTS_INCLUDE_SUBDOMAINS and
SECURE_HSTS_PRELOAD True, the middleware adds a "Strict-Transport-Security"
SECURE_HSTS_PRELOAD True, the middleware adds a "Strict-Transport-Security"
header containing both the "includeSubDomains" and "preload" directives
header containing both the "includeSubDomains" and "preload" directives
to the response.
to the response.
...
@@ -124,7 +122,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -124,7 +122,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
@override_settings
(
SECURE_HSTS_SECONDS
=
10886400
,
SECURE_HSTS_PRELOAD
=
False
)
@override_settings
(
SECURE_HSTS_SECONDS
=
10886400
,
SECURE_HSTS_PRELOAD
=
False
)
def
test_sts_no_preload
(
self
):
def
test_sts_no_preload
(
self
):
"""
"""
With HSTS_SECONDS non-zero and SECURE_HSTS_PRELOAD
With
SECURE_
HSTS_SECONDS non-zero and SECURE_HSTS_PRELOAD
False, the middleware adds a "Strict-Transport-Security" header without
False, the middleware adds a "Strict-Transport-Security" header without
the "preload" directive to the response.
the "preload" directive to the response.
"""
"""
...
@@ -134,7 +132,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -134,7 +132,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
@override_settings
(
SECURE_CONTENT_TYPE_NOSNIFF
=
True
)
@override_settings
(
SECURE_CONTENT_TYPE_NOSNIFF
=
True
)
def
test_content_type_on
(
self
):
def
test_content_type_on
(
self
):
"""
"""
With CONTENT_TYPE_NOSNIFF set to True, the middleware adds
With
SECURE_
CONTENT_TYPE_NOSNIFF set to True, the middleware adds
"X-Content-Type-Options: nosniff" header to the response.
"X-Content-Type-Options: nosniff" header to the response.
"""
"""
self
.
assertEqual
(
self
.
process_response
()[
"X-Content-Type-Options"
],
"nosniff"
)
self
.
assertEqual
(
self
.
process_response
()[
"X-Content-Type-Options"
],
"nosniff"
)
...
@@ -151,7 +149,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -151,7 +149,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
@override_settings
(
SECURE_CONTENT_TYPE_NOSNIFF
=
False
)
@override_settings
(
SECURE_CONTENT_TYPE_NOSNIFF
=
False
)
def
test_content_type_off
(
self
):
def
test_content_type_off
(
self
):
"""
"""
With CONTENT_TYPE_NOSNIFF False, the middleware does not add an
With
SECURE_
CONTENT_TYPE_NOSNIFF False, the middleware does not add an
"X-Content-Type-Options" header to the response.
"X-Content-Type-Options" header to the response.
"""
"""
self
.
assertNotIn
(
"X-Content-Type-Options"
,
self
.
process_response
())
self
.
assertNotIn
(
"X-Content-Type-Options"
,
self
.
process_response
())
...
@@ -159,12 +157,10 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -159,12 +157,10 @@ class SecurityMiddlewareTest(SimpleTestCase):
@override_settings
(
SECURE_BROWSER_XSS_FILTER
=
True
)
@override_settings
(
SECURE_BROWSER_XSS_FILTER
=
True
)
def
test_xss_filter_on
(
self
):
def
test_xss_filter_on
(
self
):
"""
"""
With BROWSER_XSS_FILTER set to True, the middleware adds
With
SECURE_
BROWSER_XSS_FILTER set to True, the middleware adds
"s-xss-protection: 1; mode=block" header to the response.
"s-xss-protection: 1; mode=block" header to the response.
"""
"""
self
.
assertEqual
(
self
.
assertEqual
(
self
.
process_response
()[
"X-XSS-Protection"
],
"1; mode=block"
)
self
.
process_response
()[
"X-XSS-Protection"
],
"1; mode=block"
)
@override_settings
(
SECURE_BROWSER_XSS_FILTER
=
True
)
@override_settings
(
SECURE_BROWSER_XSS_FILTER
=
True
)
def
test_xss_filter_already_present
(
self
):
def
test_xss_filter_already_present
(
self
):
...
@@ -175,24 +171,23 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -175,24 +171,23 @@ class SecurityMiddlewareTest(SimpleTestCase):
response
=
self
.
process_response
(
secure
=
True
,
headers
=
{
"X-XSS-Protection"
:
"foo"
})
response
=
self
.
process_response
(
secure
=
True
,
headers
=
{
"X-XSS-Protection"
:
"foo"
})
self
.
assertEqual
(
response
[
"X-XSS-Protection"
],
"foo"
)
self
.
assertEqual
(
response
[
"X-XSS-Protection"
],
"foo"
)
@override_settings
(
BROWSER_XSS_FILTER
=
False
)
@override_settings
(
SECURE_
BROWSER_XSS_FILTER
=
False
)
def
test_xss_filter_off
(
self
):
def
test_xss_filter_off
(
self
):
"""
"""
With
BROWSER_XSS_FILTER set to False, the middleware does not add an
With
SECURE_BROWSER_XSS_FILTER set to False, the middleware does not
"X-XSS-Protection" header to the response.
add an
"X-XSS-Protection" header to the response.
"""
"""
self
.
assertNotIn
(
"X-XSS-Protection"
,
self
.
process_response
())
self
.
assertNotIn
(
"X-XSS-Protection"
,
self
.
process_response
())
@override_settings
(
SECURE_SSL_REDIRECT
=
True
)
@override_settings
(
SECURE_SSL_REDIRECT
=
True
)
def
test_ssl_redirect_on
(
self
):
def
test_ssl_redirect_on
(
self
):
"""
"""
With SSL_REDIRECT True, the middleware redirects any non-secure
With S
ECURE_S
SL_REDIRECT True, the middleware redirects any non-secure
requests to the https:// version of the same URL.
requests to the https:// version of the same URL.
"""
"""
ret
=
self
.
process_request
(
"get"
,
"/some/url?query=string"
)
ret
=
self
.
process_request
(
"get"
,
"/some/url?query=string"
)
self
.
assertEqual
(
ret
.
status_code
,
301
)
self
.
assertEqual
(
ret
.
status_code
,
301
)
self
.
assertEqual
(
self
.
assertEqual
(
ret
[
"Location"
],
"https://testserver/some/url?query=string"
)
ret
[
"Location"
],
"https://testserver/some/url?query=string"
)
@override_settings
(
SECURE_SSL_REDIRECT
=
True
)
@override_settings
(
SECURE_SSL_REDIRECT
=
True
)
def
test_no_redirect_ssl
(
self
):
def
test_no_redirect_ssl
(
self
):
...
@@ -202,8 +197,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -202,8 +197,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
ret
=
self
.
process_request
(
"get"
,
"/some/url"
,
secure
=
True
)
ret
=
self
.
process_request
(
"get"
,
"/some/url"
,
secure
=
True
)
self
.
assertIsNone
(
ret
)
self
.
assertIsNone
(
ret
)
@override_settings
(
@override_settings
(
SECURE_SSL_REDIRECT
=
True
,
SECURE_REDIRECT_EXEMPT
=
[
"^insecure/"
])
SECURE_SSL_REDIRECT
=
True
,
SECURE_REDIRECT_EXEMPT
=
[
"^insecure/"
])
def
test_redirect_exempt
(
self
):
def
test_redirect_exempt
(
self
):
"""
"""
The middleware does not redirect requests with URL path matching an
The middleware does not redirect requests with URL path matching an
...
@@ -212,11 +206,10 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -212,11 +206,10 @@ class SecurityMiddlewareTest(SimpleTestCase):
ret
=
self
.
process_request
(
"get"
,
"/insecure/page"
)
ret
=
self
.
process_request
(
"get"
,
"/insecure/page"
)
self
.
assertIsNone
(
ret
)
self
.
assertIsNone
(
ret
)
@override_settings
(
@override_settings
(
SECURE_SSL_REDIRECT
=
True
,
SECURE_SSL_HOST
=
"secure.example.com"
)
SECURE_SSL_REDIRECT
=
True
,
SECURE_SSL_HOST
=
"secure.example.com"
)
def
test_redirect_ssl_host
(
self
):
def
test_redirect_ssl_host
(
self
):
"""
"""
The middleware redirects to SSL_HOST if given.
The middleware redirects to S
ECURE_S
SL_HOST if given.
"""
"""
ret
=
self
.
process_request
(
"get"
,
"/some/url"
)
ret
=
self
.
process_request
(
"get"
,
"/some/url"
)
self
.
assertEqual
(
ret
.
status_code
,
301
)
self
.
assertEqual
(
ret
.
status_code
,
301
)
...
@@ -225,7 +218,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
...
@@ -225,7 +218,7 @@ class SecurityMiddlewareTest(SimpleTestCase):
@override_settings
(
SECURE_SSL_REDIRECT
=
False
)
@override_settings
(
SECURE_SSL_REDIRECT
=
False
)
def
test_ssl_redirect_off
(
self
):
def
test_ssl_redirect_off
(
self
):
"""
"""
With S
SL_REDIRECT False, the middleware does no
redirect.
With S
ECURE_SSL_REDIRECT False, the middleware does not
redirect.
"""
"""
ret
=
self
.
process_request
(
"get"
,
"/some/url"
)
ret
=
self
.
process_request
(
"get"
,
"/some/url"
)
self
.
assertIsNone
(
ret
)
self
.
assertIsNone
(
ret
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment