--------------------- PatchSet 4259 Date: 2007/04/15 12:37:35 Author: amosjeffries Branch: squid3-ipv6 Tag: (none) Log: Add test for unbracketed IPv6 address bug (part of address may be parsed as port) Members: src/tests/testHttpRequest.cc:1.1.14.2->1.1.14.3 src/tests/testHttpRequest.h:1.1.14.2->1.1.14.3 Index: squid3/src/tests/testHttpRequest.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/tests/testHttpRequest.cc,v retrieving revision 1.1.14.2 retrieving revision 1.1.14.3 diff -u -r1.1.14.2 -r1.1.14.3 --- squid3/src/tests/testHttpRequest.cc 5 Jan 2007 17:01:22 -0000 1.1.14.2 +++ squid3/src/tests/testHttpRequest.cc 15 Apr 2007 12:37:35 -0000 1.1.14.3 @@ -43,6 +43,7 @@ CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol); CPPUNIT_ASSERT_EQUAL(String("http://foo:90/bar"), String(url)); xfree(url); + /* vanilla url, different method */ url = xstrdup("http://foo/bar"); aRequest = HttpRequest::CreateFromUrlAndMethod(url, METHOD_PUT); @@ -53,11 +54,13 @@ CPPUNIT_ASSERT_EQUAL(String("/bar"), aRequest->urlpath); CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol); CPPUNIT_ASSERT_EQUAL(String("http://foo/bar"), String(url)); + /* a connect url with non-CONNECT data */ url = xstrdup(":foo/bar"); aRequest = HttpRequest::CreateFromUrlAndMethod(url, METHOD_CONNECT); xfree(url); CPPUNIT_ASSERT_EQUAL(nullRequest, aRequest); + /* a CONNECT url with CONNECT data */ url = xstrdup("foo:45"); aRequest = HttpRequest::CreateFromUrlAndMethod(url, METHOD_CONNECT); @@ -90,3 +93,50 @@ CPPUNIT_ASSERT_EQUAL(String("http://foo:90/bar"), String(url)); xfree(url); } + +/* + * Test BUG: URL '2000:800:45' opens host 2000 port 800 !! + */ +void +testHttpRequest::testIPv6HostColonBug() +{ + ushort expected_port; + char * url = NULL; + HttpRequest *aRequest = NULL; + + /* valid IPv6 address without port */ + url = xstrdup("http://[200:800::45]/foo"); + aRequest = HttpRequest::CreateFromUrlAndMethod(url, METHOD_GET); + expected_port = 80; + CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->port); + CPPUNIT_ASSERT_EQUAL(METHOD_GET, aRequest->method); + CPPUNIT_ASSERT_EQUAL(String("200:800::45"), String(aRequest->host)); + CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest->urlpath); + CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(String("http://[200:800::45]/foo"), String(url)); + xfree(url); + + /* valid IPv6 address with port */ + url = xstrdup("http://[2000:800::45]:90/foo"); + aRequest = HttpRequest::CreateFromUrlAndMethod(url, METHOD_GET); + expected_port = 90; + CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->port); + CPPUNIT_ASSERT_EQUAL(METHOD_GET, aRequest->method); + CPPUNIT_ASSERT_EQUAL(String("2000:800::45"), String(aRequest->host)); + CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest->urlpath); + CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(String("http://[2000:800::45]:90/foo"), String(url)); + xfree(url); + + /* IPv6 address as invalid (bug trigger) */ + url = xstrdup("http://2000:800:45/foo"); + aRequest = HttpRequest::CreateFromUrlAndMethod(url, METHOD_GET); + expected_port = 80; + CPPUNIT_ASSERT_EQUAL(expected_port, aRequest->port); + CPPUNIT_ASSERT_EQUAL(METHOD_GET, aRequest->method); + CPPUNIT_ASSERT_EQUAL(String("2000:800:45"), String(aRequest->host)); + CPPUNIT_ASSERT_EQUAL(String("/foo"), aRequest->urlpath); + CPPUNIT_ASSERT_EQUAL(PROTO_HTTP, aRequest->protocol); + CPPUNIT_ASSERT_EQUAL(String("http://2000:800:45/foo"), String(url)); + xfree(url); +} Index: squid3/src/tests/testHttpRequest.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/tests/testHttpRequest.h,v retrieving revision 1.1.14.2 retrieving revision 1.1.14.3 diff -u -r1.1.14.2 -r1.1.14.3 --- squid3/src/tests/testHttpRequest.h 5 Jan 2007 17:01:23 -0000 1.1.14.2 +++ squid3/src/tests/testHttpRequest.h 15 Apr 2007 12:37:35 -0000 1.1.14.3 @@ -13,6 +13,7 @@ CPPUNIT_TEST_SUITE( testHttpRequest ); CPPUNIT_TEST( testCreateFromUrlAndMethod ); CPPUNIT_TEST( testCreateFromUrl ); + CPPUNIT_TEST( testIPv6HostColonBug ); CPPUNIT_TEST_SUITE_END(); public: @@ -20,6 +21,7 @@ protected: void testCreateFromUrlAndMethod(); void testCreateFromUrl(); + void testIPv6HostColonBug(); }; #endif