#NEWLINE# def testDoMunkiAuth( self ) : #NEWLINE# #INDENT# 'Test DoMunkiAuth().' #NEWLINE# level = 123 #NEWLINE# cookie_str = 'foo=bar' #NEWLINE# token = 'cookie value for auth.AUTH_TOKEN_COOKIE' #NEWLINE# uuid = 'session uuid' #NEWLINE# mock_valobj = self . mox . CreateMockAnything ( ) #NEWLINE# mock_valobj . value = token #NEWLINE# mock_session = self . mox . CreateMockAnything ( ) #NEWLINE# mock_session . uuid = 'session uuid' #NEWLINE# mock_environ = self . mox . CreateMockAnything ( ) #NEWLINE# mock_cookie = self . mox . CreateMockAnything ( ) #NEWLINE# mock_auth1 = self . mox . CreateMockAnything ( ) #NEWLINE# self . stubs . Set ( gaeserver . os , 'environ' , mock_environ ) #NEWLINE# self . mox . StubOutWithMock ( gaeserver . Cookie , 'SimpleCookie' , True ) #NEWLINE# self . mox . StubOutWithMock ( gaeserver , 'AuthSimianServer' , True ) #NEWLINE# mock_environ . get ( 'HTTP_COOKIE' , None ) . AndReturn ( None ) #NEWLINE# mock_environ . get ( 'HTTP_COOKIE' , None ) . AndReturn ( cookie_str ) #NEWLINE# gaeserver . Cookie . SimpleCookie ( ) . AndReturn ( mock_cookie ) #NEWLINE# mock_cookie . load ( cookie_str ) . AndRaise ( TypeError ) #NEWLINE# mock_environ . get ( 'HTTP_COOKIE' , None ) . AndReturn ( cookie_str ) #NEWLINE# gaeserver . Cookie . SimpleCookie ( ) . AndReturn ( mock_cookie ) #NEWLINE# mock_cookie . load ( cookie_str ) . AndRaise ( gaeserver . Cookie . CookieError ) #NEWLINE# mock_environ . get ( 'HTTP_COOKIE' , None ) . AndReturn ( cookie_str ) #NEWLINE# gaeserver . Cookie . SimpleCookie ( ) . AndReturn ( mock_valobj ) #NEWLINE# mock_cookie . load ( cookie_str ) . AndReturn ( None ) #NEWLINE# mock_cookie . __contains__ ( gaeserver . auth . AUTH_TOKEN_COOKIE ) . AndReturn ( False ) #NEWLINE# mock_environ . get ( 'HTTP_COOKIE' , None ) . AndReturn ( cookie_str ) #NEWLINE# gaeserver . Cookie . SimpleCookie ( ) . AndReturn ( mock_cookie ) #NEWLINE# mock_cookie . load ( cookie_str ) . AndReturn ( None ) #NEWLINE# mock_cookie . __contains__ ( gaeserver . auth . AUTH_TOKEN_COOKIE ) . AndReturn ( True ) #NEWLINE# mock_cookie . __getitem__ ( gaeserver . auth . AUTH_TOKEN_COOKIE ) . AndReturn ( mock_valobj ) #NEWLINE# gaeserver . AuthSimianServer ( ) . AndReturn ( mock_auth1 ) #NEWLINE# mock_cookie . __getitem__ ( gaeserver . auth . AUTH_TOKEN_COOKIE ) . AndReturn ( mock_valobj ) #NEWLINE# mock_auth1 . GetSessionIfAuthOK ( token , gaeserver . LEVEL_BASE ) . AndRaise ( gaeserver . base . AuthSessionError ) #NEWLINE# mock_environ . get ( 'HTTP_COOKIE' , None ) . AndReturn ( cookie_str ) #NEWLINE# gaeserver . Cookie . SimpleCookie ( ) . AndReturn ( mock_cookie ) #NEWLINE# mock_cookie . load ( cookie_str ) . AndReturn ( None ) #NEWLINE# mock_cookie . __contains__ ( gaeserver . auth . AUTH_TOKEN_COOKIE ) . AndReturn ( True ) #NEWLINE# mock_cookie . __getitem__ ( gaeserver . auth . AUTH_TOKEN_COOKIE ) . AndReturn ( mock_valobj ) #NEWLINE# gaeserver . AuthSimianServer ( ) . AndReturn ( mock_auth1 ) #NEWLINE# mock_cookie . __getitem__ ( gaeserver . auth . AUTH_TOKEN_COOKIE ) . AndReturn ( mock_valobj ) #NEWLINE# mock_auth1 . GetSessionIfAuthOK ( token , level ) . AndReturn ( mock_session ) #NEWLINE# self . mox . ReplayAll ( ) #NEWLINE# self . assertRaises ( gaeserver . NotAuthenticated , gaeserver . DoMunkiAuth , fake_noauth = True ) #NEWLINE# self . assertRaises ( gaeserver . NotAuthenticated , gaeserver . DoMunkiAuth ) #NEWLINE# self . assertRaises ( gaeserver . NotAuthenticated , gaeserver . DoMunkiAuth ) #NEWLINE# self . assertRaises ( gaeserver . NotAuthenticated , gaeserver . DoMunkiAuth ) #NEWLINE# self . assertRaises ( gaeserver . NotAuthenticated , gaeserver . DoMunkiAuth ) #NEWLINE# self . assertRaises ( gaeserver . NotAuthenticated , gaeserver . DoMunkiAuth ) #NEWLINE# session = gaeserver . DoMunkiAuth ( require_level = level ) #NEWLINE# self . assertEqual ( uuid , session . uuid ) #NEWLINE# self . mox . VerifyAll ( )