1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

fix: don't send messages if not connected

This commit is contained in:
Falk Werner 2020-06-13 17:08:05 +02:00
parent 55de95caf7
commit 4713ec3e93
4 changed files with 52 additions and 5 deletions

View File

@ -52,12 +52,15 @@ wf_impl_client_protocol_send(
bool result = false;
struct wf_client_protocol * protocol = user_data;
struct wf_message * message = wf_message_create(request);
if (NULL != message)
if (NULL != protocol->wsi)
{
wf_slist_append(&protocol->messages, &message->item);
lws_callback_on_writable(protocol->wsi);
result = true;
struct wf_message * message = wf_message_create(request);
if (NULL != message)
{
wf_slist_append(&protocol->messages, &message->item);
lws_callback_on_writable(protocol->wsi);
result = true;
}
}
return result;

View File

@ -211,6 +211,7 @@ alltests = executable('alltests',
'test/webfuse/utils/static_filesystem.c',
'test/webfuse/utils/ws_server.cc',
'test/webfuse/utils/ws_server2.cc',
'test/webfuse/utils/jansson_test_environment.cc',
'test/webfuse/mocks/fake_invokation_context.cc',
'test/webfuse/mocks/mock_authenticator.cc',
'test/webfuse/mocks/mock_request.cc',

View File

@ -208,6 +208,33 @@ TEST(AdapterClient, Authenticate)
wf_client_dispose(client);
}
TEST(AdapterClient, AuthenticateFailedWithoutConnect)
{
TimeoutWatcher watcher(TIMEOUT);
MockAdapterClientCallback callback;
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS, _)).Times(1)
.WillOnce(Invoke(GetCredentials));
bool called = false;
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATION_FAILED, nullptr)).Times(1)
.WillOnce(Invoke([&called] (wf_client *, int, void *) mutable {
called = true;
}));
wf_client * client = wf_client_create(
callback.GetCallbackFn(), callback.GetUserData());
wf_client_authenticate(client);
while (!called) {
watcher.check();
wf_client_service(client);
}
wf_client_dispose(client);
}
TEST(AdapterClient, AuthenticationFailed)
{
TimeoutWatcher watcher(TIMEOUT);

View File

@ -0,0 +1,16 @@
#include <gtest/gtest.h>
#include <jansson.h>
namespace webfuse_test
{
class JanssonTestEnvironment: public ::testing::Environment
{
public:
void SetUp()
{
json_object_seed(0);
}
};
#
}