Log create_uri_response exceptions to logger.exception
This commit is contained in:
parent
eb2af58354
commit
80441aaf32
2 changed files with 40 additions and 1 deletions
|
@ -207,7 +207,7 @@ class AuthorizeEndpoint(object):
|
|||
query_fragment['session_state'] = session_state
|
||||
|
||||
except Exception as error:
|
||||
logger.debug('[Authorize] Error when trying to create response uri: %s', error)
|
||||
logger.exception('[Authorize] Error when trying to create response uri: %s', error)
|
||||
raise AuthorizeError(self.params['redirect_uri'], 'server_error', self.grant_type)
|
||||
|
||||
uri = uri._replace(query=urlencode(query_params, doseq=True))
|
||||
|
|
|
@ -7,6 +7,7 @@ try:
|
|||
except ImportError:
|
||||
from urlparse import parse_qs, urlsplit
|
||||
import uuid
|
||||
from mock import patch
|
||||
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.core.management import call_command
|
||||
|
@ -26,6 +27,7 @@ from oidc_provider.tests.app.utils import (
|
|||
is_code_valid,
|
||||
)
|
||||
from oidc_provider.views import AuthorizeView
|
||||
from oidc_provider.lib.endpoints.authorize import AuthorizeEndpoint
|
||||
|
||||
|
||||
class AuthorizeEndpointMixin(object):
|
||||
|
@ -498,3 +500,40 @@ class AuthorizationHybridFlowTestCase(TestCase, AuthorizeEndpointMixin):
|
|||
response = self._auth_request('post', self.data, is_user_authenticated=True)
|
||||
|
||||
self.assertIn('expires_in=36000', response['Location'])
|
||||
|
||||
|
||||
class TestCreateResponseURI(TestCase):
|
||||
def setUp(self):
|
||||
url = reverse('oidc_provider:authorize')
|
||||
user = create_fake_user()
|
||||
client = create_fake_client(response_type='code', is_public=True)
|
||||
|
||||
# Base data to create a uri response
|
||||
data = {
|
||||
'client_id': client.client_id,
|
||||
'redirect_uri': client.default_redirect_uri,
|
||||
'response_type': client.response_type,
|
||||
}
|
||||
|
||||
factory = RequestFactory()
|
||||
self.request = factory.post(url, data=data)
|
||||
self.request.user = user
|
||||
|
||||
@patch('oidc_provider.lib.endpoints.authorize.create_code')
|
||||
@patch('oidc_provider.lib.endpoints.authorize.logger.exception')
|
||||
def test_create_response_uri_logs_to_error(self, log_exception, create_code):
|
||||
"""
|
||||
A lot can go wrong when creating a response uri and this is caught with a general Exception error. The
|
||||
information contained within this error should show up in the error log so production servers have something
|
||||
to work with when things don't work as expected.
|
||||
"""
|
||||
exception = Exception("Something went wrong!")
|
||||
create_code.side_effect = exception
|
||||
|
||||
authorization_endpoint = AuthorizeEndpoint(self.request)
|
||||
authorization_endpoint.validate_params()
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
authorization_endpoint.create_response_uri()
|
||||
|
||||
log_exception.assert_called_once_with('[Authorize] Error when trying to create response uri: %s', exception)
|
||||
|
|
Loading…
Reference in a new issue