]>
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 "HttpHeader.h"
8 #include "mime_header.h"
9 #include "SquidConfig.h"
10 #include "testHttpReply.h"
12 CPPUNIT_TEST_SUITE_REGISTRATION( testHttpReply
);
14 class SquidConfig Config
;
16 /* stub functions to link successfully */
18 #include "MemObject.h"
20 MemObject::endOffset() const
28 testHttpReply::setUp()
31 httpHeaderInitModule();
35 testHttpReply::testSanityCheckFirstLine()
39 Http::StatusCode error
= Http::scNone
;
43 // a valid status line
44 input
.append("HTTP/1.1 200 Okay\n\n", 19);
45 hdr_len
= headersEnd(input
.content(),input
.contentSize());
46 CPPUNIT_ASSERT( 1 && engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
47 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
51 input
.append("HTTP/1.1 200 Okay \n\n", 28);
52 hdr_len
= headersEnd(input
.content(),input
.contentSize());
53 CPPUNIT_ASSERT( 2 && engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
54 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
58 #if TODO // these cases are only checked after parse...
59 // invalid status line
60 input
.append("HTTP/1.1 999 Okay\n\n", 19);
61 hdr_len
= headersEnd(input
.content(),input
.contentSize());
62 CPPUNIT_ASSERT( 3 && !engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
63 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
67 input
.append("HTTP/1.1 2000 Okay \n\n", 29);
68 hdr_len
= headersEnd(input
.content(),input
.contentSize());
69 CPPUNIT_ASSERT( 4 && engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
70 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
75 // valid ICY protocol status line
76 input
.append("ICY 200 Okay\n\n", 14);
77 hdr_len
= headersEnd(input
.content(),input
.contentSize());
78 CPPUNIT_ASSERT( engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
79 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
82 /* NP: the engine saves details about the protocol. even when being reset :( */
83 engine
.protoPrefix
="HTTP/";
87 input
.append("\n\n", 2);
88 hdr_len
= headersEnd(input
.content(),input
.contentSize());
89 CPPUNIT_ASSERT( 5 && !engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
90 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
94 input
.append(" \n\n", 8);
95 hdr_len
= headersEnd(input
.content(),input
.contentSize());
96 CPPUNIT_ASSERT( 6 && !engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
97 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
101 // status line with no message
102 input
.append("HTTP/1.1 200\n\n", 14); /* real case seen */
103 hdr_len
= headersEnd(input
.content(),input
.contentSize());
104 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
105 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
107 error
= Http::scNone
;
109 input
.append("HTTP/1.1 200 \n\n", 15); /* real case seen */
110 hdr_len
= headersEnd(input
.content(),input
.contentSize());
111 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
112 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
114 error
= Http::scNone
;
116 // incomplete (short) status lines... not sane (yet), but no error either.
117 input
.append("H", 1);
118 hdr_len
= headersEnd(input
.content(),input
.contentSize());
119 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
120 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
122 error
= Http::scNone
;
124 input
.append("HTTP/", 5);
125 hdr_len
= headersEnd(input
.content(),input
.contentSize());
126 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
127 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
129 error
= Http::scNone
;
131 input
.append("HTTP/1", 6);
132 hdr_len
= headersEnd(input
.content(),input
.contentSize());
133 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
134 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
136 error
= Http::scNone
;
138 input
.append("HTTP/1.1", 8);
139 hdr_len
= headersEnd(input
.content(),input
.contentSize());
140 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
141 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
143 error
= Http::scNone
;
145 input
.append("HTTP/1.1 ", 9); /* real case seen */
146 hdr_len
= headersEnd(input
.content(),input
.contentSize());
147 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
148 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
150 error
= Http::scNone
;
152 input
.append("HTTP/1.1 20", 14);
153 hdr_len
= headersEnd(input
.content(),input
.contentSize());
154 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
155 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
157 error
= Http::scNone
;
159 // status line with no status
160 input
.append("HTTP/1.1 \n\n", 11);
161 hdr_len
= headersEnd(input
.content(),input
.contentSize());
162 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
163 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
165 error
= Http::scNone
;
167 input
.append("HTTP/1.1 \n\n", 15);
168 hdr_len
= headersEnd(input
.content(),input
.contentSize());
169 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
170 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
172 error
= Http::scNone
;
174 input
.append("HTTP/1.1 Okay\n\n", 16); /* real case seen */
175 hdr_len
= headersEnd(input
.content(),input
.contentSize());
176 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
177 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
179 error
= Http::scNone
;
181 // status line with nul-byte
182 input
.append("HTTP/1.1" "\0" "200 Okay\n\n", 19); /* real case seen */
183 hdr_len
= headersEnd(input
.content(),input
.contentSize());
184 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(&input
, hdr_len
, &error
) );
185 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
187 error
= Http::scNone
;
189 // status line with negative status
190 input
.append("HTTP/1.1 -000\n\n", 15); /* 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::scInvalidHeader
);
195 error
= Http::scNone
;