diff --git a/lib/webfuse/adapter/impl/client_protocol.c b/lib/webfuse/adapter/impl/client_protocol.c index 3bffaad..3eb1493 100644 --- a/lib/webfuse/adapter/impl/client_protocol.c +++ b/lib/webfuse/adapter/impl/client_protocol.c @@ -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; diff --git a/meson.build b/meson.build index 3a7a1cd..873d55b 100644 --- a/meson.build +++ b/meson.build @@ -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', diff --git a/test/webfuse/tests/adapter/test_client.cc b/test/webfuse/tests/adapter/test_client.cc index e8ab17c..179df2b 100644 --- a/test/webfuse/tests/adapter/test_client.cc +++ b/test/webfuse/tests/adapter/test_client.cc @@ -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); diff --git a/test/webfuse/utils/jansson_test_environment.cc b/test/webfuse/utils/jansson_test_environment.cc new file mode 100644 index 0000000..24d091f --- /dev/null +++ b/test/webfuse/utils/jansson_test_environment.cc @@ -0,0 +1,16 @@ +#include +#include + +namespace webfuse_test +{ + +class JanssonTestEnvironment: public ::testing::Environment +{ +public: + void SetUp() + { + json_object_seed(0); + } +}; +# +} \ No newline at end of file