]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Add unit tests for method parsing update
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 18 Dec 2013 03:00:01 +0000 (19:00 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 18 Dec 2013 03:00:01 +0000 (19:00 -0800)
src/tests/testHttpRequestMethod.cc

index 1e83ed1ce3c402e504107e4cbcbcd163cdffecb9..b90099422d909d5bdd16d1642b00533e4ff79c20 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "HttpRequestMethod.h"
 #include "Mem.h"
+#include "SquidConfig.h"
 #include "testHttpRequestMethod.h"
 
 #if HAVE_SSTREAM
@@ -83,7 +84,17 @@ testHttpRequestMethod::testConstructmethod_t()
 void
 testHttpRequestMethod::testImage()
 {
+    // relaxed RFC-compliance parse HTTP methods are upgraded to correct case
+    Config.onoff.relaxed_header_parser = 1;
+    CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("POST",NULL).image()));
+    CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("pOsT",NULL).image()));
     CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("post",NULL).image()));
+
+    // strict RFC-compliance parse HTTP methods are case sensitive
+    Config.onoff.relaxed_header_parser = 0;
+    CPPUNIT_ASSERT_EQUAL(String("POST"), String(HttpRequestMethod("POST",NULL).image()));
+    CPPUNIT_ASSERT_EQUAL(String("pOsT"), String(HttpRequestMethod("pOsT",NULL).image()));
+    CPPUNIT_ASSERT_EQUAL(String("post"), String(HttpRequestMethod("post",NULL).image()));
 }
 
 /*
@@ -117,7 +128,15 @@ testHttpRequestMethod::testNotEqualmethod_t()
 void
 testHttpRequestMethod::testStream()
 {
+    // relaxed RFC-compliance parse HTTP methods are upgraded to correct case
+    Config.onoff.relaxed_header_parser = 1;
     std::ostringstream buffer;
-    buffer << HttpRequestMethod("get",NULL);
+    buffer << HttpRequestMethod("get", NULL);
     CPPUNIT_ASSERT_EQUAL(String("GET"), String(buffer.str().c_str()));
+
+    // strict RFC-compliance parse HTTP methods are case sensitive
+    Config.onoff.relaxed_header_parser = 0;
+    std::ostringstream buffer2;
+    buffer2 << HttpRequestMethod("get", NULL);
+    CPPUNIT_ASSERT_EQUAL(String("get"), String(buffer2.str().c_str()));
 }