TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / test / suite_dissectors / group_mysql.py
blob3aedf7b349a73d422e9df36dc1b557b104988c24
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
8 """MySQL tests"""
10 import subprocess
11 import xml.etree.ElementTree as ET
14 class TestMySQL:
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
20 # Packet Length: 31
21 # Packet Number: 4
22 # Response Code: OK Packet (0x00)
23 # Row null buffer: 00
24 # Binary Field
25 # Length (JSON): 9
26 # JavaScript Object Notation
27 # Array
28 # [Path with value: /[]:1]
29 # [Member with value: []:1]
30 # Number value: 1
31 # [Path with value: /[]:2]
32 # [Member with value: []:2]
33 # Number value: 2
34 # [Path with value: /[]:3]
35 # [Member with value: []:3]
36 # Number value: 3
37 # Binary Field
38 # Length (JSON): 18
39 # JavaScript Object Notation
40 # Object
41 # Member: a
42 # [Path with value: /a:61]
43 # [Member with value: a:61]
44 # Number value: 61
45 # Key: a
46 # [Path: /a]
47 # Member: b
48 # [Path with value: /b:62]
49 # [Member with value: b:62]
50 # Number value: 62
51 # Key: b
52 # [Path: /b]
54 stdout = subprocess.check_output(
56 cmd_tshark,
57 "-r",
58 capture_file("mysql/mysql_84_ps_json.pcapng.gz"),
59 "-T",
60 "pdml",
61 "-J",
62 "mysql",
63 "-Y",
64 "mysql",
66 encoding="utf-8",
67 env=test_env,
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"))
77 assert False
79 for pkt in tree:
81 # Get the packet number
82 num = int(
83 pkt.find("./proto[@name='geninfo']/field[@name='num']").attrib["show"]
86 if num == 22:
87 assert [
88 j.attrib["name"]
89 for j in pkt.findall(
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(
99 cmd_tshark,
100 "-r",
101 capture_file("mysql/mysql_84_qa_multi.pcapng.gz"),
102 "-T",
103 "pdml",
104 "-J",
105 "mysql",
106 "-Y",
107 "mysql",
109 encoding="utf-8",
110 env=test_env,
113 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
114 expected = {
115 4: {
116 0: {
117 "showname": "MySQL Protocol",
118 "fields": [
119 "Packet Length: 73",
120 "Packet Number: 0",
121 "Server Greeting",
125 6: {
126 1: {
127 "showname": "MySQL Protocol",
128 "fields": [
129 "Packet Length: 264",
130 "Packet Number: 1",
131 "Login Request",
135 8: {
136 2: {
137 "showname": "MySQL Protocol - response OK",
138 "fields": [
139 "Packet Length: 16",
140 "Packet Number: 2",
141 "Response Code: OK Packet (0x00)",
142 "Affected Rows: 0",
143 "Server Status: 0x4002",
144 "Warnings: 0",
145 "Session tracking data",
149 9: {
150 0: {
151 "showname": "MySQL Protocol",
152 "fields": [
153 "Packet Length: 51",
154 "Packet Number: 0",
155 "Request Command Query",
159 10: {
160 1: {
161 "showname": "MySQL Protocol - response OK",
162 "fields": [
163 "Packet Length: 107",
164 "Packet Number: 1",
165 "Response Code: OK Packet (0x00)",
166 "Affected Rows: 0",
167 "Server Status: 0x4002",
168 "Warnings: 0",
169 "Session tracking data",
173 11: {
174 0: {
175 "showname": "MySQL Protocol",
176 "fields": [
177 "Packet Length: 20",
178 "Packet Number: 0",
179 "Request Command Query",
183 12: {
184 1: {
185 "showname": "MySQL Protocol - response OK",
186 "fields": [
187 "Packet Length: 107",
188 "Packet Number: 1",
189 "Response Code: OK Packet (0x00)",
190 "Affected Rows: 0",
191 "Server Status: 0x4002",
192 "Warnings: 0",
193 "Session tracking data",
197 13: {
198 0: {
199 "showname": "MySQL Protocol",
200 "fields": [
201 "Packet Length: 19",
202 "Packet Number: 0",
203 "Request Command Query",
207 14: {
208 1: {
209 "showname": "MySQL Protocol - response OK",
210 "fields": [
211 "Packet Length: 26",
212 "Packet Number: 1",
213 "Response Code: OK Packet (0x00)",
214 "Affected Rows: 0",
215 "Server Status: 0x4000",
216 "Warnings: 0",
217 "Session tracking data",
221 15: {
222 0: {
223 "showname": "MySQL Protocol",
224 "fields": [
225 "Packet Length: 1",
226 "Packet Number: 0",
227 "Request Command Ping",
231 16: {
232 1: {
233 "showname": "MySQL Protocol - response OK",
234 "fields": [
235 "Packet Length: 7",
236 "Packet Number: 1",
237 "Response Code: OK Packet (0x00)",
238 "Affected Rows: 0",
239 "Server Status: 0x0000",
240 "Warnings: 0",
244 17: {
245 0: {
246 "showname": "MySQL Protocol",
247 "fields": [
248 "Packet Length: 27",
249 "Packet Number: 0",
250 "Request Command Prepare Statement",
254 18: {
255 1: {
256 "showname": "MySQL Protocol - response to PREPARE",
257 "fields": [
258 "Packet Length: 12",
259 "Packet Number: 1",
260 "Response Code: OK Packet (0x00)",
261 "Statement ID: 1",
262 "Number of fields: 7",
263 "Number of parameter: 1",
264 "Warnings: 0",
267 2: {
268 "showname": "MySQL Protocol - parameters in response to PREPARE",
269 "fields": [
270 "Packet Length: 23",
271 "Packet Number: 2",
272 "Charset number: binary COLLATE binary (63)",
273 "Length: 21",
274 "Type: FIELD_TYPE_LONGLONG (8)",
275 "Flags: 0x0080",
276 "Decimals: 0",
279 3: {
280 "showname": "MySQL Protocol - fields in response to PREPARE",
281 "fields": [
282 "Packet Length: 34",
283 "Packet Number: 3",
284 "Charset number: binary COLLATE binary (63)",
285 "Length: 11",
286 "Type: FIELD_TYPE_LONG (3)",
287 "Flags: 0x5003",
288 "Decimals: 0",
291 4: {
292 "showname": "MySQL Protocol - fields in response to PREPARE",
293 "fields": [
294 "Packet Length: 34",
295 "Packet Number: 4",
296 "Charset number: binary COLLATE binary (63)",
297 "Length: 19",
298 "Type: FIELD_TYPE_DATETIME (12)",
299 "Flags: 0x0080",
300 "Decimals: 0",
303 5: {
304 "showname": "MySQL Protocol - fields in response to PREPARE",
305 "fields": [
306 "Packet Length: 34",
307 "Packet Number: 5",
308 "Charset number: binary COLLATE binary (63)",
309 "Length: 26",
310 "Type: FIELD_TYPE_DATETIME (12)",
311 "Flags: 0x0080",
312 "Decimals: 6",
315 6: {
316 "showname": "MySQL Protocol - fields in response to PREPARE",
317 "fields": [
318 "Packet Length: 34",
319 "Packet Number: 6",
320 "Charset number: binary COLLATE binary (63)",
321 "Length: 19",
322 "Type: FIELD_TYPE_TIMESTAMP (7)",
323 "Flags: 0x0080",
324 "Decimals: 0",
327 7: {
328 "showname": "MySQL Protocol - fields in response to PREPARE",
329 "fields": [
330 "Packet Length: 34",
331 "Packet Number: 7",
332 "Charset number: binary COLLATE binary (63)",
333 "Length: 26",
334 "Type: FIELD_TYPE_TIMESTAMP (7)",
335 "Flags: 0x0080",
336 "Decimals: 6",
339 8: {
340 "showname": "MySQL Protocol - fields in response to PREPARE",
341 "fields": [
342 "Packet Length: 34",
343 "Packet Number: 8",
344 "Charset number: binary COLLATE binary (63)",
345 "Length: 1",
346 "Type: FIELD_TYPE_BIT (16)",
347 "Flags: 0x0020",
348 "Decimals: 0",
351 9: {
352 "showname": "MySQL Protocol - fields in response to PREPARE",
353 "fields": [
354 "Packet Length: 34",
355 "Packet Number: 9",
356 "Charset number: binary COLLATE binary (63)",
357 "Length: 16",
358 "Type: FIELD_TYPE_VAR_STRING (253)",
359 "Flags: 0x0080",
360 "Decimals: 0",
364 19: {
365 0: {
366 "showname": "MySQL Protocol",
367 "fields": [
368 "Packet Length: 5",
369 "Packet Number: 0",
370 "Request Command Reset Statement",
374 20: {
375 1: {
376 "showname": "MySQL Protocol - response OK",
377 "fields": [
378 "Packet Length: 7",
379 "Packet Number: 1",
380 "Response Code: OK Packet (0x00)",
381 "Affected Rows: 0",
382 "Server Status: 0x0000",
383 "Warnings: 0",
387 21: {
388 0: {
389 "showname": "MySQL Protocol",
390 "fields": [
391 "Packet Length: 85",
392 "Packet Number: 0",
393 "Request Command Execute Statement",
397 22: {
398 1: {
399 "showname": "MySQL Protocol - column count",
400 "fields": [
401 "Packet Length: 1",
402 "Packet Number: 1",
403 "Number of fields: 7",
406 2: {
407 "showname": "MySQL Protocol - field packet",
408 "fields": [
409 "Packet Length: 34",
410 "Packet Number: 2",
411 "Charset number: binary COLLATE binary (63)",
412 "Length: 11",
413 "Type: FIELD_TYPE_LONG (3)",
414 "Flags: 0x5003",
415 "Decimals: 0",
418 3: {
419 "showname": "MySQL Protocol - field packet",
420 "fields": [
421 "Packet Length: 34",
422 "Packet Number: 3",
423 "Charset number: binary COLLATE binary (63)",
424 "Length: 19",
425 "Type: FIELD_TYPE_DATETIME (12)",
426 "Flags: 0x0080",
427 "Decimals: 0",
430 4: {
431 "showname": "MySQL Protocol - field packet",
432 "fields": [
433 "Packet Length: 34",
434 "Packet Number: 4",
435 "Charset number: binary COLLATE binary (63)",
436 "Length: 26",
437 "Type: FIELD_TYPE_DATETIME (12)",
438 "Flags: 0x0080",
439 "Decimals: 6",
442 5: {
443 "showname": "MySQL Protocol - field packet",
444 "fields": [
445 "Packet Length: 34",
446 "Packet Number: 5",
447 "Charset number: binary COLLATE binary (63)",
448 "Length: 19",
449 "Type: FIELD_TYPE_TIMESTAMP (7)",
450 "Flags: 0x0080",
451 "Decimals: 0",
454 6: {
455 "showname": "MySQL Protocol - field packet",
456 "fields": [
457 "Packet Length: 34",
458 "Packet Number: 6",
459 "Charset number: binary COLLATE binary (63)",
460 "Length: 26",
461 "Type: FIELD_TYPE_TIMESTAMP (7)",
462 "Flags: 0x0080",
463 "Decimals: 6",
466 7: {
467 "showname": "MySQL Protocol - field packet",
468 "fields": [
469 "Packet Length: 34",
470 "Packet Number: 7",
471 "Charset number: binary COLLATE binary (63)",
472 "Length: 1",
473 "Type: FIELD_TYPE_BIT (16)",
474 "Flags: 0x0020",
475 "Decimals: 0",
478 8: {
479 "showname": "MySQL Protocol - field packet",
480 "fields": [
481 "Packet Length: 34",
482 "Packet Number: 8",
483 "Charset number: binary COLLATE binary (63)",
484 "Length: 16",
485 "Type: FIELD_TYPE_VAR_STRING (253)",
486 "Flags: 0x0080",
487 "Decimals: 0",
490 9: {
491 "showname": "MySQL Protocol - row packet",
492 "fields": [
493 "Packet Length: 53",
494 "Packet Number: 9",
495 "Response Code: OK Packet (0x00)",
496 "Row null buffer: 0000",
499 10: {
500 "showname": "MySQL Protocol - response OK",
501 "fields": [
502 "Packet Length: 7",
503 "Packet Number: 10",
504 "Response Code: EOF Packet (0xfe)",
505 "EOF marker: 254",
506 "Affected Rows: 0",
507 "Server Status: 0x0021",
508 "Warnings: 0",
512 23: {
513 0: {
514 "showname": "MySQL Protocol",
515 "fields": [
516 "Packet Length: 5",
517 "Packet Number: 0",
518 "Request Command Reset Statement",
522 24: {
523 1: {
524 "showname": "MySQL Protocol - response OK",
525 "fields": [
526 "Packet Length: 7",
527 "Packet Number: 1",
528 "Response Code: OK Packet (0x00)",
529 "Affected Rows: 0",
530 "Server Status: 0x0001",
531 "Warnings: 0",
535 25: {
536 0: {
537 "showname": "MySQL Protocol",
538 "fields": [
539 "Packet Length: 5",
540 "Packet Number: 0",
541 "Request Command Close Statement",
545 26: {
546 0: {
547 "showname": "MySQL Protocol",
548 "fields": [
549 "Packet Length: 1",
550 "Packet Number: 0",
551 "Request Command Quit",
557 # Summary should look like this:
559 # <int:Packet Number>: {
560 # <int:MySQL Packet Number>: {
561 # "showname": <str>,
562 # "fields": [str, ...]
566 summary = {}
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"))
575 assert False
577 for pkt in tree:
579 # Get the packet number
580 num = int(
581 pkt.find("./proto[@name='geninfo']/field[@name='num']").attrib["show"]
583 summary[num] = {}
585 for proto in pkt.findall("./proto[@name='mysql']"):
587 mysqlnum = int(
588 proto.find("./field[@name='mysql.packet_number']").attrib["show"]
590 summary[num][mysqlnum] = {
591 "showname": proto.attrib["showname"],
592 "fields": [],
594 for field in proto.findall("./field"):
595 if "showname" in field.attrib:
596 summary[num][mysqlnum]["fields"].append(
597 field.attrib["showname"]
600 print(summary)
602 for pkt in summary:
603 for mysqlpkt in summary[pkt]:
604 assert (
605 summary[pkt][mysqlpkt]["showname"]
606 == expected[pkt][mysqlpkt]["showname"]
608 assert (
609 summary[pkt][mysqlpkt]["fields"]
610 == expected[pkt][mysqlpkt]["fields"]
613 def test_mysql_57(self, cmd_tshark, capture_file, test_env):
614 """MySQL 5.7"""
616 stdout = subprocess.check_output(
618 cmd_tshark,
619 "-r",
620 capture_file("mysql/mysql57.pcapng.gz"),
621 "-T",
622 "pdml",
623 "-J",
624 "mysql",
625 "-Y",
626 "mysql",
628 encoding="utf-8",
629 env=test_env,
632 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
633 expected = {
634 4: {
635 0: {
636 "showname": "MySQL Protocol",
637 "fields": [
638 "Packet Length: 74",
639 "Packet Number: 0",
640 "Server Greeting",
644 6: {
645 1: {
646 "showname": "MySQL Protocol",
647 "fields": [
648 "Packet Length: 181",
649 "Packet Number: 1",
650 "Login Request",
654 8: {
655 2: {
656 "showname": "MySQL Protocol - response OK",
657 "fields": [
658 "Packet Length: 7",
659 "Packet Number: 2",
660 "Response Code: OK Packet (0x00)",
661 "Affected Rows: 0",
662 "Server Status: 0x0002",
663 "Warnings: 0",
667 9: {
668 0: {
669 "showname": "MySQL Protocol",
670 "fields": [
671 "Packet Length: 33",
672 "Packet Number: 0",
673 "Request Command Query",
677 10: {
678 1: {
679 "showname": "MySQL Protocol - column count",
680 "fields": [
681 "Packet Length: 1",
682 "Packet Number: 1",
683 "Number of fields: 1",
686 2: {
687 "showname": "MySQL Protocol - field packet",
688 "fields": [
689 "Packet Length: 39",
690 "Packet Number: 2",
691 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
692 "Length: 28",
693 "Type: FIELD_TYPE_VAR_STRING (253)",
694 "Flags: 0x0000",
695 "Decimals: 31",
698 3: {
699 "showname": "MySQL Protocol - row packet",
700 "fields": ["Packet Length: 29", "Packet Number: 3"],
702 4: {
703 "showname": "MySQL Protocol - response OK",
704 "fields": [
705 "Packet Length: 7",
706 "Packet Number: 4",
707 "Response Code: EOF Packet (0xfe)",
708 "EOF marker: 254",
709 "Affected Rows: 0",
710 "Server Status: 0x0002",
711 "Warnings: 0",
715 11: {
716 0: {
717 "showname": "MySQL Protocol",
718 "fields": [
719 "Packet Length: 10",
720 "Packet Number: 0",
721 "Request Command Query",
725 12: {
726 1: {
727 "showname": "MySQL Protocol - response ERROR",
728 "fields": [
729 "Packet Length: 44",
730 "Packet Number: 1",
731 "Response Code: ERR Packet (0xff)",
732 "Error Code: 1054",
733 "SQL state: 42S22",
734 "Error message: Unknown column '$$' in 'field list'",
738 14: {
739 0: {
740 "showname": "MySQL Protocol",
741 "fields": [
742 "Packet Length: 34",
743 "Packet Number: 0",
744 "Request Command Query",
748 15: {
749 1: {
750 "showname": "MySQL Protocol - column count",
751 "fields": [
752 "Packet Length: 1",
753 "Packet Number: 1",
754 "Number of fields: 2",
757 2: {
758 "showname": "MySQL Protocol - field packet",
759 "fields": [
760 "Packet Length: 32",
761 "Packet Number: 2",
762 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
763 "Length: 34",
764 "Type: FIELD_TYPE_VAR_STRING (253)",
765 "Flags: 0x0000",
766 "Decimals: 31",
769 3: {
770 "showname": "MySQL Protocol - field packet",
771 "fields": [
772 "Packet Length: 28",
773 "Packet Number: 3",
774 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
775 "Length: 93",
776 "Type: FIELD_TYPE_VAR_STRING (253)",
777 "Flags: 0x0000",
778 "Decimals: 31",
781 4: {
782 "showname": "MySQL Protocol - row packet",
783 "fields": ["Packet Length: 16", "Packet Number: 4"],
785 5: {
786 "showname": "MySQL Protocol - response OK",
787 "fields": [
788 "Packet Length: 7",
789 "Packet Number: 5",
790 "Response Code: EOF Packet (0xfe)",
791 "EOF marker: 254",
792 "Affected Rows: 0",
793 "Server Status: 0x0002",
794 "Warnings: 0",
798 17: {
799 0: {
800 "showname": "MySQL Protocol",
801 "fields": [
802 "Packet Length: 116",
803 "Packet Number: 0",
804 "Request Command Query",
808 18: {
809 1: {
810 "showname": "MySQL Protocol - column count",
811 "fields": [
812 "Packet Length: 1",
813 "Packet Number: 1",
814 "Number of fields: 4",
817 2: {
818 "showname": "MySQL Protocol - field packet",
819 "fields": [
820 "Packet Length: 44",
821 "Packet Number: 2",
822 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
823 "Length: 6",
824 "Type: FIELD_TYPE_VAR_STRING (253)",
825 "Flags: 0x0000",
826 "Decimals: 31",
829 3: {
830 "showname": "MySQL Protocol - field packet",
831 "fields": [
832 "Packet Length: 48",
833 "Packet Number: 3",
834 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
835 "Length: 6",
836 "Type: FIELD_TYPE_VAR_STRING (253)",
837 "Flags: 0x0000",
838 "Decimals: 31",
841 4: {
842 "showname": "MySQL Protocol - field packet",
843 "fields": [
844 "Packet Length: 44",
845 "Packet Number: 4",
846 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
847 "Length: 6",
848 "Type: FIELD_TYPE_VAR_STRING (253)",
849 "Flags: 0x0000",
850 "Decimals: 31",
853 5: {
854 "showname": "MySQL Protocol - field packet",
855 "fields": [
856 "Packet Length: 46",
857 "Packet Number: 5",
858 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
859 "Length: 6",
860 "Type: FIELD_TYPE_VAR_STRING (253)",
861 "Flags: 0x0000",
862 "Decimals: 31",
865 6: {
866 "showname": "MySQL Protocol - row packet",
867 "fields": ["Packet Length: 28", "Packet Number: 6"],
869 7: {
870 "showname": "MySQL Protocol - response OK",
871 "fields": [
872 "Packet Length: 7",
873 "Packet Number: 7",
874 "Response Code: EOF Packet (0xfe)",
875 "EOF marker: 254",
876 "Affected Rows: 0",
877 "Server Status: 0x0002",
878 "Warnings: 0",
882 19: {
883 0: {
884 "showname": "MySQL Protocol",
885 "fields": [
886 "Packet Length: 1",
887 "Packet Number: 0",
888 "Request Command Statistics",
892 20: {
893 1: {
894 "showname": "MySQL Protocol",
895 "fields": [
896 "Packet Length: 132",
897 "Packet Number: 1",
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",
902 22: {
903 0: {
904 "showname": "MySQL Protocol",
905 "fields": [
906 "Packet Length: 1",
907 "Packet Number: 0",
908 "Request Command Quit",
914 # Summary should look like this:
916 # <int:Packet Number>: {
917 # <int:MySQL Packet Number>: {
918 # "showname": <str>,
919 # "fields": [str, ...]
923 summary = {}
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"))
932 assert False
934 for pkt in tree:
936 # Get the packet number
937 num = int(
938 pkt.find("./proto[@name='geninfo']/field[@name='num']").attrib["show"]
940 summary[num] = {}
942 for proto in pkt.findall("./proto[@name='mysql']"):
944 mysqlnum = int(
945 proto.find("./field[@name='mysql.packet_number']").attrib["show"]
947 summary[num][mysqlnum] = {
948 "showname": proto.attrib["showname"],
949 "fields": [],
951 for field in proto.findall("./field"):
952 if "showname" in field.attrib:
953 summary[num][mysqlnum]["fields"].append(
954 field.attrib["showname"]
957 print(summary)
959 for pkt in summary:
960 for mysqlpkt in summary[pkt]:
961 assert (
962 summary[pkt][mysqlpkt]["showname"]
963 == expected[pkt][mysqlpkt]["showname"]
965 assert (
966 summary[pkt][mysqlpkt]["fields"]
967 == expected[pkt][mysqlpkt]["fields"]
970 def test_mysql_80(self, cmd_tshark, capture_file, test_env):
971 """MySQL 8.0"""
973 stdout = subprocess.check_output(
975 cmd_tshark,
976 "-r",
977 capture_file("mysql/mysql80.pcapng.gz"),
978 "-T",
979 "pdml",
980 "-J",
981 "mysql",
982 "-Y",
983 "mysql",
985 encoding="utf-8",
986 env=test_env,
989 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
990 expected = {
991 4: {
992 0: {
993 "showname": "MySQL Protocol",
994 "fields": [
995 "Packet Length: 74",
996 "Packet Number: 0",
997 "Server Greeting",
1001 6: {
1002 1: {
1003 "showname": "MySQL Protocol",
1004 "fields": [
1005 "Packet Length: 182",
1006 "Packet Number: 1",
1007 "Login Request",
1011 8: {
1012 2: {
1013 "showname": "MySQL Protocol - response OK",
1014 "fields": [
1015 "Packet Length: 7",
1016 "Packet Number: 2",
1017 "Response Code: OK Packet (0x00)",
1018 "Affected Rows: 0",
1019 "Server Status: 0x0002",
1020 "Warnings: 0",
1024 9: {
1025 0: {
1026 "showname": "MySQL Protocol",
1027 "fields": [
1028 "Packet Length: 35",
1029 "Packet Number: 0",
1030 "Request Command Query",
1034 10: {
1035 1: {
1036 "showname": "MySQL Protocol - column count",
1037 "fields": [
1038 "Packet Length: 1",
1039 "Packet Number: 1",
1040 "Number of fields: 1",
1043 2: {
1044 "showname": "MySQL Protocol - field packet",
1045 "fields": [
1046 "Packet Length: 39",
1047 "Packet Number: 2",
1048 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1049 "Length: 87380",
1050 "Type: FIELD_TYPE_VAR_STRING (253)",
1051 "Flags: 0x0000",
1052 "Decimals: 31",
1055 3: {
1056 "showname": "MySQL Protocol - row packet",
1057 "fields": ["Packet Length: 29", "Packet Number: 3"],
1059 4: {
1060 "showname": "MySQL Protocol - response OK",
1061 "fields": [
1062 "Packet Length: 7",
1063 "Packet Number: 4",
1064 "Response Code: EOF Packet (0xfe)",
1065 "EOF marker: 254",
1066 "Affected Rows: 0",
1067 "Server Status: 0x0002",
1068 "Warnings: 0",
1072 11: {
1073 0: {
1074 "showname": "MySQL Protocol",
1075 "fields": [
1076 "Packet Length: 12",
1077 "Packet Number: 0",
1078 "Request Command Query",
1082 12: {
1083 1: {
1084 "showname": "MySQL Protocol - response ERROR",
1085 "fields": [
1086 "Packet Length: 44",
1087 "Packet Number: 1",
1088 "Response Code: ERR Packet (0xff)",
1089 "Error Code: 1054",
1090 "SQL state: 42S22",
1091 "Error message: Unknown column '$$' in 'field list'",
1095 14: {
1096 0: {
1097 "showname": "MySQL Protocol",
1098 "fields": [
1099 "Packet Length: 36",
1100 "Packet Number: 0",
1101 "Request Command Query",
1105 15: {
1106 1: {
1107 "showname": "MySQL Protocol - column count",
1108 "fields": [
1109 "Packet Length: 1",
1110 "Packet Number: 1",
1111 "Number of fields: 2",
1114 2: {
1115 "showname": "MySQL Protocol - field packet",
1116 "fields": [
1117 "Packet Length: 32",
1118 "Packet Number: 2",
1119 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1120 "Length: 136",
1121 "Type: FIELD_TYPE_VAR_STRING (253)",
1122 "Flags: 0x0000",
1123 "Decimals: 31",
1126 3: {
1127 "showname": "MySQL Protocol - field packet",
1128 "fields": [
1129 "Packet Length: 28",
1130 "Packet Number: 3",
1131 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1132 "Length: 1152",
1133 "Type: FIELD_TYPE_VAR_STRING (253)",
1134 "Flags: 0x0000",
1135 "Decimals: 31",
1138 4: {
1139 "showname": "MySQL Protocol - row packet",
1140 "fields": ["Packet Length: 16", "Packet Number: 4"],
1142 5: {
1143 "showname": "MySQL Protocol - response OK",
1144 "fields": [
1145 "Packet Length: 7",
1146 "Packet Number: 5",
1147 "Response Code: EOF Packet (0xfe)",
1148 "EOF marker: 254",
1149 "Affected Rows: 0",
1150 "Server Status: 0x0002",
1151 "Warnings: 0",
1155 17: {
1156 0: {
1157 "showname": "MySQL Protocol",
1158 "fields": [
1159 "Packet Length: 118",
1160 "Packet Number: 0",
1161 "Request Command Query",
1165 18: {
1166 1: {
1167 "showname": "MySQL Protocol - column count",
1168 "fields": [
1169 "Packet Length: 1",
1170 "Packet Number: 1",
1171 "Number of fields: 4",
1174 2: {
1175 "showname": "MySQL Protocol - field packet",
1176 "fields": [
1177 "Packet Length: 44",
1178 "Packet Number: 2",
1179 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1180 "Length: 87380",
1181 "Type: FIELD_TYPE_VAR_STRING (253)",
1182 "Flags: 0x0000",
1183 "Decimals: 31",
1186 3: {
1187 "showname": "MySQL Protocol - field packet",
1188 "fields": [
1189 "Packet Length: 48",
1190 "Packet Number: 3",
1191 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1192 "Length: 87380",
1193 "Type: FIELD_TYPE_VAR_STRING (253)",
1194 "Flags: 0x0000",
1195 "Decimals: 31",
1198 4: {
1199 "showname": "MySQL Protocol - field packet",
1200 "fields": [
1201 "Packet Length: 44",
1202 "Packet Number: 4",
1203 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1204 "Length: 87380",
1205 "Type: FIELD_TYPE_VAR_STRING (253)",
1206 "Flags: 0x0000",
1207 "Decimals: 31",
1210 5: {
1211 "showname": "MySQL Protocol - field packet",
1212 "fields": [
1213 "Packet Length: 46",
1214 "Packet Number: 5",
1215 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1216 "Length: 87380",
1217 "Type: FIELD_TYPE_VAR_STRING (253)",
1218 "Flags: 0x0000",
1219 "Decimals: 31",
1222 6: {
1223 "showname": "MySQL Protocol - row packet",
1224 "fields": ["Packet Length: 32", "Packet Number: 6"],
1226 7: {
1227 "showname": "MySQL Protocol - response OK",
1228 "fields": [
1229 "Packet Length: 7",
1230 "Packet Number: 7",
1231 "Response Code: EOF Packet (0xfe)",
1232 "EOF marker: 254",
1233 "Affected Rows: 0",
1234 "Server Status: 0x0002",
1235 "Warnings: 0",
1239 19: {
1240 0: {
1241 "showname": "MySQL Protocol",
1242 "fields": [
1243 "Packet Length: 1",
1244 "Packet Number: 0",
1245 "Request Command Statistics",
1249 20: {
1250 1: {
1251 "showname": "MySQL Protocol",
1252 "fields": [
1253 "Packet Length: 130",
1254 "Packet Number: 1",
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",
1259 22: {
1260 0: {
1261 "showname": "MySQL Protocol",
1262 "fields": [
1263 "Packet Length: 1",
1264 "Packet Number: 0",
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, ...]
1280 summary = {}
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"))
1289 assert False
1291 for pkt in tree:
1293 # Get the packet number
1294 num = int(
1295 pkt.find("./proto[@name='geninfo']/field[@name='num']").attrib["show"]
1297 summary[num] = {}
1299 for proto in pkt.findall("./proto[@name='mysql']"):
1301 mysqlnum = int(
1302 proto.find("./field[@name='mysql.packet_number']").attrib["show"]
1304 summary[num][mysqlnum] = {
1305 "showname": proto.attrib["showname"],
1306 "fields": [],
1308 for field in proto.findall("./field"):
1309 if "showname" in field.attrib:
1310 summary[num][mysqlnum]["fields"].append(
1311 field.attrib["showname"]
1314 print(summary)
1316 for pkt in summary:
1317 for mysqlpkt in summary[pkt]:
1318 assert (
1319 summary[pkt][mysqlpkt]["showname"]
1320 == expected[pkt][mysqlpkt]["showname"]
1322 assert (
1323 summary[pkt][mysqlpkt]["fields"]
1324 == expected[pkt][mysqlpkt]["fields"]
1327 def test_mariadb_114(self, cmd_tshark, capture_file, test_env):
1328 """MariaDB 11.4"""
1330 stdout = subprocess.check_output(
1332 cmd_tshark,
1333 "-r",
1334 capture_file("mysql/mariadb114.pcapng.gz"),
1335 "-T",
1336 "pdml",
1337 "-J",
1338 "mysql",
1339 "-Y",
1340 "mysql",
1342 encoding="utf-8",
1343 env=test_env,
1346 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
1347 expected = {
1348 4: {
1349 0: {
1350 "showname": "MySQL Protocol",
1351 "fields": [
1352 "Packet Length: 90",
1353 "Packet Number: 0",
1354 "Server Greeting",
1358 6: {
1359 1: {
1360 "showname": "MySQL Protocol",
1361 "fields": [
1362 "Packet Length: 181",
1363 "Packet Number: 1",
1364 "Login Request",
1368 8: {
1369 2: {
1370 "showname": "MySQL Protocol - response OK",
1371 "fields": [
1372 "Packet Length: 7",
1373 "Packet Number: 2",
1374 "Response Code: OK Packet (0x00)",
1375 "Affected Rows: 0",
1376 "Server Status: 0x0002",
1377 "Warnings: 0",
1381 9: {
1382 0: {
1383 "showname": "MySQL Protocol",
1384 "fields": [
1385 "Packet Length: 33",
1386 "Packet Number: 0",
1387 "Request Command Query",
1391 10: {
1392 1: {
1393 "showname": "MySQL Protocol - column count",
1394 "fields": [
1395 "Packet Length: 1",
1396 "Packet Number: 1",
1397 "Number of fields: 1",
1400 2: {
1401 "showname": "MySQL Protocol - field packet",
1402 "fields": [
1403 "Packet Length: 39",
1404 "Packet Number: 2",
1405 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1406 "Length: 124",
1407 "Type: FIELD_TYPE_VAR_STRING (253)",
1408 "Flags: 0x0000",
1409 "Decimals: 39",
1412 3: {
1413 "showname": "MySQL Protocol - row packet",
1414 "fields": ["Packet Length: 32", "Packet Number: 3"],
1416 4: {
1417 "showname": "MySQL Protocol - response OK",
1418 "fields": [
1419 "Packet Length: 7",
1420 "Packet Number: 4",
1421 "Response Code: EOF Packet (0xfe)",
1422 "EOF marker: 254",
1423 "Affected Rows: 0",
1424 "Server Status: 0x0002",
1425 "Warnings: 0",
1429 11: {
1430 0: {
1431 "showname": "MySQL Protocol",
1432 "fields": [
1433 "Packet Length: 10",
1434 "Packet Number: 0",
1435 "Request Command Query",
1439 12: {
1440 1: {
1441 "showname": "MySQL Protocol - response ERROR",
1442 "fields": [
1443 "Packet Length: 44",
1444 "Packet Number: 1",
1445 "Response Code: ERR Packet (0xff)",
1446 "Error Code: 1054",
1447 "SQL state: 42S22",
1448 "Error message: Unknown column '$$' in 'field list'",
1452 14: {
1453 0: {
1454 "showname": "MySQL Protocol",
1455 "fields": [
1456 "Packet Length: 34",
1457 "Packet Number: 0",
1458 "Request Command Query",
1462 15: {
1463 1: {
1464 "showname": "MySQL Protocol - column count",
1465 "fields": [
1466 "Packet Length: 1",
1467 "Packet Number: 1",
1468 "Number of fields: 2",
1471 2: {
1472 "showname": "MySQL Protocol - field packet",
1473 "fields": [
1474 "Packet Length: 32",
1475 "Packet Number: 2",
1476 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1477 "Length: 256",
1478 "Type: FIELD_TYPE_VAR_STRING (253)",
1479 "Flags: 0x0000",
1480 "Decimals: 39",
1483 3: {
1484 "showname": "MySQL Protocol - field packet",
1485 "fields": [
1486 "Packet Length: 28",
1487 "Packet Number: 3",
1488 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1489 "Length: 1536",
1490 "Type: FIELD_TYPE_VAR_STRING (253)",
1491 "Flags: 0x0000",
1492 "Decimals: 39",
1495 4: {
1496 "showname": "MySQL Protocol - row packet",
1497 "fields": ["Packet Length: 16", "Packet Number: 4"],
1499 5: {
1500 "showname": "MySQL Protocol - response OK",
1501 "fields": [
1502 "Packet Length: 7",
1503 "Packet Number: 5",
1504 "Response Code: EOF Packet (0xfe)",
1505 "EOF marker: 254",
1506 "Affected Rows: 0",
1507 "Server Status: 0x0002",
1508 "Warnings: 0",
1512 17: {
1513 0: {
1514 "showname": "MySQL Protocol",
1515 "fields": [
1516 "Packet Length: 116",
1517 "Packet Number: 0",
1518 "Request Command Query",
1522 18: {
1523 1: {
1524 "showname": "MySQL Protocol - column count",
1525 "fields": [
1526 "Packet Length: 1",
1527 "Packet Number: 1",
1528 "Number of fields: 4",
1531 2: {
1532 "showname": "MySQL Protocol - field packet",
1533 "fields": [
1534 "Packet Length: 44",
1535 "Packet Number: 2",
1536 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1537 "Length: 28",
1538 "Type: FIELD_TYPE_VAR_STRING (253)",
1539 "Flags: 0x0000",
1540 "Decimals: 39",
1543 3: {
1544 "showname": "MySQL Protocol - field packet",
1545 "fields": [
1546 "Packet Length: 48",
1547 "Packet Number: 3",
1548 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1549 "Length: 28",
1550 "Type: FIELD_TYPE_VAR_STRING (253)",
1551 "Flags: 0x0000",
1552 "Decimals: 39",
1555 4: {
1556 "showname": "MySQL Protocol - field packet",
1557 "fields": [
1558 "Packet Length: 44",
1559 "Packet Number: 4",
1560 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1561 "Length: 28",
1562 "Type: FIELD_TYPE_VAR_STRING (253)",
1563 "Flags: 0x0000",
1564 "Decimals: 39",
1567 5: {
1568 "showname": "MySQL Protocol - field packet",
1569 "fields": [
1570 "Packet Length: 46",
1571 "Packet Number: 5",
1572 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1573 "Length: 28",
1574 "Type: FIELD_TYPE_VAR_STRING (253)",
1575 "Flags: 0x0000",
1576 "Decimals: 39",
1579 6: {
1580 "showname": "MySQL Protocol - row packet",
1581 "fields": ["Packet Length: 32", "Packet Number: 6"],
1583 7: {
1584 "showname": "MySQL Protocol - response OK",
1585 "fields": [
1586 "Packet Length: 7",
1587 "Packet Number: 7",
1588 "Response Code: EOF Packet (0xfe)",
1589 "EOF marker: 254",
1590 "Affected Rows: 0",
1591 "Server Status: 0x0002",
1592 "Warnings: 0",
1596 19: {
1597 0: {
1598 "showname": "MySQL Protocol",
1599 "fields": [
1600 "Packet Length: 1",
1601 "Packet Number: 0",
1602 "Request Command Statistics",
1606 20: {
1607 1: {
1608 "showname": "MySQL Protocol",
1609 "fields": [
1610 "Packet Length: 112",
1611 "Packet Number: 1",
1612 "Message: Uptime: 25 Threads: 1 Questions: 5 Slow queries: 0 Opens: 17 Open tables: 10 Queries per second avg: 0.200",
1616 22: {
1617 0: {
1618 "showname": "MySQL Protocol",
1619 "fields": [
1620 "Packet Length: 1",
1621 "Packet Number: 0",
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, ...]
1637 summary = {}
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"))
1646 assert False
1648 for pkt in tree:
1650 # Get the packet number
1651 num = int(
1652 pkt.find("./proto[@name='geninfo']/field[@name='num']").attrib["show"]
1654 summary[num] = {}
1656 for proto in pkt.findall("./proto[@name='mysql']"):
1658 mysqlnum = int(
1659 proto.find("./field[@name='mysql.packet_number']").attrib["show"]
1661 summary[num][mysqlnum] = {
1662 "showname": proto.attrib["showname"],
1663 "fields": [],
1665 for field in proto.findall("./field"):
1666 if "showname" in field.attrib:
1667 summary[num][mysqlnum]["fields"].append(
1668 field.attrib["showname"]
1671 print(summary)
1673 for pkt in summary:
1674 for mysqlpkt in summary[pkt]:
1675 assert (
1676 summary[pkt][mysqlpkt]["showname"]
1677 == expected[pkt][mysqlpkt]["showname"]
1679 assert (
1680 summary[pkt][mysqlpkt]["fields"]
1681 == expected[pkt][mysqlpkt]["fields"]
1684 def test_tidb_81(self, cmd_tshark, capture_file, test_env):
1685 """TiDB 8.1"""
1687 stdout = subprocess.check_output(
1689 cmd_tshark,
1690 "-r",
1691 capture_file("mysql/tidb81.pcapng.gz"),
1692 "-T",
1693 "pdml",
1694 "-J",
1695 "mysql",
1696 "-Y",
1697 "mysql",
1699 encoding="utf-8",
1700 env=test_env,
1703 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
1704 expected = {
1705 4: {
1706 0: {
1707 "showname": "MySQL Protocol",
1708 "fields": [
1709 "Packet Length: 86",
1710 "Packet Number: 0",
1711 "Server Greeting",
1715 6: {
1716 1: {
1717 "showname": "MySQL Protocol",
1718 "fields": [
1719 "Packet Length: 181",
1720 "Packet Number: 1",
1721 "Login Request",
1725 8: {
1726 2: {
1727 "showname": "MySQL Protocol - response OK",
1728 "fields": [
1729 "Packet Length: 7",
1730 "Packet Number: 2",
1731 "Response Code: OK Packet (0x00)",
1732 "Affected Rows: 0",
1733 "Server Status: 0x0002",
1734 "Warnings: 0",
1738 9: {
1739 0: {
1740 "showname": "MySQL Protocol",
1741 "fields": [
1742 "Packet Length: 33",
1743 "Packet Number: 0",
1744 "Request Command Query",
1748 10: {
1749 1: {
1750 "showname": "MySQL Protocol - column count",
1751 "fields": [
1752 "Packet Length: 1",
1753 "Packet Number: 1",
1754 "Number of fields: 1",
1757 2: {
1758 "showname": "MySQL Protocol - field packet",
1759 "fields": [
1760 "Packet Length: 39",
1761 "Packet Number: 2",
1762 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1763 "Length: 0",
1764 "Type: FIELD_TYPE_VAR_STRING (253)",
1765 "Flags: 0x0000",
1766 "Decimals: 31",
1769 3: {
1770 "showname": "MySQL Protocol - row packet",
1771 "fields": ["Packet Length: 73", "Packet Number: 3"],
1773 4: {
1774 "showname": "MySQL Protocol - response OK",
1775 "fields": [
1776 "Packet Length: 7",
1777 "Packet Number: 4",
1778 "Response Code: EOF Packet (0xfe)",
1779 "EOF marker: 254",
1780 "Affected Rows: 0",
1781 "Server Status: 0x0002",
1782 "Warnings: 0",
1786 11: {
1787 0: {
1788 "showname": "MySQL Protocol",
1789 "fields": [
1790 "Packet Length: 10",
1791 "Packet Number: 0",
1792 "Request Command Query",
1796 12: {
1797 1: {
1798 "showname": "MySQL Protocol - response ERROR",
1799 "fields": [
1800 "Packet Length: 44",
1801 "Packet Number: 1",
1802 "Response Code: ERR Packet (0xff)",
1803 "Error Code: 1054",
1804 "SQL state: 42S22",
1805 "Error message: Unknown column '$$' in 'field list'",
1809 14: {
1810 0: {
1811 "showname": "MySQL Protocol",
1812 "fields": [
1813 "Packet Length: 34",
1814 "Packet Number: 0",
1815 "Request Command Query",
1819 15: {
1820 1: {
1821 "showname": "MySQL Protocol - column count",
1822 "fields": [
1823 "Packet Length: 1",
1824 "Packet Number: 1",
1825 "Number of fields: 2",
1828 2: {
1829 "showname": "MySQL Protocol - field packet",
1830 "fields": [
1831 "Packet Length: 32",
1832 "Packet Number: 2",
1833 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1834 "Length: 256",
1835 "Type: FIELD_TYPE_VAR_STRING (253)",
1836 "Flags: 0x0000",
1837 "Decimals: 31",
1840 3: {
1841 "showname": "MySQL Protocol - field packet",
1842 "fields": [
1843 "Packet Length: 28",
1844 "Packet Number: 3",
1845 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1846 "Length: 256",
1847 "Type: FIELD_TYPE_VAR_STRING (253)",
1848 "Flags: 0x0001",
1849 "Decimals: 31",
1852 4: {
1853 "showname": "MySQL Protocol - row packet",
1854 "fields": ["Packet Length: 16", "Packet Number: 4"],
1856 5: {
1857 "showname": "MySQL Protocol - response OK",
1858 "fields": [
1859 "Packet Length: 7",
1860 "Packet Number: 5",
1861 "Response Code: EOF Packet (0xfe)",
1862 "EOF marker: 254",
1863 "Affected Rows: 0",
1864 "Server Status: 0x0002",
1865 "Warnings: 0",
1869 17: {
1870 0: {
1871 "showname": "MySQL Protocol",
1872 "fields": [
1873 "Packet Length: 116",
1874 "Packet Number: 0",
1875 "Request Command Query",
1879 18: {
1880 1: {
1881 "showname": "MySQL Protocol - column count",
1882 "fields": [
1883 "Packet Length: 1",
1884 "Packet Number: 1",
1885 "Number of fields: 4",
1888 2: {
1889 "showname": "MySQL Protocol - field packet",
1890 "fields": [
1891 "Packet Length: 44",
1892 "Packet Number: 2",
1893 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1894 "Length: 0",
1895 "Type: FIELD_TYPE_VAR_STRING (253)",
1896 "Flags: 0x0000",
1897 "Decimals: 31",
1900 3: {
1901 "showname": "MySQL Protocol - field packet",
1902 "fields": [
1903 "Packet Length: 48",
1904 "Packet Number: 3",
1905 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1906 "Length: 0",
1907 "Type: FIELD_TYPE_VAR_STRING (253)",
1908 "Flags: 0x0000",
1909 "Decimals: 31",
1912 4: {
1913 "showname": "MySQL Protocol - field packet",
1914 "fields": [
1915 "Packet Length: 44",
1916 "Packet Number: 4",
1917 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1918 "Length: 0",
1919 "Type: FIELD_TYPE_VAR_STRING (253)",
1920 "Flags: 0x0000",
1921 "Decimals: 31",
1924 5: {
1925 "showname": "MySQL Protocol - field packet",
1926 "fields": [
1927 "Packet Length: 46",
1928 "Packet Number: 5",
1929 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1930 "Length: 0",
1931 "Type: FIELD_TYPE_VAR_STRING (253)",
1932 "Flags: 0x0000",
1933 "Decimals: 31",
1936 6: {
1937 "showname": "MySQL Protocol - row packet",
1938 "fields": ["Packet Length: 32", "Packet Number: 6"],
1940 7: {
1941 "showname": "MySQL Protocol - response OK",
1942 "fields": [
1943 "Packet Length: 7",
1944 "Packet Number: 7",
1945 "Response Code: EOF Packet (0xfe)",
1946 "EOF marker: 254",
1947 "Affected Rows: 0",
1948 "Server Status: 0x0002",
1949 "Warnings: 0",
1953 19: {
1954 0: {
1955 "showname": "MySQL Protocol",
1956 "fields": [
1957 "Packet Length: 1",
1958 "Packet Number: 0",
1959 "Request Command Statistics",
1963 20: {
1964 1: {
1965 "showname": "MySQL Protocol",
1966 "fields": [
1967 "Packet Length: 127",
1968 "Packet Number: 1",
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",
1973 22: {
1974 0: {
1975 "showname": "MySQL Protocol",
1976 "fields": [
1977 "Packet Length: 1",
1978 "Packet Number: 0",
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, ...]
1994 summary = {}
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"))
2003 assert False
2005 for pkt in tree:
2007 # Get the packet number
2008 num = int(
2009 pkt.find("./proto[@name='geninfo']/field[@name='num']").attrib["show"]
2011 summary[num] = {}
2013 for proto in pkt.findall("./proto[@name='mysql']"):
2015 mysqlnum = int(
2016 proto.find("./field[@name='mysql.packet_number']").attrib["show"]
2018 summary[num][mysqlnum] = {
2019 "showname": proto.attrib["showname"],
2020 "fields": [],
2022 for field in proto.findall("./field"):
2023 if "showname" in field.attrib:
2024 summary[num][mysqlnum]["fields"].append(
2025 field.attrib["showname"]
2028 print(summary)
2030 for pkt in summary:
2031 for mysqlpkt in summary[pkt]:
2032 assert (
2033 summary[pkt][mysqlpkt]["showname"]
2034 == expected[pkt][mysqlpkt]["showname"]
2036 assert (
2037 summary[pkt][mysqlpkt]["fields"]
2038 == expected[pkt][mysqlpkt]["fields"]