예제 #1
0
 def wait_and_terminate_authorize_code_process(
         self, timeout: Optional[float] = None) -> str:
     if self.authorization_code_context is None:
         raise Exception('Authorization code not started')
     else:
         try:
             self.authorization_code_context.results.wait(timeout)
             error = self.authorization_code_context.results.get(
                 'error', None)
             error_description = self.authorization_code_context.results.get(
                 'error_description', '')
             code = self.authorization_code_context.results.get(
                 'code', None)
             state = self.authorization_code_context.results.get(
                 'state', None)
             if error is not None:
                 raise OAuthError(HTTPStatus.UNAUTHORIZED, error,
                                  error_description)
             elif state != self.authorization_code_context.state:
                 _logger.warning(
                     'State received does not match the one that was sent')
                 raise OAuthError(
                     HTTPStatus.INTERNAL_SERVER_ERROR, 'invalid_state',
                     'Sate returned does not match: Sent(%s) <> Got(%s)' %
                     (self.authorization_code_context.state, state))
             elif code is None:
                 raise OAuthError(HTTPStatus.INTERNAL_SERVER_ERROR,
                                  'no_code', 'No code returned')
             else:
                 return code
         finally:
             stop_http_server(self.authorization_code_context.server)
             self.authorization_code_context = None
예제 #2
0
 def tearDownClass(cls):
     if TestServer.SERVER is not None:
         stop_http_server(TestServer.SERVER)
예제 #3
0
 def tearDownClass(cls):
     if TestServer.SERVER is not None:
         stop_http_server(TestServer.SERVER)