test: reduce further influence from the environment
[metze/wireshark/wip.git] / test / suite_follow.py
1 #
2 # -*- coding: utf-8 -*-
3 # Wireshark tests
4 #
5 # Copyright (c) 2018 Peter Wu <peter@lekensteyn.nl>
6 #
7 # SPDX-License-Identifier: GPL-2.0-or-later
8 #
9 '''Follow Stream tests'''
10
11 import config
12 import os.path
13 import subprocesstest
14 import unittest
15
16
17 class case_follow_tcp(subprocesstest.SubprocessTestCase):
18     def test_follow_tcp_bad_conditions(self):
19         '''Checks whether Follow TCP correctly handles lots of edge cases.'''
20         # Edge cases include:
21         # 1. two sequential segments
22         # 2. out-of-order (swapped two sequential segments)
23         # 3. Bad overlap (second overlap with different data should be ignored)
24         # 4. Ignore bad retransmitted data, but extend with remaining data.
25         # 5. Check handling of overlapping data while fragments are incomplete
26         #    (out-of-order - cannot add fragments to stream)
27         # 6. lost but acked segments
28         # 7. lost 3/5 fragments, but acked
29         # Not checked: lost and not acked (currently truncated, is that OK?)
30         capture_file = os.path.join(config.capture_dir, 'tcp-badsegments.pcap')
31         proc = self.runProcess([config.cmd_tshark,
32                                 '-r', capture_file,
33                                 '-qz', 'follow,tcp,hex,0',
34                                 ], env=config.test_env)
35
36         self.assertIn("""\
37 ===================================================================
38 Follow: tcp,hex
39 Filter: tcp.stream eq 0
40 Node 0: 10.0.0.1:32323
41 Node 1: 10.0.0.2:80
42 00000000  47 45 54 20 2f 20 48 54  54 50 2f 31 2e 31 0d 0a  GET / HT TP/1.1..
43 00000010  48 6f 73 74 3a 6c 6f 63  61 6c 68 6f 73 74 0d 0a  Host:loc alhost..
44 00000020  58 2d 53 77 61 70 70 65  64 3a 20 31 73 74 0d 0a  X-Swappe d: 1st..
45 00000030  58 2d 53 77 61 70 70 65  64 3a 20 32 6e 64 0d 0a  X-Swappe d: 2nd..
46 00000040  58 2d 4f 76 65 72 6c 61  70 2d 50 61 63 6b 65 74  X-Overla p-Packet
47 00000050  3a 20 65 78 74 72 61 20  64 61 74 61 2d 2d 0d 0a  : extra  data--..
48 00000060  58 2d 4f 6f 4f 2d 4f 76  65 72 6c 61 70 3a 20 74  X-OoO-Ov erlap: t
49 00000070  68 69 73 20 69 73 20 64  65 6c 61 79 65 64 0d 0a  his is d elayed..
50 00000080  58 2d 4f 6f 4f 2d 4f 76  65 72 6c 61 70 32 3a 20  X-OoO-Ov erlap2:
51 00000090  73 65 63 6f 6e 64 20 64  65 6c 61 79 65 64 0d 0a  second d elayed..
52 000000A0  58 2d 4f 6f 4f 2d 4f 76  65 72 6c 61 70 33 3a 65  X-OoO-Ov erlap3:e
53 000000B0  78 74 65 6e 64 20 66 72  61 67 6d 65 6e 74 0d 0a  xtend fr agment..
54 000000C0  5b 33 32 20 62 79 74 65  73 20 6d 69 73 73 69 6e  [32 byte s missin
55 000000D0  67 20 69 6e 20 63 61 70  74 75 72 65 20 66 69 6c  g in cap ture fil
56 000000E0  65 5d 00                                          e].
57 000000E3  58 2d 4d 69 73 73 69 6e  67 2d 42 75 74 2d 41 63  X-Missin g-But-Ac
58 000000F3  6b 65 64 2d 50 72 65 76  69 6f 75 73 3a 31 0d 0a  ked-Prev ious:1..
59 00000103  5b 31 36 20 62 79 74 65  73 20 6d 69 73 73 69 6e  [16 byte s missin
60 00000113  67 20 69 6e 20 63 61 70  74 75 72 65 20 66 69 6c  g in cap ture fil
61 00000123  65 5d 00                                          e].
62 00000126  3a                                                :
63 00000127  5b 31 33 20 62 79 74 65  73 20 6d 69 73 73 69 6e  [13 byte s missin
64 00000137  67 20 69 6e 20 63 61 70  74 75 72 65 20 66 69 6c  g in cap ture fil
65 00000147  65 5d 00                                          e].
66 0000014A  0d                                                .
67 0000014B  5b 31 20 62 79 74 65 73  20 6d 69 73 73 69 6e 67  [1 bytes  missing
68 0000015B  20 69 6e 20 63 61 70 74  75 72 65 20 66 69 6c 65   in capt ure file
69 0000016B  5d 00                                             ].
70 0000016D  58 2d 4d 69 73 73 69 6e  67 2d 33 2d 4f 75 74 2d  X-Missin g-3-Out-
71 0000017D  4f 66 2d 35 2d 42 75 74  2d 41 43 4b 3a 59 0d 0a  Of-5-But -ACK:Y..
72 0000018D  0d 0a                                             ..
73 ===================================================================
74 """.replace("\r\n", "\n"),
75             proc.stdout_str.replace("\r\n", "\n"))