示例#1
0
    def test_token_error_reponse_calls_to_error_view_if_set(self):
        token_endpoint = ISSUER + '/token'
        error_response = {
            'error': 'invalid_request',
            'error_description': 'test error'
        }
        responses.add(responses.POST,
                      token_endpoint,
                      body=json.dumps(error_response),
                      content_type='application/json')

        authn = OIDCAuthentication(self.app,
                                   provider_configuration_info={
                                       'issuer': ISSUER,
                                       'token_endpoint': token_endpoint
                                   },
                                   client_registration_info=dict(
                                       client_id='abc', client_secret='foo'))
        error_view_mock = MagicMock()
        authn._error_view = error_view_mock
        state = 'test_tate'
        with self.app.test_request_context('/redirect_uri?code=foo&state=' +
                                           state):
            flask.session['state'] = state
            authn._handle_authentication_response()
        error_view_mock.assert_called_with(**error_response)
示例#2
0
 def test_authentication_error_reponse_calls_to_error_view_if_set(self):
     state = 'test_tate'
     error_response = {
         'error': 'invalid_request',
         'error_description': 'test error'
     }
     authn = OIDCAuthentication(
         self.app,
         provider_configuration_info={'issuer': ISSUER},
         client_registration_info=dict(client_id='abc',
                                       client_secret='foo'))
     error_view_mock = MagicMock()
     authn._error_view = error_view_mock
     with self.app.test_request_context(
             '/redirect_uri?{error}&state={state}'.format(
                 error=urlencode(error_response), state=state)):
         flask.session['state'] = state
         authn._handle_authentication_response()
     error_view_mock.assert_called_with(**error_response)