summaryrefslogtreecommitdiffhomepage
path: root/tests/test-webserver.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-10 14:22:47 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-10 14:22:47 +0100
commitd02a29f0ff33279268e675aae0856f3f8cf9d939 (patch)
treebbb22aeb9c14488ef0871b34f0400259658d46f0 /tests/test-webserver.cpp
parent1191f07767583a9b19280a4f29cb1b0bd6799785 (diff)
Configurable Websocket für HTTPS
Diffstat (limited to 'tests/test-webserver.cpp')
-rw-r--r--tests/test-webserver.cpp168
1 files changed, 114 insertions, 54 deletions
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(<webserver>
- <user>www-data</user>
- <group>www-data</group>
- <threads>10</threads>
- <statisticspath>stats.db</sttaisticspath>
- <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");
+ 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(<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"};
+ init(config);
+ }
+
~WebserverProcess()
{
stop();
@@ -506,7 +517,7 @@ public:
try
{
auto const address = boost::asio::ip::make_address("::1");
- auto const port = static_cast<unsigned short>(9876);
+ auto const port = static_cast<unsigned short>(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(<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>websocket</plugin>
+ <target>::1:8765</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{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)));