From 8475a181be2301702c409a20dc99115ee54ec9cc Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Wed, 4 Jan 2023 20:08:12 +0100 Subject: Added test for HTTP 404 --- tests/test-webserver.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/test-webserver.cpp b/tests/test-webserver.cpp index aa09a01..de38cf3 100644 --- a/tests/test-webserver.cpp +++ b/tests/test-webserver.cpp @@ -360,16 +360,30 @@ public: ~Fixture(){} }; -BOOST_DATA_TEST_CASE_F(Fixture, http_download, data::make({false, true}) * data::make({false, true}) * data::make({false, true}), ipv6, http11, https) +BOOST_DATA_TEST_CASE_F(Fixture, http_get, data::make({false, true}) * data::make({false, true}) * data::make({false, true}), ipv6, http11, https) { WebserverProcess serverProcess; BOOST_REQUIRE(serverProcess.isRunning()); auto response{(https ? HTTPSGet("/webserver.conf") : HTTPGet("/webserver.conf"))}; BOOST_REQUIRE(serverProcess.isRunning()); - BOOST_REQUIRE_EQUAL(response.first, "HTTP/1.1 200 OK\r\nServer: Reichwein.IT Webserver 1.17\r\nContent-Type: application/text\r\nContent-Length: 1021\r\n\r\n"); + BOOST_REQUIRE_EQUAL(response.first, "HTTP/1.1 200 OK\r\nServer: Reichwein.IT Webserver " VERSION "\r\nContent-Type: application/text\r\nContent-Length: 1021\r\n\r\n"); BOOST_REQUIRE_EQUAL(response.second, File::getFile(serverProcess.testConfigFilename)); auto output{serverProcess.output()}; BOOST_REQUIRE_MESSAGE(boost::algorithm::contains(output, "Serving"), "Bad output: "s + output); } +BOOST_DATA_TEST_CASE_F(Fixture, http_get_file_not_found, data::make({false, true}) * data::make({false, true}) * data::make({false, true}), ipv6, http11, https) +{ + WebserverProcess serverProcess; + + BOOST_REQUIRE(serverProcess.isRunning()); + BOOST_REQUIRE(!fs::exists("./webserver.confSUFFIX")); + auto response{(https ? HTTPSGet("/webserver.confSUFFIX") : HTTPGet("/webserver.confSUFFIX"))}; + BOOST_REQUIRE(serverProcess.isRunning()); + BOOST_REQUIRE_EQUAL(response.first, "HTTP/1.1 404 Not Found\r\nServer: Reichwein.IT Webserver " VERSION "\r\nContent-Type: text/html\r\nContent-Length: 36\r\n\r\n"); + BOOST_REQUIRE_EQUAL(response.second, "404 Not found: /webserver.confSUFFIX"); + auto output{serverProcess.output()}; + BOOST_REQUIRE_MESSAGE(boost::algorithm::contains(output, "Serving"), "Bad output: "s + output); +} + -- cgit v1.2.3