1 # Test for the MySQL protocol dissector of Wireshark
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # Using PDML instead of JSON as output of tshark works better
6 # as some field names are duplicated, which isn't accepted in JSON
11 import xml
.etree
.ElementTree
as ET
16 def test_mysql_84_ps_json(self
, cmd_tshark
, capture_file
, test_env
):
17 """MySQL 8.4.0 with results in binary resultset from prepared statement including the JSON field type"""
19 # MySQL Protocol - row packet
22 # Response Code: OK Packet (0x00)
26 # JavaScript Object Notation
28 # [Path with value: /[]:1]
29 # [Member with value: []:1]
31 # [Path with value: /[]:2]
32 # [Member with value: []:2]
34 # [Path with value: /[]:3]
35 # [Member with value: []:3]
39 # JavaScript Object Notation
42 # [Path with value: /a:61]
43 # [Member with value: a:61]
48 # [Path with value: /b:62]
49 # [Member with value: b:62]
54 stdout
= subprocess
.check_output(
58 capture_file("mysql/mysql_84_ps_json.pcapng.gz"),
70 tree
= ET
.fromstring(stdout
)
72 # There should not be any expert info as that indicates the dissector is incomplete
73 for expertinfo
in tree
.findall(
74 "./proto[@name='mysql']//field[@name='_ws.expert']"
76 print(ET
.tostring(expertinfo
, "unicode"))
81 # Get the packet number
83 pkt
.find("./proto[@name='geninfo']/field[@name='num']").attrib
["show"]
90 "./proto/field[@show='Binary Field']/proto/field"
92 ] == ["json.array", "json.object"]
94 def test_mysql_84_qa_multi(self
, cmd_tshark
, capture_file
, test_env
):
95 """MySQL 8.4.0 with prepared statement and query attributes"""
97 stdout
= subprocess
.check_output(
101 capture_file("mysql/mysql_84_qa_multi.pcapng.gz"),
113 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
117 "showname": "MySQL Protocol",
127 "showname": "MySQL Protocol",
129 "Packet Length: 264",
137 "showname": "MySQL Protocol - response OK",
141 "Response Code: OK Packet (0x00)",
143 "Server Status: 0x4002",
145 "Session tracking data",
151 "showname": "MySQL Protocol",
155 "Request Command Query",
161 "showname": "MySQL Protocol - response OK",
163 "Packet Length: 107",
165 "Response Code: OK Packet (0x00)",
167 "Server Status: 0x4002",
169 "Session tracking data",
175 "showname": "MySQL Protocol",
179 "Request Command Query",
185 "showname": "MySQL Protocol - response OK",
187 "Packet Length: 107",
189 "Response Code: OK Packet (0x00)",
191 "Server Status: 0x4002",
193 "Session tracking data",
199 "showname": "MySQL Protocol",
203 "Request Command Query",
209 "showname": "MySQL Protocol - response OK",
213 "Response Code: OK Packet (0x00)",
215 "Server Status: 0x4000",
217 "Session tracking data",
223 "showname": "MySQL Protocol",
227 "Request Command Ping",
233 "showname": "MySQL Protocol - response OK",
237 "Response Code: OK Packet (0x00)",
239 "Server Status: 0x0000",
246 "showname": "MySQL Protocol",
250 "Request Command Prepare Statement",
256 "showname": "MySQL Protocol - response to PREPARE",
260 "Response Code: OK Packet (0x00)",
262 "Number of fields: 7",
263 "Number of parameter: 1",
268 "showname": "MySQL Protocol - parameters in response to PREPARE",
272 "Charset number: binary COLLATE binary (63)",
274 "Type: FIELD_TYPE_LONGLONG (8)",
280 "showname": "MySQL Protocol - fields in response to PREPARE",
284 "Charset number: binary COLLATE binary (63)",
286 "Type: FIELD_TYPE_LONG (3)",
292 "showname": "MySQL Protocol - fields in response to PREPARE",
296 "Charset number: binary COLLATE binary (63)",
298 "Type: FIELD_TYPE_DATETIME (12)",
304 "showname": "MySQL Protocol - fields in response to PREPARE",
308 "Charset number: binary COLLATE binary (63)",
310 "Type: FIELD_TYPE_DATETIME (12)",
316 "showname": "MySQL Protocol - fields in response to PREPARE",
320 "Charset number: binary COLLATE binary (63)",
322 "Type: FIELD_TYPE_TIMESTAMP (7)",
328 "showname": "MySQL Protocol - fields in response to PREPARE",
332 "Charset number: binary COLLATE binary (63)",
334 "Type: FIELD_TYPE_TIMESTAMP (7)",
340 "showname": "MySQL Protocol - fields in response to PREPARE",
344 "Charset number: binary COLLATE binary (63)",
346 "Type: FIELD_TYPE_BIT (16)",
352 "showname": "MySQL Protocol - fields in response to PREPARE",
356 "Charset number: binary COLLATE binary (63)",
358 "Type: FIELD_TYPE_VAR_STRING (253)",
366 "showname": "MySQL Protocol",
370 "Request Command Reset Statement",
376 "showname": "MySQL Protocol - response OK",
380 "Response Code: OK Packet (0x00)",
382 "Server Status: 0x0000",
389 "showname": "MySQL Protocol",
393 "Request Command Execute Statement",
399 "showname": "MySQL Protocol - column count",
403 "Number of fields: 7",
407 "showname": "MySQL Protocol - field packet",
411 "Charset number: binary COLLATE binary (63)",
413 "Type: FIELD_TYPE_LONG (3)",
419 "showname": "MySQL Protocol - field packet",
423 "Charset number: binary COLLATE binary (63)",
425 "Type: FIELD_TYPE_DATETIME (12)",
431 "showname": "MySQL Protocol - field packet",
435 "Charset number: binary COLLATE binary (63)",
437 "Type: FIELD_TYPE_DATETIME (12)",
443 "showname": "MySQL Protocol - field packet",
447 "Charset number: binary COLLATE binary (63)",
449 "Type: FIELD_TYPE_TIMESTAMP (7)",
455 "showname": "MySQL Protocol - field packet",
459 "Charset number: binary COLLATE binary (63)",
461 "Type: FIELD_TYPE_TIMESTAMP (7)",
467 "showname": "MySQL Protocol - field packet",
471 "Charset number: binary COLLATE binary (63)",
473 "Type: FIELD_TYPE_BIT (16)",
479 "showname": "MySQL Protocol - field packet",
483 "Charset number: binary COLLATE binary (63)",
485 "Type: FIELD_TYPE_VAR_STRING (253)",
491 "showname": "MySQL Protocol - row packet",
495 "Response Code: OK Packet (0x00)",
496 "Row null buffer: 0000",
500 "showname": "MySQL Protocol - response OK",
504 "Response Code: EOF Packet (0xfe)",
507 "Server Status: 0x0021",
514 "showname": "MySQL Protocol",
518 "Request Command Reset Statement",
524 "showname": "MySQL Protocol - response OK",
528 "Response Code: OK Packet (0x00)",
530 "Server Status: 0x0001",
537 "showname": "MySQL Protocol",
541 "Request Command Close Statement",
547 "showname": "MySQL Protocol",
551 "Request Command Quit",
557 # Summary should look like this:
559 # <int:Packet Number>: {
560 # <int:MySQL Packet Number>: {
562 # "fields": [str, ...]
568 tree
= ET
.fromstring(stdout
)
570 # There should not be any expert info as that indicates the dissector is incomplete
571 for expertinfo
in tree
.findall(
572 "./proto[@name='mysql']//field[@name='_ws.expert']"
574 print(ET
.tostring(expertinfo
, "unicode"))
579 # Get the packet number
581 pkt
.find("./proto[@name='geninfo']/field[@name='num']").attrib
["show"]
585 for proto
in pkt
.findall("./proto[@name='mysql']"):
588 proto
.find("./field[@name='mysql.packet_number']").attrib
["show"]
590 summary
[num
][mysqlnum
] = {
591 "showname": proto
.attrib
["showname"],
594 for field
in proto
.findall("./field"):
595 if "showname" in field
.attrib
:
596 summary
[num
][mysqlnum
]["fields"].append(
597 field
.attrib
["showname"]
603 for mysqlpkt
in summary
[pkt
]:
605 summary
[pkt
][mysqlpkt
]["showname"]
606 == expected
[pkt
][mysqlpkt
]["showname"]
609 summary
[pkt
][mysqlpkt
]["fields"]
610 == expected
[pkt
][mysqlpkt
]["fields"]
613 def test_mysql_57(self
, cmd_tshark
, capture_file
, test_env
):
616 stdout
= subprocess
.check_output(
620 capture_file("mysql/mysql57.pcapng.gz"),
632 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
636 "showname": "MySQL Protocol",
646 "showname": "MySQL Protocol",
648 "Packet Length: 181",
656 "showname": "MySQL Protocol - response OK",
660 "Response Code: OK Packet (0x00)",
662 "Server Status: 0x0002",
669 "showname": "MySQL Protocol",
673 "Request Command Query",
679 "showname": "MySQL Protocol - column count",
683 "Number of fields: 1",
687 "showname": "MySQL Protocol - field packet",
691 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
693 "Type: FIELD_TYPE_VAR_STRING (253)",
699 "showname": "MySQL Protocol - row packet",
700 "fields": ["Packet Length: 29", "Packet Number: 3"],
703 "showname": "MySQL Protocol - response OK",
707 "Response Code: EOF Packet (0xfe)",
710 "Server Status: 0x0002",
717 "showname": "MySQL Protocol",
721 "Request Command Query",
727 "showname": "MySQL Protocol - response ERROR",
731 "Response Code: ERR Packet (0xff)",
734 "Error message: Unknown column '$$' in 'field list'",
740 "showname": "MySQL Protocol",
744 "Request Command Query",
750 "showname": "MySQL Protocol - column count",
754 "Number of fields: 2",
758 "showname": "MySQL Protocol - field packet",
762 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
764 "Type: FIELD_TYPE_VAR_STRING (253)",
770 "showname": "MySQL Protocol - field packet",
774 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
776 "Type: FIELD_TYPE_VAR_STRING (253)",
782 "showname": "MySQL Protocol - row packet",
783 "fields": ["Packet Length: 16", "Packet Number: 4"],
786 "showname": "MySQL Protocol - response OK",
790 "Response Code: EOF Packet (0xfe)",
793 "Server Status: 0x0002",
800 "showname": "MySQL Protocol",
802 "Packet Length: 116",
804 "Request Command Query",
810 "showname": "MySQL Protocol - column count",
814 "Number of fields: 4",
818 "showname": "MySQL Protocol - field packet",
822 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
824 "Type: FIELD_TYPE_VAR_STRING (253)",
830 "showname": "MySQL Protocol - field packet",
834 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
836 "Type: FIELD_TYPE_VAR_STRING (253)",
842 "showname": "MySQL Protocol - field packet",
846 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
848 "Type: FIELD_TYPE_VAR_STRING (253)",
854 "showname": "MySQL Protocol - field packet",
858 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
860 "Type: FIELD_TYPE_VAR_STRING (253)",
866 "showname": "MySQL Protocol - row packet",
867 "fields": ["Packet Length: 28", "Packet Number: 6"],
870 "showname": "MySQL Protocol - response OK",
874 "Response Code: EOF Packet (0xfe)",
877 "Server Status: 0x0002",
884 "showname": "MySQL Protocol",
888 "Request Command Statistics",
894 "showname": "MySQL Protocol",
896 "Packet Length: 132",
898 "Message: Uptime: 126 Threads: 1 Questions: 18 Slow queries: 0 Opens: 105 Flush tables: 1 Open tables: 98 Queries per second avg: 0.142",
904 "showname": "MySQL Protocol",
908 "Request Command Quit",
914 # Summary should look like this:
916 # <int:Packet Number>: {
917 # <int:MySQL Packet Number>: {
919 # "fields": [str, ...]
925 tree
= ET
.fromstring(stdout
)
927 # There should not be any expert info as that indicates the dissector is incomplete
928 for expertinfo
in tree
.findall(
929 "./proto[@name='mysql']//field[@name='_ws.expert']"
931 print(ET
.tostring(expertinfo
, "unicode"))
936 # Get the packet number
938 pkt
.find("./proto[@name='geninfo']/field[@name='num']").attrib
["show"]
942 for proto
in pkt
.findall("./proto[@name='mysql']"):
945 proto
.find("./field[@name='mysql.packet_number']").attrib
["show"]
947 summary
[num
][mysqlnum
] = {
948 "showname": proto
.attrib
["showname"],
951 for field
in proto
.findall("./field"):
952 if "showname" in field
.attrib
:
953 summary
[num
][mysqlnum
]["fields"].append(
954 field
.attrib
["showname"]
960 for mysqlpkt
in summary
[pkt
]:
962 summary
[pkt
][mysqlpkt
]["showname"]
963 == expected
[pkt
][mysqlpkt
]["showname"]
966 summary
[pkt
][mysqlpkt
]["fields"]
967 == expected
[pkt
][mysqlpkt
]["fields"]
970 def test_mysql_80(self
, cmd_tshark
, capture_file
, test_env
):
973 stdout
= subprocess
.check_output(
977 capture_file("mysql/mysql80.pcapng.gz"),
989 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
993 "showname": "MySQL Protocol",
1003 "showname": "MySQL Protocol",
1005 "Packet Length: 182",
1013 "showname": "MySQL Protocol - response OK",
1017 "Response Code: OK Packet (0x00)",
1019 "Server Status: 0x0002",
1026 "showname": "MySQL Protocol",
1028 "Packet Length: 35",
1030 "Request Command Query",
1036 "showname": "MySQL Protocol - column count",
1040 "Number of fields: 1",
1044 "showname": "MySQL Protocol - field packet",
1046 "Packet Length: 39",
1048 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1050 "Type: FIELD_TYPE_VAR_STRING (253)",
1056 "showname": "MySQL Protocol - row packet",
1057 "fields": ["Packet Length: 29", "Packet Number: 3"],
1060 "showname": "MySQL Protocol - response OK",
1064 "Response Code: EOF Packet (0xfe)",
1067 "Server Status: 0x0002",
1074 "showname": "MySQL Protocol",
1076 "Packet Length: 12",
1078 "Request Command Query",
1084 "showname": "MySQL Protocol - response ERROR",
1086 "Packet Length: 44",
1088 "Response Code: ERR Packet (0xff)",
1091 "Error message: Unknown column '$$' in 'field list'",
1097 "showname": "MySQL Protocol",
1099 "Packet Length: 36",
1101 "Request Command Query",
1107 "showname": "MySQL Protocol - column count",
1111 "Number of fields: 2",
1115 "showname": "MySQL Protocol - field packet",
1117 "Packet Length: 32",
1119 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1121 "Type: FIELD_TYPE_VAR_STRING (253)",
1127 "showname": "MySQL Protocol - field packet",
1129 "Packet Length: 28",
1131 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1133 "Type: FIELD_TYPE_VAR_STRING (253)",
1139 "showname": "MySQL Protocol - row packet",
1140 "fields": ["Packet Length: 16", "Packet Number: 4"],
1143 "showname": "MySQL Protocol - response OK",
1147 "Response Code: EOF Packet (0xfe)",
1150 "Server Status: 0x0002",
1157 "showname": "MySQL Protocol",
1159 "Packet Length: 118",
1161 "Request Command Query",
1167 "showname": "MySQL Protocol - column count",
1171 "Number of fields: 4",
1175 "showname": "MySQL Protocol - field packet",
1177 "Packet Length: 44",
1179 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1181 "Type: FIELD_TYPE_VAR_STRING (253)",
1187 "showname": "MySQL Protocol - field packet",
1189 "Packet Length: 48",
1191 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1193 "Type: FIELD_TYPE_VAR_STRING (253)",
1199 "showname": "MySQL Protocol - field packet",
1201 "Packet Length: 44",
1203 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1205 "Type: FIELD_TYPE_VAR_STRING (253)",
1211 "showname": "MySQL Protocol - field packet",
1213 "Packet Length: 46",
1215 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1217 "Type: FIELD_TYPE_VAR_STRING (253)",
1223 "showname": "MySQL Protocol - row packet",
1224 "fields": ["Packet Length: 32", "Packet Number: 6"],
1227 "showname": "MySQL Protocol - response OK",
1231 "Response Code: EOF Packet (0xfe)",
1234 "Server Status: 0x0002",
1241 "showname": "MySQL Protocol",
1245 "Request Command Statistics",
1251 "showname": "MySQL Protocol",
1253 "Packet Length: 130",
1255 "Message: Uptime: 30 Threads: 2 Questions: 6 Slow queries: 0 Opens: 119 Flush tables: 3 Open tables: 38 Queries per second avg: 0.200",
1261 "showname": "MySQL Protocol",
1265 "Request Command Quit",
1271 # Summary should look like this:
1273 # <int:Packet Number>: {
1274 # <int:MySQL Packet Number>: {
1275 # "showname": <str>,
1276 # "fields": [str, ...]
1282 tree
= ET
.fromstring(stdout
)
1284 # There should not be any expert info as that indicates the dissector is incomplete
1285 for expertinfo
in tree
.findall(
1286 "./proto[@name='mysql']//field[@name='_ws.expert']"
1288 print(ET
.tostring(expertinfo
, "unicode"))
1293 # Get the packet number
1295 pkt
.find("./proto[@name='geninfo']/field[@name='num']").attrib
["show"]
1299 for proto
in pkt
.findall("./proto[@name='mysql']"):
1302 proto
.find("./field[@name='mysql.packet_number']").attrib
["show"]
1304 summary
[num
][mysqlnum
] = {
1305 "showname": proto
.attrib
["showname"],
1308 for field
in proto
.findall("./field"):
1309 if "showname" in field
.attrib
:
1310 summary
[num
][mysqlnum
]["fields"].append(
1311 field
.attrib
["showname"]
1317 for mysqlpkt
in summary
[pkt
]:
1319 summary
[pkt
][mysqlpkt
]["showname"]
1320 == expected
[pkt
][mysqlpkt
]["showname"]
1323 summary
[pkt
][mysqlpkt
]["fields"]
1324 == expected
[pkt
][mysqlpkt
]["fields"]
1327 def test_mariadb_114(self
, cmd_tshark
, capture_file
, test_env
):
1330 stdout
= subprocess
.check_output(
1334 capture_file("mysql/mariadb114.pcapng.gz"),
1346 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
1350 "showname": "MySQL Protocol",
1352 "Packet Length: 90",
1360 "showname": "MySQL Protocol",
1362 "Packet Length: 181",
1370 "showname": "MySQL Protocol - response OK",
1374 "Response Code: OK Packet (0x00)",
1376 "Server Status: 0x0002",
1383 "showname": "MySQL Protocol",
1385 "Packet Length: 33",
1387 "Request Command Query",
1393 "showname": "MySQL Protocol - column count",
1397 "Number of fields: 1",
1401 "showname": "MySQL Protocol - field packet",
1403 "Packet Length: 39",
1405 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1407 "Type: FIELD_TYPE_VAR_STRING (253)",
1413 "showname": "MySQL Protocol - row packet",
1414 "fields": ["Packet Length: 32", "Packet Number: 3"],
1417 "showname": "MySQL Protocol - response OK",
1421 "Response Code: EOF Packet (0xfe)",
1424 "Server Status: 0x0002",
1431 "showname": "MySQL Protocol",
1433 "Packet Length: 10",
1435 "Request Command Query",
1441 "showname": "MySQL Protocol - response ERROR",
1443 "Packet Length: 44",
1445 "Response Code: ERR Packet (0xff)",
1448 "Error message: Unknown column '$$' in 'field list'",
1454 "showname": "MySQL Protocol",
1456 "Packet Length: 34",
1458 "Request Command Query",
1464 "showname": "MySQL Protocol - column count",
1468 "Number of fields: 2",
1472 "showname": "MySQL Protocol - field packet",
1474 "Packet Length: 32",
1476 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1478 "Type: FIELD_TYPE_VAR_STRING (253)",
1484 "showname": "MySQL Protocol - field packet",
1486 "Packet Length: 28",
1488 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1490 "Type: FIELD_TYPE_VAR_STRING (253)",
1496 "showname": "MySQL Protocol - row packet",
1497 "fields": ["Packet Length: 16", "Packet Number: 4"],
1500 "showname": "MySQL Protocol - response OK",
1504 "Response Code: EOF Packet (0xfe)",
1507 "Server Status: 0x0002",
1514 "showname": "MySQL Protocol",
1516 "Packet Length: 116",
1518 "Request Command Query",
1524 "showname": "MySQL Protocol - column count",
1528 "Number of fields: 4",
1532 "showname": "MySQL Protocol - field packet",
1534 "Packet Length: 44",
1536 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1538 "Type: FIELD_TYPE_VAR_STRING (253)",
1544 "showname": "MySQL Protocol - field packet",
1546 "Packet Length: 48",
1548 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1550 "Type: FIELD_TYPE_VAR_STRING (253)",
1556 "showname": "MySQL Protocol - field packet",
1558 "Packet Length: 44",
1560 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1562 "Type: FIELD_TYPE_VAR_STRING (253)",
1568 "showname": "MySQL Protocol - field packet",
1570 "Packet Length: 46",
1572 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1574 "Type: FIELD_TYPE_VAR_STRING (253)",
1580 "showname": "MySQL Protocol - row packet",
1581 "fields": ["Packet Length: 32", "Packet Number: 6"],
1584 "showname": "MySQL Protocol - response OK",
1588 "Response Code: EOF Packet (0xfe)",
1591 "Server Status: 0x0002",
1598 "showname": "MySQL Protocol",
1602 "Request Command Statistics",
1608 "showname": "MySQL Protocol",
1610 "Packet Length: 112",
1612 "Message: Uptime: 25 Threads: 1 Questions: 5 Slow queries: 0 Opens: 17 Open tables: 10 Queries per second avg: 0.200",
1618 "showname": "MySQL Protocol",
1622 "Request Command Quit",
1628 # Summary should look like this:
1630 # <int:Packet Number>: {
1631 # <int:MySQL Packet Number>: {
1632 # "showname": <str>,
1633 # "fields": [str, ...]
1639 tree
= ET
.fromstring(stdout
)
1641 # There should not be any expert info as that indicates the dissector is incomplete
1642 for expertinfo
in tree
.findall(
1643 "./proto[@name='mysql']//field[@name='_ws.expert']"
1645 print(ET
.tostring(expertinfo
, "unicode"))
1650 # Get the packet number
1652 pkt
.find("./proto[@name='geninfo']/field[@name='num']").attrib
["show"]
1656 for proto
in pkt
.findall("./proto[@name='mysql']"):
1659 proto
.find("./field[@name='mysql.packet_number']").attrib
["show"]
1661 summary
[num
][mysqlnum
] = {
1662 "showname": proto
.attrib
["showname"],
1665 for field
in proto
.findall("./field"):
1666 if "showname" in field
.attrib
:
1667 summary
[num
][mysqlnum
]["fields"].append(
1668 field
.attrib
["showname"]
1674 for mysqlpkt
in summary
[pkt
]:
1676 summary
[pkt
][mysqlpkt
]["showname"]
1677 == expected
[pkt
][mysqlpkt
]["showname"]
1680 summary
[pkt
][mysqlpkt
]["fields"]
1681 == expected
[pkt
][mysqlpkt
]["fields"]
1684 def test_tidb_81(self
, cmd_tshark
, capture_file
, test_env
):
1687 stdout
= subprocess
.check_output(
1691 capture_file("mysql/tidb81.pcapng.gz"),
1703 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
1707 "showname": "MySQL Protocol",
1709 "Packet Length: 86",
1717 "showname": "MySQL Protocol",
1719 "Packet Length: 181",
1727 "showname": "MySQL Protocol - response OK",
1731 "Response Code: OK Packet (0x00)",
1733 "Server Status: 0x0002",
1740 "showname": "MySQL Protocol",
1742 "Packet Length: 33",
1744 "Request Command Query",
1750 "showname": "MySQL Protocol - column count",
1754 "Number of fields: 1",
1758 "showname": "MySQL Protocol - field packet",
1760 "Packet Length: 39",
1762 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1764 "Type: FIELD_TYPE_VAR_STRING (253)",
1770 "showname": "MySQL Protocol - row packet",
1771 "fields": ["Packet Length: 73", "Packet Number: 3"],
1774 "showname": "MySQL Protocol - response OK",
1778 "Response Code: EOF Packet (0xfe)",
1781 "Server Status: 0x0002",
1788 "showname": "MySQL Protocol",
1790 "Packet Length: 10",
1792 "Request Command Query",
1798 "showname": "MySQL Protocol - response ERROR",
1800 "Packet Length: 44",
1802 "Response Code: ERR Packet (0xff)",
1805 "Error message: Unknown column '$$' in 'field list'",
1811 "showname": "MySQL Protocol",
1813 "Packet Length: 34",
1815 "Request Command Query",
1821 "showname": "MySQL Protocol - column count",
1825 "Number of fields: 2",
1829 "showname": "MySQL Protocol - field packet",
1831 "Packet Length: 32",
1833 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1835 "Type: FIELD_TYPE_VAR_STRING (253)",
1841 "showname": "MySQL Protocol - field packet",
1843 "Packet Length: 28",
1845 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1847 "Type: FIELD_TYPE_VAR_STRING (253)",
1853 "showname": "MySQL Protocol - row packet",
1854 "fields": ["Packet Length: 16", "Packet Number: 4"],
1857 "showname": "MySQL Protocol - response OK",
1861 "Response Code: EOF Packet (0xfe)",
1864 "Server Status: 0x0002",
1871 "showname": "MySQL Protocol",
1873 "Packet Length: 116",
1875 "Request Command Query",
1881 "showname": "MySQL Protocol - column count",
1885 "Number of fields: 4",
1889 "showname": "MySQL Protocol - field packet",
1891 "Packet Length: 44",
1893 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1895 "Type: FIELD_TYPE_VAR_STRING (253)",
1901 "showname": "MySQL Protocol - field packet",
1903 "Packet Length: 48",
1905 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1907 "Type: FIELD_TYPE_VAR_STRING (253)",
1913 "showname": "MySQL Protocol - field packet",
1915 "Packet Length: 44",
1917 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1919 "Type: FIELD_TYPE_VAR_STRING (253)",
1925 "showname": "MySQL Protocol - field packet",
1927 "Packet Length: 46",
1929 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1931 "Type: FIELD_TYPE_VAR_STRING (253)",
1937 "showname": "MySQL Protocol - row packet",
1938 "fields": ["Packet Length: 32", "Packet Number: 6"],
1941 "showname": "MySQL Protocol - response OK",
1945 "Response Code: EOF Packet (0xfe)",
1948 "Server Status: 0x0002",
1955 "showname": "MySQL Protocol",
1959 "Request Command Statistics",
1965 "showname": "MySQL Protocol",
1967 "Packet Length: 127",
1969 "Message: Uptime: 19 Threads: 0 Questions: 0 Slow queries: 0 Opens: 0 Flush tables: 0 Open tables: 0 Queries per second avg: 0.000",
1975 "showname": "MySQL Protocol",
1979 "Request Command Quit",
1985 # Summary should look like this:
1987 # <int:Packet Number>: {
1988 # <int:MySQL Packet Number>: {
1989 # "showname": <str>,
1990 # "fields": [str, ...]
1996 tree
= ET
.fromstring(stdout
)
1998 # There should not be any expert info as that indicates the dissector is incomplete
1999 for expertinfo
in tree
.findall(
2000 "./proto[@name='mysql']//field[@name='_ws.expert']"
2002 print(ET
.tostring(expertinfo
, "unicode"))
2007 # Get the packet number
2009 pkt
.find("./proto[@name='geninfo']/field[@name='num']").attrib
["show"]
2013 for proto
in pkt
.findall("./proto[@name='mysql']"):
2016 proto
.find("./field[@name='mysql.packet_number']").attrib
["show"]
2018 summary
[num
][mysqlnum
] = {
2019 "showname": proto
.attrib
["showname"],
2022 for field
in proto
.findall("./field"):
2023 if "showname" in field
.attrib
:
2024 summary
[num
][mysqlnum
]["fields"].append(
2025 field
.attrib
["showname"]
2031 for mysqlpkt
in summary
[pkt
]:
2033 summary
[pkt
][mysqlpkt
]["showname"]
2034 == expected
[pkt
][mysqlpkt
]["showname"]
2037 summary
[pkt
][mysqlpkt
]["fields"]
2038 == expected
[pkt
][mysqlpkt
]["fields"]