From d02a29f0ff33279268e675aae0856f3f8cf9d939 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 10 Jan 2023 14:22:47 +0100 Subject: Configurable Websocket für HTTPS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test-response.cpp | 2 +- tests/test-webserver.cpp | 168 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 115 insertions(+), 55 deletions(-) (limited to 'tests') diff --git a/tests/test-response.cpp b/tests/test-response.cpp index 3f83a6d..1c27bf0 100644 --- a/tests/test-response.cpp +++ b/tests/test-response.cpp @@ -22,7 +22,7 @@ public: void teardown(){} }; -BOOST_FIXTURE_TEST_CASE(response, ResponseFixture) +BOOST_FIXTURE_TEST_CASE(response1, ResponseFixture) { } diff --git a/tests/test-webserver.cpp b/tests/test-webserver.cpp index 1c1e6cc..10f6dca 100644 --- a/tests/test-webserver.cpp +++ b/tests/test-webserver.cpp @@ -56,58 +56,9 @@ const fs::path testKeyFilename{"./testkey.pem"}; class WebserverProcess { -public: - WebserverProcess(): m_pid{} + void init(const std::string& config) { - File::setFile(testConfigFilename, R"CONFIG( - www-data - www-data - 10 - stats.db - ../plugins - - - localhost - ip6-localhost - localhost - 127.0.0.1 - [::1] - - static-files - . - - testchain.pem - testkey.pem - - - - -
127.0.0.1
- 8080 - http - localhost -
- -
::1
- 8080 - http - localhost -
- -
127.0.0.1
- 8081 - https - localhost -
- -
::1
- 8081 - https - localhost -
-
-
-)CONFIG"); + File::setFile(testConfigFilename, config); // test self signed certificate File::setFile(testCertFilename, R"(-----BEGIN CERTIFICATE----- @@ -161,6 +112,66 @@ VZTqPHmb+db0rFA3XlAg2A== start(); } +public: + WebserverProcess(const std::string& config): m_pid{} + { + init(config); + } + + WebserverProcess(): m_pid{} + { + std::string config{R"CONFIG( + www-data + www-data + 10 + stats.db + ../plugins + + + localhost + ip6-localhost + localhost + 127.0.0.1 + [::1] + + static-files + . + + testchain.pem + testkey.pem + + + + +
127.0.0.1
+ 8080 + http + localhost +
+ +
::1
+ 8080 + http + localhost +
+ +
127.0.0.1
+ 8081 + https + localhost +
+ +
::1
+ 8081 + https + localhost +
+
+
+)CONFIG"}; + init(config); + } + ~WebserverProcess() { stop(); @@ -506,7 +517,7 @@ public: try { auto const address = boost::asio::ip::make_address("::1"); - auto const port = static_cast(9876); + auto const port = static_cast(8765); // The io_context is required for all I/O boost::asio::io_context ioc{1}; @@ -558,7 +569,56 @@ private: BOOST_FIXTURE_TEST_CASE(websocket, Fixture) { - WebserverProcess serverProcess; + std::string webserver_config{R"CONFIG( + www-data + www-data + 10 + stats.db + ../plugins + + + localhost + ip6-localhost + localhost + 127.0.0.1 + [::1] + + websocket + ::1:8765 + + testchain.pem + testkey.pem + + + + +
127.0.0.1
+ 8080 + http + localhost +
+ +
::1
+ 8080 + http + localhost +
+ +
127.0.0.1
+ 8081 + https + localhost +
+ +
::1
+ 8081 + https + localhost +
+
+
+)CONFIG"}; + WebserverProcess serverProcess{webserver_config}; BOOST_REQUIRE(serverProcess.is_running()); WebsocketServerProcess websocketProcess; @@ -598,6 +658,7 @@ BOOST_FIXTURE_TEST_CASE(websocket, Fixture) // Update the host_ string. This will provide the value of the // Host HTTP header during the WebSocket handshake. // See https://tools.ietf.org/html/rfc7230#section-5.4 + host = "[" + host + "]"; host += ':' + std::to_string(ep.port()); // Perform the SSL handshake @@ -632,7 +693,6 @@ BOOST_FIXTURE_TEST_CASE(websocket, Fixture) data = std::string(boost::asio::buffers_begin(buffer.data()), boost::asio::buffers_end(buffer.data())); BOOST_CHECK_EQUAL(data, "request1: 1"); - buffer.consume(buffer.size()); ws.write(boost::asio::buffer(std::string(text))); -- cgit v1.2.3