def test_encrypt_decrypt(self): session = SessionStore() session['test'] = 'in-test' session.save() eid = sessionrefcipher.encrypt(session) sess = sessionrefcipher.decrypt(eid) self.assertEqual(sess.get('test'), 'in-test')
def test_unique_encrypted_are_generated_after_revocation(self): session = SessionStore() session['test'] = 'in-test' session.save() eid1 = sessionrefcipher.encrypt(session) session = sessionrefcipher.decrypt(eid1) eid2 = sessionrefcipher.encrypt(session) self.assertNotEqual(eid1, eid2)
def test_revoked_encrypted_id_raises_valueerror(self): session = SessionStore() session['test'] = 'in-test' session.save() eid1 = sessionrefcipher.encrypt(session) session = sessionrefcipher.decrypt(eid1) eid2 = sessionrefcipher.encrypt(session) if eid1 == eid2: raise SkipTest('Non-unique encrypted IDs generated') self.assertRaises(ValueError, sessionrefcipher.decrypt, eid1)
def auth(session_id, key): try: session = sessionrefcipher.decrypt(session_id) except ValueError: return None request = set_request('/') user = authenticate(ssh_key=key) if user and user.is_active: login(request, user) init_otp(request) session.update(request.session) session.save() return 'Authenticated.' return None
def clean_session(self): try: return sessionrefcipher.decrypt(self.cleaned_data['session']) except ValueError: raise forms.ValidationError('Invalid session id')
def clean_session(self): try: return sessionrefcipher.decrypt( self.cleaned_data['session']) except ValueError: raise forms.ValidationError('Invalid session id')