1 # Copyright (c) 2013 by Gilbert Ramirez <gram@alumni.rice.edu>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 from dftestlib
import dftest
22 class testString(dftest
.DFTest
):
23 trace_file
= "http.pcap"
26 dfilter
= 'http.request.method == "HEAD"'
27 self
.assertDFilterCount(dfilter
, 1)
30 dfilter
= 'http.request.method == "POST"'
31 self
.assertDFilterCount(dfilter
, 0)
34 dfilter
= 'http.request.method > "HEAC"'
35 self
.assertDFilterCount(dfilter
, 1)
38 dfilter
= 'http.request.method > "HEAD"'
39 self
.assertDFilterCount(dfilter
, 0)
42 dfilter
= 'http.request.method > "HEAE"'
43 self
.assertDFilterCount(dfilter
, 0)
46 dfilter
= 'http.request.method >= "HEAC"'
47 self
.assertDFilterCount(dfilter
, 1)
50 dfilter
= 'http.request.method >= "HEAD"'
51 self
.assertDFilterCount(dfilter
, 1)
54 dfilter
= 'http.request.method >= "HEAE"'
55 self
.assertDFilterCount(dfilter
, 0)
58 dfilter
= 'http.request.method < "HEAC"'
59 self
.assertDFilterCount(dfilter
, 0)
62 dfilter
= 'http.request.method < "HEAD"'
63 self
.assertDFilterCount(dfilter
, 0)
66 dfilter
= 'http.request.method < "HEAE"'
67 self
.assertDFilterCount(dfilter
, 1)
70 dfilter
= 'http.request.method <= "HEAC"'
71 self
.assertDFilterCount(dfilter
, 0)
74 dfilter
= 'http.request.method <= "HEAD"'
75 self
.assertDFilterCount(dfilter
, 1)
78 dfilter
= 'http.request.method <= "HEAE"'
79 self
.assertDFilterCount(dfilter
, 1)
81 def test_slice_1(self
):
82 dfilter
= 'http.request.method[0] == "H"'
83 self
.assertDFilterCount(dfilter
, 1)
85 def test_slice_2(self
):
86 dfilter
= 'http.request.method[0] == "P"'
87 self
.assertDFilterCount(dfilter
, 0)
89 def test_slice_3(self
):
90 dfilter
= 'http.request.method[0:4] == "HEAD"'
91 self
.assertDFilterCount(dfilter
, 1)
93 def test_slice_4(self
):
94 dfilter
= 'http.request.method[0:4] != "HEAD"'
95 self
.assertDFilterCount(dfilter
, 0)
97 def test_slice_5(self
):
98 dfilter
= 'http.request.method[1:2] == "EA"'
99 self
.assertDFilterCount(dfilter
, 1)
101 def test_slice_6(self
):
102 dfilter
= 'http.request.method[1:2] > "EA"'
103 self
.assertDFilterCount(dfilter
, 0)
105 def test_slice_7(self
):
106 dfilter
= 'http.request.method[-1] == "D"'
107 self
.assertDFilterCount(dfilter
, 1)
109 def test_slice_8(self
):
110 dfilter
= 'http.request.method[-2] == "D"'
111 self
.assertDFilterCount(dfilter
, 0)
113 def xxxtest_stringz_1(self
):
114 return self
.DFilterCount(pkt_tftp
,
115 'tftp.type == "octet"', 1)
117 def xxxtest_stringz_2(self
):
118 return self
.DFilterCount(pkt_tftp
,
119 'tftp.type == "junk"', 0)
121 def test_contains_1(self
):
122 dfilter
= 'http.request.method contains "E"'
123 self
.assertDFilterCount(dfilter
, 1)
125 def test_contains_2(self
):
126 dfilter
= 'http.request.method contains "EA"'
127 self
.assertDFilterCount(dfilter
, 1)
129 def test_contains_3(self
):
130 dfilter
= 'http.request.method contains "HEAD"'
131 self
.assertDFilterCount(dfilter
, 1)
133 def test_contains_4(self
):
134 dfilter
= 'http.request.method contains "POST"'
135 self
.assertDFilterCount(dfilter
, 0)
137 def test_contains_5(self
):
138 dfilter
= 'http.request.method contains 50:4f:53:54' # "POST"
139 self
.assertDFilterCount(dfilter
, 0)
141 def test_contains_6(self
):
142 dfilter
= 'http.request.method contains 48:45:41:44' # "HEAD"
143 self
.assertDFilterCount(dfilter
, 1)
145 def test_contains_fail_0(self
):
146 dfilter
= 'http.user_agent contains "update"'
147 self
.assertDFilterCount(dfilter
, 0)
149 def test_contains_fail_1(self
):
150 dfilter
= 'http.user_agent contains "UPDATE"'
151 self
.assertDFilterCount(dfilter
, 0)
153 def test_contains_upper_0(self
):
154 dfilter
= 'upper(http.user_agent) contains "UPDATE"'
155 self
.assertDFilterCount(dfilter
, 1)
157 def test_contains_upper_1(self
):
158 dfilter
= 'upper(http.user_agent) contains "update"'
159 self
.assertDFilterCount(dfilter
, 0)
161 def test_contains_upper_2(self
):
162 dfilter
= 'upper(tcp.seq) == 4'
163 self
.assertDFilterFail(dfilter
)
165 def test_contains_lower_0(self
):
166 dfilter
= 'lower(http.user_agent) contains "UPDATE"'
167 self
.assertDFilterCount(dfilter
, 0)
169 def test_contains_lower_1(self
):
170 dfilter
= 'lower(http.user_agent) contains "update"'
171 self
.assertDFilterCount(dfilter
, 1)
173 def test_contains_lower_2(self
):
174 dfilter
= 'lower(tcp.seq) == 4'
175 self
.assertDFilterFail(dfilter
)