]>
Commit | Line | Data |
---|---|---|
0f9db2d6 AJ |
1 | #include "config.h" |
2 | #include <cppunit/TestAssert.h> | |
3 | ||
4 | #include "testHttpReply.h" | |
5 | #include "HttpReply.h" | |
6 | #include "Mem.h" | |
7 | ||
0f9db2d6 AJ |
8 | CPPUNIT_TEST_SUITE_REGISTRATION( testHttpReply ); |
9 | ||
10 | struct SquidConfig Config; | |
11 | ||
12 | /* stub functions to link successfully */ | |
13 | ||
14 | #include "Store.h" | |
15 | void | |
16 | StoreEntry::timestampsSet() | |
17 | { | |
18 | fatal("StoreEntry::timestampsSet. Not implemented."); | |
19 | } | |
20 | ||
21 | void | |
22 | StoreEntry::setPublicKey() | |
23 | { | |
24 | fatal("StoreEntry::setPulicKey. Not implemented."); | |
25 | } | |
26 | ||
27 | #include "MemObject.h" | |
28 | int64_t | |
29 | MemObject::endOffset() const | |
30 | { | |
31 | return 0; | |
32 | } | |
33 | ||
34 | #include "ConfigParser.h" | |
35 | void | |
36 | ConfigParser::destruct() | |
37 | { | |
38 | // CALLED as shutdown no-op | |
39 | // fatal("ConfigParser::destruct. Not implemented."); | |
40 | } | |
41 | ||
42 | void | |
43 | eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata) | |
44 | { | |
45 | // CALLED as setUp no-op | |
46 | // fatal("eventAdd. Not implemented."); | |
47 | } | |
48 | ||
49 | /* end */ | |
50 | ||
51 | void | |
52 | testHttpReply::setUp() | |
53 | { | |
54 | Mem::Init(); | |
55 | httpHeaderInitModule(); | |
56 | } | |
57 | ||
58 | void | |
59 | testHttpReply::testSanityCheckFirstLine() | |
60 | { | |
61 | MemBuf input; | |
62 | HttpReply engine; | |
63 | http_status error = HTTP_STATUS_NONE; | |
64 | size_t hdr_len; | |
65 | input.init(); | |
66 | ||
67 | // a valid status line | |
68 | input.append("HTTP/1.1 200 Okay\n\n", 19); | |
69 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
70 | CPPUNIT_ASSERT( 1 && engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
71 | CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE); | |
72 | input.reset(); | |
73 | error = HTTP_STATUS_NONE; | |
74 | ||
75 | input.append("HTTP/1.1 200 Okay \n\n", 28); | |
76 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
77 | CPPUNIT_ASSERT( 2 && engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
78 | CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE); | |
79 | input.reset(); | |
80 | error = HTTP_STATUS_NONE; | |
81 | ||
82 | #if TODO // these cases are only checked after parse... | |
83 | // invalid status line | |
84 | input.append("HTTP/1.1 999 Okay\n\n", 19); | |
85 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
86 | CPPUNIT_ASSERT( 3 && !engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
87 | CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER); | |
88 | input.reset(); | |
89 | error = HTTP_STATUS_NONE; | |
90 | ||
91 | input.append("HTTP/1.1 2000 Okay \n\n", 29); | |
92 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
93 | CPPUNIT_ASSERT( 4 && engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
94 | CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE); | |
95 | input.reset(); | |
96 | error = HTTP_STATUS_NONE; | |
97 | #endif | |
98 | ||
e77d7ef0 AJ |
99 | // valid ICY protocol status line |
100 | input.append("ICY 200 Okay\n\n", 18); | |
101 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
102 | CPPUNIT_ASSERT( engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
103 | CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE); | |
104 | input.reset(); | |
105 | error = HTTP_STATUS_NONE; | |
0f741291 AJ |
106 | /* NP: the engine saves details about the protocol. even when being reset :( */ |
107 | engine.protoPrefix="HTTP/"; | |
108 | engine.reset(); | |
e77d7ef0 | 109 | |
0f9db2d6 AJ |
110 | // empty status line |
111 | input.append("\n\n", 2); | |
112 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
113 | CPPUNIT_ASSERT( 5 && !engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
114 | CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER); | |
115 | input.reset(); | |
116 | error = HTTP_STATUS_NONE; | |
117 | ||
118 | input.append(" \n\n", 8); | |
119 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
120 | CPPUNIT_ASSERT( 6 && !engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
121 | CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER); | |
122 | input.reset(); | |
123 | error = HTTP_STATUS_NONE; | |
124 | ||
125 | // status line with no message | |
126 | input.append("HTTP/1.1 200\n\n", 14); /* real case seen */ | |
127 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
128 | CPPUNIT_ASSERT(engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
129 | CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE); | |
130 | input.reset(); | |
131 | error = HTTP_STATUS_NONE; | |
132 | ||
133 | input.append("HTTP/1.1 200 \n\n", 15); /* real case seen */ | |
134 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
135 | CPPUNIT_ASSERT(engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
136 | CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE); | |
137 | input.reset(); | |
138 | error = HTTP_STATUS_NONE; | |
139 | ||
6934ca51 AJ |
140 | // incomplete (short) status lines... not sane (yet), but no error either. |
141 | input.append("H", 1); | |
142 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
143 | CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
144 | CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE); | |
145 | input.reset(); | |
146 | error = HTTP_STATUS_NONE; | |
147 | ||
148 | input.append("HTTP/", 5); | |
149 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
150 | CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
151 | CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE); | |
152 | input.reset(); | |
153 | error = HTTP_STATUS_NONE; | |
154 | ||
155 | input.append("HTTP/1", 6); | |
156 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
157 | CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
158 | CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE); | |
159 | input.reset(); | |
160 | error = HTTP_STATUS_NONE; | |
161 | ||
162 | input.append("HTTP/1.1", 8); | |
163 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
164 | CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
165 | CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE); | |
166 | input.reset(); | |
167 | error = HTTP_STATUS_NONE; | |
168 | ||
169 | input.append("HTTP/1.1 ", 9); /* real case seen */ | |
170 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
171 | CPPUNIT_ASSERT(engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
172 | CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE); | |
173 | input.reset(); | |
174 | error = HTTP_STATUS_NONE; | |
175 | ||
176 | input.append("HTTP/1.1 20", 14); | |
177 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
178 | CPPUNIT_ASSERT(engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
179 | CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE); | |
180 | input.reset(); | |
181 | error = HTTP_STATUS_NONE; | |
0f9db2d6 AJ |
182 | |
183 | // status line with no status | |
184 | input.append("HTTP/1.1 \n\n", 11); | |
185 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
186 | CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
187 | CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER); | |
188 | input.reset(); | |
189 | error = HTTP_STATUS_NONE; | |
190 | ||
191 | input.append("HTTP/1.1 \n\n", 15); | |
192 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
193 | CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
194 | CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER); | |
195 | input.reset(); | |
196 | error = HTTP_STATUS_NONE; | |
197 | ||
198 | input.append("HTTP/1.1 Okay\n\n", 16); /* real case seen */ | |
199 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
200 | CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
201 | CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER); | |
202 | input.reset(); | |
203 | error = HTTP_STATUS_NONE; | |
204 | ||
205 | // status line with nul-byte | |
206 | input.append("HTTP/1.1\0200 Okay\n\n", 19); /* real case seen */ | |
207 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
208 | CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
209 | CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER); | |
210 | input.reset(); | |
211 | error = HTTP_STATUS_NONE; | |
212 | ||
213 | // status line with negative status | |
214 | input.append("HTTP/1.1 -000\n\n", 15); /* real case seen */ | |
215 | hdr_len = headersEnd(input.content(),input.contentSize()); | |
216 | CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) ); | |
217 | CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER); | |
218 | input.reset(); | |
219 | error = HTTP_STATUS_NONE; | |
0f9db2d6 | 220 | } |