]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testHttpReply.cc
1 #define SQUID_UNIT_TEST 1
3 #include <cppunit/TestAssert.h>
5 #include "testHttpReply.h"
6 #include "HttpHeader.h"
9 #include "mime_header.h"
11 CPPUNIT_TEST_SUITE_REGISTRATION( testHttpReply
);
13 struct SquidConfig Config
;
15 /* stub functions to link successfully */
17 #include "MemObject.h"
19 MemObject::endOffset() const
24 #include "ConfigParser.h"
26 ConfigParser::destruct()
28 // CALLED as shutdown no-op
29 // fatal("ConfigParser::destruct. Not implemented.");
33 eventAdd(const char *name
, EVH
* func
, void *arg
, double when
, int, bool cbdata
)
35 // CALLED as setUp no-op
36 // fatal("eventAdd. Not implemented.");
42 testHttpReply::setUp()
45 httpHeaderInitModule();
49 testHttpReply::testSanityCheckFirstLine()
53 http_status error
= HTTP_STATUS_NONE
;
57 // a valid status line
58 input
.append("HTTP/1.1 200 Okay\n\n", 19);
59 hdr_len
= headersEnd(input
.content(),input
.contentSize());
60 CPPUNIT_ASSERT( 1 && engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
61 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
63 error
= HTTP_STATUS_NONE
;
65 input
.append("HTTP/1.1 200 Okay \n\n", 28);
66 hdr_len
= headersEnd(input
.content(),input
.contentSize());
67 CPPUNIT_ASSERT( 2 && engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
68 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
70 error
= HTTP_STATUS_NONE
;
72 #if TODO // these cases are only checked after parse...
73 // invalid status line
74 input
.append("HTTP/1.1 999 Okay\n\n", 19);
75 hdr_len
= headersEnd(input
.content(),input
.contentSize());
76 CPPUNIT_ASSERT( 3 && !engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
77 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
79 error
= HTTP_STATUS_NONE
;
81 input
.append("HTTP/1.1 2000 Okay \n\n", 29);
82 hdr_len
= headersEnd(input
.content(),input
.contentSize());
83 CPPUNIT_ASSERT( 4 && engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
84 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
86 error
= HTTP_STATUS_NONE
;
89 // valid ICY protocol status line
90 input
.append("ICY 200 Okay\n\n", 18);
91 hdr_len
= headersEnd(input
.content(),input
.contentSize());
92 CPPUNIT_ASSERT( engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
93 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
95 error
= HTTP_STATUS_NONE
;
96 /* NP: the engine saves details about the protocol. even when being reset :( */
97 engine
.protoPrefix
="HTTP/";
101 input
.append("\n\n", 2);
102 hdr_len
= headersEnd(input
.content(),input
.contentSize());
103 CPPUNIT_ASSERT( 5 && !engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
104 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
106 error
= HTTP_STATUS_NONE
;
108 input
.append(" \n\n", 8);
109 hdr_len
= headersEnd(input
.content(),input
.contentSize());
110 CPPUNIT_ASSERT( 6 && !engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
111 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
113 error
= HTTP_STATUS_NONE
;
115 // status line with no message
116 input
.append("HTTP/1.1 200\n\n", 14); /* real case seen */
117 hdr_len
= headersEnd(input
.content(),input
.contentSize());
118 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
119 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
121 error
= HTTP_STATUS_NONE
;
123 input
.append("HTTP/1.1 200 \n\n", 15); /* real case seen */
124 hdr_len
= headersEnd(input
.content(),input
.contentSize());
125 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
126 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
128 error
= HTTP_STATUS_NONE
;
130 // incomplete (short) status lines... not sane (yet), but no error either.
131 input
.append("H", 1);
132 hdr_len
= headersEnd(input
.content(),input
.contentSize());
133 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
134 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
136 error
= HTTP_STATUS_NONE
;
138 input
.append("HTTP/", 5);
139 hdr_len
= headersEnd(input
.content(),input
.contentSize());
140 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
141 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
143 error
= HTTP_STATUS_NONE
;
145 input
.append("HTTP/1", 6);
146 hdr_len
= headersEnd(input
.content(),input
.contentSize());
147 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
148 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
150 error
= HTTP_STATUS_NONE
;
152 input
.append("HTTP/1.1", 8);
153 hdr_len
= headersEnd(input
.content(),input
.contentSize());
154 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
155 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
157 error
= HTTP_STATUS_NONE
;
159 input
.append("HTTP/1.1 ", 9); /* real case seen */
160 hdr_len
= headersEnd(input
.content(),input
.contentSize());
161 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
162 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
164 error
= HTTP_STATUS_NONE
;
166 input
.append("HTTP/1.1 20", 14);
167 hdr_len
= headersEnd(input
.content(),input
.contentSize());
168 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
169 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
171 error
= HTTP_STATUS_NONE
;
173 // status line with no status
174 input
.append("HTTP/1.1 \n\n", 11);
175 hdr_len
= headersEnd(input
.content(),input
.contentSize());
176 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
177 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
179 error
= HTTP_STATUS_NONE
;
181 input
.append("HTTP/1.1 \n\n", 15);
182 hdr_len
= headersEnd(input
.content(),input
.contentSize());
183 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
184 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
186 error
= HTTP_STATUS_NONE
;
188 input
.append("HTTP/1.1 Okay\n\n", 16); /* real case seen */
189 hdr_len
= headersEnd(input
.content(),input
.contentSize());
190 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
191 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
193 error
= HTTP_STATUS_NONE
;
195 // status line with nul-byte
196 input
.append("HTTP/1.1\0200 Okay\n\n", 19); /* real case seen */
197 hdr_len
= headersEnd(input
.content(),input
.contentSize());
198 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
199 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
201 error
= HTTP_STATUS_NONE
;
203 // status line with negative status
204 input
.append("HTTP/1.1 -000\n\n", 15); /* real case seen */
205 hdr_len
= headersEnd(input
.content(),input
.contentSize());
206 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
207 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
209 error
= HTTP_STATUS_NONE
;