From 0aded7a5277d7d046902473feda71bd4a6831198 Mon Sep 17 00:00:00 2001 From: Julian Mundhahs Date: Mon, 27 Jan 2025 15:05:12 +0100 Subject: [PATCH] add tests --- test/ServerTest.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/ServerTest.cpp b/test/ServerTest.cpp index 211adcb9bb..5b08990e53 100644 --- a/test/ServerTest.cpp +++ b/test/ServerTest.cpp @@ -51,6 +51,9 @@ TEST(ServerTest, parseHttpRequest) { "/?query=SELECT+%2A%20WHERE%20%7B%7D&action=csv_export")), ParsedRequestIs("/", {{"action", {"csv_export"}}}, Query{"SELECT * WHERE {}"})); + AD_EXPECT_THROW_WITH_MESSAGE( + parse(makeGetRequest("/?update=SELECT+%2A%20WHERE%20%7B%7D")), + testing::HasSubstr("SPARQL Update is not allowed as GET request.")); EXPECT_THAT( parse(makeGetRequest("/?graph=%3Cfoo%3E")), ParsedRequestIs("/", {{"graph", {""}}}, GraphStoreOperation{})); @@ -64,6 +67,14 @@ TEST(ServerTest, parseHttpRequest) { parse(makeGetRequest("/?graph=%3Cfoo%3E&graph=%3Cbar%3E")), testing::HasSubstr("Parameter \"graph\" must be " "given exactly once. Is: 2")); + AD_EXPECT_THROW_WITH_MESSAGE( + parse(makeGetRequest("/?query=SELECT+%2A%20WHERE%20%7B%7D&graph=foo")), + testing::HasSubstr( + R"(Request contains parameters for both a SPARQL Query ("query") and a Graph Store Protocol operation ("graph" or "default").)")); + AD_EXPECT_THROW_WITH_MESSAGE( + parse(makeGetRequest("/?query=SELECT+%2A%20WHERE%20%7B%7D&default")), + testing::HasSubstr( + R"(Request contains parameters for both a SPARQL Query ("query") and a Graph Store Protocol operation ("graph" or "default").)")); EXPECT_THAT( parse(makePostRequest("/", URLENCODED, "query=SELECT+%2A%20WHERE%20%7B%7D&send=100")), @@ -114,11 +125,34 @@ TEST(ServerTest, parseHttpRequest) { "parameters in the URL.")); EXPECT_THAT(parse(makePostRequest("/", URLENCODED, "cmd=clear-cache")), ParsedRequestIs("/", {{"cmd", {"clear-cache"}}}, None{})); + AD_EXPECT_THROW_WITH_MESSAGE( + parse(makePostRequest("/", URLENCODED, "query=a&update=b")), + testing::HasSubstr( + R"(Request must only contain one of "query" and "update".)")); + AD_EXPECT_THROW_WITH_MESSAGE( + parse(makePostRequest("/", URLENCODED, "graph=foo")), + testing::HasSubstr(absl::StrCat("Unsupported Content type \"", URLENCODED, + "\" for " + "Graph Store protocol."))); + AD_EXPECT_THROW_WITH_MESSAGE( + parse(makePostRequest("/", URLENCODED, "default")), + testing::HasSubstr(absl::StrCat("Unsupported Content type \"", URLENCODED, + "\" for Graph Store protocol."))); EXPECT_THAT(parse(makePostRequest("/", QUERY, "SELECT * WHERE {}")), ParsedRequestIs("/", {}, Query{"SELECT * WHERE {}"})); EXPECT_THAT( parse(makePostRequest("/?send=100", QUERY, "SELECT * WHERE {}")), ParsedRequestIs("/", {{"send", {"100"}}}, Query{"SELECT * WHERE {}"})); + AD_EXPECT_THROW_WITH_MESSAGE( + parse(makePostRequest("/?graph=foo", QUERY, "")), + testing::HasSubstr( + "Unsupported Content type \"application/sparql-query\" for " + "Graph Store protocol.")); + AD_EXPECT_THROW_WITH_MESSAGE( + parse(makePostRequest("/?default", QUERY, "")), + testing::HasSubstr( + "Unsupported Content type \"application/sparql-query\" for " + "Graph Store protocol.")); AD_EXPECT_THROW_WITH_MESSAGE( parse(makeRequest(http::verb::patch, "/")), testing::StrEq( @@ -134,6 +168,16 @@ TEST(ServerTest, parseHttpRequest) { testing::StrEq("SPARQL Update is not allowed as GET request.")); EXPECT_THAT(parse(makePostRequest("/", UPDATE, "DELETE * WHERE {}")), ParsedRequestIs("/", {}, Update{"DELETE * WHERE {}"})); + AD_EXPECT_THROW_WITH_MESSAGE( + parse(makePostRequest("/?graph=foo", UPDATE, "")), + testing::HasSubstr( + "Unsupported Content type \"application/sparql-update\" for " + "Graph Store protocol.")); + AD_EXPECT_THROW_WITH_MESSAGE( + parse(makePostRequest("/?default", UPDATE, "")), + testing::HasSubstr( + "Unsupported Content type \"application/sparql-update\" for " + "Graph Store protocol.")); EXPECT_THAT(parse(makePostRequest("/", URLENCODED, "update=DELETE%20%2A%20WHERE%20%7B%7D")), ParsedRequestIs("/", {}, Update{"DELETE * WHERE {}"}));