diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-01-14 11:12:21 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-01-14 11:12:21 +0100 |
commit | 3b42785c57768e619ade198f7b4760e16288e0f3 (patch) | |
tree | e0a64115a6fea8c89629de2fdfc4ef1cc02874e9 | |
parent | c0d9d61e3330d4f69a9547cc3d0e62970fb7427e (diff) |
Added config tests, moved from BSD license to CC0
-rw-r--r-- | LICENSE.txt | 28 | ||||
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | debian/copyright | 31 | ||||
-rw-r--r-- | http.cpp | 11 | ||||
-rw-r--r-- | tests/test-webserver.cpp | 118 | ||||
-rw-r--r-- | tests/webserverprocess.cpp | 16 | ||||
-rw-r--r-- | tests/webserverprocess.h | 6 |
7 files changed, 143 insertions, 71 deletions
diff --git a/LICENSE.txt b/LICENSE.txt index 89ed2c4..689d2b3 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,26 +1,4 @@ -Copyright 2021 Roland Reichwein +Author: Roland Reichwein <mail@reichwein.it>, 2020-2023 -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +Both upstream source code and Debian packaging is available +under the conditions of CC0 1.0 Universal @@ -1,5 +1,3 @@ -example conf files: -- php Big file bug - dynamic plugin interface (file buffer, ...) @@ -7,7 +5,7 @@ stats.png cgi unhandled headers git via smart http / cgi git via web interface -php +php, example SCGI? weblog: link consistency check (cron?) Integrate into Debian: WNPP diff --git a/debian/copyright b/debian/copyright index 8e3ebb6..689d2b3 100644 --- a/debian/copyright +++ b/debian/copyright @@ -1,29 +1,4 @@ -This package is Copyright 2021 by Roland Reichwein <mail@reichwein.it> +Author: Roland Reichwein <mail@reichwein.it>, 2020-2023 -Both upstream source code and Debian packaging is licensed under the BSD -license: - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +Both upstream source code and Debian packaging is available +under the conditions of CC0 1.0 Universal @@ -6,6 +6,8 @@ #include "response.h" #include "websocket.h" +#include <fmt/core.h> + #include <openssl/ssl.h> #include <openssl/crypto.h> @@ -326,7 +328,8 @@ public: acceptor_.open(endpoint.protocol(), ec); if (ec) { - fail(ec, "http listener open"); + //fail(ec, "http listener open"); + throw std::runtime_error(fmt::format("http listener open unsuccessful: {}:{}", endpoint.address().to_string(), endpoint.port())); return; } @@ -342,7 +345,8 @@ public: acceptor_.bind(endpoint, ec); if (ec) { - fail(ec, "http listener bind"); + //fail(ec, "http listener bind"); + throw std::runtime_error(fmt::format("http listener bind unsuccessful: {}:{}", endpoint.address().to_string(), endpoint.port())); return; } @@ -350,7 +354,8 @@ public: acceptor_.listen(net::socket_base::max_listen_connections, ec); if (ec) { - fail(ec, "http listener listen"); + //fail(ec, "http listener listen"); + throw std::runtime_error(fmt::format("http listen unsuccessful: {}:{}", endpoint.address().to_string(), endpoint.port())); return; } } diff --git a/tests/test-webserver.cpp b/tests/test-webserver.cpp index 5353c6a..72f2ab2 100644 --- a/tests/test-webserver.cpp +++ b/tests/test-webserver.cpp @@ -532,14 +532,14 @@ echo -ne "HTTP_HOST: $HTTP_HOST\r\n" BOOST_CHECK_EQUAL(result.second, "500 Bad Script: test2.sh/path1"); } -BOOST_FIXTURE_TEST_CASE(empty_config, Fixture) +BOOST_FIXTURE_TEST_CASE(config_empty, Fixture) { - WebserverProcess serverProcess{""}; + WebserverProcess serverProcess{std::string{}}; std::this_thread::sleep_for(std::chrono::milliseconds(50)); BOOST_REQUIRE_EQUAL(serverProcess.is_running(), false); } -BOOST_FIXTURE_TEST_CASE(incomplete_config, Fixture) +BOOST_FIXTURE_TEST_CASE(config_incomplete, Fixture) { std::string webserver_config{R"CONFIG(<webserver> <user>www-data</user> @@ -550,6 +550,118 @@ BOOST_FIXTURE_TEST_CASE(incomplete_config, Fixture) BOOST_REQUIRE_EQUAL(serverProcess.is_running(), false); } +BOOST_FIXTURE_TEST_CASE(config_bad_syntax, Fixture) +{ + std::string config{R"CONFIG(<webserver> + <user>www-data</user> + <group>www-data</group> + <threads>10</threads> + <statisticspath>stats.db</statisticspath> + <plugin-directory>../plugins</plugin-directory> + <sites> + <site> + <name>localhost</name> + <host>ip6-localhost</host> + <host>localhost</host> + <host>127.0.0.1</host> + <host>[::1]</host> + <path requested="/"> + <plugin>static-files</plugin> + <target>.</target> + </path> + <certpath>testchain.pem</certpath> + <keypath>testkey.pem</keypath> + </site> + </sites> + <sockets> + <socket> + <address>127.0.0.1</address> + <port>8080</port> + <protocol>http</protocol> + <site>localhost</site> + </socket> + <socket> + <address>::1</address> + <port>8080</port> + <protocol>http</protocol> + <site>localhost</site> + </socket> + <socket> + <address>127.0.0.1</address> + <port>8081</port> + <protocol>https</protocol> + <site>localhost</site> + </socket> + <socket> + <address>::1</address> + <port>8081</port> + <protocol>https</protocol> + <site>localhost</site> + <!-- </socket> --> + </sockets> +</webserver> +)CONFIG"}; + WebserverProcess serverProcess{config, false}; + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + BOOST_REQUIRE_EQUAL(serverProcess.is_running(), false); +} + +BOOST_FIXTURE_TEST_CASE(config_bad_socket, Fixture) +{ + std::string config{R"CONFIG(<webserver> + <user>www-data</user> + <group>www-data</group> + <threads>10</threads> + <statisticspath>stats.db</statisticspath> + <plugin-directory>../plugins</plugin-directory> + <sites> + <site> + <name>localhost</name> + <host>ip6-localhost</host> + <host>localhost</host> + <host>127.0.0.1</host> + <host>[::1]</host> + <path requested="/"> + <plugin>static-files</plugin> + <target>.</target> + </path> + <certpath>testchain.pem</certpath> + <keypath>testkey.pem</keypath> + </site> + </sites> + <sockets> + <socket> + <address>127.0.0.1</address> + <port>8080</port> + <protocol>http</protocol> + <site>localhost</site> + </socket> + <socket> + <address>::1</address> + <port>8080</port> + <protocol>http</protocol> + <site>localhost</site> + </socket> + <socket> + <address>127.0.0.1</address> + <port>8081</port> + <protocol>https</protocol> + <site>localhost</site> + </socket> + <socket> + <address>1234:5678::1</address> + <port>8081</port> + <protocol>https</protocol> + <site>localhost</site> + </socket> + </sockets> +</webserver> +)CONFIG"}; + WebserverProcess serverProcess{config, false}; + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + BOOST_REQUIRE_EQUAL(serverProcess.is_running(), false); +} + BOOST_FIXTURE_TEST_CASE(http_redirect, Fixture) { std::string webserver_config{R"CONFIG(<webserver> diff --git a/tests/webserverprocess.cpp b/tests/webserverprocess.cpp index f9ecdd3..31c9766 100644 --- a/tests/webserverprocess.cpp +++ b/tests/webserverprocess.cpp @@ -109,12 +109,14 @@ VZTqPHmb+db0rFA3XlAg2A== start(); } -WebserverProcess::WebserverProcess(const std::string& config): m_pid{} +WebserverProcess::WebserverProcess(const std::string& config, bool wait_for_listener): + m_pid{}, m_wait_for_listener{wait_for_listener} { init(config); } -WebserverProcess::WebserverProcess(): m_pid{} +WebserverProcess::WebserverProcess(bool wait_for_listener): + m_pid{}, m_wait_for_listener{wait_for_listener} { std::string config{R"CONFIG(<webserver> <user>www-data</user> @@ -190,10 +192,12 @@ void WebserverProcess::start() webserver(sizeof(argv) / sizeof(char*), argv); exit(0); } - - // wait for server to start up - if (int port{port_from_config(m_config)}; port >= 0) - Process::wait_for_pid_listening_on(m_pid, port); + + if (m_wait_for_listener) { + // wait for server to start up + if (int port{port_from_config(m_config)}; port >= 0) + Process::wait_for_pid_listening_on(m_pid, port); + } std::this_thread::sleep_for(std::chrono::milliseconds(20)); } diff --git a/tests/webserverprocess.h b/tests/webserverprocess.h index 5593c70..3a4b7d6 100644 --- a/tests/webserverprocess.h +++ b/tests/webserverprocess.h @@ -14,8 +14,8 @@ class WebserverProcess private: void init(const std::string& config); public: - WebserverProcess(const std::string& config); - WebserverProcess(); + WebserverProcess(const std::string& config, bool wait_for_listener = true); + WebserverProcess(bool wait_for_listener = true); ~WebserverProcess(); void start(); void stop(); @@ -25,6 +25,6 @@ public: private: pid_t m_pid; std::string m_config; - + bool m_wait_for_listener; }; // class WebserverProcess |