~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/tests/testHttpReply.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2009-09-24 14:51:06 UTC
  • mfrom: (1.1.12 upstream)
  • mto: (20.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090924145106-38jgrzmj0d73pha5
Tags: 3.1.0.13-1
* Upload to experimental

* New upstream release
  - Fixes Follow-X-Forwarded-For support (Closes: #523943)
  - Adds IPv6 support (Closes: #432351)

* debian/rules
  - Removed obsolete configuration options
  - Enable db and radius basic authentication modules

* debian/patches/01-cf.data.debian
  - Adapted to new upstream version

* debian/patches/02-makefile-defaults
  - Adapted to new upstream version

* debian/{squid.postinst,squid.rc,README.Debian,watch}
  - Updated references to squid 3.1

* debian/squid3.install
  - Install CSS file for error pages
  - Install manual pages for new authentication modules

* debian/squid3-common.install
  - Install documented version of configuration file in /usr/share/doc/squid3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "config.h"
 
2
#include <cppunit/TestAssert.h>
 
3
 
 
4
#include "testHttpReply.h"
 
5
#include "HttpReply.h"
 
6
#include "Mem.h"
 
7
 
 
8
/* to avoid libsquid.la and its comm stuff */
 
9
#include "TextException.cc"
 
10
 
 
11
CPPUNIT_TEST_SUITE_REGISTRATION( testHttpReply );
 
12
 
 
13
struct SquidConfig Config;
 
14
 
 
15
/* stub functions to link successfully */
 
16
 
 
17
#include "Store.h"
 
18
void
 
19
StoreEntry::timestampsSet()
 
20
{
 
21
    fatal("StoreEntry::timestampsSet. Not implemented.");
 
22
}
 
23
 
 
24
void
 
25
StoreEntry::setPublicKey()
 
26
{
 
27
    fatal("StoreEntry::setPulicKey. Not implemented.");
 
28
}
 
29
 
 
30
#include "MemObject.h"
 
31
int64_t
 
32
MemObject::endOffset() const
 
33
{
 
34
    return 0;
 
35
}
 
36
 
 
37
#include "ConfigParser.h"
 
38
void
 
39
ConfigParser::destruct()
 
40
{
 
41
// CALLED as shutdown no-op
 
42
//    fatal("ConfigParser::destruct. Not implemented.");
 
43
}
 
44
 
 
45
void
 
46
eventAdd(const char *name, EVH * func, void *arg, double when, int, bool cbdata)
 
47
{
 
48
// CALLED as setUp no-op
 
49
//    fatal("eventAdd. Not implemented.");
 
50
}
 
51
 
 
52
/* end */
 
53
 
 
54
void
 
55
testHttpReply::setUp()
 
56
{
 
57
    Mem::Init();
 
58
    httpHeaderInitModule();
 
59
}
 
60
 
 
61
void
 
62
testHttpReply::testSanityCheckFirstLine()
 
63
{
 
64
    MemBuf input;
 
65
    HttpReply engine;
 
66
    http_status error = HTTP_STATUS_NONE;
 
67
    size_t hdr_len;
 
68
    input.init();
 
69
 
 
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);
 
75
    input.reset();
 
76
    error = HTTP_STATUS_NONE;
 
77
 
 
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);
 
82
    input.reset();
 
83
    error = HTTP_STATUS_NONE;
 
84
 
 
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);
 
91
    input.reset();
 
92
    error = HTTP_STATUS_NONE;
 
93
 
 
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);
 
98
    input.reset();
 
99
    error = HTTP_STATUS_NONE;
 
100
#endif
 
101
 
 
102
    // empty status line
 
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);
 
107
    input.reset();
 
108
    error = HTTP_STATUS_NONE;
 
109
 
 
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);
 
114
    input.reset();
 
115
    error = HTTP_STATUS_NONE;
 
116
 
 
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);
 
122
    input.reset();
 
123
    error = HTTP_STATUS_NONE;
 
124
 
 
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);
 
129
    input.reset();
 
130
    error = HTTP_STATUS_NONE;
 
131
 
 
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);
 
137
    input.reset();
 
138
    error = HTTP_STATUS_NONE;
 
139
 
 
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);
 
144
    input.reset();
 
145
    error = HTTP_STATUS_NONE;
 
146
 
 
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);
 
151
    input.reset();
 
152
    error = HTTP_STATUS_NONE;
 
153
 
 
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);
 
159
    input.reset();
 
160
    error = HTTP_STATUS_NONE;
 
161
 
 
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);
 
167
    input.reset();
 
168
    error = HTTP_STATUS_NONE;
 
169
 
 
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);
 
177
    input.reset();
 
178
    error = HTTP_STATUS_NONE;
 
179
}