Ejemplo n.º 1
0
 def test_valid_short_data(self):
     req = Request.create_query(0xa000, 0)  # client hello
     res = Response(req)
     res_msg = bytearray(req.get_message())
     res_msg.extend(b'\x00\x00')
     res.set_message(res_msg)
     self.assertFalse(res.valid())
Ejemplo n.º 2
0
 def test_validate_wrong_data(self):
     req = Request.create_query(0xa000, 0)  # client hello
     res = Response(req)
     res_msg = bytearray(req.get_message())
     res_msg.extend(b'\x01\x02')
     res_msg.extend(b'\x03\x04')
     res.set_message(res_msg)
     response = b'12345678901234567890123456'
     with self.assertRaises(ValidationException) as context:
         res.validate()
     self.assertEqual('Incorrect CRC (0x4fc5)', context.exception.args[0])
Ejemplo n.º 3
0
 def test_expected_length_0(self):
     req = Request.create_query(0xa000, 0)
     self.assertEqual(12, Response(req).expected_length())
Ejemplo n.º 4
0
 def test_valid_no_data(self):
     req = Request.create_query(0xa000, 0)  # client hello
     res = Response(req)
     self.assertFalse(res.valid())
Ejemplo n.º 5
0
 def test_as_bytes_hello(self):
     req = Request.create_query(0xa000, 0)
     expected = b'Q\x00\x00\xa0\x00\x00\x9dK'
     self.assertEqual(expected, req.get_message())
Ejemplo n.º 6
0
 def test_word_length_ff(self):
     self.assertEqual(256,
                      Request.create_query(0xa000, 0xff).get_word_length())
Ejemplo n.º 7
0
 def test_word_length_0(self):
     self.assertEqual(16,
                      Request.create_query(0xa000, 15).get_word_length())
Ejemplo n.º 8
0
 def test_as_bytes_load_power(self):
     req = Request.create_query(0xa093, 3)
     expected = b'\x51\x03\x93\xa0\x00\x00\x53\x9d'
     self.assertEqual(expected, req.get_message())