Esempio n. 1
0
 def test_key_exchange(self):
     """
     Tests the auth function before the client has paired.  This triggers
     key exchanging.
     
     Verifies:
         * remote command "exchange_keys" is sent
         * Avatar response is received and decoded
         * response triggers client save_key to be called
         * server key is received
         * response triggers server save_key to be called
         * client key is received
     """
     client = RSAClient(self.priv_key, self.pub_key_values)
     remote = RemoteProxy()
     save_key_server = CallProxy(None, False)
     save_key_client = CallProxy(None, False)
     client.auth(remote, save_key=save_key_client)
     args, kwargs, deferred = remote.assertCalled(self, 'exchange_keys')
     
     avatar = RSAAvatar(self.priv_key, self.pub_key_values, self.pub_key, save_key=save_key_server, key_size=KEY_SIZE)
     deferred.callback(avatar.perspective_exchange_keys(*args[1:]))
     
     args, kwargs = save_key_server.assertCalled(self)
     key = simplejson.loads(''.join(args[0]))
     self.assert_(key==self.pub_key_values, 'keys do not match')
     
     args, kwargs = save_key_client.assertCalled(self)
     key = simplejson.loads(''.join(args[0]))
     self.assert_(key==self.pub_key_values, 'keys do not match')
Esempio n. 2
0
 def test_auth(self):
     """
     Tests the auth function
     
     Verifies:
         * auth_challenge is sent
     """
     client = RSAClient(self.priv_key)
     remote = RemoteProxy()
     client.auth(remote, server_key=self.pub_key)
     remote.assertCalled(self, 'auth_challenge')
Esempio n. 3
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')
Esempio n. 4
0
 def test_auth_challenge_no_challenge(self):
     """
     Tests auth_challenge when the challenge received is None
     
     Verifies:
         * remote call is sent
         * auth is denied
     """
     client = RSAClient(self.priv_key)
     remote = RemoteProxy()
     
     challenge = None
     client.auth_challenge(challenge, remote, self.pub_key)
     
     #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')
Esempio n. 5
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')
Esempio n. 6
0
 def assertCalled(self, remote, function, *args, **kwargs):
     return RemoteProxy.assertCalled(remote, self, function, *args, **kwargs)