adding logger for tests

This commit is contained in:
niccolasmendoza@gmail.com 2015-06-08 16:36:49 -03:00
parent 521ff2d7dc
commit 521708f718
3 changed files with 73 additions and 2 deletions

View file

@ -1,8 +1,12 @@
import logging
from oidc_provider.lib.errors import * from oidc_provider.lib.errors import *
from oidc_provider.lib.utils.params import * from oidc_provider.lib.utils.params import *
from oidc_provider.lib.utils.token import * from oidc_provider.lib.utils.token import *
from oidc_provider.models import * from oidc_provider.models import *
logger = logging.getLogger(__name__)
class AuthorizeEndpoint(object): class AuthorizeEndpoint(object):
@ -128,6 +132,10 @@ class AuthorizeEndpoint(object):
if self.params.response_type == 'id_token token': if self.params.response_type == 'id_token token':
uri += '&access_token={0}'.format(token.access_token) uri += '&access_token={0}'.format(token.access_token)
except: except:
logger.error('Authorization server error, grant_type: %s' %self.grant_type, extra={
'redirect_uri': self.redirect_uri,
'state': self.params.state
})
raise AuthorizeError( raise AuthorizeError(
self.params.redirect_uri, self.params.redirect_uri,
'server_error', 'server_error',

View file

@ -1,3 +1,4 @@
import logging
import urllib import urllib
from django.http import JsonResponse from django.http import JsonResponse
@ -8,6 +9,7 @@ from oidc_provider.lib.utils.token import *
from oidc_provider.models import * from oidc_provider.models import *
from oidc_provider import settings from oidc_provider import settings
logger = logging.getLogger(__name__)
class TokenEndpoint(object): class TokenEndpoint(object):
@ -16,6 +18,11 @@ class TokenEndpoint(object):
self.params = Params() self.params = Params()
self._extract_params() self._extract_params()
logger.debug('Request %s', self.request)
logger.debug('TokenEndPoint request.POST --> : %s', self.request.POST)
logger.debug('TokenEndpoint request.GET --> : %s', self.request.GET)
logger.debug('TokenEndPoint extract_params --> : %s', self.params.__dict__)
def _extract_params(self): def _extract_params(self):
query_dict = self.request.POST query_dict = self.request.POST
@ -29,21 +36,25 @@ class TokenEndpoint(object):
def validate_params(self): def validate_params(self):
if not (self.params.grant_type == 'authorization_code'): if not (self.params.grant_type == 'authorization_code'):
logger.error('Unsupported grant type: --> : %s', self.params.grant_type)
raise TokenError('unsupported_grant_type') raise TokenError('unsupported_grant_type')
try: try:
self.client = Client.objects.get(client_id=self.params.client_id) self.client = Client.objects.get(client_id=self.params.client_id)
if not (self.client.client_secret == self.params.client_secret): if not (self.client.client_secret == self.params.client_secret):
logger.error('Invalid client, client secret -->: %s', self.params.client_secret)
raise TokenError('invalid_client') raise TokenError('invalid_client')
if not (self.params.redirect_uri in self.client.redirect_uris): if not (self.params.redirect_uri in self.client.redirect_uris):
logger.error('Invalid client, redirect_uri --> : %s', self.params.redirect_uri)
raise TokenError('invalid_client') raise TokenError('invalid_client')
self.code = Code.objects.get(code=self.params.code) self.code = Code.objects.get(code=self.params.code)
if not (self.code.client == self.client) \ if not (self.code.client == self.client) \
or self.code.has_expired(): or self.code.has_expired():
logger.error('Invalid grant, code client --> %s', self.code.client)
raise TokenError('invalid_grant') raise TokenError('invalid_grant')
except Client.DoesNotExist: except Client.DoesNotExist:
@ -77,7 +88,7 @@ class TokenEndpoint(object):
'expires_in': settings.get('OIDC_TOKEN_EXPIRE'), 'expires_in': settings.get('OIDC_TOKEN_EXPIRE'),
'id_token': id_token, 'id_token': id_token,
} }
logger.debug('Response dictionary --> : %s', dic)
return dic return dic
@classmethod @classmethod
@ -89,4 +100,6 @@ class TokenEndpoint(object):
response['Cache-Control'] = 'no-store' response['Cache-Control'] = 'no-store'
response['Pragma'] = 'no-cache' response['Pragma'] = 'no-cache'
logger.debug('JSON Response --> : %s', response.__dict__)
return response return response

View file

@ -1,5 +1,8 @@
import os
from datetime import timedelta from datetime import timedelta
DEBUG = False
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
@ -16,6 +19,53 @@ MIDDLEWARE_CLASSES = (
) )
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '%(asctime)s %(process)d [%(levelname)s] %(name)s Line: %(lineno)s id: %(process)d : %(message)s'
}
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse',
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'filters': ['require_debug_false'],
'formatter': 'simple',
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler',
'formatter': 'simple',
},
"debug_file_handler": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"formatter": "simple",
'filename': 'debug.log',
'formatter': 'simple',
"maxBytes": 10485760,
"backupCount": 20,
"encoding": "utf8"
}
},
'loggers': {
'oidc_provider': {
'handlers': ['console', 'debug_file_handler'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
},
},
}
INSTALLED_APPS = ( INSTALLED_APPS = (
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
@ -27,7 +77,7 @@ INSTALLED_APPS = (
'oidc_provider', 'oidc_provider',
) )
SECRET_KEY = 'secret-for-test-secret-secret' SECRET_KEY = 'secret-for-test-secret-top-secret'
ROOT_URLCONF = 'oidc_provider.tests.test_urls' ROOT_URLCONF = 'oidc_provider.tests.test_urls'