当前位置: 首页>>代码示例>>Python>>正文


Python Client.process_message_from_server方法代码示例

本文整理汇总了Python中Client.Client.process_message_from_server方法的典型用法代码示例。如果您正苦于以下问题:Python Client.process_message_from_server方法的具体用法?Python Client.process_message_from_server怎么用?Python Client.process_message_from_server使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Client.Client的用法示例。


在下文中一共展示了Client.process_message_from_server方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Client

# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import process_message_from_server [as 别名]
 def test_connect_from_server_if_encrypted_message_cannot_be_decrypted_to_two_elements_will_return_error_signal(
         self):
     client = Client(client_id=None, client_key=3197, server=None, server_id=None)
     random_value_from_server = 11
     encrypted_message = encrypt('{0}:{1}'.format('nonce', 'session-key'), self.client_key)
     response = client.process_message_from_server((random_value_from_server, encrypted_message))
     self.assertEqual(response, client.error_signal)
开发者ID:jan-osch,项目名称:Otway-Rees-BSK,代码行数:9,代码来源:test_client.py

示例2: ClientTests

# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import process_message_from_server [as 别名]
class ClientTests(unittest.TestCase):
    def setUp(self):
        self.client_key = 1231241
        self.client_id = 'client_id_element'
        self.client = Client(client_id=None, client_key=self.client_key, server=None, server_id=None)

    def test_connect_produces_a_3_element_tuple_for_server(self):
        output = self.client.prepare_message_for_server()
        self.assertEqual(len(output), 4)
        self.assertTrue(isinstance(output, tuple))

    def test_connect_generates_random_message_and_saves_it_and_sends_it_as_first_element(self):
        output = self.client.prepare_message_for_server()
        random_value = self.client.random_value
        self.assertEqual(output[0], random_value)

    def test_connect_sends_client_id_as_second_element(self):
        client = Client(client_id=self.client_id, client_key=self.client_key, server=None, server_id=None)
        output = client.prepare_message_for_server()
        self.assertEqual(output[1], self.client_id)

    def test_connect_sends_server_id_as_third_element(self):
        server_id = 'secret_server_id'
        client = Client(client_id=None, client_key=123, server=None, server_id=server_id)
        output = client.prepare_message_for_server()
        self.assertEqual(output[2], server_id)

    def test_connect_sends_encrypted_with_own_key_element_that_contains_4_elements_separated_by_colons(self):
        encrypted = self.client.prepare_message_for_server()[3]
        decrypted = decrypt(encrypted, self.client_key).split(':')
        self.assertEqual(len(decrypted), 4)

    def test_connect_sends_encrypted_own_nonce_at_first_position(self):
        encrypted = self.client.prepare_message_for_server()[3]
        nonce = self.client.nonce
        decrypted = decrypt(encrypted, self.client_key).split(':')
        self.assertEqual(decrypted[0], nonce)

    def test_connect_sends_encrypted_random_value_at_second_position(self):
        encrypted = self.client.prepare_message_for_server()[3]
        random = self.client.random_value
        decrypted = decrypt(encrypted, self.client_key).split(':')
        self.assertEqual(int(decrypted[1]), random)

    def test_connect_sends_encrypted_random_value_at_third_position(self):
        cid = 'client_id'
        client = Client(client_id=cid, client_key=self.client_key, server=None, server_id=None)
        encrypted = client.prepare_message_for_server()[3]
        decrypted = decrypt(encrypted, self.client_key).split(':')
        self.assertEqual(decrypted[2], '%s' % cid)

    def test_connect_sends_encrypted_random_server_id_at_last_position(self):
        sid = 'server_id'
        client = Client(client_id=None, client_key=self.client_key, server=None, server_id=sid)
        encrypted = client.prepare_message_for_server()[3]
        decrypted = decrypt(encrypted, self.client_key).split(':')
        self.assertEqual(decrypted[3], '%s' % sid)

    def test_connect_from_server_unpacks_message(self):
        random_value_from_server = 53082
        self.client.process_message_from_server(('%s' % random_value_from_server, 'anything'))
        self.assertEqual(self.client.server_random_value, random_value_from_server)

    def test_connect_from_server_unpacks_encrypted_message(self):
        random_value_from_server = 41280
        encrypted_message = encrypt('{0}:{1}'.format('nonce', 'session-key'), self.client_key)
        self.client.process_message_from_server((random_value_from_server, encrypted_message))
        self.assertEqual(self.client.trusted_nonce, 'nonce')
        self.assertEqual(self.client.session_key, 'session-key')

    def test_connect_from_server_if_encrypted_message_cannot_be_decrypted_to_two_elements_will_return_error_signal(
            self):
        client = Client(client_id=None, client_key=3197, server=None, server_id=None)
        random_value_from_server = 11
        encrypted_message = encrypt('{0}:{1}'.format('nonce', 'session-key'), self.client_key)
        response = client.process_message_from_server((random_value_from_server, encrypted_message))
        self.assertEqual(response, client.error_signal)

    def test_process_message_from_server_returns_error_when_nonce_does_not_match(self):
        random_value_from_server = 1231
        self.client.nonce = 'one-nonce'
        self.client.random_value = random_value_from_server
        encrypted_message = encrypt('{0}:{1}'.format('two-nonce', 'session-key'), self.client_key)
        response = self.client.process_message_from_server((random_value_from_server, encrypted_message))
        self.assertEqual(response, self.client.error_signal)

    def test_process_message_from_server_returns_error_when_random_message_does_not_match(self):
        random_value_from_server = 312789
        self.client.random_value = 41279412
        self.client.nonce = 'one-nonce'
        encrypted_message = encrypt('{0}:{1}'.format(self.client.nonce, 'session-key'), self.client_key)
        response = self.client.process_message_from_server((random_value_from_server, encrypted_message))
        self.assertEqual(response, self.client.error_signal)

    def test_connect_from_server_if_nested_message_matches_returns_own_ok_signal(self):
        random_value_from_server =  12312
        self.client.random_value = random_value_from_server
        generated_nonce = 'generated-nonce'
        self.client.nonce = generated_nonce
        encrypted_message = encrypt('{0}:{1}'.format('%s' % generated_nonce, 'session-key'), self.client_key)
#.........这里部分代码省略.........
开发者ID:jan-osch,项目名称:Otway-Rees-BSK,代码行数:103,代码来源:test_client.py


注:本文中的Client.Client.process_message_from_server方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。