]>
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"
12 CPPUNIT_TEST_SUITE_REGISTRATION( testHttpReply
);
14 struct SquidConfig Config
;
16 /* stub functions to link successfully */
18 #include "MemObject.h"
20 MemObject::endOffset() const
25 #include "ConfigParser.h"
27 ConfigParser::destruct()
29 // CALLED as shutdown no-op
30 // fatal("ConfigParser::destruct. Not implemented.");
34 eventAdd(const char *name
, EVH
* func
, void *arg
, double when
, int, bool cbdata
)
36 // CALLED as setUp no-op
37 // fatal("eventAdd. Not implemented.");
43 testHttpReply::setUp()
46 httpHeaderInitModule();
50 testHttpReply::testSanityCheckFirstLine()
54 http_status error
= HTTP_STATUS_NONE
;
58 // a valid status line
59 input
.append("HTTP/1.1 200 Okay\n\n", 19);
60 hdr_len
= headersEnd(input
.content(),input
.contentSize());
61 CPPUNIT_ASSERT( 1 && engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
62 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
64 error
= HTTP_STATUS_NONE
;
66 input
.append("HTTP/1.1 200 Okay \n\n", 28);
67 hdr_len
= headersEnd(input
.content(),input
.contentSize());
68 CPPUNIT_ASSERT( 2 && engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
69 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
71 error
= HTTP_STATUS_NONE
;
73 #if TODO // these cases are only checked after parse...
74 // invalid status line
75 input
.append("HTTP/1.1 999 Okay\n\n", 19);
76 hdr_len
= headersEnd(input
.content(),input
.contentSize());
77 CPPUNIT_ASSERT( 3 && !engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
78 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
80 error
= HTTP_STATUS_NONE
;
82 input
.append("HTTP/1.1 2000 Okay \n\n", 29);
83 hdr_len
= headersEnd(input
.content(),input
.contentSize());
84 CPPUNIT_ASSERT( 4 && engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
85 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
87 error
= HTTP_STATUS_NONE
;
90 // valid ICY protocol status line
91 input
.append("ICY 200 Okay\n\n", 18);
92 hdr_len
= headersEnd(input
.content(),input
.contentSize());
93 CPPUNIT_ASSERT( engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
94 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
96 error
= HTTP_STATUS_NONE
;
97 /* NP: the engine saves details about the protocol. even when being reset :( */
98 engine
.protoPrefix
="HTTP/";
102 input
.append("\n\n", 2);
103 hdr_len
= headersEnd(input
.content(),input
.contentSize());
104 CPPUNIT_ASSERT( 5 && !engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
105 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
107 error
= HTTP_STATUS_NONE
;
109 input
.append(" \n\n", 8);
110 hdr_len
= headersEnd(input
.content(),input
.contentSize());
111 CPPUNIT_ASSERT( 6 && !engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
112 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
114 error
= HTTP_STATUS_NONE
;
116 // status line with no message
117 input
.append("HTTP/1.1 200\n\n", 14); /* real case seen */
118 hdr_len
= headersEnd(input
.content(),input
.contentSize());
119 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
120 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
122 error
= HTTP_STATUS_NONE
;
124 input
.append("HTTP/1.1 200 \n\n", 15); /* real case seen */
125 hdr_len
= headersEnd(input
.content(),input
.contentSize());
126 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
127 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
129 error
= HTTP_STATUS_NONE
;
131 // incomplete (short) status lines... not sane (yet), but no error either.
132 input
.append("H", 1);
133 hdr_len
= headersEnd(input
.content(),input
.contentSize());
134 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
135 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
137 error
= HTTP_STATUS_NONE
;
139 input
.append("HTTP/", 5);
140 hdr_len
= headersEnd(input
.content(),input
.contentSize());
141 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
142 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
144 error
= HTTP_STATUS_NONE
;
146 input
.append("HTTP/1", 6);
147 hdr_len
= headersEnd(input
.content(),input
.contentSize());
148 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
149 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
151 error
= HTTP_STATUS_NONE
;
153 input
.append("HTTP/1.1", 8);
154 hdr_len
= headersEnd(input
.content(),input
.contentSize());
155 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
156 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
158 error
= HTTP_STATUS_NONE
;
160 input
.append("HTTP/1.1 ", 9); /* real case seen */
161 hdr_len
= headersEnd(input
.content(),input
.contentSize());
162 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
163 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
165 error
= HTTP_STATUS_NONE
;
167 input
.append("HTTP/1.1 20", 14);
168 hdr_len
= headersEnd(input
.content(),input
.contentSize());
169 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
170 CPPUNIT_ASSERT_EQUAL(error
, HTTP_STATUS_NONE
);
172 error
= HTTP_STATUS_NONE
;
174 // status line with no status
175 input
.append("HTTP/1.1 \n\n", 11);
176 hdr_len
= headersEnd(input
.content(),input
.contentSize());
177 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
178 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
180 error
= HTTP_STATUS_NONE
;
182 input
.append("HTTP/1.1 \n\n", 15);
183 hdr_len
= headersEnd(input
.content(),input
.contentSize());
184 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
185 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
187 error
= HTTP_STATUS_NONE
;
189 input
.append("HTTP/1.1 Okay\n\n", 16); /* real case seen */
190 hdr_len
= headersEnd(input
.content(),input
.contentSize());
191 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
192 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
194 error
= HTTP_STATUS_NONE
;
196 // status line with nul-byte
197 input
.append("HTTP/1.1\0200 Okay\n\n", 19); /* real case seen */
198 hdr_len
= headersEnd(input
.content(),input
.contentSize());
199 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
200 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
202 error
= HTTP_STATUS_NONE
;
204 // status line with negative status
205 input
.append("HTTP/1.1 -000\n\n", 15); /* real case seen */
206 hdr_len
= headersEnd(input
.content(),input
.contentSize());
207 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
208 CPPUNIT_ASSERT_EQUAL(error
, HTTP_INVALID_HEADER
);
210 error
= HTTP_STATUS_NONE
;