コード例 #1
0
ファイル: rsa_auth.py プロジェクト: brianmartin/Pydra
 def test_challenge_no_key(self):
     """
     Tests challenge function if there is no key for the client.
     """
     avatar = RSAAvatar(self.priv_key, None, None)
     result = avatar.perspective_auth_challenge()
     self.assertEquals(result, -1, 'No public key for client, challenge result should be error (-1)')
コード例 #2
0
ファイル: rsa_auth.py プロジェクト: brianmartin/Pydra
    def test_challenge(self):
        """
        Test a normal challenge where both keys are present
        """
        avatar = RSAAvatar(self.priv_key, None, self.pub_key, key_size=KEY_SIZE)
        challenge = avatar.perspective_auth_challenge()

        self.verify_challenge(challenge, avatar.challenge)
コード例 #3
0
ファイル: rsa_auth.py プロジェクト: brianmartin/Pydra
 def test_response_first_use(self):
     """
     Test the response function when first_use_flag is set
     """
     avatar = RSAAvatar(self.priv_key, None, None, key_size=KEY_SIZE)
     challenge = avatar.perspective_auth_challenge()
     result = avatar.perspective_auth_response(None)
     self.assertFalse(result, 'auth_response should return None if handshake is successful')
     self.assert_(avatar.authenticated, 'avatar.authenticated flag should be True if auth_response succeeds')
コード例 #4
0
ファイル: rsa_auth.py プロジェクト: brianmartin/Pydra
 def test_response(self):
     """
     Test the response function given the correct response
     """
     avatar = RSAAvatar(self.priv_key, None, self.pub_key, key_size=KEY_SIZE)
     challenge = avatar.perspective_auth_challenge()
     response = self.create_response(challenge)
     result = avatar.perspective_auth_response(response)
     self.assertFalse(result, 'auth_response should return None if handshake is successful')
     self.assert_(avatar.authenticated, 'avatar.authenticated flag should be True if auth_response succeeds')
コード例 #5
0
ファイル: rsa_auth.py プロジェクト: brianmartin/Pydra
    def test_challenge_no_key_first_use(self):
        """
        Tests challenge function when there is no key, but the first_use flag is set.
        """
        avatar = RSAAvatar(self.priv_key, None, None, key_size=KEY_SIZE)
        challenge = avatar.perspective_auth_challenge()

        # challenge should be None, no_key_first_use is a flag to allow keyless access the first
        # time authenticating, which happens prior to key exchange
        self.assertFalse(challenge, avatar.challenge)
コード例 #6
0
ファイル: rsa_auth.py プロジェクト: brianmartin/Pydra
    def test_success_callback(self):
        """
        Test the callback after a successful auth
        """
        avatar = RSAAvatar(self.priv_key, None, self.pub_key, authenticated_callback=self.callback, key_size=KEY_SIZE)
        challenge = avatar.perspective_auth_challenge()
        response = self.create_response(challenge)
        result = avatar.perspective_auth_response(response)

        self.assert_(self.callback_avatar, 'Callback was not called after success')
        self.assertEqual(self.callback_avatar, avatar, 'Callback was not called after success')
コード例 #7
0
ファイル: rsa_auth.py プロジェクト: brianmartin/Pydra
 def test_bad_response(self):
     """
     Test the response function when given an incorrect response
     """
     avatar = RSAAvatar(self.priv_key, None, self.pub_key, key_size=KEY_SIZE)
     challenge = avatar.perspective_auth_challenge()
     #create response that can't be string because its longer than the hash
     response = secureRandom(600)
     result = avatar.perspective_auth_response(response)
     self.assertEqual(result, -1, 'auth_response should return error (-1) when given bad response')
     self.assertFalse(avatar.authenticated, 'avatar.authenticated flag should be False if auth_response fails')
コード例 #8
0
ファイル: rsa_auth.py プロジェクト: brianmartin/Pydra
    def test_auth_challenge_no_server_key(self):
        """
        Tests auth_challenge when server key is None.
        """
        client = RSAClient(self.priv_key)
        avatar = RSAAvatar(self.priv_key, None, self.pub_key, key_size=KEY_SIZE)
        remote = RemoteProxy()

        challenge = avatar.perspective_auth_challenge()
        client.auth_challenge(challenge, remote, None)

        #verify that auth_response got called
        self.assertEqual(remote.func, 'auth_response', 'Calling auth_challenge should trigger auth_response call on server')

        #verify the correct response was sent
        self.assertFalse(remote.kwargs['response'], 'Response did not match the expected response')
コード例 #9
0
 def test_auth_challenge(self):
     """
     Tests a normal challenge string
     
     Verifies:
         * remote call is sent
         * response equals challenge
     """
     client = RSAClient(self.priv_key)
     avatar = RSAAvatar(self.priv_key, None, self.pub_key, key_size=KEY_SIZE)
     remote = RemoteProxy()
     
     challenge = avatar.perspective_auth_challenge()
     client.auth_challenge(challenge, remote, self.pub_key)
     
     #verify that auth_response got called
     args, kwargs, deferred = remote.assertCalled(self, 'auth_response')
     self.assertEqual(kwargs['response'], avatar.challenge, 'Response did not match the expected response')
コード例 #10
0
 def test_auth_challenge_no_server_key(self):
     """
     Tests auth_challenge when server key is None.
     
     Verifies:
         * remote call is sent
         * auth is denied
     """
     client = RSAClient(self.priv_key)
     avatar = RSAAvatar(self.priv_key, None, self.pub_key, key_size=KEY_SIZE)
     remote = RemoteProxy()
     
     challenge = avatar.perspective_auth_challenge()
     client.auth_challenge(challenge, remote, None)
     
     #verify that auth_response got called
     args, kwargs, deferred = remote.assertCalled(self, 'auth_response')
     
     #verify the correct response was sent
     self.assertFalse(kwargs['response'], 'Response did not match the expected response')