]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testHttpReply.cc
2 #include <cppunit/TestAssert.h>
4 #include "testHttpReply.h"
8 CPPUNIT_TEST_SUITE_REGISTRATION( testHttpReply
);
10 struct SquidConfig Config
;
12 /* stub functions to link successfully */
16 StoreEntry::timestampsSet()
18 fatal("StoreEntry::timestampsSet. Not implemented.");
22 StoreEntry::setPublicKey()
24 fatal("StoreEntry::setPulicKey. Not implemented.");
27 #include "MemObject.h"
29 MemObject::endOffset() const
34 #include "ConfigParser.h"
36 ConfigParser::destruct()
38 // CALLED as shutdown no-op
39 // fatal("ConfigParser::destruct. Not implemented.");
43 eventAdd(const char *name
, EVH
* func
, void *arg
, double when
, int, bool cbdata
)
45 // CALLED as setUp no-op
46 // fatal("eventAdd. Not implemented.");
52 testHttpReply::setUp()
55 httpHeaderInitModule();
59 testHttpReply::testSanityCheckFirstLine()
63 http_status error
= HTTP_STATUS_NONE
;
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
);
73 error
= HTTP_STATUS_NONE
;
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
);
80 error
= HTTP_STATUS_NONE
;
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
);
89 error
= HTTP_STATUS_NONE
;
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
);
96 error
= HTTP_STATUS_NONE
;
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
);
105 error
= HTTP_STATUS_NONE
;
106 /* NP: the engine saves details about the protocol. even when being reset :( */
107 engine
.protoPrefix
="HTTP/";
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
);
116 error
= HTTP_STATUS_NONE
;
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
);
123 error
= HTTP_STATUS_NONE
;
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
);
131 error
= HTTP_STATUS_NONE
;
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
);
138 error
= HTTP_STATUS_NONE
;
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
);
146 error
= HTTP_STATUS_NONE
;
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
);
153 error
= HTTP_STATUS_NONE
;
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
);
160 error
= HTTP_STATUS_NONE
;
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
);
167 error
= HTTP_STATUS_NONE
;
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
);
174 error
= HTTP_STATUS_NONE
;
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
);
181 error
= HTTP_STATUS_NONE
;
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
);
189 error
= HTTP_STATUS_NONE
;
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
);
196 error
= HTTP_STATUS_NONE
;
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
);
203 error
= HTTP_STATUS_NONE
;
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
);
211 error
= HTTP_STATUS_NONE
;
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
);
219 error
= HTTP_STATUS_NONE
;