<s> from django . conf import settings <EOL> from django . core . checks . security import base , csrf , sessions <EOL> from django . test import SimpleTestCase <EOL> from django . test . utils import override_settings <EOL> class CheckSessionCookieSecureTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . sessions import check_session_cookie_secure <EOL> return check_session_cookie_secure <EOL> @ override_settings ( <EOL> SESSION_COOKIE_SECURE = False , <EOL> INSTALLED_APPS = [ "<STR_LIT>" ] , <EOL> MIDDLEWARE_CLASSES = [ ] ) <EOL> def test_session_cookie_secure_with_installed_app ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ sessions . W010 ] ) <EOL> @ override_settings ( <EOL> SESSION_COOKIE_SECURE = False , <EOL> INSTALLED_APPS = [ ] , <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] ) <EOL> def test_session_cookie_secure_with_middleware ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ sessions . W011 ] ) <EOL> @ override_settings ( <EOL> SESSION_COOKIE_SECURE = False , <EOL> INSTALLED_APPS = [ "<STR_LIT>" ] , <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] ) <EOL> def test_session_cookie_secure_both ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ sessions . W012 ] ) <EOL> @ override_settings ( <EOL> SESSION_COOKIE_SECURE = True , <EOL> INSTALLED_APPS = [ "<STR_LIT>" ] , <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] ) <EOL> def test_session_cookie_secure_true ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckSessionCookieHttpOnlyTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . sessions import check_session_cookie_httponly <EOL> return check_session_cookie_httponly <EOL> @ override_settings ( <EOL> SESSION_COOKIE_HTTPONLY = False , <EOL> INSTALLED_APPS = [ "<STR_LIT>" ] , <EOL> MIDDLEWARE_CLASSES = [ ] ) <EOL> def test_session_cookie_httponly_with_installed_app ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ sessions . W013 ] ) <EOL> @ override_settings ( <EOL> SESSION_COOKIE_HTTPONLY = False , <EOL> INSTALLED_APPS = [ ] , <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] ) <EOL> def test_session_cookie_httponly_with_middleware ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ sessions . W014 ] ) <EOL> @ override_settings ( <EOL> SESSION_COOKIE_HTTPONLY = False , <EOL> INSTALLED_APPS = [ "<STR_LIT>" ] , <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] ) <EOL> def test_session_cookie_httponly_both ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ sessions . W015 ] ) <EOL> @ override_settings ( <EOL> SESSION_COOKIE_HTTPONLY = True , <EOL> INSTALLED_APPS = [ "<STR_LIT>" ] , <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] ) <EOL> def test_session_cookie_httponly_true ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckCSRFMiddlewareTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . csrf import check_csrf_middleware <EOL> return check_csrf_middleware <EOL> @ override_settings ( MIDDLEWARE_CLASSES = [ ] ) <EOL> def test_no_csrf_middleware ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ csrf . W003 ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] ) <EOL> def test_with_csrf_middleware ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckCSRFCookieSecureTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . csrf import check_csrf_cookie_secure <EOL> return check_csrf_cookie_secure <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> CSRF_COOKIE_SECURE = False ) <EOL> def test_with_csrf_cookie_secure_false ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ csrf . W016 ] ) <EOL> @ override_settings ( MIDDLEWARE_CLASSES = [ ] , CSRF_COOKIE_SECURE = False ) <EOL> def test_with_csrf_cookie_secure_false_no_middleware ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> CSRF_COOKIE_SECURE = True ) <EOL> def test_with_csrf_cookie_secure_true ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckCSRFCookieHttpOnlyTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . csrf import check_csrf_cookie_httponly <EOL> return check_csrf_cookie_httponly <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> CSRF_COOKIE_HTTPONLY = False ) <EOL> def test_with_csrf_cookie_httponly_false ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ csrf . W017 ] ) <EOL> @ override_settings ( MIDDLEWARE_CLASSES = [ ] , CSRF_COOKIE_HTTPONLY = False ) <EOL> def test_with_csrf_cookie_httponly_false_no_middleware ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> CSRF_COOKIE_HTTPONLY = True ) <EOL> def test_with_csrf_cookie_httponly_true ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckSecurityMiddlewareTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . base import check_security_middleware <EOL> return check_security_middleware <EOL> @ override_settings ( MIDDLEWARE_CLASSES = [ ] ) <EOL> def test_no_security_middleware ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ base . W001 ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] ) <EOL> def test_with_security_middleware ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckStrictTransportSecurityTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . base import check_sts <EOL> return check_sts <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> SECURE_HSTS_SECONDS = <NUM_LIT:0> ) <EOL> def test_no_sts ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ base . W004 ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ ] , <EOL> SECURE_HSTS_SECONDS = <NUM_LIT:0> ) <EOL> def test_no_sts_no_middleware ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> SECURE_HSTS_SECONDS = <NUM_LIT> ) <EOL> def test_with_sts ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckStrictTransportSecuritySubdomainsTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . base import check_sts_include_subdomains <EOL> return check_sts_include_subdomains <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> SECURE_HSTS_INCLUDE_SUBDOMAINS = False , <EOL> SECURE_HSTS_SECONDS = <NUM_LIT> ) <EOL> def test_no_sts_subdomains ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ base . W005 ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ ] , <EOL> SECURE_HSTS_INCLUDE_SUBDOMAINS = False , <EOL> SECURE_HSTS_SECONDS = <NUM_LIT> ) <EOL> def test_no_sts_subdomains_no_middleware ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> SECURE_SSL_REDIRECT = False , <EOL> SECURE_HSTS_SECONDS = None ) <EOL> def test_no_sts_subdomains_no_seconds ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> SECURE_HSTS_INCLUDE_SUBDOMAINS = True , <EOL> SECURE_HSTS_SECONDS = <NUM_LIT> ) <EOL> def test_with_sts_subdomains ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckXFrameOptionsMiddlewareTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . base import check_xframe_options_middleware <EOL> return check_xframe_options_middleware <EOL> @ override_settings ( MIDDLEWARE_CLASSES = [ ] ) <EOL> def test_middleware_not_installed ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ base . W002 ] ) <EOL> @ override_settings ( MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] ) <EOL> def test_middleware_installed ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckXFrameOptionsDenyTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . base import check_xframe_deny <EOL> return check_xframe_deny <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> X_FRAME_OPTIONS = '<STR_LIT>' , <EOL> ) <EOL> def test_x_frame_options_not_deny ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ base . W019 ] ) <EOL> @ override_settings ( MIDDLEWARE_CLASSES = [ ] , X_FRAME_OPTIONS = '<STR_LIT>' ) <EOL> def test_middleware_not_installed ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> X_FRAME_OPTIONS = '<STR_LIT>' , <EOL> ) <EOL> def test_xframe_deny ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckContentTypeNosniffTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . base import check_content_type_nosniff <EOL> return check_content_type_nosniff <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> SECURE_CONTENT_TYPE_NOSNIFF = False ) <EOL> def test_no_content_type_nosniff ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ base . W006 ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ ] , <EOL> SECURE_CONTENT_TYPE_NOSNIFF = False ) <EOL> def test_no_content_type_nosniff_no_middleware ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> SECURE_CONTENT_TYPE_NOSNIFF = True ) <EOL> def test_with_content_type_nosniff ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckXssFilterTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . base import check_xss_filter <EOL> return check_xss_filter <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> SECURE_BROWSER_XSS_FILTER = False ) <EOL> def test_no_xss_filter ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ base . W007 ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ ] , <EOL> SECURE_BROWSER_XSS_FILTER = False ) <EOL> def test_no_xss_filter_no_middleware ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> SECURE_BROWSER_XSS_FILTER = True ) <EOL> def test_with_xss_filter ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckSSLRedirectTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . base import check_ssl_redirect <EOL> return check_ssl_redirect <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> SECURE_SSL_REDIRECT = False ) <EOL> def test_no_ssl_redirect ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ base . W008 ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ ] , <EOL> SECURE_SSL_REDIRECT = False ) <EOL> def test_no_ssl_redirect_no_middleware ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> @ override_settings ( <EOL> MIDDLEWARE_CLASSES = [ "<STR_LIT>" ] , <EOL> SECURE_SSL_REDIRECT = True ) <EOL> def test_with_ssl_redirect ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckSecretKeyTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . base import check_secret_key <EOL> return check_secret_key <EOL> @ override_settings ( SECRET_KEY = ( '<STR_LIT>' * <NUM_LIT:2> ) + '<STR_LIT>' ) <EOL> def test_okay_secret_key ( self ) : <EOL> self . assertEqual ( len ( settings . SECRET_KEY ) , base . SECRET_KEY_MIN_LENGTH ) <EOL> self . assertGreater ( len ( set ( settings . SECRET_KEY ) ) , base . SECRET_KEY_MIN_UNIQUE_CHARACTERS ) <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> @ override_settings ( SECRET_KEY = '<STR_LIT>' ) <EOL> def test_empty_secret_key ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ base . W009 ] ) <EOL> @ override_settings ( SECRET_KEY = None ) <EOL> def test_missing_secret_key ( self ) : <EOL> del settings . SECRET_KEY <EOL> self . assertEqual ( self . func ( None ) , [ base . W009 ] ) <EOL> @ override_settings ( SECRET_KEY = None ) <EOL> def test_none_secret_key ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ base . W009 ] ) <EOL> @ override_settings ( SECRET_KEY = ( '<STR_LIT>' * <NUM_LIT:2> ) + '<STR_LIT:a>' ) <EOL> def test_low_length_secret_key ( self ) : <EOL> self . assertEqual ( len ( settings . SECRET_KEY ) , base . SECRET_KEY_MIN_LENGTH - <NUM_LIT:1> ) <EOL> self . assertEqual ( self . func ( None ) , [ base . W009 ] ) <EOL> @ override_settings ( SECRET_KEY = '<STR_LIT>' * <NUM_LIT:20> ) <EOL> def test_low_entropy_secret_key ( self ) : <EOL> self . assertGreater ( len ( settings . SECRET_KEY ) , base . SECRET_KEY_MIN_LENGTH ) <EOL> self . assertLess ( len ( set ( settings . SECRET_KEY ) ) , base . SECRET_KEY_MIN_UNIQUE_CHARACTERS ) <EOL> self . assertEqual ( self . func ( None ) , [ base . W009 ] ) <EOL> class CheckDebugTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . base import check_debug <EOL> return check_debug <EOL> @ override_settings ( DEBUG = True ) <EOL> def test_debug_true ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( self . func ( None ) , [ base . W018 ] ) <EOL> @ override_settings ( DEBUG = False ) <EOL> def test_debug_false ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) <EOL> class CheckAllowedHostsTest ( SimpleTestCase ) : <EOL> @ property <EOL> def func ( self ) : <EOL> from django . core . checks . security . base import check_allowed_hosts <EOL> return check_allowed_hosts <EOL> @ override_settings ( ALLOWED_HOSTS = [ ] ) <EOL> def test_allowed_hosts_empty ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ base . W020 ] ) <EOL> @ override_settings ( ALLOWED_HOSTS = [ '<STR_LIT>' , ] ) <EOL> def test_allowed_hosts_set ( self ) : <EOL> self . assertEqual ( self . func ( None ) , [ ] ) </s>
