diff options
Diffstat (limited to 'icespider/unittests')
-rw-r--r-- | icespider/unittests/testApp.cpp | 20 | ||||
-rw-r--r-- | icespider/unittests/testCompile.cpp | 4 | ||||
-rw-r--r-- | icespider/unittests/testFcgi.cpp | 9 | ||||
-rw-r--r-- | icespider/unittests/testRoutes.json | 14 |
4 files changed, 43 insertions, 4 deletions
diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp index ddf1579..de5e921 100644 --- a/icespider/unittests/testApp.cpp +++ b/icespider/unittests/testApp.cpp @@ -28,7 +28,7 @@ void forceEarlyChangeDir() BOOST_AUTO_TEST_CASE( testLoadConfiguration ) { - BOOST_REQUIRE_EQUAL(11, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size()); + BOOST_REQUIRE_EQUAL(12, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size()); } class TestRequest : public IHttpRequest { @@ -64,6 +64,11 @@ class TestRequest : public IHttpRequest { return qs.find(key) == qs.end() ? IceUtil::Optional<std::string>() : qs.find(key)->second; } + IceUtil::Optional<std::string> getCookieParam(const std::string & key) const override + { + return cookies.find(key) == cookies.end() ? IceUtil::Optional<std::string>() : cookies.find(key)->second; + } + IceUtil::Optional<std::string> getHeaderParam(const std::string & key) const override { return hdr.find(key) == hdr.end() ? IceUtil::Optional<std::string>() : hdr.find(key)->second; @@ -83,6 +88,7 @@ class TestRequest : public IHttpRequest { typedef std::vector<std::string> UrlVars; UrlVars url; MapVars qs; + MapVars cookies; MapVars hdr; MapVars env; mutable std::stringstream input; @@ -144,7 +150,7 @@ BOOST_AUTO_TEST_CASE( testCoreSettings ) { BOOST_REQUIRE_EQUAL(5, routes.size()); BOOST_REQUIRE_EQUAL(1, routes[0].size()); - BOOST_REQUIRE_EQUAL(5, routes[1].size()); + BOOST_REQUIRE_EQUAL(6, routes[1].size()); BOOST_REQUIRE_EQUAL(1, routes[2].size()); BOOST_REQUIRE_EQUAL(2, routes[3].size()); BOOST_REQUIRE_EQUAL(2, routes[4].size()); @@ -543,5 +549,15 @@ BOOST_AUTO_TEST_CASE( testCallSearchMissingI ) BOOST_REQUIRE(request.output.eof()); } +BOOST_AUTO_TEST_CASE( testCookies ) +{ + TestRequest request(this, HttpMethod::GET, "/cookies"); + request.cookies["mycookievar"] = "something"; + request.qs["i"] = "1234"; + process(&request); + auto h = parseHeaders(request.output); + BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); +} + BOOST_AUTO_TEST_SUITE_END(); diff --git a/icespider/unittests/testCompile.cpp b/icespider/unittests/testCompile.cpp index 8d1cefa..0d7e36c 100644 --- a/icespider/unittests/testCompile.cpp +++ b/icespider/unittests/testCompile.cpp @@ -36,7 +36,7 @@ BOOST_AUTO_TEST_CASE( testLoadConfiguration ) rc.applyDefaults(cfg, u); BOOST_REQUIRE_EQUAL("common", cfg->name); - BOOST_REQUIRE_EQUAL(11, cfg->routes.size()); + BOOST_REQUIRE_EQUAL(12, cfg->routes.size()); BOOST_REQUIRE_EQUAL("/", cfg->routes["index"]->path); BOOST_REQUIRE_EQUAL(HttpMethod::GET, cfg->routes["index"]->method); @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE( testLoad ) BOOST_TEST_INFO(dlerror()); BOOST_REQUIRE(lib); - BOOST_REQUIRE_EQUAL(11, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size()); + BOOST_REQUIRE_EQUAL(12, AdHoc::PluginManager::getDefault()->getAll<IceSpider::RouteHandlerFactory>().size()); // smoke test (block ensure dlclose dones't cause segfault) { auto route = AdHoc::PluginManager::getDefault()->get<IceSpider::RouteHandlerFactory>("common::index"); diff --git a/icespider/unittests/testFcgi.cpp b/icespider/unittests/testFcgi.cpp index 923c28d..2c93c32 100644 --- a/icespider/unittests/testFcgi.cpp +++ b/icespider/unittests/testFcgi.cpp @@ -264,5 +264,14 @@ BOOST_AUTO_TEST_CASE( postjson_dictionary ) BOOST_REQUIRE_EQUAL("", n["empty"]); } +BOOST_AUTO_TEST_CASE( cookies ) +{ + CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No", "CONTENT_TYPE=application/json", "HTTP_COOKIE=valueA=1234; value+B=Something+with+spaces." }); + TestRequest r(this, env); + BOOST_REQUIRE_EQUAL(1234, *r.IceSpider::IHttpRequest::getCookieParam<Ice::Int>("valueA")); + BOOST_REQUIRE_EQUAL("Something with spaces.", *r.IceSpider::IHttpRequest::getCookieParam<std::string>("value B")); + BOOST_REQUIRE(!r.IceSpider::IHttpRequest::getCookieParam<Ice::Int>("notAThing")); +} + BOOST_AUTO_TEST_SUITE_END(); diff --git a/icespider/unittests/testRoutes.json b/icespider/unittests/testRoutes.json index 5bf002f..3bc6fda 100644 --- a/icespider/unittests/testRoutes.json +++ b/icespider/unittests/testRoutes.json @@ -124,6 +124,20 @@ "source": "QueryString" } } + }, + "cookies": { + "path": "/cookies", + "method": "GET", + "operation": "TestIceSpider.TestApi.withParams", + "params": { + "s": { + "source": "Cookie", + "key": "mycookievar" + }, + "i": { + "source": "QueryString" + } + } } }, "slices": [ |