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
@ -25,3 +25,23 @@ TEST(Client, Connect)
|
|||||||
|
|
||||||
wfp_client_config_dispose(config);
|
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
|
class WebfuseServer::Private: public IServer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Private()
|
Private(bool use_tls)
|
||||||
: is_connected(false)
|
: is_connected(false)
|
||||||
, is_shutdown_requested(false)
|
, is_shutdown_requested(false)
|
||||||
, client(nullptr)
|
, client(nullptr)
|
||||||
@ -99,10 +99,17 @@ public:
|
|||||||
|
|
||||||
context = lws_create_context(&info);
|
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);
|
struct lws_vhost * vhost = lws_create_vhost(context, &info);
|
||||||
int port = lws_get_vhost_port(vhost);
|
int port = lws_get_vhost_port(vhost);
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
stream << "ws://localhost:" << port << "/";
|
stream << (use_tls ? "wss://" : "ws://") << "localhost:" << port << "/";
|
||||||
url = stream.str();
|
url = stream.str();
|
||||||
|
|
||||||
thread = std::thread(&Run, this);
|
thread = std::thread(&Run, this);
|
||||||
@ -244,8 +251,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
WebfuseServer::WebfuseServer()
|
WebfuseServer::WebfuseServer(bool use_tls)
|
||||||
: d(new Private())
|
: d(new Private(use_tls))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class WebfuseServer
|
|||||||
WebfuseServer(WebfuseServer const &) = delete;
|
WebfuseServer(WebfuseServer const &) = delete;
|
||||||
WebfuseServer& operator=(WebfuseServer const &) = delete;
|
WebfuseServer& operator=(WebfuseServer const &) = delete;
|
||||||
public:
|
public:
|
||||||
WebfuseServer();
|
WebfuseServer(bool use_tls = false);
|
||||||
~WebfuseServer();
|
~WebfuseServer();
|
||||||
std::string const & GetUrl();
|
std::string const & GetUrl();
|
||||||
void AwaitConnection();
|
void AwaitConnection();
|
||||||
|
Loading…
Reference in New Issue
Block a user