def test_response_before_challenge(self): """ Test sending a response before a challenge has been created """ avatar = RSAAvatar(self.priv_key, None, None, key_size=KEY_SIZE) result = avatar.perspective_auth_response(None) self.assertEqual(result, 0, 'auth_response should return error (0) when called before auth_challenge')
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')
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')
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')
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')