def test_parse_with_name_length_short_by_one(self): server_name = SNIExtension() p = Parser(bytearray( b'\x00\x1c' + # length of array - 28 bytes b'\x0a' + # type of entry - unassigned (10) b'\x00\x0a' + # length of name - 10 bytes (short by one) # UTF-8 encoding of example.org b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67' + b'\x00' + # type of entry - host_name (0) b'\x00\x0b' + # length of name - 11 bytes # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d')) with self.assertRaises(SyntaxError): server_name = server_name.parse(p) server_name = SNIExtension() p = Parser(bytearray( b'\x00\x1c' + # length of array - 28 bytes b'\x0a' + # type of entry - unassigned (10) b'\x00\x0b' + # length of name - 11 bytes # UTF-8 encoding of example.org b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67' + b'\x00' + # type of entry - host_name (0) b'\x00\x0a' + # length of name - 10 bytes (short by one) # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d')) with self.assertRaises(SyntaxError): server_name = server_name.parse(p)
def test_parse_with_name_length_short_by_one(self): server_name = SNIExtension() p = Parser( bytearray(b'\x00\x1c' + # length of array - 28 bytes b'\x0a' + # type of entry - unassigned (10) b'\x00\x0a' + # length of name - 10 bytes (short by one) # UTF-8 encoding of example.org b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67' + b'\x00' + # type of entry - host_name (0) b'\x00\x0b' + # length of name - 11 bytes # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d')) with self.assertRaises(SyntaxError): server_name = server_name.parse(p) server_name = SNIExtension() p = Parser( bytearray(b'\x00\x1c' + # length of array - 28 bytes b'\x0a' + # type of entry - unassigned (10) b'\x00\x0b' + # length of name - 11 bytes # UTF-8 encoding of example.org b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67' + b'\x00' + # type of entry - host_name (0) b'\x00\x0a' + # length of name - 10 bytes (short by one) # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d')) with self.assertRaises(SyntaxError): server_name = server_name.parse(p)
def tes_parse_with_invalid_data(self): server_name = SNIExtension() p = Parser(bytearray(b'\x00\x01')) with self.assertRaises(SyntaxError): server_name.parse(p)
def test_parse_with_multiple_host_names(self): server_name = SNIExtension() p = Parser(bytearray( b'\x00\x1c' + # length of array - 28 bytes b'\x0a' + # type of entry - unassigned (10) b'\x00\x0b' + # length of name - 11 bytes # UTF-8 encoding of example.org b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67' + b'\x00' + # type of entry - host_name (0) b'\x00\x0b' + # length of name - 11 bytes # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d')) server_name = server_name.parse(p) self.assertEqual(bytearray(b'example.com'), server_name.host_names[0]) self.assertEqual(tuple([bytearray(b'example.com')]), server_name.host_names) SN = SNIExtension.ServerName self.assertEqual([ SN(10, bytearray(b'example.org')), SN(0, bytearray(b'example.com')) ], server_name.server_names)
def test_parse(self): server_name = SNIExtension() p = Parser(bytearray(0)) with self.assertRaises(SyntaxError): server_name = server_name.parse(p)
def test_parse_with_multiple_hostNames(self): server_name = SNIExtension() p = Parser( bytearray(b'\x00\x1c' + # length of array - 28 bytes b'\x0a' + # type of entry - unassigned (10) b'\x00\x0b' + # length of name - 11 bytes # UTF-8 encoding of example.org b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x6f\x72\x67' + b'\x00' + # type of entry - host_name (0) b'\x00\x0b' + # length of name - 11 bytes # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d')) server_name = server_name.parse(p) self.assertEqual(bytearray(b'example.com'), server_name.hostNames[0]) self.assertEqual(tuple([bytearray(b'example.com')]), server_name.hostNames) SN = SNIExtension.ServerName self.assertEqual([ SN(10, bytearray(b'example.org')), SN(0, bytearray(b'example.com')) ], server_name.serverNames)
def test_parse_null_length_array(self): server_name = SNIExtension() p = Parser(bytearray(b'\x00\x00')) server_name = server_name.parse(p) self.assertEqual([], server_name.server_names)
def test_parse_null_length_array(self): server_name = SNIExtension() p = Parser(bytearray(b'\x00\x00')) server_name = server_name.parse(p) self.assertEqual([], server_name.serverNames)
def test_parse_of_server_side_version(self): server_name = SNIExtension() p = Parser(bytearray(0)) server_name = server_name.parse(p) self.assertIsNone(server_name.serverNames)
def test_parse_with_array_length_short_by_one(self): server_name = SNIExtension() p = Parser(bytearray( b'\x00\x0d' + # length of array (one too short) b'\x00' + # type of entry - host_name (0) b'\x00\x0b' + # length of name - 11 bytes # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d')) with self.assertRaises(SyntaxError): server_name = server_name.parse(p)
def test_parse_with_array_length_short_by_one(self): server_name = SNIExtension() p = Parser( bytearray(b'\x00\x0d' + # length of array (one too short) b'\x00' + # type of entry - host_name (0) b'\x00\x0b' + # length of name - 11 bytes # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d')) with self.assertRaises(SyntaxError): server_name = server_name.parse(p)
def test_parse_with_host_name(self): server_name = SNIExtension() p = Parser(bytearray( b'\x00\x0e' + # length of array b'\x00' + # type of entry - host_name (0) b'\x00\x0b' + # length of name - 11 bytes # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d')) server_name = server_name.parse(p) self.assertEqual(bytearray(b'example.com'), server_name.host_names[0]) self.assertEqual(tuple([bytearray(b'example.com')]), server_name.host_names)
def test_parse_with_host_name(self): server_name = SNIExtension() p = Parser( bytearray(b'\x00\x0e' + # length of array b'\x00' + # type of entry - host_name (0) b'\x00\x0b' + # length of name - 11 bytes # UTF-8 encoding of example.com b'\x65\x78\x61\x6d\x70\x6c\x65\x2e\x63\x6f\x6d')) server_name = server_name.parse(p) self.assertEqual(bytearray(b'example.com'), server_name.hostNames[0]) self.assertEqual(tuple([bytearray(b'example.com')]), server_name.hostNames)