<s> """<STR_LIT>""" <EOL> import re <EOL> import unittest <EOL> import wsgiref . util <EOL> from google . appengine . api import appinfo <EOL> from google . appengine . tools . devappserver2 import constants <EOL> from google . appengine . tools . devappserver2 import url_handler <EOL> from google . appengine . tools . devappserver2 import wsgi_test_utils <EOL> COOKIE = '<STR_LIT>' <EOL> COOKIE_ADMIN = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> class TestURLHandler ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_match ( self ) : <EOL> handler = url_handler . URLHandler ( re . compile ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( handler . match ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( handler . match ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( handler . match ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( handler . match ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( handler . match ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( handler . match ( '<STR_LIT>' ) ) <EOL> class TestAuthorization ( wsgi_test_utils . WSGITestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . environ = { } <EOL> wsgiref . util . setup_testing_defaults ( self . environ ) <EOL> self . environ [ '<STR_LIT>' ] = '<STR_LIT:127.0.0.1>' <EOL> self . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> def test_optional ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> def start_response ( unused_status , unused_response_headers , <EOL> unused_exc_info = None ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> r = h . handle_authorization ( self . environ , start_response ) <EOL> self . assertEqual ( None , r ) <EOL> def test_required_redirect_no_login ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> expected_status = '<STR_LIT>' <EOL> expected_location = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> expected_headers = { '<STR_LIT>' : expected_location } <EOL> self . assertResponse ( expected_status , expected_headers , '<STR_LIT>' , <EOL> h . handle_authorization , self . environ ) <EOL> def test_required_unauthorized_no_login ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' , <EOL> auth_fail_action = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> expected_status = '<STR_LIT>' <EOL> expected_headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> expected_content = '<STR_LIT>' <EOL> self . assertResponse ( expected_status , expected_headers , expected_content , <EOL> h . handle_authorization , self . environ ) <EOL> def test_required_succeed ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> self . environ [ '<STR_LIT>' ] = COOKIE <EOL> def start_response ( unused_status , unused_response_headers , <EOL> unused_exc_info = None ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> r = h . handle_authorization ( self . environ , start_response ) <EOL> self . assertEqual ( None , r ) <EOL> def test_required_no_login_fake_is_admin ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> self . environ [ constants . FAKE_IS_ADMIN_HEADER ] = '<STR_LIT:1>' <EOL> expected_status = '<STR_LIT>' <EOL> expected_location = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> expected_headers = { '<STR_LIT>' : expected_location } <EOL> self . assertResponse ( expected_status , expected_headers , '<STR_LIT>' , <EOL> h . handle_authorization , self . environ ) <EOL> def test_admin_no_login_fake_logged_in ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> self . environ [ constants . FAKE_LOGGED_IN_HEADER ] = '<STR_LIT:1>' <EOL> expected_status = '<STR_LIT>' <EOL> expected_headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> expected_content = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertResponse ( expected_status , expected_headers , expected_content , <EOL> h . handle_authorization , self . environ ) <EOL> def test_required_succeed_fake_is_admin ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> self . environ [ '<STR_LIT>' ] = COOKIE <EOL> self . environ [ constants . FAKE_IS_ADMIN_HEADER ] = '<STR_LIT:1>' <EOL> def start_response ( unused_status , unused_response_headers , <EOL> unused_exc_info = None ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> r = h . handle_authorization ( self . environ , start_response ) <EOL> self . assertEqual ( None , r ) <EOL> def test_admin_redirect_no_login ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> expected_status = '<STR_LIT>' <EOL> expected_location = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> expected_headers = { '<STR_LIT>' : expected_location } <EOL> self . assertResponse ( expected_status , expected_headers , '<STR_LIT>' , <EOL> h . handle_authorization , self . environ ) <EOL> def test_admin_unauthorized_no_login ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' , <EOL> auth_fail_action = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> expected_status = '<STR_LIT>' <EOL> expected_headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> expected_content = '<STR_LIT>' <EOL> self . assertResponse ( expected_status , expected_headers , expected_content , <EOL> h . handle_authorization , self . environ ) <EOL> def test_admin_no_admin ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> self . environ [ '<STR_LIT>' ] = COOKIE <EOL> expected_status = '<STR_LIT>' <EOL> expected_headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> expected_content = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertResponse ( expected_status , expected_headers , expected_content , <EOL> h . handle_authorization , self . environ ) <EOL> def test_admin_succeed ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> self . environ [ '<STR_LIT>' ] = COOKIE_ADMIN <EOL> def start_response ( unused_status , unused_response_headers , <EOL> unused_exc_info = None ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> r = h . handle_authorization ( self . environ , start_response ) <EOL> self . assertEqual ( None , r ) <EOL> def test_admin_no_login_fake_is_admin ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> self . environ [ constants . FAKE_IS_ADMIN_HEADER ] = '<STR_LIT:1>' <EOL> def start_response ( unused_status , unused_response_headers , <EOL> unused_exc_info = None ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> r = h . handle_authorization ( self . environ , start_response ) <EOL> self . assertEqual ( None , r ) <EOL> def test_admin_no_admin_fake_is_admin ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> self . environ [ '<STR_LIT>' ] = COOKIE <EOL> self . environ [ constants . FAKE_IS_ADMIN_HEADER ] = '<STR_LIT:1>' <EOL> def start_response ( unused_status , unused_response_headers , <EOL> unused_exc_info = None ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> r = h . handle_authorization ( self . environ , start_response ) <EOL> self . assertEqual ( None , r ) <EOL> def test_admin_succeed_fake_is_admin ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> self . environ [ '<STR_LIT>' ] = COOKIE_ADMIN <EOL> self . environ [ constants . FAKE_IS_ADMIN_HEADER ] = '<STR_LIT:1>' <EOL> def start_response ( unused_status , unused_response_headers , <EOL> unused_exc_info = None ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> r = h . handle_authorization ( self . environ , start_response ) <EOL> self . assertEqual ( None , r ) <EOL> def test_admin_no_login_fake_is_admin_header ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> self . environ [ constants . FAKE_IS_ADMIN_HEADER ] = '<STR_LIT:1>' <EOL> def start_response ( unused_status , unused_response_headers , <EOL> unused_exc_info = None ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> r = h . handle_authorization ( self . environ , start_response ) <EOL> self . assertEqual ( None , r ) <EOL> def test_login_required_no_login_fake_logged_in_header ( self ) : <EOL> """<STR_LIT>""" <EOL> url_map = appinfo . URLMap ( url = '<STR_LIT:/>' , <EOL> login = '<STR_LIT>' ) <EOL> h = url_handler . UserConfiguredURLHandler ( url_map , '<STR_LIT>' ) <EOL> self . environ [ constants . FAKE_LOGGED_IN_HEADER ] = '<STR_LIT:1>' <EOL> def start_response ( unused_status , unused_response_headers , <EOL> unused_exc_info = None ) : <EOL> self . fail ( '<STR_LIT>' ) <EOL> r = h . handle_authorization ( self . environ , start_response ) <EOL> self . assertEqual ( None , r ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
