Beispiel #1
0
    def testWrongKeycardClass(self):
        keycard = keycards.Keycard()
        d = defer.maybeDeferred(self.bouncer.authenticate, keycard)

        def wrongKeycardClassCallback(result):
            self.failIf(result)
        d.addCallback(wrongKeycardClassCallback)
        return d
Beispiel #2
0
    def testEarlyCanceling(self):
        keycard = keycards.Keycard()
        answer = pb.unjelly(pb.jelly(keycard))
        self.failUnless(self.bouncer.startAuthSession(answer))

        # Bouncer cancel the authentication
        self.bouncer.cancelAuthSession(answer)
        self.assertEquals(answer.state, keycards.REFUSED)
        self.failIf(self.bouncer.hasKeycard(answer))
        self.failIf(self.bouncer.hasAuthSession(answer))
        self.assertEqual(None, self.bouncer.getAuthSessionInfo(answer))
Beispiel #3
0
    def testNormalBehaviors(self):
        # Client create a keycard
        keycard = keycards.Keycard()
        self.assertEquals(keycard.state, keycards.REQUESTING)

        # Client send the keycard to the bouncer
        answer = pb.unjelly(pb.jelly(keycard))
        self.assertEquals(answer.state, keycards.REQUESTING)
        self.assertNotEquals(keycard, answer)

        # Bouncer do not know about the keycard
        self.failIf(self.bouncer.hasKeycard(answer))
        self.failIf(self.bouncer.hasAuthSession(answer))
        self.assertEqual(None, self.bouncer.getAuthSessionInfo(answer))

        # Bouncer start an authentication session
        self.failUnless(self.bouncer.startAuthSession(answer))
        self.assertEquals(answer.state, keycards.REQUESTING)
        self.failIf(self.bouncer.hasKeycard(answer))
        self.failUnless(self.bouncer.hasAuthSession(answer))
        self.assertEqual(answer, self.bouncer.getAuthSessionInfo(answer))

        # Bouncer send back the keycard to the client
        challenge = pb.unjelly(pb.jelly(answer))
        self.assertEquals(challenge.state, keycards.REQUESTING)
        self.assertNotEquals(answer, challenge)

        # Client send back a response keycard
        response = pb.unjelly(pb.jelly(challenge))
        self.assertEquals(response.state, keycards.REQUESTING)
        self.assertNotEquals(challenge, response)

        # Bouncer state did not change, and the keycard are associated
        self.failIf(self.bouncer.hasKeycard(answer))
        self.failIf(self.bouncer.hasKeycard(response))
        self.failUnless(self.bouncer.hasAuthSession(answer))
        self.failUnless(self.bouncer.hasAuthSession(response))
        self.assertEqual(answer, self.bouncer.getAuthSessionInfo(answer))
        self.assertEqual(answer, self.bouncer.getAuthSessionInfo(response))
        self.assertNotEqual(response, self.bouncer.getAuthSessionInfo(answer))
        self.assertNotEqual(response,
                            self.bouncer.getAuthSessionInfo(response))

        # Bouncer confirm the authentication
        self.failUnless(self.bouncer.confirmAuthSession(response))
        self.assertEquals(response.state, keycards.AUTHENTICATED)
        self.assertEquals(answer.state, keycards.REQUESTING)
        self.failIf(self.bouncer.hasKeycard(answer))
        self.failUnless(self.bouncer.hasKeycard(response))
        self.failIf(self.bouncer.hasAuthSession(answer))
        self.failIf(self.bouncer.hasAuthSession(response))
        self.assertEqual(None, self.bouncer.getAuthSessionInfo(answer))
        self.assertEqual(None, self.bouncer.getAuthSessionInfo(response))
Beispiel #4
0
    def testLateCanceling(self):
        keycard = keycards.Keycard()
        answer = pb.unjelly(pb.jelly(keycard))
        self.failUnless(self.bouncer.startAuthSession(answer))
        challenge = pb.unjelly(pb.jelly(answer))
        response = pb.unjelly(pb.jelly(challenge))

        # Bouncer cancel the authentication
        self.bouncer.cancelAuthSession(response)
        self.assertEquals(response.state, keycards.REFUSED)
        self.assertEquals(answer.state, keycards.REQUESTING)
        self.failIf(self.bouncer.hasKeycard(answer))
        self.failIf(self.bouncer.hasKeycard(response))
        self.failIf(self.bouncer.hasAuthSession(answer))
        self.failIf(self.bouncer.hasAuthSession(response))
        self.assertEqual(None, self.bouncer.getAuthSessionInfo(answer))
        self.assertEqual(None, self.bouncer.getAuthSessionInfo(response))
Beispiel #5
0
    def testSessionExpiration(self):
        keycard = keycards.Keycard()
        keycard.ttl = 10
        answer = pb.unjelly(pb.jelly(keycard))

        # Bouncer stqrt a session and return the keycard to the client
        self.failUnless(self.bouncer.startAuthSession(answer))
        challenge = pb.unjelly(pb.jelly(answer))

        self.failIf(self.bouncer.hasKeycard(answer))
        self.failUnless(self.bouncer.hasAuthSession(answer))
        self.assertEqual(answer, self.bouncer.getAuthSessionInfo(answer))

        # Then the session expire
        self.bouncer._expire()

        self.failIf(self.bouncer.hasKeycard(answer))
        self.failIf(self.bouncer.hasAuthSession(answer))
        self.assertEqual(None, self.bouncer.getAuthSessionInfo(answer))

        # The client return the response keycard
        response = pb.unjelly(pb.jelly(challenge))

        self.failIf(self.bouncer.hasKeycard(response))
        self.failIf(self.bouncer.hasAuthSession(response))
        self.assertEqual(None, self.bouncer.getAuthSessionInfo(response))

        # The confirmation is refused
        self.failIf(self.bouncer.confirmAuthSession(response))
        self.assertEquals(response.state, keycards.REFUSED)
        self.assertEquals(answer.state, keycards.REQUESTING)
        self.failIf(self.bouncer.hasKeycard(answer))
        self.failIf(self.bouncer.hasKeycard(response))
        self.failIf(self.bouncer.hasAuthSession(answer))
        self.failIf(self.bouncer.hasAuthSession(response))
        self.assertEqual(None, self.bouncer.getAuthSessionInfo(answer))
        self.assertEqual(None, self.bouncer.getAuthSessionInfo(response))