diff --git a/test/webfuse_provider/provider/test_client.cc b/test/webfuse_provider/provider/test_client.cc index 0d17560..18a13a5 100644 --- a/test/webfuse_provider/provider/test_client.cc +++ b/test/webfuse_provider/provider/test_client.cc @@ -23,5 +23,25 @@ TEST(Client, Connect) server.AwaitConnection(); + wfp_client_config_dispose(config); +} + +TEST(Client, ConnectWithTls) +{ + MockProviderClient provider; + EXPECT_CALL(provider, OnConnected()).Times(1); + EXPECT_CALL(provider, OnDisconnected()).Times(1); + + wfp_client_config * config = wfp_client_config_create(); + wfp_client_config_set_certpath(config, "client-cert.pem"); + wfp_client_config_set_keypath(config, "client-key.pem"); + wfp_client_config_set_ca_filepath(config, "server-cert.pem"); + provider.AttachTo(config); + + WebfuseServer server(true); + Client client(config, server.GetUrl()); + + server.AwaitConnection(); + wfp_client_config_dispose(config); } \ No newline at end of file diff --git a/test/webfuse_provider/test_util/webfuse_server.cc b/test/webfuse_provider/test_util/webfuse_server.cc index 7121507..ec6b20b 100644 --- a/test/webfuse_provider/test_util/webfuse_server.cc +++ b/test/webfuse_provider/test_util/webfuse_server.cc @@ -73,7 +73,7 @@ namespace webfuse_test class WebfuseServer::Private: public IServer { public: - Private() + Private(bool use_tls) : is_connected(false) , is_shutdown_requested(false) , client(nullptr) @@ -99,10 +99,17 @@ public: context = lws_create_context(&info); + if (use_tls) + { + info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT; + info.ssl_cert_filepath = "server-cert.pem"; + info.ssl_private_key_filepath = "server-key.pem"; + } + struct lws_vhost * vhost = lws_create_vhost(context, &info); int port = lws_get_vhost_port(vhost); - std::ostringstream stream; - stream << "ws://localhost:" << port << "/"; + std::ostringstream stream; + stream << (use_tls ? "wss://" : "ws://") << "localhost:" << port << "/"; url = stream.str(); thread = std::thread(&Run, this); @@ -244,8 +251,8 @@ private: }; -WebfuseServer::WebfuseServer() -: d(new Private()) +WebfuseServer::WebfuseServer(bool use_tls) +: d(new Private(use_tls)) { } diff --git a/test/webfuse_provider/test_util/webfuse_server.hpp b/test/webfuse_provider/test_util/webfuse_server.hpp index eb467e0..e0b3393 100644 --- a/test/webfuse_provider/test_util/webfuse_server.hpp +++ b/test/webfuse_provider/test_util/webfuse_server.hpp @@ -12,7 +12,7 @@ class WebfuseServer WebfuseServer(WebfuseServer const &) = delete; WebfuseServer& operator=(WebfuseServer const &) = delete; public: - WebfuseServer(); + WebfuseServer(bool use_tls = false); ~WebfuseServer(); std::string const & GetUrl(); void AwaitConnection();