]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testHttpReply.cc
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
10 #include <cppunit/TestAssert.h>
12 #include "HttpHeader.h"
13 #include "HttpReply.h"
14 #include "mime_header.h"
15 #include "SquidConfig.h"
16 #include "testHttpReply.h"
17 #include "unitTestMain.h"
19 CPPUNIT_TEST_SUITE_REGISTRATION( testHttpReply
);
21 class SquidConfig Config
;
23 /* stub functions to link successfully */
25 #include "MemObject.h"
27 MemObject::endOffset() const
35 testHttpReply::setUp()
38 httpHeaderInitModule();
42 testHttpReply::testSanityCheckFirstLine()
46 Http::StatusCode error
= Http::scNone
;
50 // a valid status line
51 input
.append("HTTP/1.1 200 Okay\n\n", 19);
52 hdr_len
= headersEnd(input
.content(),input
.contentSize());
53 CPPUNIT_ASSERT( 1 && engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
54 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
58 input
.append("HTTP/1.1 200 Okay \n\n", 28);
59 hdr_len
= headersEnd(input
.content(),input
.contentSize());
60 CPPUNIT_ASSERT( 2 && engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
61 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
65 #if TODO // these cases are only checked after parse...
66 // invalid status line
67 input
.append("HTTP/1.1 999 Okay\n\n", 19);
68 hdr_len
= headersEnd(input
.content(),input
.contentSize());
69 CPPUNIT_ASSERT( 3 && !engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
70 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
74 input
.append("HTTP/1.1 2000 Okay \n\n", 29);
75 hdr_len
= headersEnd(input
.content(),input
.contentSize());
76 CPPUNIT_ASSERT( 4 && engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
77 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
82 // valid ICY protocol status line
83 input
.append("ICY 200 Okay\n\n", 14);
84 hdr_len
= headersEnd(input
.content(),input
.contentSize());
85 CPPUNIT_ASSERT( engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
86 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
89 /* NP: the engine saves details about the protocol. even when being reset :( */
90 engine
.protoPrefix
="HTTP/";
94 input
.append("\n\n", 2);
95 hdr_len
= headersEnd(input
.content(),input
.contentSize());
96 CPPUNIT_ASSERT( 5 && !engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
97 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
101 input
.append(" \n\n", 8);
102 hdr_len
= headersEnd(input
.content(),input
.contentSize());
103 CPPUNIT_ASSERT( 6 && !engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
104 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
106 error
= Http::scNone
;
108 // status line with no message
109 input
.append("HTTP/1.1 200\n\n", 14); /* real case seen */
110 hdr_len
= headersEnd(input
.content(),input
.contentSize());
111 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
112 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
114 error
= Http::scNone
;
116 input
.append("HTTP/1.1 200 \n\n", 15); /* real case seen */
117 hdr_len
= headersEnd(input
.content(),input
.contentSize());
118 CPPUNIT_ASSERT(engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
119 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
121 error
= Http::scNone
;
123 // incomplete (short) status lines... not sane (yet), but no error either.
124 input
.append("H", 1);
125 hdr_len
= headersEnd(input
.content(),input
.contentSize());
126 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
127 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
129 error
= Http::scNone
;
131 input
.append("HTTP/", 5);
132 hdr_len
= headersEnd(input
.content(),input
.contentSize());
133 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
134 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
136 error
= Http::scNone
;
138 input
.append("HTTP/1", 6);
139 hdr_len
= headersEnd(input
.content(),input
.contentSize());
140 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
141 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
143 error
= Http::scNone
;
145 input
.append("HTTP/1.1", 8);
146 hdr_len
= headersEnd(input
.content(),input
.contentSize());
147 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
148 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
150 error
= Http::scNone
;
152 input
.append("HTTP/1.1 ", 9); /* real case seen */
153 hdr_len
= headersEnd(input
.content(),input
.contentSize());
154 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
155 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
157 error
= Http::scNone
;
159 input
.append("HTTP/1.1 20", 14);
160 hdr_len
= headersEnd(input
.content(),input
.contentSize());
161 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
162 CPPUNIT_ASSERT_EQUAL(error
, Http::scNone
);
164 error
= Http::scNone
;
166 // status line with no status
167 input
.append("HTTP/1.1 \n\n", 11);
168 hdr_len
= headersEnd(input
.content(),input
.contentSize());
169 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
170 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
172 error
= Http::scNone
;
174 input
.append("HTTP/1.1 \n\n", 15);
175 hdr_len
= headersEnd(input
.content(),input
.contentSize());
176 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
177 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
179 error
= Http::scNone
;
181 input
.append("HTTP/1.1 Okay\n\n", 16); /* real case seen */
182 hdr_len
= headersEnd(input
.content(),input
.contentSize());
183 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
184 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
186 error
= Http::scNone
;
188 // status line with nul-byte
189 input
.append("HTTP/1.1" "\0" "200 Okay\n\n", 19); /* real case seen */
190 hdr_len
= headersEnd(input
.content(),input
.contentSize());
191 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
192 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
194 error
= Http::scNone
;
196 // status line with negative status
197 input
.append("HTTP/1.1 -000\n\n", 15); /* real case seen */
198 hdr_len
= headersEnd(input
.content(),input
.contentSize());
199 CPPUNIT_ASSERT(!engine
.sanityCheckStartLine(input
.content(), hdr_len
, &error
) );
200 CPPUNIT_ASSERT_EQUAL(error
, Http::scInvalidHeader
);
202 error
= Http::scNone
;