Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / test / suite_dissectors / group_mysql.py
blob8aab73fd188e260c542311c486ba340c06224d49
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 "Last INSERT ID: 0",
144 "Server Status: 0x4002",
145 "Warnings: 0",
146 "Session tracking data",
150 9: {
151 0: {
152 "showname": "MySQL Protocol",
153 "fields": [
154 "Packet Length: 51",
155 "Packet Number: 0",
156 "Request Command Query",
160 10: {
161 1: {
162 "showname": "MySQL Protocol - response OK",
163 "fields": [
164 "Packet Length: 107",
165 "Packet Number: 1",
166 "Response Code: OK Packet (0x00)",
167 "Affected Rows: 0",
168 "Last INSERT ID: 0",
169 "Server Status: 0x4002",
170 "Warnings: 0",
171 "Session tracking data",
175 11: {
176 0: {
177 "showname": "MySQL Protocol",
178 "fields": [
179 "Packet Length: 20",
180 "Packet Number: 0",
181 "Request Command Query",
185 12: {
186 1: {
187 "showname": "MySQL Protocol - response OK",
188 "fields": [
189 "Packet Length: 107",
190 "Packet Number: 1",
191 "Response Code: OK Packet (0x00)",
192 "Affected Rows: 0",
193 "Last INSERT ID: 0",
194 "Server Status: 0x4002",
195 "Warnings: 0",
196 "Session tracking data",
200 13: {
201 0: {
202 "showname": "MySQL Protocol",
203 "fields": [
204 "Packet Length: 19",
205 "Packet Number: 0",
206 "Request Command Query",
210 14: {
211 1: {
212 "showname": "MySQL Protocol - response OK",
213 "fields": [
214 "Packet Length: 26",
215 "Packet Number: 1",
216 "Response Code: OK Packet (0x00)",
217 "Affected Rows: 0",
218 "Last INSERT ID: 0",
219 "Server Status: 0x4000",
220 "Warnings: 0",
221 "Session tracking data",
225 15: {
226 0: {
227 "showname": "MySQL Protocol",
228 "fields": [
229 "Packet Length: 1",
230 "Packet Number: 0",
231 "Request Command Ping",
235 16: {
236 1: {
237 "showname": "MySQL Protocol - response OK",
238 "fields": [
239 "Packet Length: 7",
240 "Packet Number: 1",
241 "Response Code: OK Packet (0x00)",
242 "Affected Rows: 0",
243 "Last INSERT ID: 0",
244 "Server Status: 0x0000",
245 "Warnings: 0",
249 17: {
250 0: {
251 "showname": "MySQL Protocol",
252 "fields": [
253 "Packet Length: 27",
254 "Packet Number: 0",
255 "Request Command Prepare Statement",
259 18: {
260 1: {
261 "showname": "MySQL Protocol - response to PREPARE",
262 "fields": [
263 "Packet Length: 12",
264 "Packet Number: 1",
265 "Response Code: OK Packet (0x00)",
266 "Statement ID: 1",
267 "Number of fields: 7",
268 "Number of parameter: 1",
269 "Warnings: 0",
272 2: {
273 "showname": "MySQL Protocol - parameters in response to PREPARE",
274 "fields": [
275 "Packet Length: 23",
276 "Packet Number: 2",
277 "Charset number: binary COLLATE binary (63)",
278 "Length: 21",
279 "Type: FIELD_TYPE_LONGLONG (8)",
280 "Flags: 0x0080",
281 "Decimals: 0",
284 3: {
285 "showname": "MySQL Protocol - fields in response to PREPARE",
286 "fields": [
287 "Packet Length: 34",
288 "Packet Number: 3",
289 "Charset number: binary COLLATE binary (63)",
290 "Length: 11",
291 "Type: FIELD_TYPE_LONG (3)",
292 "Flags: 0x5003",
293 "Decimals: 0",
296 4: {
297 "showname": "MySQL Protocol - fields in response to PREPARE",
298 "fields": [
299 "Packet Length: 34",
300 "Packet Number: 4",
301 "Charset number: binary COLLATE binary (63)",
302 "Length: 19",
303 "Type: FIELD_TYPE_DATETIME (12)",
304 "Flags: 0x0080",
305 "Decimals: 0",
308 5: {
309 "showname": "MySQL Protocol - fields in response to PREPARE",
310 "fields": [
311 "Packet Length: 34",
312 "Packet Number: 5",
313 "Charset number: binary COLLATE binary (63)",
314 "Length: 26",
315 "Type: FIELD_TYPE_DATETIME (12)",
316 "Flags: 0x0080",
317 "Decimals: 6",
320 6: {
321 "showname": "MySQL Protocol - fields in response to PREPARE",
322 "fields": [
323 "Packet Length: 34",
324 "Packet Number: 6",
325 "Charset number: binary COLLATE binary (63)",
326 "Length: 19",
327 "Type: FIELD_TYPE_TIMESTAMP (7)",
328 "Flags: 0x0080",
329 "Decimals: 0",
332 7: {
333 "showname": "MySQL Protocol - fields in response to PREPARE",
334 "fields": [
335 "Packet Length: 34",
336 "Packet Number: 7",
337 "Charset number: binary COLLATE binary (63)",
338 "Length: 26",
339 "Type: FIELD_TYPE_TIMESTAMP (7)",
340 "Flags: 0x0080",
341 "Decimals: 6",
344 8: {
345 "showname": "MySQL Protocol - fields in response to PREPARE",
346 "fields": [
347 "Packet Length: 34",
348 "Packet Number: 8",
349 "Charset number: binary COLLATE binary (63)",
350 "Length: 1",
351 "Type: FIELD_TYPE_BIT (16)",
352 "Flags: 0x0020",
353 "Decimals: 0",
356 9: {
357 "showname": "MySQL Protocol - fields in response to PREPARE",
358 "fields": [
359 "Packet Length: 34",
360 "Packet Number: 9",
361 "Charset number: binary COLLATE binary (63)",
362 "Length: 16",
363 "Type: FIELD_TYPE_VAR_STRING (253)",
364 "Flags: 0x0080",
365 "Decimals: 0",
369 19: {
370 0: {
371 "showname": "MySQL Protocol",
372 "fields": [
373 "Packet Length: 5",
374 "Packet Number: 0",
375 "Request Command Reset Statement",
379 20: {
380 1: {
381 "showname": "MySQL Protocol - response OK",
382 "fields": [
383 "Packet Length: 7",
384 "Packet Number: 1",
385 "Response Code: OK Packet (0x00)",
386 "Affected Rows: 0",
387 "Last INSERT ID: 0",
388 "Server Status: 0x0000",
389 "Warnings: 0",
393 21: {
394 0: {
395 "showname": "MySQL Protocol",
396 "fields": [
397 "Packet Length: 85",
398 "Packet Number: 0",
399 "Request Command Execute Statement",
403 22: {
404 1: {
405 "showname": "MySQL Protocol - column count",
406 "fields": [
407 "Packet Length: 1",
408 "Packet Number: 1",
409 "Number of fields: 7",
412 2: {
413 "showname": "MySQL Protocol - field packet",
414 "fields": [
415 "Packet Length: 34",
416 "Packet Number: 2",
417 "Charset number: binary COLLATE binary (63)",
418 "Length: 11",
419 "Type: FIELD_TYPE_LONG (3)",
420 "Flags: 0x5003",
421 "Decimals: 0",
424 3: {
425 "showname": "MySQL Protocol - field packet",
426 "fields": [
427 "Packet Length: 34",
428 "Packet Number: 3",
429 "Charset number: binary COLLATE binary (63)",
430 "Length: 19",
431 "Type: FIELD_TYPE_DATETIME (12)",
432 "Flags: 0x0080",
433 "Decimals: 0",
436 4: {
437 "showname": "MySQL Protocol - field packet",
438 "fields": [
439 "Packet Length: 34",
440 "Packet Number: 4",
441 "Charset number: binary COLLATE binary (63)",
442 "Length: 26",
443 "Type: FIELD_TYPE_DATETIME (12)",
444 "Flags: 0x0080",
445 "Decimals: 6",
448 5: {
449 "showname": "MySQL Protocol - field packet",
450 "fields": [
451 "Packet Length: 34",
452 "Packet Number: 5",
453 "Charset number: binary COLLATE binary (63)",
454 "Length: 19",
455 "Type: FIELD_TYPE_TIMESTAMP (7)",
456 "Flags: 0x0080",
457 "Decimals: 0",
460 6: {
461 "showname": "MySQL Protocol - field packet",
462 "fields": [
463 "Packet Length: 34",
464 "Packet Number: 6",
465 "Charset number: binary COLLATE binary (63)",
466 "Length: 26",
467 "Type: FIELD_TYPE_TIMESTAMP (7)",
468 "Flags: 0x0080",
469 "Decimals: 6",
472 7: {
473 "showname": "MySQL Protocol - field packet",
474 "fields": [
475 "Packet Length: 34",
476 "Packet Number: 7",
477 "Charset number: binary COLLATE binary (63)",
478 "Length: 1",
479 "Type: FIELD_TYPE_BIT (16)",
480 "Flags: 0x0020",
481 "Decimals: 0",
484 8: {
485 "showname": "MySQL Protocol - field packet",
486 "fields": [
487 "Packet Length: 34",
488 "Packet Number: 8",
489 "Charset number: binary COLLATE binary (63)",
490 "Length: 16",
491 "Type: FIELD_TYPE_VAR_STRING (253)",
492 "Flags: 0x0080",
493 "Decimals: 0",
496 9: {
497 "showname": "MySQL Protocol - row packet",
498 "fields": [
499 "Packet Length: 53",
500 "Packet Number: 9",
501 "Response Code: OK Packet (0x00)",
502 "Row null buffer: 0000",
505 10: {
506 "showname": "MySQL Protocol - response OK",
507 "fields": [
508 "Packet Length: 7",
509 "Packet Number: 10",
510 "Response Code: EOF Packet (0xfe)",
511 "EOF marker: 254",
512 "Affected Rows: 0",
513 "Last INSERT ID: 0",
514 "Server Status: 0x0021",
515 "Warnings: 0",
519 23: {
520 0: {
521 "showname": "MySQL Protocol",
522 "fields": [
523 "Packet Length: 5",
524 "Packet Number: 0",
525 "Request Command Reset Statement",
529 24: {
530 1: {
531 "showname": "MySQL Protocol - response OK",
532 "fields": [
533 "Packet Length: 7",
534 "Packet Number: 1",
535 "Response Code: OK Packet (0x00)",
536 "Affected Rows: 0",
537 "Last INSERT ID: 0",
538 "Server Status: 0x0001",
539 "Warnings: 0",
543 25: {
544 0: {
545 "showname": "MySQL Protocol",
546 "fields": [
547 "Packet Length: 5",
548 "Packet Number: 0",
549 "Request Command Close Statement",
553 26: {
554 0: {
555 "showname": "MySQL Protocol",
556 "fields": [
557 "Packet Length: 1",
558 "Packet Number: 0",
559 "Request Command Quit",
565 # Summary should look like this:
567 # <int:Packet Number>: {
568 # <int:MySQL Packet Number>: {
569 # "showname": <str>,
570 # "fields": [str, ...]
574 summary = {}
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"))
583 assert False
585 for pkt in tree:
587 # Get the packet number
588 num = int(
589 pkt.find("./proto[@name='geninfo']/field[@name='num']").attrib["show"]
591 summary[num] = {}
593 for proto in pkt.findall("./proto[@name='mysql']"):
595 mysqlnum = int(
596 proto.find("./field[@name='mysql.packet_number']").attrib["show"]
598 summary[num][mysqlnum] = {
599 "showname": proto.attrib["showname"],
600 "fields": [],
602 for field in proto.findall("./field"):
603 if "showname" in field.attrib:
604 summary[num][mysqlnum]["fields"].append(
605 field.attrib["showname"]
608 print(summary)
610 for pkt in summary:
611 for mysqlpkt in summary[pkt]:
612 assert (
613 summary[pkt][mysqlpkt]["showname"]
614 == expected[pkt][mysqlpkt]["showname"]
616 assert (
617 summary[pkt][mysqlpkt]["fields"]
618 == expected[pkt][mysqlpkt]["fields"]
621 def test_mysql_57(self, cmd_tshark, capture_file, test_env):
622 """MySQL 5.7"""
624 stdout = subprocess.check_output(
626 cmd_tshark,
627 "-r",
628 capture_file("mysql/mysql57.pcapng.gz"),
629 "-T",
630 "pdml",
631 "-J",
632 "mysql",
633 "-Y",
634 "mysql",
636 encoding="utf-8",
637 env=test_env,
640 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
641 expected = {
642 4: {
643 0: {
644 "showname": "MySQL Protocol",
645 "fields": [
646 "Packet Length: 74",
647 "Packet Number: 0",
648 "Server Greeting",
652 6: {
653 1: {
654 "showname": "MySQL Protocol",
655 "fields": [
656 "Packet Length: 181",
657 "Packet Number: 1",
658 "Login Request",
662 8: {
663 2: {
664 "showname": "MySQL Protocol - response OK",
665 "fields": [
666 "Packet Length: 7",
667 "Packet Number: 2",
668 "Response Code: OK Packet (0x00)",
669 "Affected Rows: 0",
670 "Last INSERT ID: 0",
671 "Server Status: 0x0002",
672 "Warnings: 0",
676 9: {
677 0: {
678 "showname": "MySQL Protocol",
679 "fields": [
680 "Packet Length: 33",
681 "Packet Number: 0",
682 "Request Command Query",
686 10: {
687 1: {
688 "showname": "MySQL Protocol - column count",
689 "fields": [
690 "Packet Length: 1",
691 "Packet Number: 1",
692 "Number of fields: 1",
695 2: {
696 "showname": "MySQL Protocol - field packet",
697 "fields": [
698 "Packet Length: 39",
699 "Packet Number: 2",
700 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
701 "Length: 28",
702 "Type: FIELD_TYPE_VAR_STRING (253)",
703 "Flags: 0x0000",
704 "Decimals: 31",
707 3: {
708 "showname": "MySQL Protocol - row packet",
709 "fields": ["Packet Length: 29", "Packet Number: 3"],
711 4: {
712 "showname": "MySQL Protocol - response OK",
713 "fields": [
714 "Packet Length: 7",
715 "Packet Number: 4",
716 "Response Code: EOF Packet (0xfe)",
717 "EOF marker: 254",
718 "Affected Rows: 0",
719 "Last INSERT ID: 0",
720 "Server Status: 0x0002",
721 "Warnings: 0",
725 11: {
726 0: {
727 "showname": "MySQL Protocol",
728 "fields": [
729 "Packet Length: 10",
730 "Packet Number: 0",
731 "Request Command Query",
735 12: {
736 1: {
737 "showname": "MySQL Protocol - response ERROR",
738 "fields": [
739 "Packet Length: 44",
740 "Packet Number: 1",
741 "Response Code: ERR Packet (0xff)",
742 "Error Code: 1054",
743 "SQL state: 42S22",
744 "Error message: Unknown column '$$' in 'field list'",
748 14: {
749 0: {
750 "showname": "MySQL Protocol",
751 "fields": [
752 "Packet Length: 34",
753 "Packet Number: 0",
754 "Request Command Query",
758 15: {
759 1: {
760 "showname": "MySQL Protocol - column count",
761 "fields": [
762 "Packet Length: 1",
763 "Packet Number: 1",
764 "Number of fields: 2",
767 2: {
768 "showname": "MySQL Protocol - field packet",
769 "fields": [
770 "Packet Length: 32",
771 "Packet Number: 2",
772 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
773 "Length: 34",
774 "Type: FIELD_TYPE_VAR_STRING (253)",
775 "Flags: 0x0000",
776 "Decimals: 31",
779 3: {
780 "showname": "MySQL Protocol - field packet",
781 "fields": [
782 "Packet Length: 28",
783 "Packet Number: 3",
784 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
785 "Length: 93",
786 "Type: FIELD_TYPE_VAR_STRING (253)",
787 "Flags: 0x0000",
788 "Decimals: 31",
791 4: {
792 "showname": "MySQL Protocol - row packet",
793 "fields": ["Packet Length: 16", "Packet Number: 4"],
795 5: {
796 "showname": "MySQL Protocol - response OK",
797 "fields": [
798 "Packet Length: 7",
799 "Packet Number: 5",
800 "Response Code: EOF Packet (0xfe)",
801 "EOF marker: 254",
802 "Affected Rows: 0",
803 "Last INSERT ID: 0",
804 "Server Status: 0x0002",
805 "Warnings: 0",
809 17: {
810 0: {
811 "showname": "MySQL Protocol",
812 "fields": [
813 "Packet Length: 116",
814 "Packet Number: 0",
815 "Request Command Query",
819 18: {
820 1: {
821 "showname": "MySQL Protocol - column count",
822 "fields": [
823 "Packet Length: 1",
824 "Packet Number: 1",
825 "Number of fields: 4",
828 2: {
829 "showname": "MySQL Protocol - field packet",
830 "fields": [
831 "Packet Length: 44",
832 "Packet Number: 2",
833 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
834 "Length: 6",
835 "Type: FIELD_TYPE_VAR_STRING (253)",
836 "Flags: 0x0000",
837 "Decimals: 31",
840 3: {
841 "showname": "MySQL Protocol - field packet",
842 "fields": [
843 "Packet Length: 48",
844 "Packet Number: 3",
845 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
846 "Length: 6",
847 "Type: FIELD_TYPE_VAR_STRING (253)",
848 "Flags: 0x0000",
849 "Decimals: 31",
852 4: {
853 "showname": "MySQL Protocol - field packet",
854 "fields": [
855 "Packet Length: 44",
856 "Packet Number: 4",
857 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
858 "Length: 6",
859 "Type: FIELD_TYPE_VAR_STRING (253)",
860 "Flags: 0x0000",
861 "Decimals: 31",
864 5: {
865 "showname": "MySQL Protocol - field packet",
866 "fields": [
867 "Packet Length: 46",
868 "Packet Number: 5",
869 "Charset number: latin1 COLLATE latin1_swedish_ci (8)",
870 "Length: 6",
871 "Type: FIELD_TYPE_VAR_STRING (253)",
872 "Flags: 0x0000",
873 "Decimals: 31",
876 6: {
877 "showname": "MySQL Protocol - row packet",
878 "fields": ["Packet Length: 28", "Packet Number: 6"],
880 7: {
881 "showname": "MySQL Protocol - response OK",
882 "fields": [
883 "Packet Length: 7",
884 "Packet Number: 7",
885 "Response Code: EOF Packet (0xfe)",
886 "EOF marker: 254",
887 "Affected Rows: 0",
888 "Last INSERT ID: 0",
889 "Server Status: 0x0002",
890 "Warnings: 0",
894 19: {
895 0: {
896 "showname": "MySQL Protocol",
897 "fields": [
898 "Packet Length: 1",
899 "Packet Number: 0",
900 "Request Command Statistics",
904 20: {
905 1: {
906 "showname": "MySQL Protocol",
907 "fields": [
908 "Packet Length: 132",
909 "Packet Number: 1",
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",
914 22: {
915 0: {
916 "showname": "MySQL Protocol",
917 "fields": [
918 "Packet Length: 1",
919 "Packet Number: 0",
920 "Request Command Quit",
926 # Summary should look like this:
928 # <int:Packet Number>: {
929 # <int:MySQL Packet Number>: {
930 # "showname": <str>,
931 # "fields": [str, ...]
935 summary = {}
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"))
944 assert False
946 for pkt in tree:
948 # Get the packet number
949 num = int(
950 pkt.find("./proto[@name='geninfo']/field[@name='num']").attrib["show"]
952 summary[num] = {}
954 for proto in pkt.findall("./proto[@name='mysql']"):
956 mysqlnum = int(
957 proto.find("./field[@name='mysql.packet_number']").attrib["show"]
959 summary[num][mysqlnum] = {
960 "showname": proto.attrib["showname"],
961 "fields": [],
963 for field in proto.findall("./field"):
964 if "showname" in field.attrib:
965 summary[num][mysqlnum]["fields"].append(
966 field.attrib["showname"]
969 print(summary)
971 for pkt in summary:
972 for mysqlpkt in summary[pkt]:
973 assert (
974 summary[pkt][mysqlpkt]["showname"]
975 == expected[pkt][mysqlpkt]["showname"]
977 assert (
978 summary[pkt][mysqlpkt]["fields"]
979 == expected[pkt][mysqlpkt]["fields"]
982 def test_mysql_80(self, cmd_tshark, capture_file, test_env):
983 """MySQL 8.0"""
985 stdout = subprocess.check_output(
987 cmd_tshark,
988 "-r",
989 capture_file("mysql/mysql80.pcapng.gz"),
990 "-T",
991 "pdml",
992 "-J",
993 "mysql",
994 "-Y",
995 "mysql",
997 encoding="utf-8",
998 env=test_env,
1001 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
1002 expected = {
1003 4: {
1004 0: {
1005 "showname": "MySQL Protocol",
1006 "fields": [
1007 "Packet Length: 74",
1008 "Packet Number: 0",
1009 "Server Greeting",
1013 6: {
1014 1: {
1015 "showname": "MySQL Protocol",
1016 "fields": [
1017 "Packet Length: 182",
1018 "Packet Number: 1",
1019 "Login Request",
1023 8: {
1024 2: {
1025 "showname": "MySQL Protocol - response OK",
1026 "fields": [
1027 "Packet Length: 7",
1028 "Packet Number: 2",
1029 "Response Code: OK Packet (0x00)",
1030 "Affected Rows: 0",
1031 "Last INSERT ID: 0",
1032 "Server Status: 0x0002",
1033 "Warnings: 0",
1037 9: {
1038 0: {
1039 "showname": "MySQL Protocol",
1040 "fields": [
1041 "Packet Length: 35",
1042 "Packet Number: 0",
1043 "Request Command Query",
1047 10: {
1048 1: {
1049 "showname": "MySQL Protocol - column count",
1050 "fields": [
1051 "Packet Length: 1",
1052 "Packet Number: 1",
1053 "Number of fields: 1",
1056 2: {
1057 "showname": "MySQL Protocol - field packet",
1058 "fields": [
1059 "Packet Length: 39",
1060 "Packet Number: 2",
1061 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1062 "Length: 87380",
1063 "Type: FIELD_TYPE_VAR_STRING (253)",
1064 "Flags: 0x0000",
1065 "Decimals: 31",
1068 3: {
1069 "showname": "MySQL Protocol - row packet",
1070 "fields": ["Packet Length: 29", "Packet Number: 3"],
1072 4: {
1073 "showname": "MySQL Protocol - response OK",
1074 "fields": [
1075 "Packet Length: 7",
1076 "Packet Number: 4",
1077 "Response Code: EOF Packet (0xfe)",
1078 "EOF marker: 254",
1079 "Affected Rows: 0",
1080 "Last INSERT ID: 0",
1081 "Server Status: 0x0002",
1082 "Warnings: 0",
1086 11: {
1087 0: {
1088 "showname": "MySQL Protocol",
1089 "fields": [
1090 "Packet Length: 12",
1091 "Packet Number: 0",
1092 "Request Command Query",
1096 12: {
1097 1: {
1098 "showname": "MySQL Protocol - response ERROR",
1099 "fields": [
1100 "Packet Length: 44",
1101 "Packet Number: 1",
1102 "Response Code: ERR Packet (0xff)",
1103 "Error Code: 1054",
1104 "SQL state: 42S22",
1105 "Error message: Unknown column '$$' in 'field list'",
1109 14: {
1110 0: {
1111 "showname": "MySQL Protocol",
1112 "fields": [
1113 "Packet Length: 36",
1114 "Packet Number: 0",
1115 "Request Command Query",
1119 15: {
1120 1: {
1121 "showname": "MySQL Protocol - column count",
1122 "fields": [
1123 "Packet Length: 1",
1124 "Packet Number: 1",
1125 "Number of fields: 2",
1128 2: {
1129 "showname": "MySQL Protocol - field packet",
1130 "fields": [
1131 "Packet Length: 32",
1132 "Packet Number: 2",
1133 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1134 "Length: 136",
1135 "Type: FIELD_TYPE_VAR_STRING (253)",
1136 "Flags: 0x0000",
1137 "Decimals: 31",
1140 3: {
1141 "showname": "MySQL Protocol - field packet",
1142 "fields": [
1143 "Packet Length: 28",
1144 "Packet Number: 3",
1145 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1146 "Length: 1152",
1147 "Type: FIELD_TYPE_VAR_STRING (253)",
1148 "Flags: 0x0000",
1149 "Decimals: 31",
1152 4: {
1153 "showname": "MySQL Protocol - row packet",
1154 "fields": ["Packet Length: 16", "Packet Number: 4"],
1156 5: {
1157 "showname": "MySQL Protocol - response OK",
1158 "fields": [
1159 "Packet Length: 7",
1160 "Packet Number: 5",
1161 "Response Code: EOF Packet (0xfe)",
1162 "EOF marker: 254",
1163 "Affected Rows: 0",
1164 "Last INSERT ID: 0",
1165 "Server Status: 0x0002",
1166 "Warnings: 0",
1170 17: {
1171 0: {
1172 "showname": "MySQL Protocol",
1173 "fields": [
1174 "Packet Length: 118",
1175 "Packet Number: 0",
1176 "Request Command Query",
1180 18: {
1181 1: {
1182 "showname": "MySQL Protocol - column count",
1183 "fields": [
1184 "Packet Length: 1",
1185 "Packet Number: 1",
1186 "Number of fields: 4",
1189 2: {
1190 "showname": "MySQL Protocol - field packet",
1191 "fields": [
1192 "Packet Length: 44",
1193 "Packet Number: 2",
1194 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1195 "Length: 87380",
1196 "Type: FIELD_TYPE_VAR_STRING (253)",
1197 "Flags: 0x0000",
1198 "Decimals: 31",
1201 3: {
1202 "showname": "MySQL Protocol - field packet",
1203 "fields": [
1204 "Packet Length: 48",
1205 "Packet Number: 3",
1206 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1207 "Length: 87380",
1208 "Type: FIELD_TYPE_VAR_STRING (253)",
1209 "Flags: 0x0000",
1210 "Decimals: 31",
1213 4: {
1214 "showname": "MySQL Protocol - field packet",
1215 "fields": [
1216 "Packet Length: 44",
1217 "Packet Number: 4",
1218 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1219 "Length: 87380",
1220 "Type: FIELD_TYPE_VAR_STRING (253)",
1221 "Flags: 0x0000",
1222 "Decimals: 31",
1225 5: {
1226 "showname": "MySQL Protocol - field packet",
1227 "fields": [
1228 "Packet Length: 46",
1229 "Packet Number: 5",
1230 "Charset number: utf8mb4 COLLATE utf8mb4_0900_ai_ci (255)",
1231 "Length: 87380",
1232 "Type: FIELD_TYPE_VAR_STRING (253)",
1233 "Flags: 0x0000",
1234 "Decimals: 31",
1237 6: {
1238 "showname": "MySQL Protocol - row packet",
1239 "fields": ["Packet Length: 32", "Packet Number: 6"],
1241 7: {
1242 "showname": "MySQL Protocol - response OK",
1243 "fields": [
1244 "Packet Length: 7",
1245 "Packet Number: 7",
1246 "Response Code: EOF Packet (0xfe)",
1247 "EOF marker: 254",
1248 "Affected Rows: 0",
1249 "Last INSERT ID: 0",
1250 "Server Status: 0x0002",
1251 "Warnings: 0",
1255 19: {
1256 0: {
1257 "showname": "MySQL Protocol",
1258 "fields": [
1259 "Packet Length: 1",
1260 "Packet Number: 0",
1261 "Request Command Statistics",
1265 20: {
1266 1: {
1267 "showname": "MySQL Protocol",
1268 "fields": [
1269 "Packet Length: 130",
1270 "Packet Number: 1",
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",
1275 22: {
1276 0: {
1277 "showname": "MySQL Protocol",
1278 "fields": [
1279 "Packet Length: 1",
1280 "Packet Number: 0",
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, ...]
1296 summary = {}
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"))
1305 assert False
1307 for pkt in tree:
1309 # Get the packet number
1310 num = int(
1311 pkt.find("./proto[@name='geninfo']/field[@name='num']").attrib["show"]
1313 summary[num] = {}
1315 for proto in pkt.findall("./proto[@name='mysql']"):
1317 mysqlnum = int(
1318 proto.find("./field[@name='mysql.packet_number']").attrib["show"]
1320 summary[num][mysqlnum] = {
1321 "showname": proto.attrib["showname"],
1322 "fields": [],
1324 for field in proto.findall("./field"):
1325 if "showname" in field.attrib:
1326 summary[num][mysqlnum]["fields"].append(
1327 field.attrib["showname"]
1330 print(summary)
1332 for pkt in summary:
1333 for mysqlpkt in summary[pkt]:
1334 assert (
1335 summary[pkt][mysqlpkt]["showname"]
1336 == expected[pkt][mysqlpkt]["showname"]
1338 assert (
1339 summary[pkt][mysqlpkt]["fields"]
1340 == expected[pkt][mysqlpkt]["fields"]
1343 def test_mariadb_114(self, cmd_tshark, capture_file, test_env):
1344 """MariaDB 11.4"""
1346 stdout = subprocess.check_output(
1348 cmd_tshark,
1349 "-r",
1350 capture_file("mysql/mariadb114.pcapng.gz"),
1351 "-T",
1352 "pdml",
1353 "-J",
1354 "mysql",
1355 "-Y",
1356 "mysql",
1358 encoding="utf-8",
1359 env=test_env,
1362 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
1363 expected = {
1364 4: {
1365 0: {
1366 "showname": "MySQL Protocol",
1367 "fields": [
1368 "Packet Length: 90",
1369 "Packet Number: 0",
1370 "Server Greeting",
1374 6: {
1375 1: {
1376 "showname": "MySQL Protocol",
1377 "fields": [
1378 "Packet Length: 181",
1379 "Packet Number: 1",
1380 "Login Request",
1384 8: {
1385 2: {
1386 "showname": "MySQL Protocol - response OK",
1387 "fields": [
1388 "Packet Length: 7",
1389 "Packet Number: 2",
1390 "Response Code: OK Packet (0x00)",
1391 "Affected Rows: 0",
1392 "Last INSERT ID: 0",
1393 "Server Status: 0x0002",
1394 "Warnings: 0",
1398 9: {
1399 0: {
1400 "showname": "MySQL Protocol",
1401 "fields": [
1402 "Packet Length: 33",
1403 "Packet Number: 0",
1404 "Request Command Query",
1408 10: {
1409 1: {
1410 "showname": "MySQL Protocol - column count",
1411 "fields": [
1412 "Packet Length: 1",
1413 "Packet Number: 1",
1414 "Number of fields: 1",
1417 2: {
1418 "showname": "MySQL Protocol - field packet",
1419 "fields": [
1420 "Packet Length: 39",
1421 "Packet Number: 2",
1422 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1423 "Length: 124",
1424 "Type: FIELD_TYPE_VAR_STRING (253)",
1425 "Flags: 0x0000",
1426 "Decimals: 39",
1429 3: {
1430 "showname": "MySQL Protocol - row packet",
1431 "fields": ["Packet Length: 32", "Packet Number: 3"],
1433 4: {
1434 "showname": "MySQL Protocol - response OK",
1435 "fields": [
1436 "Packet Length: 7",
1437 "Packet Number: 4",
1438 "Response Code: EOF Packet (0xfe)",
1439 "EOF marker: 254",
1440 "Affected Rows: 0",
1441 "Last INSERT ID: 0",
1442 "Server Status: 0x0002",
1443 "Warnings: 0",
1447 11: {
1448 0: {
1449 "showname": "MySQL Protocol",
1450 "fields": [
1451 "Packet Length: 10",
1452 "Packet Number: 0",
1453 "Request Command Query",
1457 12: {
1458 1: {
1459 "showname": "MySQL Protocol - response ERROR",
1460 "fields": [
1461 "Packet Length: 44",
1462 "Packet Number: 1",
1463 "Response Code: ERR Packet (0xff)",
1464 "Error Code: 1054",
1465 "SQL state: 42S22",
1466 "Error message: Unknown column '$$' in 'field list'",
1470 14: {
1471 0: {
1472 "showname": "MySQL Protocol",
1473 "fields": [
1474 "Packet Length: 34",
1475 "Packet Number: 0",
1476 "Request Command Query",
1480 15: {
1481 1: {
1482 "showname": "MySQL Protocol - column count",
1483 "fields": [
1484 "Packet Length: 1",
1485 "Packet Number: 1",
1486 "Number of fields: 2",
1489 2: {
1490 "showname": "MySQL Protocol - field packet",
1491 "fields": [
1492 "Packet Length: 32",
1493 "Packet Number: 2",
1494 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1495 "Length: 256",
1496 "Type: FIELD_TYPE_VAR_STRING (253)",
1497 "Flags: 0x0000",
1498 "Decimals: 39",
1501 3: {
1502 "showname": "MySQL Protocol - field packet",
1503 "fields": [
1504 "Packet Length: 28",
1505 "Packet Number: 3",
1506 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1507 "Length: 1536",
1508 "Type: FIELD_TYPE_VAR_STRING (253)",
1509 "Flags: 0x0000",
1510 "Decimals: 39",
1513 4: {
1514 "showname": "MySQL Protocol - row packet",
1515 "fields": ["Packet Length: 16", "Packet Number: 4"],
1517 5: {
1518 "showname": "MySQL Protocol - response OK",
1519 "fields": [
1520 "Packet Length: 7",
1521 "Packet Number: 5",
1522 "Response Code: EOF Packet (0xfe)",
1523 "EOF marker: 254",
1524 "Affected Rows: 0",
1525 "Last INSERT ID: 0",
1526 "Server Status: 0x0002",
1527 "Warnings: 0",
1531 17: {
1532 0: {
1533 "showname": "MySQL Protocol",
1534 "fields": [
1535 "Packet Length: 116",
1536 "Packet Number: 0",
1537 "Request Command Query",
1541 18: {
1542 1: {
1543 "showname": "MySQL Protocol - column count",
1544 "fields": [
1545 "Packet Length: 1",
1546 "Packet Number: 1",
1547 "Number of fields: 4",
1550 2: {
1551 "showname": "MySQL Protocol - field packet",
1552 "fields": [
1553 "Packet Length: 44",
1554 "Packet Number: 2",
1555 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1556 "Length: 28",
1557 "Type: FIELD_TYPE_VAR_STRING (253)",
1558 "Flags: 0x0000",
1559 "Decimals: 39",
1562 3: {
1563 "showname": "MySQL Protocol - field packet",
1564 "fields": [
1565 "Packet Length: 48",
1566 "Packet Number: 3",
1567 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1568 "Length: 28",
1569 "Type: FIELD_TYPE_VAR_STRING (253)",
1570 "Flags: 0x0000",
1571 "Decimals: 39",
1574 4: {
1575 "showname": "MySQL Protocol - field packet",
1576 "fields": [
1577 "Packet Length: 44",
1578 "Packet Number: 4",
1579 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1580 "Length: 28",
1581 "Type: FIELD_TYPE_VAR_STRING (253)",
1582 "Flags: 0x0000",
1583 "Decimals: 39",
1586 5: {
1587 "showname": "MySQL Protocol - field packet",
1588 "fields": [
1589 "Packet Length: 46",
1590 "Packet Number: 5",
1591 "Charset number: utf8mb4 COLLATE utf8mb4_unicode_ci (224)",
1592 "Length: 28",
1593 "Type: FIELD_TYPE_VAR_STRING (253)",
1594 "Flags: 0x0000",
1595 "Decimals: 39",
1598 6: {
1599 "showname": "MySQL Protocol - row packet",
1600 "fields": ["Packet Length: 32", "Packet Number: 6"],
1602 7: {
1603 "showname": "MySQL Protocol - response OK",
1604 "fields": [
1605 "Packet Length: 7",
1606 "Packet Number: 7",
1607 "Response Code: EOF Packet (0xfe)",
1608 "EOF marker: 254",
1609 "Affected Rows: 0",
1610 "Last INSERT ID: 0",
1611 "Server Status: 0x0002",
1612 "Warnings: 0",
1616 19: {
1617 0: {
1618 "showname": "MySQL Protocol",
1619 "fields": [
1620 "Packet Length: 1",
1621 "Packet Number: 0",
1622 "Request Command Statistics",
1626 20: {
1627 1: {
1628 "showname": "MySQL Protocol",
1629 "fields": [
1630 "Packet Length: 112",
1631 "Packet Number: 1",
1632 "Message: Uptime: 25 Threads: 1 Questions: 5 Slow queries: 0 Opens: 17 Open tables: 10 Queries per second avg: 0.200",
1636 22: {
1637 0: {
1638 "showname": "MySQL Protocol",
1639 "fields": [
1640 "Packet Length: 1",
1641 "Packet Number: 0",
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, ...]
1657 summary = {}
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"))
1666 assert False
1668 for pkt in tree:
1670 # Get the packet number
1671 num = int(
1672 pkt.find("./proto[@name='geninfo']/field[@name='num']").attrib["show"]
1674 summary[num] = {}
1676 for proto in pkt.findall("./proto[@name='mysql']"):
1678 mysqlnum = int(
1679 proto.find("./field[@name='mysql.packet_number']").attrib["show"]
1681 summary[num][mysqlnum] = {
1682 "showname": proto.attrib["showname"],
1683 "fields": [],
1685 for field in proto.findall("./field"):
1686 if "showname" in field.attrib:
1687 summary[num][mysqlnum]["fields"].append(
1688 field.attrib["showname"]
1691 print(summary)
1693 for pkt in summary:
1694 for mysqlpkt in summary[pkt]:
1695 assert (
1696 summary[pkt][mysqlpkt]["showname"]
1697 == expected[pkt][mysqlpkt]["showname"]
1699 assert (
1700 summary[pkt][mysqlpkt]["fields"]
1701 == expected[pkt][mysqlpkt]["fields"]
1704 def test_tidb_81(self, cmd_tshark, capture_file, test_env):
1705 """TiDB 8.1"""
1707 stdout = subprocess.check_output(
1709 cmd_tshark,
1710 "-r",
1711 capture_file("mysql/tidb81.pcapng.gz"),
1712 "-T",
1713 "pdml",
1714 "-J",
1715 "mysql",
1716 "-Y",
1717 "mysql",
1719 encoding="utf-8",
1720 env=test_env,
1723 # This is just a copy-paste of the `summary` variable and then formatted with the black formatter for python.
1724 expected = {
1725 4: {
1726 0: {
1727 "showname": "MySQL Protocol",
1728 "fields": [
1729 "Packet Length: 86",
1730 "Packet Number: 0",
1731 "Server Greeting",
1735 6: {
1736 1: {
1737 "showname": "MySQL Protocol",
1738 "fields": [
1739 "Packet Length: 181",
1740 "Packet Number: 1",
1741 "Login Request",
1745 8: {
1746 2: {
1747 "showname": "MySQL Protocol - response OK",
1748 "fields": [
1749 "Packet Length: 7",
1750 "Packet Number: 2",
1751 "Response Code: OK Packet (0x00)",
1752 "Affected Rows: 0",
1753 "Last INSERT ID: 0",
1754 "Server Status: 0x0002",
1755 "Warnings: 0",
1759 9: {
1760 0: {
1761 "showname": "MySQL Protocol",
1762 "fields": [
1763 "Packet Length: 33",
1764 "Packet Number: 0",
1765 "Request Command Query",
1769 10: {
1770 1: {
1771 "showname": "MySQL Protocol - column count",
1772 "fields": [
1773 "Packet Length: 1",
1774 "Packet Number: 1",
1775 "Number of fields: 1",
1778 2: {
1779 "showname": "MySQL Protocol - field packet",
1780 "fields": [
1781 "Packet Length: 39",
1782 "Packet Number: 2",
1783 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1784 "Length: 0",
1785 "Type: FIELD_TYPE_VAR_STRING (253)",
1786 "Flags: 0x0000",
1787 "Decimals: 31",
1790 3: {
1791 "showname": "MySQL Protocol - row packet",
1792 "fields": ["Packet Length: 73", "Packet Number: 3"],
1794 4: {
1795 "showname": "MySQL Protocol - response OK",
1796 "fields": [
1797 "Packet Length: 7",
1798 "Packet Number: 4",
1799 "Response Code: EOF Packet (0xfe)",
1800 "EOF marker: 254",
1801 "Affected Rows: 0",
1802 "Last INSERT ID: 0",
1803 "Server Status: 0x0002",
1804 "Warnings: 0",
1808 11: {
1809 0: {
1810 "showname": "MySQL Protocol",
1811 "fields": [
1812 "Packet Length: 10",
1813 "Packet Number: 0",
1814 "Request Command Query",
1818 12: {
1819 1: {
1820 "showname": "MySQL Protocol - response ERROR",
1821 "fields": [
1822 "Packet Length: 44",
1823 "Packet Number: 1",
1824 "Response Code: ERR Packet (0xff)",
1825 "Error Code: 1054",
1826 "SQL state: 42S22",
1827 "Error message: Unknown column '$$' in 'field list'",
1831 14: {
1832 0: {
1833 "showname": "MySQL Protocol",
1834 "fields": [
1835 "Packet Length: 34",
1836 "Packet Number: 0",
1837 "Request Command Query",
1841 15: {
1842 1: {
1843 "showname": "MySQL Protocol - column count",
1844 "fields": [
1845 "Packet Length: 1",
1846 "Packet Number: 1",
1847 "Number of fields: 2",
1850 2: {
1851 "showname": "MySQL Protocol - field packet",
1852 "fields": [
1853 "Packet Length: 32",
1854 "Packet Number: 2",
1855 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1856 "Length: 256",
1857 "Type: FIELD_TYPE_VAR_STRING (253)",
1858 "Flags: 0x0000",
1859 "Decimals: 31",
1862 3: {
1863 "showname": "MySQL Protocol - field packet",
1864 "fields": [
1865 "Packet Length: 28",
1866 "Packet Number: 3",
1867 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1868 "Length: 256",
1869 "Type: FIELD_TYPE_VAR_STRING (253)",
1870 "Flags: 0x0001",
1871 "Decimals: 31",
1874 4: {
1875 "showname": "MySQL Protocol - row packet",
1876 "fields": ["Packet Length: 16", "Packet Number: 4"],
1878 5: {
1879 "showname": "MySQL Protocol - response OK",
1880 "fields": [
1881 "Packet Length: 7",
1882 "Packet Number: 5",
1883 "Response Code: EOF Packet (0xfe)",
1884 "EOF marker: 254",
1885 "Affected Rows: 0",
1886 "Last INSERT ID: 0",
1887 "Server Status: 0x0002",
1888 "Warnings: 0",
1892 17: {
1893 0: {
1894 "showname": "MySQL Protocol",
1895 "fields": [
1896 "Packet Length: 116",
1897 "Packet Number: 0",
1898 "Request Command Query",
1902 18: {
1903 1: {
1904 "showname": "MySQL Protocol - column count",
1905 "fields": [
1906 "Packet Length: 1",
1907 "Packet Number: 1",
1908 "Number of fields: 4",
1911 2: {
1912 "showname": "MySQL Protocol - field packet",
1913 "fields": [
1914 "Packet Length: 44",
1915 "Packet Number: 2",
1916 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1917 "Length: 0",
1918 "Type: FIELD_TYPE_VAR_STRING (253)",
1919 "Flags: 0x0000",
1920 "Decimals: 31",
1923 3: {
1924 "showname": "MySQL Protocol - field packet",
1925 "fields": [
1926 "Packet Length: 48",
1927 "Packet Number: 3",
1928 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1929 "Length: 0",
1930 "Type: FIELD_TYPE_VAR_STRING (253)",
1931 "Flags: 0x0000",
1932 "Decimals: 31",
1935 4: {
1936 "showname": "MySQL Protocol - field packet",
1937 "fields": [
1938 "Packet Length: 44",
1939 "Packet Number: 4",
1940 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1941 "Length: 0",
1942 "Type: FIELD_TYPE_VAR_STRING (253)",
1943 "Flags: 0x0000",
1944 "Decimals: 31",
1947 5: {
1948 "showname": "MySQL Protocol - field packet",
1949 "fields": [
1950 "Packet Length: 46",
1951 "Packet Number: 5",
1952 "Charset number: utf8mb4 COLLATE utf8mb4_bin (46)",
1953 "Length: 0",
1954 "Type: FIELD_TYPE_VAR_STRING (253)",
1955 "Flags: 0x0000",
1956 "Decimals: 31",
1959 6: {
1960 "showname": "MySQL Protocol - row packet",
1961 "fields": ["Packet Length: 32", "Packet Number: 6"],
1963 7: {
1964 "showname": "MySQL Protocol - response OK",
1965 "fields": [
1966 "Packet Length: 7",
1967 "Packet Number: 7",
1968 "Response Code: EOF Packet (0xfe)",
1969 "EOF marker: 254",
1970 "Affected Rows: 0",
1971 "Last INSERT ID: 0",
1972 "Server Status: 0x0002",
1973 "Warnings: 0",
1977 19: {
1978 0: {
1979 "showname": "MySQL Protocol",
1980 "fields": [
1981 "Packet Length: 1",
1982 "Packet Number: 0",
1983 "Request Command Statistics",
1987 20: {
1988 1: {
1989 "showname": "MySQL Protocol",
1990 "fields": [
1991 "Packet Length: 127",
1992 "Packet Number: 1",
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",
1997 22: {
1998 0: {
1999 "showname": "MySQL Protocol",
2000 "fields": [
2001 "Packet Length: 1",
2002 "Packet Number: 0",
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, ...]
2018 summary = {}
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"))
2027 assert False
2029 for pkt in tree:
2031 # Get the packet number
2032 num = int(
2033 pkt.find("./proto[@name='geninfo']/field[@name='num']").attrib["show"]
2035 summary[num] = {}
2037 for proto in pkt.findall("./proto[@name='mysql']"):
2039 mysqlnum = int(
2040 proto.find("./field[@name='mysql.packet_number']").attrib["show"]
2042 summary[num][mysqlnum] = {
2043 "showname": proto.attrib["showname"],
2044 "fields": [],
2046 for field in proto.findall("./field"):
2047 if "showname" in field.attrib:
2048 summary[num][mysqlnum]["fields"].append(
2049 field.attrib["showname"]
2052 print(summary)
2054 for pkt in summary:
2055 for mysqlpkt in summary[pkt]:
2056 assert (
2057 summary[pkt][mysqlpkt]["showname"]
2058 == expected[pkt][mysqlpkt]["showname"]
2060 assert (
2061 summary[pkt][mysqlpkt]["fields"]
2062 == expected[pkt][mysqlpkt]["fields"]