]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testHttpReply.cc
2 #include <cppunit/TestAssert.h>
4 #include "testHttpReply.h"
8 /* to avoid libsquid.la and its comm stuff */
9 #include "TextException.cc"
11 CPPUNIT_TEST_SUITE_REGISTRATION( testHttpReply
);
13 struct SquidConfig Config
;
15 /* stub functions to link successfully */
19 StoreEntry::timestampsSet()
21 fatal("StoreEntry::timestampsSet. Not implemented.");
25 StoreEntry::setPublicKey()
27 fatal("StoreEntry::setPulicKey. Not implemented.");
30 #include "MemObject.h"
32 MemObject::endOffset() const
37 #include "ConfigParser.h"
39 ConfigParser::destruct()
41 // CALLED as shutdown no-op
42 // fatal("ConfigParser::destruct. Not implemented.");
46 eventAdd(const char *name
, EVH
* func
, void *arg
, double when
, int, bool cbdata
)
48 // CALLED as setUp no-op
49 // fatal("eventAdd. Not implemented.");
55 testHttpReply::setUp()
58 httpHeaderInitModule();
62 testHttpReply::testSanityCheckFirstLine()
66 http_status error
= HTTP_STATUS_NONE
;
70 // a valid status line
71 input
.append("HTTP/1.1 200 Okay\n\n", 19);
72 hdr_len
= headersEnd(input
.content(),input
.contentSize());
73 CPPUNIT_ASSERT( 1 && engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
74 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
76 error
= HTTP_STATUS_NONE
;
78 input
.append("HTTP/1.1 200 Okay \n\n", 28);
79 hdr_len
= headersEnd(input
.content(),input
.contentSize());
80 CPPUNIT_ASSERT( 2 && engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
81 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
83 error
= HTTP_STATUS_NONE
;
85 #if TODO // these cases are only checked after parse...
86 // invalid status line
87 input
.append("HTTP/1.1 999 Okay\n\n", 19);
88 hdr_len
= headersEnd(input
.content(),input
.contentSize());
89 CPPUNIT_ASSERT( 3 && !engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
90 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
92 error
= HTTP_STATUS_NONE
;
94 input
.append("HTTP/1.1 2000 Okay \n\n", 29);
95 hdr_len
= headersEnd(input
.content(),input
.contentSize());
96 CPPUNIT_ASSERT( 4 && engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
97 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
99 error
= HTTP_STATUS_NONE
;
103 input
.append("\n\n", 2);
104 hdr_len
= headersEnd(input
.content(),input
.contentSize());
105 CPPUNIT_ASSERT( 5 && !engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
106 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
108 error
= HTTP_STATUS_NONE
;
110 input
.append(" \n\n", 8);
111 hdr_len
= headersEnd(input
.content(),input
.contentSize());
112 CPPUNIT_ASSERT( 6 && !engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
113 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
115 error
= HTTP_STATUS_NONE
;
117 // status line with no message
118 input
.append("HTTP/1.1 200\n\n", 14); /* real case seen */
119 hdr_len
= headersEnd(input
.content(),input
.contentSize());
120 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
121 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
123 error
= HTTP_STATUS_NONE
;
125 input
.append("HTTP/1.1 200 \n\n", 15); /* real case seen */
126 hdr_len
= headersEnd(input
.content(),input
.contentSize());
127 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
128 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
130 error
= HTTP_STATUS_NONE
;
132 // incomplete (short) status lines... not sane (yet), but no error either.
133 input
.append("H", 1);
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
);
138 error
= HTTP_STATUS_NONE
;
140 input
.append("HTTP/", 5);
141 hdr_len
= headersEnd(input
.content(),input
.contentSize());
142 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
143 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
145 error
= HTTP_STATUS_NONE
;
147 input
.append("HTTP/1", 6);
148 hdr_len
= headersEnd(input
.content(),input
.contentSize());
149 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
150 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
152 error
= HTTP_STATUS_NONE
;
154 input
.append("HTTP/1.1", 8);
155 hdr_len
= headersEnd(input
.content(),input
.contentSize());
156 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
157 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
159 error
= HTTP_STATUS_NONE
;
161 input
.append("HTTP/1.1 ", 9); /* real case seen */
162 hdr_len
= headersEnd(input
.content(),input
.contentSize());
163 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
164 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
166 error
= HTTP_STATUS_NONE
;
168 input
.append("HTTP/1.1 20", 14);
169 hdr_len
= headersEnd(input
.content(),input
.contentSize());
170 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
171 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
173 error
= HTTP_STATUS_NONE
;
175 // status line with no status
176 input
.append("HTTP/1.1 \n\n", 11);
177 hdr_len
= headersEnd(input
.content(),input
.contentSize());
178 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
179 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
181 error
= HTTP_STATUS_NONE
;
183 input
.append("HTTP/1.1 \n\n", 15);
184 hdr_len
= headersEnd(input
.content(),input
.contentSize());
185 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
186 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
188 error
= HTTP_STATUS_NONE
;
190 input
.append("HTTP/1.1 Okay\n\n", 16); /* real case seen */
191 hdr_len
= headersEnd(input
.content(),input
.contentSize());
192 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
193 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
195 error
= HTTP_STATUS_NONE
;
197 // status line with nul-byte
198 input
.append("HTTP/1.1\0200 Okay\n\n", 19); /* 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
);
203 error
= HTTP_STATUS_NONE
;
205 // status line with negative status
206 input
.append("HTTP/1.1 -000\n\n", 15); /* 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
);
211 error
= HTTP_STATUS_NONE
;
213 // status line with non-HTTP protocol
214 input
.append("ICY/1.1 200 Okay\n\n", 18); /* real case seen */
215 hdr_len
= headersEnd(input
.content(),input
.contentSize());
216 /* NP: for nw ICY is handled as a pass-thru */
217 /* Squid-3 will ignore it (and mangle the headers as per HTTP). */
218 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
219 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
221 error
= HTTP_STATUS_NONE
;