Skip to content

Commit

Permalink
Immediate remove request.user when ping fails
Browse files Browse the repository at this point in the history
Since we were setting request.user even when ping fails, the site
would still let you load 1 page before logging you out.  This should
resolve that weird issue.
  • Loading branch information
kevin1024 committed Aug 22, 2014
1 parent 048a337 commit 4fc958b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions oauthadmin/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def _verify_ping_interval(request, ping_interval, ping_func):
is_valid = ping_func(request.session['oauth_token'])
if not is_valid:
destroy_session(request)
from django.contrib.auth.models import AnonymousUser
request.user = AnonymousUser()

class OauthAdminSessionMiddleware(object):
def process_request(self, request):
Expand Down
11 changes: 11 additions & 0 deletions test/test_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ def test_process_request_with_user():
assert request.user.get('id') is data['id']


false_mock_pinger = Mock(return_value = False)

@override_settings(OAUTHADMIN_PING_INTERVAL=5)
@override_settings(OAUTHADMIN_PING='test.test_middleware.false_mock_pinger')
def test_that_anonymoususer_goes_in_request_user_if_ping_fails():
request.session = {'user':'not anonymous', 'oauth_token':'abc'}
request.user = 'not anonymous'
mw.process_request(request)
assert isinstance(request.user, AnonymousUser)


mock_pinger = Mock()

@override_settings(OAUTHADMIN_PING_INTERVAL=5)
Expand Down

0 comments on commit 4fc958b

Please sign in to comment.