diff options
author | Jon Marius Venstad <jonmv@users.noreply.github.com> | 2019-01-13 15:24:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-13 15:24:00 +0100 |
commit | 44c89edf64fcae684ab39c42b59fe8b22183f173 (patch) | |
tree | 6bfe2ca36265bcd642106e77e37e2c0335b565da /vespalib/src/tests | |
parent | 03a344eba3265b5fc5d99d849e9d52ba05a31832 (diff) | |
parent | 028fd60d61854d074d2d8e5a4fb8b416abc7a62c (diff) |
Merge branch 'master' into jvenstad/remove-feature-flag-for-cache-invalidation-strategy
Diffstat (limited to 'vespalib/src/tests')
-rw-r--r-- | vespalib/src/tests/portal/http_request/http_request_test.cpp | 55 | ||||
-rw-r--r-- | vespalib/src/tests/portal/portal_test.cpp | 36 |
2 files changed, 91 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(); } diff --git a/vespalib/src/tests/portal/portal_test.cpp b/vespalib/src/tests/portal/portal_test.cpp index 299340fd131..ee5d10a313a 100644 --- a/vespalib/src/tests/portal/portal_test.cpp +++ b/vespalib/src/tests/portal/portal_test.cpp @@ -346,4 +346,40 @@ TEST_MT_FFF("require that portal destruction waits for request completion", 3, //----------------------------------------------------------------------------- +TEST("require that query parameters can be inspected") { + auto portal = Portal::create(null_crypto(), 0); + MyGetHandler handler([](Portal::GetRequest request) + { + EXPECT_EQUAL(request.get_uri(), "/test?a=b&x=y"); + EXPECT_EQUAL(request.get_path(), "/test"); + EXPECT_TRUE(request.has_param("a")); + EXPECT_TRUE(request.has_param("x")); + EXPECT_TRUE(!request.has_param("b")); + EXPECT_EQUAL(request.get_param("a"), "b"); + EXPECT_EQUAL(request.get_param("x"), "y"); + EXPECT_EQUAL(request.get_param("b"), ""); + auto params = request.export_params(); + EXPECT_EQUAL(params.size(), 2u); + EXPECT_EQUAL(params["a"], "b"); + EXPECT_EQUAL(params["x"], "y"); + request.respond_with_content("a", "b"); + }); + auto bound = portal->bind("/test", handler); + auto result = fetch(portal->listen_port(), null_crypto(), "/test?a=b&x=y"); + EXPECT_EQUAL(result, make_expected_response("a", "b")); +} + +TEST("require that request path is dequoted before handler dispatching") { + auto portal = Portal::create(null_crypto(), 0); + MyGetHandler handler([](Portal::GetRequest request) + { + EXPECT_EQUAL(request.get_uri(), "/%5btest%5D"); + EXPECT_EQUAL(request.get_path(), "/[test]"); + request.respond_with_content("a", "b"); + }); + auto bound = portal->bind("/[test]", handler); + auto result = fetch(portal->listen_port(), null_crypto(), "/%5btest%5D"); + EXPECT_EQUAL(result, make_expected_response("a", "b")); +} + TEST_MAIN() { TEST_RUN_ALL(); } |