Ejemplo n.º 1
0
    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')
Ejemplo n.º 2
0
    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')
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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)
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
 def clean_session(self):
     try:
         return sessionrefcipher.decrypt(self.cleaned_data['session'])
     except ValueError:
         raise forms.ValidationError('Invalid session id')
Ejemplo n.º 10
0
 def clean_session(self):
     try:
         return sessionrefcipher.decrypt(
             self.cleaned_data['session'])
     except ValueError:
         raise forms.ValidationError('Invalid session id')