summaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/portal/http_request/http_request_test.cpp
diff options
context:
space:
mode:
authorJon Marius Venstad <jonmv@users.noreply.github.com>2019-01-13 15:24:00 +0100
committerGitHub <noreply@github.com>2019-01-13 15:24:00 +0100
commit44c89edf64fcae684ab39c42b59fe8b22183f173 (patch)
tree6bfe2ca36265bcd642106e77e37e2c0335b565da /vespalib/src/tests/portal/http_request/http_request_test.cpp
parent03a344eba3265b5fc5d99d849e9d52ba05a31832 (diff)
parent028fd60d61854d074d2d8e5a4fb8b416abc7a62c (diff)
Merge branch 'master' into jvenstad/remove-feature-flag-for-cache-invalidation-strategy
Diffstat (limited to 'vespalib/src/tests/portal/http_request/http_request_test.cpp')
-rw-r--r--vespalib/src/tests/portal/http_request/http_request_test.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/vespalib/src/tests/portal/http_request/http_request_test.cpp b/vespalib/src/tests/portal/http_request/http_request_test.cpp
index 6e1527efa4b..047fde5750c 100644
--- a/vespalib/src/tests/portal/http_request/http_request_test.cpp
+++ b/vespalib/src/tests/portal/http_request/http_request_test.cpp
@@ -2,6 +2,7 @@
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/portal/http_request.h>
+#include <vespa/vespalib/util/stringfmt.h>
using namespace vespalib;
using namespace vespalib::portal;
@@ -117,4 +118,58 @@ TEST("require that header line must contain separator") {
"missing separator\r\n"));
}
+TEST("require that uri parameters can be parsed") {
+ auto req = make_request("GET /my/path?foo=bar&baz HTTP/1.1\r\n\r\n");
+ EXPECT_EQUAL(req.get_uri(), "/my/path?foo=bar&baz");
+ EXPECT_EQUAL(req.get_path(), "/my/path");
+ EXPECT_TRUE(req.has_param("foo"));
+ EXPECT_TRUE(!req.has_param("bar"));
+ EXPECT_TRUE(req.has_param("baz"));
+ EXPECT_EQUAL(req.get_param("foo"), "bar");
+ EXPECT_EQUAL(req.get_param("bar"), "");
+ EXPECT_EQUAL(req.get_param("baz"), "");
+}
+
+TEST("require that byte values in uri segments (path, key, value) are dequoted as expected") {
+ vespalib::string str = "0123456789aBcDeF";
+ for (size_t a = 0; a < 16; ++a) {
+ for (size_t b = 0; b < 16; ++b) {
+ vespalib::string expect = " foo ";
+ expect.push_back((a * 16) + b);
+ expect.push_back((a * 16) + b);
+ expect.append(" bar ");
+ vespalib::string input = vespalib::make_string("+foo+%%%c%c%%%c%c+bar+",
+ str[a], str[b], str[a], str[b]);
+ vespalib::string uri = vespalib::make_string("%s?%s=%s&extra=yes",
+ input.c_str(), input.c_str(), input.c_str());
+ auto req = make_request(vespalib::make_string("GET %s HTTP/1.1\r\n\r\n",
+ uri.c_str()));
+ EXPECT_EQUAL(req.get_uri(), uri);
+ EXPECT_EQUAL(req.get_path(), expect);
+ EXPECT_TRUE(req.has_param(expect));
+ EXPECT_EQUAL(req.get_param(expect), expect);
+ EXPECT_TRUE(req.has_param("extra"));
+ EXPECT_EQUAL(req.get_param("extra"), "yes");
+ }
+ }
+}
+
+TEST("require that percent character becomes plain if not followed by exactly 2 hex digits") {
+ auto req = make_request("GET %/5%5:%@5%5G%`5%5g%5?% HTTP/1.1\r\n\r\n");
+ EXPECT_EQUAL(req.get_path(), "%/5%5:%@5%5G%`5%5g%5");
+ EXPECT_TRUE(req.has_param("%"));
+}
+
+TEST("require that last character of uri segments (path, key, value) can be quoted") {
+ auto req = make_request("GET /%41?%42=%43 HTTP/1.1\r\n\r\n");
+ EXPECT_EQUAL(req.get_path(), "/A");
+ EXPECT_EQUAL(req.get_param("B"), "C");
+}
+
+TEST("require that additional query and key/value separators are not special") {
+ auto req = make_request("GET /?" "?== HTTP/1.1\r\n\r\n");
+ EXPECT_EQUAL(req.get_path(), "/");
+ EXPECT_EQUAL(req.get_param("?"), "=");
+}
+
TEST_MAIN() { TEST_RUN_ALL(); }