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)",
144 "Server Status: 0x4002",
146 "Session tracking data",
152 "showname": "MySQL Protocol",
156 "Request Command Query",
162 "showname": "MySQL Protocol - response OK",
164 "Packet Length: 107",
166 "Response Code: OK Packet (0x00)",
169 "Server Status: 0x4002",
171 "Session tracking data",
177 "showname": "MySQL Protocol",
181 "Request Command Query",
187 "showname": "MySQL Protocol - response OK",
189 "Packet Length: 107",
191 "Response Code: OK Packet (0x00)",
194 "Server Status: 0x4002",
196 "Session tracking data",
202 "showname": "MySQL Protocol",
206 "Request Command Query",
212 "showname": "MySQL Protocol - response OK",
216 "Response Code: OK Packet (0x00)",
219 "Server Status: 0x4000",
221 "Session tracking data",
227 "showname": "MySQL Protocol",
231 "Request Command Ping",
237 "showname": "MySQL Protocol - response OK",
241 "Response Code: OK Packet (0x00)",
244 "Server Status: 0x0000",
251 "showname": "MySQL Protocol",
255 "Request Command Prepare Statement",
261 "showname": "MySQL Protocol - response to PREPARE",
265 "Response Code: OK Packet (0x00)",
267 "Number of fields: 7",
268 "Number of parameter: 1",
273 "showname": "MySQL Protocol - parameters in response to PREPARE",
277 "Charset number: binary COLLATE binary (63)",
279 "Type: FIELD_TYPE_LONGLONG (8)",
285 "showname": "MySQL Protocol - fields in response to PREPARE",
289 "Charset number: binary COLLATE binary (63)",
291 "Type: FIELD_TYPE_LONG (3)",
297 "showname": "MySQL Protocol - fields in response to PREPARE",
301 "Charset number: binary COLLATE binary (63)",
303 "Type: FIELD_TYPE_DATETIME (12)",
309 "showname": "MySQL Protocol - fields in response to PREPARE",
313 "Charset number: binary COLLATE binary (63)",
315 "Type: FIELD_TYPE_DATETIME (12)",
321 "showname": "MySQL Protocol - fields in response to PREPARE",
325 "Charset number: binary COLLATE binary (63)",
327 "Type: FIELD_TYPE_TIMESTAMP (7)",
333 "showname": "MySQL Protocol - fields in response to PREPARE",
337 "Charset number: binary COLLATE binary (63)",
339 "Type: FIELD_TYPE_TIMESTAMP (7)",
345 "showname": "MySQL Protocol - fields in response to PREPARE",
349 "Charset number: binary COLLATE binary (63)",
351 "Type: FIELD_TYPE_BIT (16)",
357 "showname": "MySQL Protocol - fields in response to PREPARE",
361 "Charset number: binary COLLATE binary (63)",
363 "Type: FIELD_TYPE_VAR_STRING (253)",
371 "showname": "MySQL Protocol",
375 "Request Command Reset Statement",
381 "showname": "MySQL Protocol - response OK",
385 "Response Code: OK Packet (0x00)",
388 "Server Status: 0x0000",
395 "showname": "MySQL Protocol",
399 "Request Command Execute Statement",
405 "showname": "MySQL Protocol - column count",
409 "Number of fields: 7",
413 "showname": "MySQL Protocol - field packet",
417 "Charset number: binary COLLATE binary (63)",
419 "Type: FIELD_TYPE_LONG (3)",
425 "showname": "MySQL Protocol - field packet",
429 "Charset number: binary COLLATE binary (63)",
431 "Type: FIELD_TYPE_DATETIME (12)",
437 "showname": "MySQL Protocol - field packet",
441 "Charset number: binary COLLATE binary (63)",
443 "Type: FIELD_TYPE_DATETIME (12)",
449 "showname": "MySQL Protocol - field packet",
453 "Charset number: binary COLLATE binary (63)",
455 "Type: FIELD_TYPE_TIMESTAMP (7)",
461 "showname": "MySQL Protocol - field packet",
465 "Charset number: binary COLLATE binary (63)",
467 "Type: FIELD_TYPE_TIMESTAMP (7)",
473 "showname": "MySQL Protocol - field packet",
477 "Charset number: binary COLLATE binary (63)",
479 "Type: FIELD_TYPE_BIT (16)",
485 "showname": "MySQL Protocol - field packet",
489 "Charset number: binary COLLATE binary (63)",
491 "Type: FIELD_TYPE_VAR_STRING (253)",
497 "showname": "MySQL Protocol - row packet",
501 "Response Code: OK Packet (0x00)",
502 "Row null buffer: 0000",
506 "showname": "MySQL Protocol - response OK",
510 "Response Code: EOF Packet (0xfe)",
514 "Server Status: 0x0021",
521 "showname": "MySQL Protocol",
525 "Request Command Reset Statement",
531 "showname": "MySQL Protocol - response OK",
535 "Response Code: OK Packet (0x00)",
538 "Server Status: 0x0001",
545 "showname": "MySQL Protocol",
549 "Request Command Close Statement",
555 "showname": "MySQL Protocol",
559 "Request Command Quit",
565 # Summary should look like this:
567 # <int:Packet Number>: {
568 # <int:MySQL Packet Number>: {
570 # "fields": [str, ...]
576 tree
= ET
.fromstring(stdout
)
578 # There should not be any expert info as that indicates the dissector is incomplete
579 for expertinfo
in tree
.findall(
580 "./proto[@name='mysql']//field[@name='_ws.expert']"
582 print(ET
.tostring(expertinfo
, "unicode"))
587 # Get the packet number
589 pkt
.find("./proto[@name='geninfo']/field[@name='num']").attrib
["show"]
593 for proto
in pkt
.findall("./proto[@name='mysql']"):
596 proto
.find("./field[@name='mysql.packet_number']").attrib
["show"]
598 summary
[num
][mysqlnum
] = {
599 "showname": proto
.attrib
["showname"],
602 for field
in proto
.findall("./field"):
603 if "showname" in field
.attrib
:
604 summary
[num
][mysqlnum
]["fields"].append(
605 field
.attrib
["showname"]
611 for mysqlpkt
in summary
[pkt
]:
613 summary
[pkt
][mysqlpkt
]["showname"]
614 == expected
[pkt
][mysqlpkt
]["showname"]
617 summary
[pkt
][mysqlpkt
]["fields"]
618 == expected
[pkt
][mysqlpkt
]["fields"]
621 def test_mysql_57(self
, cmd_tshark
, capture_file
, test_env
):
624 stdout
= subprocess
.check_output(
628 capture_file("mysql/mysql57.pcapng.gz"),
640 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
644 "showname": "MySQL Protocol",
654 "showname": "MySQL Protocol",
656 "Packet Length: 181",
664 "showname": "MySQL Protocol - response OK",
668 "Response Code: OK Packet (0x00)",
671 "Server Status: 0x0002",
678 "showname": "MySQL Protocol",
682 "Request Command Query",
688 "showname": "MySQL Protocol - column count",
692 "Number of fields: 1",
696 "showname": "MySQL Protocol - field packet",
700 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
702 "Type: FIELD_TYPE_VAR_STRING (253)",
708 "showname": "MySQL Protocol - row packet",
709 "fields": ["Packet Length: 29", "Packet Number: 3"],
712 "showname": "MySQL Protocol - response OK",
716 "Response Code: EOF Packet (0xfe)",
720 "Server Status: 0x0002",
727 "showname": "MySQL Protocol",
731 "Request Command Query",
737 "showname": "MySQL Protocol - response ERROR",
741 "Response Code: ERR Packet (0xff)",
744 "Error message: Unknown column '$$' in 'field list'",
750 "showname": "MySQL Protocol",
754 "Request Command Query",
760 "showname": "MySQL Protocol - column count",
764 "Number of fields: 2",
768 "showname": "MySQL Protocol - field packet",
772 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
774 "Type: FIELD_TYPE_VAR_STRING (253)",
780 "showname": "MySQL Protocol - field packet",
784 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
786 "Type: FIELD_TYPE_VAR_STRING (253)",
792 "showname": "MySQL Protocol - row packet",
793 "fields": ["Packet Length: 16", "Packet Number: 4"],
796 "showname": "MySQL Protocol - response OK",
800 "Response Code: EOF Packet (0xfe)",
804 "Server Status: 0x0002",
811 "showname": "MySQL Protocol",
813 "Packet Length: 116",
815 "Request Command Query",
821 "showname": "MySQL Protocol - column count",
825 "Number of fields: 4",
829 "showname": "MySQL Protocol - field packet",
833 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
835 "Type: FIELD_TYPE_VAR_STRING (253)",
841 "showname": "MySQL Protocol - field packet",
845 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
847 "Type: FIELD_TYPE_VAR_STRING (253)",
853 "showname": "MySQL Protocol - field packet",
857 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
859 "Type: FIELD_TYPE_VAR_STRING (253)",
865 "showname": "MySQL Protocol - field packet",
869 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
871 "Type: FIELD_TYPE_VAR_STRING (253)",
877 "showname": "MySQL Protocol - row packet",
878 "fields": ["Packet Length: 28", "Packet Number: 6"],
881 "showname": "MySQL Protocol - response OK",
885 "Response Code: EOF Packet (0xfe)",
889 "Server Status: 0x0002",
896 "showname": "MySQL Protocol",
900 "Request Command Statistics",
906 "showname": "MySQL Protocol",
908 "Packet Length: 132",
910 "Message: Uptime: 126 Threads: 1 Questions: 18 Slow queries: 0 Opens: 105 Flush tables: 1 Open tables: 98 Queries per second avg: 0.142",
916 "showname": "MySQL Protocol",
920 "Request Command Quit",
926 # Summary should look like this:
928 # <int:Packet Number>: {
929 # <int:MySQL Packet Number>: {
931 # "fields": [str, ...]
937 tree
= ET
.fromstring(stdout
)
939 # There should not be any expert info as that indicates the dissector is incomplete
940 for expertinfo
in tree
.findall(
941 "./proto[@name='mysql']//field[@name='_ws.expert']"
943 print(ET
.tostring(expertinfo
, "unicode"))
948 # Get the packet number
950 pkt
.find("./proto[@name='geninfo']/field[@name='num']").attrib
["show"]
954 for proto
in pkt
.findall("./proto[@name='mysql']"):
957 proto
.find("./field[@name='mysql.packet_number']").attrib
["show"]
959 summary
[num
][mysqlnum
] = {
960 "showname": proto
.attrib
["showname"],
963 for field
in proto
.findall("./field"):
964 if "showname" in field
.attrib
:
965 summary
[num
][mysqlnum
]["fields"].append(
966 field
.attrib
["showname"]
972 for mysqlpkt
in summary
[pkt
]:
974 summary
[pkt
][mysqlpkt
]["showname"]
975 == expected
[pkt
][mysqlpkt
]["showname"]
978 summary
[pkt
][mysqlpkt
]["fields"]
979 == expected
[pkt
][mysqlpkt
]["fields"]
982 def test_mysql_80(self
, cmd_tshark
, capture_file
, test_env
):
985 stdout
= subprocess
.check_output(
989 capture_file("mysql/mysql80.pcapng.gz"),
1001 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
1005 "showname": "MySQL Protocol",
1007 "Packet Length: 74",
1015 "showname": "MySQL Protocol",
1017 "Packet Length: 182",
1025 "showname": "MySQL Protocol - response OK",
1029 "Response Code: OK Packet (0x00)",
1031 "Last INSERT ID: 0",
1032 "Server Status: 0x0002",
1039 "showname": "MySQL Protocol",
1041 "Packet Length: 35",
1043 "Request Command Query",
1049 "showname": "MySQL Protocol - column count",
1053 "Number of fields: 1",
1057 "showname": "MySQL Protocol - field packet",
1059 "Packet Length: 39",
1061 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1063 "Type: FIELD_TYPE_VAR_STRING (253)",
1069 "showname": "MySQL Protocol - row packet",
1070 "fields": ["Packet Length: 29", "Packet Number: 3"],
1073 "showname": "MySQL Protocol - response OK",
1077 "Response Code: EOF Packet (0xfe)",
1080 "Last INSERT ID: 0",
1081 "Server Status: 0x0002",
1088 "showname": "MySQL Protocol",
1090 "Packet Length: 12",
1092 "Request Command Query",
1098 "showname": "MySQL Protocol - response ERROR",
1100 "Packet Length: 44",
1102 "Response Code: ERR Packet (0xff)",
1105 "Error message: Unknown column '$$' in 'field list'",
1111 "showname": "MySQL Protocol",
1113 "Packet Length: 36",
1115 "Request Command Query",
1121 "showname": "MySQL Protocol - column count",
1125 "Number of fields: 2",
1129 "showname": "MySQL Protocol - field packet",
1131 "Packet Length: 32",
1133 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1135 "Type: FIELD_TYPE_VAR_STRING (253)",
1141 "showname": "MySQL Protocol - field packet",
1143 "Packet Length: 28",
1145 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1147 "Type: FIELD_TYPE_VAR_STRING (253)",
1153 "showname": "MySQL Protocol - row packet",
1154 "fields": ["Packet Length: 16", "Packet Number: 4"],
1157 "showname": "MySQL Protocol - response OK",
1161 "Response Code: EOF Packet (0xfe)",
1164 "Last INSERT ID: 0",
1165 "Server Status: 0x0002",
1172 "showname": "MySQL Protocol",
1174 "Packet Length: 118",
1176 "Request Command Query",
1182 "showname": "MySQL Protocol - column count",
1186 "Number of fields: 4",
1190 "showname": "MySQL Protocol - field packet",
1192 "Packet Length: 44",
1194 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1196 "Type: FIELD_TYPE_VAR_STRING (253)",
1202 "showname": "MySQL Protocol - field packet",
1204 "Packet Length: 48",
1206 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1208 "Type: FIELD_TYPE_VAR_STRING (253)",
1214 "showname": "MySQL Protocol - field packet",
1216 "Packet Length: 44",
1218 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1220 "Type: FIELD_TYPE_VAR_STRING (253)",
1226 "showname": "MySQL Protocol - field packet",
1228 "Packet Length: 46",
1230 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1232 "Type: FIELD_TYPE_VAR_STRING (253)",
1238 "showname": "MySQL Protocol - row packet",
1239 "fields": ["Packet Length: 32", "Packet Number: 6"],
1242 "showname": "MySQL Protocol - response OK",
1246 "Response Code: EOF Packet (0xfe)",
1249 "Last INSERT ID: 0",
1250 "Server Status: 0x0002",
1257 "showname": "MySQL Protocol",
1261 "Request Command Statistics",
1267 "showname": "MySQL Protocol",
1269 "Packet Length: 130",
1271 "Message: Uptime: 30 Threads: 2 Questions: 6 Slow queries: 0 Opens: 119 Flush tables: 3 Open tables: 38 Queries per second avg: 0.200",
1277 "showname": "MySQL Protocol",
1281 "Request Command Quit",
1287 # Summary should look like this:
1289 # <int:Packet Number>: {
1290 # <int:MySQL Packet Number>: {
1291 # "showname": <str>,
1292 # "fields": [str, ...]
1298 tree
= ET
.fromstring(stdout
)
1300 # There should not be any expert info as that indicates the dissector is incomplete
1301 for expertinfo
in tree
.findall(
1302 "./proto[@name='mysql']//field[@name='_ws.expert']"
1304 print(ET
.tostring(expertinfo
, "unicode"))
1309 # Get the packet number
1311 pkt
.find("./proto[@name='geninfo']/field[@name='num']").attrib
["show"]
1315 for proto
in pkt
.findall("./proto[@name='mysql']"):
1318 proto
.find("./field[@name='mysql.packet_number']").attrib
["show"]
1320 summary
[num
][mysqlnum
] = {
1321 "showname": proto
.attrib
["showname"],
1324 for field
in proto
.findall("./field"):
1325 if "showname" in field
.attrib
:
1326 summary
[num
][mysqlnum
]["fields"].append(
1327 field
.attrib
["showname"]
1333 for mysqlpkt
in summary
[pkt
]:
1335 summary
[pkt
][mysqlpkt
]["showname"]
1336 == expected
[pkt
][mysqlpkt
]["showname"]
1339 summary
[pkt
][mysqlpkt
]["fields"]
1340 == expected
[pkt
][mysqlpkt
]["fields"]
1343 def test_mariadb_114(self
, cmd_tshark
, capture_file
, test_env
):
1346 stdout
= subprocess
.check_output(
1350 capture_file("mysql/mariadb114.pcapng.gz"),
1362 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
1366 "showname": "MySQL Protocol",
1368 "Packet Length: 90",
1376 "showname": "MySQL Protocol",
1378 "Packet Length: 181",
1386 "showname": "MySQL Protocol - response OK",
1390 "Response Code: OK Packet (0x00)",
1392 "Last INSERT ID: 0",
1393 "Server Status: 0x0002",
1400 "showname": "MySQL Protocol",
1402 "Packet Length: 33",
1404 "Request Command Query",
1410 "showname": "MySQL Protocol - column count",
1414 "Number of fields: 1",
1418 "showname": "MySQL Protocol - field packet",
1420 "Packet Length: 39",
1422 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1424 "Type: FIELD_TYPE_VAR_STRING (253)",
1430 "showname": "MySQL Protocol - row packet",
1431 "fields": ["Packet Length: 32", "Packet Number: 3"],
1434 "showname": "MySQL Protocol - response OK",
1438 "Response Code: EOF Packet (0xfe)",
1441 "Last INSERT ID: 0",
1442 "Server Status: 0x0002",
1449 "showname": "MySQL Protocol",
1451 "Packet Length: 10",
1453 "Request Command Query",
1459 "showname": "MySQL Protocol - response ERROR",
1461 "Packet Length: 44",
1463 "Response Code: ERR Packet (0xff)",
1466 "Error message: Unknown column '$$' in 'field list'",
1472 "showname": "MySQL Protocol",
1474 "Packet Length: 34",
1476 "Request Command Query",
1482 "showname": "MySQL Protocol - column count",
1486 "Number of fields: 2",
1490 "showname": "MySQL Protocol - field packet",
1492 "Packet Length: 32",
1494 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1496 "Type: FIELD_TYPE_VAR_STRING (253)",
1502 "showname": "MySQL Protocol - field packet",
1504 "Packet Length: 28",
1506 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1508 "Type: FIELD_TYPE_VAR_STRING (253)",
1514 "showname": "MySQL Protocol - row packet",
1515 "fields": ["Packet Length: 16", "Packet Number: 4"],
1518 "showname": "MySQL Protocol - response OK",
1522 "Response Code: EOF Packet (0xfe)",
1525 "Last INSERT ID: 0",
1526 "Server Status: 0x0002",
1533 "showname": "MySQL Protocol",
1535 "Packet Length: 116",
1537 "Request Command Query",
1543 "showname": "MySQL Protocol - column count",
1547 "Number of fields: 4",
1551 "showname": "MySQL Protocol - field packet",
1553 "Packet Length: 44",
1555 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1557 "Type: FIELD_TYPE_VAR_STRING (253)",
1563 "showname": "MySQL Protocol - field packet",
1565 "Packet Length: 48",
1567 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1569 "Type: FIELD_TYPE_VAR_STRING (253)",
1575 "showname": "MySQL Protocol - field packet",
1577 "Packet Length: 44",
1579 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1581 "Type: FIELD_TYPE_VAR_STRING (253)",
1587 "showname": "MySQL Protocol - field packet",
1589 "Packet Length: 46",
1591 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1593 "Type: FIELD_TYPE_VAR_STRING (253)",
1599 "showname": "MySQL Protocol - row packet",
1600 "fields": ["Packet Length: 32", "Packet Number: 6"],
1603 "showname": "MySQL Protocol - response OK",
1607 "Response Code: EOF Packet (0xfe)",
1610 "Last INSERT ID: 0",
1611 "Server Status: 0x0002",
1618 "showname": "MySQL Protocol",
1622 "Request Command Statistics",
1628 "showname": "MySQL Protocol",
1630 "Packet Length: 112",
1632 "Message: Uptime: 25 Threads: 1 Questions: 5 Slow queries: 0 Opens: 17 Open tables: 10 Queries per second avg: 0.200",
1638 "showname": "MySQL Protocol",
1642 "Request Command Quit",
1648 # Summary should look like this:
1650 # <int:Packet Number>: {
1651 # <int:MySQL Packet Number>: {
1652 # "showname": <str>,
1653 # "fields": [str, ...]
1659 tree
= ET
.fromstring(stdout
)
1661 # There should not be any expert info as that indicates the dissector is incomplete
1662 for expertinfo
in tree
.findall(
1663 "./proto[@name='mysql']//field[@name='_ws.expert']"
1665 print(ET
.tostring(expertinfo
, "unicode"))
1670 # Get the packet number
1672 pkt
.find("./proto[@name='geninfo']/field[@name='num']").attrib
["show"]
1676 for proto
in pkt
.findall("./proto[@name='mysql']"):
1679 proto
.find("./field[@name='mysql.packet_number']").attrib
["show"]
1681 summary
[num
][mysqlnum
] = {
1682 "showname": proto
.attrib
["showname"],
1685 for field
in proto
.findall("./field"):
1686 if "showname" in field
.attrib
:
1687 summary
[num
][mysqlnum
]["fields"].append(
1688 field
.attrib
["showname"]
1694 for mysqlpkt
in summary
[pkt
]:
1696 summary
[pkt
][mysqlpkt
]["showname"]
1697 == expected
[pkt
][mysqlpkt
]["showname"]
1700 summary
[pkt
][mysqlpkt
]["fields"]
1701 == expected
[pkt
][mysqlpkt
]["fields"]
1704 def test_tidb_81(self
, cmd_tshark
, capture_file
, test_env
):
1707 stdout
= subprocess
.check_output(
1711 capture_file("mysql/tidb81.pcapng.gz"),
1723 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
1727 "showname": "MySQL Protocol",
1729 "Packet Length: 86",
1737 "showname": "MySQL Protocol",
1739 "Packet Length: 181",
1747 "showname": "MySQL Protocol - response OK",
1751 "Response Code: OK Packet (0x00)",
1753 "Last INSERT ID: 0",
1754 "Server Status: 0x0002",
1761 "showname": "MySQL Protocol",
1763 "Packet Length: 33",
1765 "Request Command Query",
1771 "showname": "MySQL Protocol - column count",
1775 "Number of fields: 1",
1779 "showname": "MySQL Protocol - field packet",
1781 "Packet Length: 39",
1783 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1785 "Type: FIELD_TYPE_VAR_STRING (253)",
1791 "showname": "MySQL Protocol - row packet",
1792 "fields": ["Packet Length: 73", "Packet Number: 3"],
1795 "showname": "MySQL Protocol - response OK",
1799 "Response Code: EOF Packet (0xfe)",
1802 "Last INSERT ID: 0",
1803 "Server Status: 0x0002",
1810 "showname": "MySQL Protocol",
1812 "Packet Length: 10",
1814 "Request Command Query",
1820 "showname": "MySQL Protocol - response ERROR",
1822 "Packet Length: 44",
1824 "Response Code: ERR Packet (0xff)",
1827 "Error message: Unknown column '$$' in 'field list'",
1833 "showname": "MySQL Protocol",
1835 "Packet Length: 34",
1837 "Request Command Query",
1843 "showname": "MySQL Protocol - column count",
1847 "Number of fields: 2",
1851 "showname": "MySQL Protocol - field packet",
1853 "Packet Length: 32",
1855 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1857 "Type: FIELD_TYPE_VAR_STRING (253)",
1863 "showname": "MySQL Protocol - field packet",
1865 "Packet Length: 28",
1867 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1869 "Type: FIELD_TYPE_VAR_STRING (253)",
1875 "showname": "MySQL Protocol - row packet",
1876 "fields": ["Packet Length: 16", "Packet Number: 4"],
1879 "showname": "MySQL Protocol - response OK",
1883 "Response Code: EOF Packet (0xfe)",
1886 "Last INSERT ID: 0",
1887 "Server Status: 0x0002",
1894 "showname": "MySQL Protocol",
1896 "Packet Length: 116",
1898 "Request Command Query",
1904 "showname": "MySQL Protocol - column count",
1908 "Number of fields: 4",
1912 "showname": "MySQL Protocol - field packet",
1914 "Packet Length: 44",
1916 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1918 "Type: FIELD_TYPE_VAR_STRING (253)",
1924 "showname": "MySQL Protocol - field packet",
1926 "Packet Length: 48",
1928 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1930 "Type: FIELD_TYPE_VAR_STRING (253)",
1936 "showname": "MySQL Protocol - field packet",
1938 "Packet Length: 44",
1940 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1942 "Type: FIELD_TYPE_VAR_STRING (253)",
1948 "showname": "MySQL Protocol - field packet",
1950 "Packet Length: 46",
1952 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1954 "Type: FIELD_TYPE_VAR_STRING (253)",
1960 "showname": "MySQL Protocol - row packet",
1961 "fields": ["Packet Length: 32", "Packet Number: 6"],
1964 "showname": "MySQL Protocol - response OK",
1968 "Response Code: EOF Packet (0xfe)",
1971 "Last INSERT ID: 0",
1972 "Server Status: 0x0002",
1979 "showname": "MySQL Protocol",
1983 "Request Command Statistics",
1989 "showname": "MySQL Protocol",
1991 "Packet Length: 127",
1993 "Message: Uptime: 19 Threads: 0 Questions: 0 Slow queries: 0 Opens: 0 Flush tables: 0 Open tables: 0 Queries per second avg: 0.000",
1999 "showname": "MySQL Protocol",
2003 "Request Command Quit",
2009 # Summary should look like this:
2011 # <int:Packet Number>: {
2012 # <int:MySQL Packet Number>: {
2013 # "showname": <str>,
2014 # "fields": [str, ...]
2020 tree
= ET
.fromstring(stdout
)
2022 # There should not be any expert info as that indicates the dissector is incomplete
2023 for expertinfo
in tree
.findall(
2024 "./proto[@name='mysql']//field[@name='_ws.expert']"
2026 print(ET
.tostring(expertinfo
, "unicode"))
2031 # Get the packet number
2033 pkt
.find("./proto[@name='geninfo']/field[@name='num']").attrib
["show"]
2037 for proto
in pkt
.findall("./proto[@name='mysql']"):
2040 proto
.find("./field[@name='mysql.packet_number']").attrib
["show"]
2042 summary
[num
][mysqlnum
] = {
2043 "showname": proto
.attrib
["showname"],
2046 for field
in proto
.findall("./field"):
2047 if "showname" in field
.attrib
:
2048 summary
[num
][mysqlnum
]["fields"].append(
2049 field
.attrib
["showname"]
2055 for mysqlpkt
in summary
[pkt
]:
2057 summary
[pkt
][mysqlpkt
]["showname"]
2058 == expected
[pkt
][mysqlpkt
]["showname"]
2061 summary
[pkt
][mysqlpkt
]["fields"]
2062 == expected
[pkt
][mysqlpkt
]["fields"]