mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
added test using TLS connection
This commit is contained in:
parent
a557f0b6fe
commit
dc6e05b1b8
@ -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);
|
||||
}
|
@ -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))
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user