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