summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2016-09-17 15:39:33 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2016-09-17 15:39:33 +0100
commit35841416d8480db608488e10ac49f9879f8ba753 (patch)
treeff8945bc52c20ee51f508cd8a257a3e7be7fc155
parentBad request on missing or invalid parameters (diff)
downloadicespider-35841416d8480db608488e10ac49f9879f8ba753.tar.bz2
icespider-35841416d8480db608488e10ac49f9879f8ba753.tar.xz
icespider-35841416d8480db608488e10ac49f9879f8ba753.zip
Fix up lots of test coverage
-rw-r--r--icespider/compile/main.cpp2
-rw-r--r--icespider/core/core.cpp3
-rw-r--r--icespider/core/exceptions.h3
-rw-r--r--icespider/core/irouteHandler.h2
-rw-r--r--icespider/fcgi/cgiRequestBase.cpp9
-rw-r--r--icespider/unittests/testApp.cpp2
-rw-r--r--icespider/unittests/testFcgi.cpp25
-rw-r--r--icespider/xslt/exslt.cpp2
8 files changed, 43 insertions, 5 deletions
diff --git a/icespider/compile/main.cpp b/icespider/compile/main.cpp
index 6a8af6c..3d5311f 100644
--- a/icespider/compile/main.cpp
+++ b/icespider/compile/main.cpp
@@ -23,8 +23,10 @@ main(int c, char ** v)
po::notify(vm);
if (showHelp || input.empty() || output.empty()) {
+ // LCOV_EXCL_START
std::cout << opts << std::endl;
return 1;
+ // LCOV_EXCL_STOP
}
rc.searchPath.push_back(input.parent_path());
diff --git a/icespider/core/core.cpp b/icespider/core/core.cpp
index fc50bd1..9ca37ea 100644
--- a/icespider/core/core.cpp
+++ b/icespider/core/core.cpp
@@ -68,6 +68,7 @@ namespace IceSpider {
Core::findRoute(const IHttpRequest * request) const
{
const auto & pathparts = request->getRequestPath();
+ const auto method = request->getRequestMethod();
if (pathparts.size() >= routes.size()) {
throw Http404_NotFound();
}
@@ -75,7 +76,7 @@ namespace IceSpider {
bool match = false;
for (const auto & r : routeSet) {
if (pathparts /= r) {
- if (r->method == request->getRequestMethod()) {
+ if (r->method == method) {
return r;
}
match = true;
diff --git a/icespider/core/exceptions.h b/icespider/core/exceptions.h
index 71e6e71..38df81b 100644
--- a/icespider/core/exceptions.h
+++ b/icespider/core/exceptions.h
@@ -2,9 +2,10 @@
#define ICESPIDER_EXCEPTIONS_H
#include "http.h"
+#include <visibility.h>
#define DeclareHttpEx(Name) \
- class Name : public ::IceSpider::HttpException { \
+ class DLL_PUBLIC Name : public ::IceSpider::HttpException { \
public: \
Name(); \
static const int code; \
diff --git a/icespider/core/irouteHandler.h b/icespider/core/irouteHandler.h
index 595ea95..f3e271b 100644
--- a/icespider/core/irouteHandler.h
+++ b/icespider/core/irouteHandler.h
@@ -35,7 +35,9 @@ namespace IceSpider {
inline T requiredParameterNotFound(const char * s, const K & key) const
{
requiredParameterNotFound(s, key);
+ // LCOV_EXCL_START unreachable, requiredParameterNotFound always throws
return T();
+ // LCOV_EXCL_STOP
}
void addRouteSerializer(const MimeType &, StreamSerializerFactoryPtr);
diff --git a/icespider/fcgi/cgiRequestBase.cpp b/icespider/fcgi/cgiRequestBase.cpp
index 85f7966..d77fb84 100644
--- a/icespider/fcgi/cgiRequestBase.cpp
+++ b/icespider/fcgi/cgiRequestBase.cpp
@@ -76,9 +76,14 @@ namespace IceSpider {
HttpMethod
CgiRequestBase::getRequestMethod() const
{
- auto i = envmap.find("REQUEST_METHOD");
- return Slicer::ModelPartForEnum<HttpMethod>::lookup(
+ try {
+ auto i = envmap.find("REQUEST_METHOD");
+ return Slicer::ModelPartForEnum<HttpMethod>::lookup(
std::string(std::get<0>(i->second), std::get<1>(i->second)));
+ }
+ catch (const Slicer::InvalidEnumerationValue &) {
+ throw IceSpider::Http405_MethodNotAllowed();
+ }
}
OptionalString
diff --git a/icespider/unittests/testApp.cpp b/icespider/unittests/testApp.cpp
index 0806542..df2f7ff 100644
--- a/icespider/unittests/testApp.cpp
+++ b/icespider/unittests/testApp.cpp
@@ -119,7 +119,7 @@ BOOST_AUTO_TEST_CASE( testFindRoutes )
TestRequest requestGetItemDefault(this, HttpMethod::GET, "/item/something");
BOOST_REQUIRE(findRoute(&requestGetItemDefault));
- TestRequest requestGetItemLong(this, HttpMethod::GET, "/view/something/something/extra");
+ TestRequest requestGetItemLong(this, HttpMethod::GET, "/view/something/something/extra/many/things/longer/than/longest/route");
BOOST_REQUIRE_THROW(findRoute(&requestGetItemLong), IceSpider::Http404_NotFound);
TestRequest requestGetItemShort(this, HttpMethod::GET, "/view/missingSomething");
diff --git a/icespider/unittests/testFcgi.cpp b/icespider/unittests/testFcgi.cpp
index a717c4d..f2a58a4 100644
--- a/icespider/unittests/testFcgi.cpp
+++ b/icespider/unittests/testFcgi.cpp
@@ -11,6 +11,7 @@ class TestRequest : public IceSpider::CgiRequestBase {
initialize();
}
+ // LCOV_EXCL_START we never actually read or write anything here
std::ostream & getOutputStream() const override
{
return std::cout;
@@ -20,6 +21,7 @@ class TestRequest : public IceSpider::CgiRequestBase {
{
return std::cin;
}
+ // LCOV_EXCL_STOP
};
class CharPtrPtrArray : public std::vector<char *> {
@@ -51,6 +53,7 @@ class CharPtrPtrArray : public std::vector<char *> {
};
namespace std {
+ // LCOV_EXCL_START assert failure helper only
static
std::ostream &
operator<<(std::ostream & s, const IceSpider::PathElements & pe)
@@ -60,6 +63,7 @@ namespace std {
}
return s;
}
+ // LCOV_EXCL_STOP
}
BOOST_FIXTURE_TEST_SUITE( CgiRequestBase, IceSpider::Core );
@@ -147,5 +151,26 @@ BOOST_AUTO_TEST_CASE( query_string_three_noVal )
BOOST_REQUIRE_EQUAL("3", *r.getQueryStringParam("three"));
}
+BOOST_AUTO_TEST_CASE( requestmethod_get )
+{
+ CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=GET" });
+ TestRequest r(this, env);
+ BOOST_REQUIRE_EQUAL(IceSpider::HttpMethod::GET, r.getRequestMethod());
+}
+
+BOOST_AUTO_TEST_CASE( requestmethod_post )
+{
+ CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=POST" });
+ TestRequest r(this, env);
+ BOOST_REQUIRE_EQUAL(IceSpider::HttpMethod::POST, r.getRequestMethod());
+}
+
+BOOST_AUTO_TEST_CASE( requestmethod_bad )
+{
+ CharPtrPtrArray env ({ "SCRIPT_NAME=/", "REQUEST_METHOD=No" });
+ TestRequest r(this, env);
+ BOOST_REQUIRE_THROW(r.getRequestMethod(), IceSpider::Http405_MethodNotAllowed);
+}
+
BOOST_AUTO_TEST_SUITE_END();
diff --git a/icespider/xslt/exslt.cpp b/icespider/xslt/exslt.cpp
index 63bd0d1..772ef5e 100644
--- a/icespider/xslt/exslt.cpp
+++ b/icespider/xslt/exslt.cpp
@@ -8,10 +8,12 @@ void initLibXml()
exsltRegisterAll();
}
+// LCOV_EXCL_START lcov actually misses destructor functions
static void cleanupLibXml() __attribute__((destructor(102)));
void cleanupLibXml()
{
xsltCleanupGlobals();
xmlCleanupParser();
}
+// LCOV_EXCL_STOP