2
#include <cppunit/TestAssert.h>
4
#include "testHttpReply.h"
8
/* to avoid libsquid.la and its comm stuff */
9
#include "TextException.cc"
11
CPPUNIT_TEST_SUITE_REGISTRATION( testHttpReply );
13
struct SquidConfig Config;
15
/* stub functions to link successfully */
19
StoreEntry::timestampsSet()
21
fatal("StoreEntry::timestampsSet. Not implemented.");
25
StoreEntry::setPublicKey()
27
fatal("StoreEntry::setPulicKey. Not implemented.");
30
#include "MemObject.h"
32
MemObject::endOffset() const
37
#include "ConfigParser.h"
39
ConfigParser::destruct()
41
// CALLED as shutdown no-op
42
// fatal("ConfigParser::destruct. Not implemented.");
46
eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata)
48
// CALLED as setUp no-op
49
// fatal("eventAdd. Not implemented.");
55
testHttpReply::setUp()
58
httpHeaderInitModule();
62
testHttpReply::testSanityCheckFirstLine()
66
http_status error = HTTP_STATUS_NONE;
70
// a valid status line
71
input.append("HTTP/1.1 200 Okay\n\n", 19);
72
hdr_len = headersEnd(input.content(),input.contentSize());
73
CPPUNIT_ASSERT( 1 && engine.sanityCheckStartLine(&input, hdr_len, &error) );
74
CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE);
76
error = HTTP_STATUS_NONE;
78
input.append("HTTP/1.1 200 Okay \n\n", 28);
79
hdr_len = headersEnd(input.content(),input.contentSize());
80
CPPUNIT_ASSERT( 2 && engine.sanityCheckStartLine(&input, hdr_len, &error) );
81
CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE);
83
error = HTTP_STATUS_NONE;
85
#if TODO // these cases are only checked after parse...
86
// invalid status line
87
input.append("HTTP/1.1 999 Okay\n\n", 19);
88
hdr_len = headersEnd(input.content(),input.contentSize());
89
CPPUNIT_ASSERT( 3 && !engine.sanityCheckStartLine(&input, hdr_len, &error) );
90
CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER);
92
error = HTTP_STATUS_NONE;
94
input.append("HTTP/1.1 2000 Okay \n\n", 29);
95
hdr_len = headersEnd(input.content(),input.contentSize());
96
CPPUNIT_ASSERT( 4 && engine.sanityCheckStartLine(&input, hdr_len, &error) );
97
CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE);
99
error = HTTP_STATUS_NONE;
103
input.append("\n\n", 2);
104
hdr_len = headersEnd(input.content(),input.contentSize());
105
CPPUNIT_ASSERT( 5 && !engine.sanityCheckStartLine(&input, hdr_len, &error) );
106
CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER);
108
error = HTTP_STATUS_NONE;
110
input.append(" \n\n", 8);
111
hdr_len = headersEnd(input.content(),input.contentSize());
112
CPPUNIT_ASSERT( 6 && !engine.sanityCheckStartLine(&input, hdr_len, &error) );
113
CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER);
115
error = HTTP_STATUS_NONE;
117
// status line with no message
118
input.append("HTTP/1.1 200\n\n", 14); /* real case seen */
119
hdr_len = headersEnd(input.content(),input.contentSize());
120
CPPUNIT_ASSERT(engine.sanityCheckStartLine(&input, hdr_len, &error) );
121
CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE);
123
error = HTTP_STATUS_NONE;
125
input.append("HTTP/1.1 200 \n\n", 15); /* real case seen */
126
hdr_len = headersEnd(input.content(),input.contentSize());
127
CPPUNIT_ASSERT(engine.sanityCheckStartLine(&input, hdr_len, &error) );
128
CPPUNIT_ASSERT_EQUAL(error, HTTP_STATUS_NONE);
130
error = HTTP_STATUS_NONE;
132
// status line with no status
133
input.append("HTTP/1.1 \n\n", 11);
134
hdr_len = headersEnd(input.content(),input.contentSize());
135
CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) );
136
CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER);
138
error = HTTP_STATUS_NONE;
140
input.append("HTTP/1.1 \n\n", 15);
141
hdr_len = headersEnd(input.content(),input.contentSize());
142
CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) );
143
CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER);
145
error = HTTP_STATUS_NONE;
147
input.append("HTTP/1.1 Okay\n\n", 16); /* real case seen */
148
hdr_len = headersEnd(input.content(),input.contentSize());
149
CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) );
150
CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER);
152
error = HTTP_STATUS_NONE;
154
// status line with nul-byte
155
input.append("HTTP/1.1\0200 Okay\n\n", 19); /* real case seen */
156
hdr_len = headersEnd(input.content(),input.contentSize());
157
CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) );
158
CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER);
160
error = HTTP_STATUS_NONE;
162
// status line with negative status
163
input.append("HTTP/1.1 -000\n\n", 15); /* real case seen */
164
hdr_len = headersEnd(input.content(),input.contentSize());
165
CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) );
166
CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER);
168
error = HTTP_STATUS_NONE;
170
// status line with non-HTTP protocol
171
input.append("ICY/1.1 200 Okay\n\n", 18); /* real case seen */
172
hdr_len = headersEnd(input.content(),input.contentSize());
173
/* NP: for nw ICY is handled as a pass-thru */
174
/* Squid-3 will ignore it (and mangle the headers as per HTTP). */
175
CPPUNIT_ASSERT(!engine.sanityCheckStartLine(&input, hdr_len, &error) );
176
CPPUNIT_ASSERT_EQUAL(error, HTTP_INVALID_HEADER);
178
error = HTTP_STATUS_NONE;