diff options
| author | Stefan Boberg <[email protected]> | 2026-03-12 17:02:01 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2026-03-12 17:02:01 +0100 |
| commit | 3aa6aa83d05249d7081a8c19a28ce9b9c4566da2 (patch) | |
| tree | f4f14006e82cdf0ed05083c9af90e17116614368 /src/zenserver-test/zenserver-test.cpp | |
| parent | Update CHANGELOG.md (diff) | |
| download | zen-3aa6aa83d05249d7081a8c19a28ce9b9c4566da2.tar.xz zen-3aa6aa83d05249d7081a8c19a28ce9b9c4566da2.zip | |
Add --no-network option (#831)
- Add `--no-network` CLI option which disables all TCP/HTTPS listeners, restricting zenserver to Unix domain socket communication only.
- Also fixes asio upgrade breakage on main
Diffstat (limited to 'src/zenserver-test/zenserver-test.cpp')
| -rw-r--r-- | src/zenserver-test/zenserver-test.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/zenserver-test/zenserver-test.cpp b/src/zenserver-test/zenserver-test.cpp index 0b2bc50c0..e89812c1f 100644 --- a/src/zenserver-test/zenserver-test.cpp +++ b/src/zenserver-test/zenserver-test.cpp @@ -380,6 +380,37 @@ TEST_CASE("http.unixsocket") CHECK(Res.ResponsePayload.GetView().EqualBytes(Body.GetView())); } } + +TEST_CASE("http.nonetwork") +{ + std::filesystem::path TestDir = TestEnv.CreateNewTestDir(); + std::filesystem::path SocketDir = TestEnv.CreateNewTestDir(); + std::string SocketPath = (SocketDir / "zen.sock").string(); + + ZenServerInstance Instance(TestEnv); + Instance.SetDataDir(TestDir); + const uint16_t PortNumber = Instance.SpawnServerAndWaitUntilReady(fmt::format("--http=asio --no-network --unix-socket {}", SocketPath)); + + // Verify communication works via Unix socket + HttpClientSettings Settings; + Settings.UnixSocketPath = SocketPath; + HttpClient Http{fmt::format("http://localhost:{}", PortNumber), Settings, {}}; + + SUBCASE("GET over unix socket succeeds") + { + HttpClient::Response Res = Http.Get("/testing/hello"); + CHECK(Res.IsSuccess()); + } + + SUBCASE("TCP connection is refused") + { + asio::io_context IoContext; + asio::ip::tcp::socket Socket(IoContext); + asio::error_code Ec; + Socket.connect(asio::ip::tcp::endpoint(asio::ip::make_address("127.0.0.1"), PortNumber), Ec); + CHECK(Ec); // Expect an error (connection refused) + } +} # endif TEST_SUITE_END(); |