Coverage for gramex\transforms\auth.py: 82%

# Coverage for gramex\transforms\auth.py : 82%

## 19 statements 17 run 2 missing 0 excluded 4 partial

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1'''

2 Authentication transforms

3'''

4 import six

5 from gramex.config import app_log

6

7

8 def ensure_single_session(handler):

9 '''

10 Ensure that user in this session is logged out of all other sessions.

11 '''

12 user_id = handler.session.get('user', {}).get('id')

13 if user_id is not None: 13 ↛ exitline 13 didn't return from function 'ensure_single_session', because the condition on line 13 was never false

14 for key in handler._session_store.keys():

15 # Ignore current session or OTP sessions

16 if key == handler.session.get('id'): 16 ↛ 17line 16 didn't jump to line 17, because the condition on line 16 was never true

17 continue

18 if isinstance(key, six.text_type) and key.startswith('otp:'):

19 continue

20 if isinstance(key, six.binary_type) and key.startswith(b'otp:'): 20 ↛ 21line 20 didn't jump to line 21, because the condition on line 20 was never true

21 continue

22 # Remove user from all other sessions

23 other_session = handler._session_store.load(key)

24 if other_session is not None: 24 ↛ 14line 24 didn't jump to line 14, because the condition on line 24 was never false

25 other_user = other_session.get('user')

26 if other_user is not None and other_user.get('id'):

27 other_session.pop('user')

28 handler._session_store.dump(key, other_session)

29 app_log.debug('dropped user %s from session %s', user_id, other_session['id'])