]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/testHttpRequest.cc
3 #include <cppunit/TestAssert.h>
5 #include "testHttpRequest.h"
6 #include "HttpRequest.h"
10 CPPUNIT_TEST_SUITE_REGISTRATION( testHttpRequest
);
12 /* stub functions to link successfully */
23 /* init memory pools */
26 testHttpRequest::setUp()
32 * Test creating an HttpRequest object from a Url and method
35 testHttpRequest::testCreateFromUrlAndMethod()
39 char * url
= xstrdup("http://foo:90/bar");
40 HttpRequest
*aRequest
= HttpRequest::CreateFromUrlAndMethod(url
, METHOD_GET
);
42 HttpRequest
*nullRequest
= NULL
;
43 CPPUNIT_ASSERT_EQUAL(expected_port
, aRequest
->port
);
44 CPPUNIT_ASSERT(aRequest
->method
== METHOD_GET
);
45 CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest
->GetHost()));
46 CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest
->urlpath
);
47 CPPUNIT_ASSERT_EQUAL(PROTO_HTTP
, aRequest
->protocol
);
48 CPPUNIT_ASSERT_EQUAL(String("http://foo:90/bar"), String(url
));
51 /* vanilla url, different method */
52 url
= xstrdup("http://foo/bar");
53 aRequest
= HttpRequest::CreateFromUrlAndMethod(url
, METHOD_PUT
);
55 CPPUNIT_ASSERT_EQUAL(expected_port
, aRequest
->port
);
56 CPPUNIT_ASSERT(aRequest
->method
== METHOD_PUT
);
57 CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest
->GetHost()));
58 CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest
->urlpath
);
59 CPPUNIT_ASSERT_EQUAL(PROTO_HTTP
, aRequest
->protocol
);
60 CPPUNIT_ASSERT_EQUAL(String("http://foo/bar"), String(url
));
62 /* a connect url with non-CONNECT data */
63 url
= xstrdup(":foo/bar");
64 aRequest
= HttpRequest::CreateFromUrlAndMethod(url
, METHOD_CONNECT
);
66 CPPUNIT_ASSERT_EQUAL(nullRequest
, aRequest
);
68 /* a CONNECT url with CONNECT data */
69 url
= xstrdup("foo:45");
70 aRequest
= HttpRequest::CreateFromUrlAndMethod(url
, METHOD_CONNECT
);
72 CPPUNIT_ASSERT_EQUAL(expected_port
, aRequest
->port
);
73 CPPUNIT_ASSERT(aRequest
->method
== METHOD_CONNECT
);
74 CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest
->GetHost()));
75 CPPUNIT_ASSERT_EQUAL(String(""), aRequest
->urlpath
);
76 CPPUNIT_ASSERT_EQUAL(PROTO_NONE
, aRequest
->protocol
);
77 CPPUNIT_ASSERT_EQUAL(String("foo:45"), String(url
));
82 * Test creating an HttpRequest object from a Url alone.
85 testHttpRequest::testCreateFromUrl()
89 char * url
= xstrdup("http://foo:90/bar");
90 HttpRequest
*aRequest
= HttpRequest::CreateFromUrl(url
);
92 CPPUNIT_ASSERT_EQUAL(expected_port
, aRequest
->port
);
93 CPPUNIT_ASSERT(aRequest
->method
== METHOD_GET
);
94 CPPUNIT_ASSERT_EQUAL(String("foo"), String(aRequest
->GetHost()));
95 CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest
->urlpath
);
96 CPPUNIT_ASSERT_EQUAL(PROTO_HTTP
, aRequest
->protocol
);
97 CPPUNIT_ASSERT_EQUAL(String("http://foo:90/bar"), String(url
));
102 * Test BUG: URL '2000:800:45' opens host 2000 port 800 !!
105 testHttpRequest::testIPv6HostColonBug()
107 ushort expected_port
;
109 HttpRequest
*aRequest
= NULL
;
111 /* valid IPv6 address without port */
112 url
= xstrdup("http://[2000:800::45]/foo");
113 aRequest
= HttpRequest::CreateFromUrlAndMethod(url
, METHOD_GET
);
115 CPPUNIT_ASSERT_EQUAL(expected_port
, aRequest
->port
);
116 CPPUNIT_ASSERT(aRequest
->method
== METHOD_GET
);
117 CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest
->GetHost()));
118 CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest
->urlpath
);
119 CPPUNIT_ASSERT_EQUAL(PROTO_HTTP
, aRequest
->protocol
);
120 CPPUNIT_ASSERT_EQUAL(String("http://[2000:800::45]/foo"), String(url
));
123 /* valid IPv6 address with port */
124 url
= xstrdup("http://[2000:800::45]:90/foo");
125 aRequest
= HttpRequest::CreateFromUrlAndMethod(url
, METHOD_GET
);
127 CPPUNIT_ASSERT_EQUAL(expected_port
, aRequest
->port
);
128 CPPUNIT_ASSERT(aRequest
->method
== METHOD_GET
);
129 CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest
->GetHost()));
130 CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest
->urlpath
);
131 CPPUNIT_ASSERT_EQUAL(PROTO_HTTP
, aRequest
->protocol
);
132 CPPUNIT_ASSERT_EQUAL(String("http://[2000:800::45]:90/foo"), String(url
));
135 /* IPv6 address as invalid (bug trigger) */
136 url
= xstrdup("http://2000:800::45/foo");
137 aRequest
= HttpRequest::CreateFromUrlAndMethod(url
, METHOD_GET
);
139 CPPUNIT_ASSERT_EQUAL(expected_port
, aRequest
->port
);
140 CPPUNIT_ASSERT(aRequest
->method
== METHOD_GET
);
142 /* We hasve fixed this in IPv6 build. */
143 CPPUNIT_ASSERT_EQUAL(String("[2000:800::45]"), String(aRequest
->GetHost()));
145 /* NO fix is possible in IPv4-pure build. */
146 CPPUNIT_ASSERT_EQUAL(String("2000:800::45"), String(aRequest
->GetHost()));
148 CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest
->urlpath
);
149 CPPUNIT_ASSERT_EQUAL(PROTO_HTTP
, aRequest
->protocol
);
150 CPPUNIT_ASSERT_EQUAL(String("http://2000:800::45/foo"), String(url
));