mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
removed dobuild and adapter stuff
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
#include "webfuse/mocks/mock_fuse.hpp"
|
||||
#include "webfuse/utils/wrap.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static webfuse_test::FuseMock * webfuse_test_FuseMock = nullptr;
|
||||
|
||||
WF_WRAP_FUNC1(webfuse_test_FuseMock, void*, fuse_req_userdata, fuse_req_t);
|
||||
WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_open, fuse_req_t, const struct fuse_file_info *);
|
||||
WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_err, fuse_req_t, int);
|
||||
WF_WRAP_FUNC3(webfuse_test_FuseMock, int, fuse_reply_buf, fuse_req_t, const char *, size_t);
|
||||
WF_WRAP_FUNC3(webfuse_test_FuseMock, int, fuse_reply_attr, fuse_req_t, const struct stat *, double);
|
||||
WF_WRAP_FUNC1(webfuse_test_FuseMock, const struct fuse_ctx *, fuse_req_ctx, fuse_req_t);
|
||||
WF_WRAP_FUNC2(webfuse_test_FuseMock, int, fuse_reply_entry, fuse_req_t, const struct fuse_entry_param *);
|
||||
}
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
FuseMock::FuseMock()
|
||||
{
|
||||
webfuse_test_FuseMock = this;
|
||||
}
|
||||
|
||||
FuseMock::~FuseMock()
|
||||
{
|
||||
webfuse_test_FuseMock = nullptr;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
#ifndef MOCK_FUSE_HPP
|
||||
#define MOCK_FUSE_HPP
|
||||
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
class FuseMock
|
||||
{
|
||||
public:
|
||||
FuseMock();
|
||||
virtual ~FuseMock();
|
||||
|
||||
MOCK_METHOD1(fuse_req_userdata, void *(fuse_req_t req));
|
||||
MOCK_METHOD2(fuse_reply_open, int (fuse_req_t req, const struct fuse_file_info *fi));
|
||||
MOCK_METHOD2(fuse_reply_err, int (fuse_req_t req, int err));
|
||||
MOCK_METHOD3(fuse_reply_buf, int (fuse_req_t req, const char *buf, size_t size));
|
||||
MOCK_METHOD3(fuse_reply_attr, int (fuse_req_t req, const struct stat *attr, double attr_timeout));
|
||||
MOCK_METHOD1(fuse_req_ctx, const struct fuse_ctx *(fuse_req_t req));
|
||||
MOCK_METHOD2(fuse_reply_entry, int (fuse_req_t req, const struct fuse_entry_param *e));
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,56 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/close.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfuse/mocks/mock_fuse.hpp"
|
||||
#include "webfuse/mocks/mock_operation_context.hpp"
|
||||
#include "webfuse/mocks/mock_jsonrpc_proxy.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using webfuse_test::MockJsonRpcProxy;
|
||||
using webfuse_test::MockOperationContext;
|
||||
using webfuse_test::FuseMock;
|
||||
using testing::_;
|
||||
using testing::Return;
|
||||
using testing::StrEq;
|
||||
|
||||
TEST(wf_impl_operation_close, notify_proxy)
|
||||
{
|
||||
MockJsonRpcProxy proxy;
|
||||
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,StrEq("close"),StrEq("siii"))).Times(1);
|
||||
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(reinterpret_cast<wf_jsonrpc_proxy*>(&proxy)));
|
||||
|
||||
wf_impl_operation_context op_context;
|
||||
op_context.name = nullptr;
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context));
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, 0)).Times(1).WillOnce(Return(0));
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
fuse_file_info file_info;
|
||||
file_info.flags = 0;
|
||||
wf_impl_operation_close(request, inode, &file_info);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_close, fail_rpc_null)
|
||||
{
|
||||
MockJsonRpcProxy proxy;
|
||||
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vnotify(_,_,_)).Times(0);
|
||||
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(nullptr));
|
||||
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, 0)).Times(1).WillOnce(Return(0));
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
fuse_file_info * file_info = nullptr;
|
||||
wf_impl_operation_close(request, inode, file_info);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/context.h"
|
||||
#include "webfuse/adapter/impl/session.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(wf_impl_operation_context, get_proxy)
|
||||
{
|
||||
wf_jsonrpc_proxy * proxy = reinterpret_cast<wf_jsonrpc_proxy*>(42);
|
||||
wf_impl_operation_context context;
|
||||
context.proxy = proxy;
|
||||
|
||||
ASSERT_EQ(proxy, wf_impl_operation_context_get_proxy(&context));
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_context, get_proxy_fail_no_session)
|
||||
{
|
||||
wf_impl_operation_context context;
|
||||
context.proxy = nullptr;
|
||||
|
||||
ASSERT_EQ(nullptr, wf_impl_operation_context_get_proxy(&context));
|
||||
|
||||
}
|
||||
@@ -1,213 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/getattr.h"
|
||||
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#include "webfuse/mocks/mock_fuse.hpp"
|
||||
#include "webfuse/mocks/mock_operation_context.hpp"
|
||||
#include "webfuse/mocks/mock_jsonrpc_proxy.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using webfuse_test::MockJsonRpcProxy;
|
||||
using webfuse_test::MockOperationContext;
|
||||
using webfuse_test::FuseMock;
|
||||
using testing::_;
|
||||
using testing::Return;
|
||||
using testing::Invoke;
|
||||
using testing::StrEq;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void free_context(
|
||||
struct wf_jsonrpc_proxy * ,
|
||||
wf_jsonrpc_proxy_finished_fn * ,
|
||||
void * user_data,
|
||||
char const * ,
|
||||
char const *)
|
||||
{
|
||||
free(user_data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_getattr, invoke_proxy)
|
||||
{
|
||||
MockJsonRpcProxy proxy;
|
||||
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("getattr"),StrEq("si"))).Times(1)
|
||||
.WillOnce(Invoke(free_context));
|
||||
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(reinterpret_cast<wf_jsonrpc_proxy*>(&proxy)));
|
||||
|
||||
wf_impl_operation_context op_context;
|
||||
op_context.name = nullptr;
|
||||
fuse_ctx fuse_context;
|
||||
fuse_context.gid = 0;
|
||||
fuse_context.uid = 0;
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_ctx(_)).Times(1).WillOnce(Return(&fuse_context));
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context));
|
||||
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
fuse_file_info * file_info = nullptr;
|
||||
wf_impl_operation_getattr(request, inode, file_info);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_getattr, fail_rpc_null)
|
||||
{
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(nullptr));
|
||||
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_ctx(_)).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
fuse_file_info * file_info = nullptr;
|
||||
wf_impl_operation_getattr(request, inode, file_info);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_getattr, finished_file)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_attr(_,_,_)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "mode", json_integer(0755));
|
||||
json_object_set_new(result, "type", json_string("file"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_getattr_context*>(malloc(sizeof(wf_impl_operation_getattr_context)));
|
||||
context->inode = 1;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_getattr_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_getattr, finished_dir)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_attr(_,_,_)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "mode", json_integer(0755));
|
||||
json_object_set_new(result, "type", json_string("dir"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_getattr_context*>(malloc(sizeof(wf_impl_operation_getattr_context)));
|
||||
context->inode = 1;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_getattr_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_getattr, finished_unknown_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_attr(_,_,_)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "mode", json_integer(0755));
|
||||
json_object_set_new(result, "type", json_string("unknown"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_getattr_context*>(malloc(sizeof(wf_impl_operation_getattr_context)));
|
||||
context->inode = 1;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_getattr_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_getattr, finished_fail_missing_mode)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "type", json_string("file"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_getattr_context*>(malloc(sizeof(wf_impl_operation_getattr_context)));
|
||||
context->inode = 1;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_getattr_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_getattr, finished_fail_invalid_mode_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "mode", json_string("0755"));
|
||||
json_object_set_new(result, "type", json_string("file"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_getattr_context*>(malloc(sizeof(wf_impl_operation_getattr_context)));
|
||||
context->inode = 1;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_getattr_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_getattr, finished_fail_type_mode)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "mode", json_integer(0755));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_getattr_context*>(malloc(sizeof(wf_impl_operation_getattr_context)));
|
||||
context->inode = 1;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_getattr_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_getattr, finished_fail_invalid_type_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "mode", json_integer(0755));
|
||||
json_object_set_new(result, "type", json_integer(42));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_getattr_context*>(malloc(sizeof(wf_impl_operation_getattr_context)));
|
||||
context->inode = 1;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_getattr_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_getattr, finished_error)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * error = json_object();
|
||||
json_object_set_new(error, "code", json_integer(WF_BAD));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_getattr_context*>(malloc(sizeof(wf_impl_operation_getattr_context)));
|
||||
context->inode = 1;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_getattr_finished(context, nullptr, error);
|
||||
json_decref(error);
|
||||
}
|
||||
@@ -1,255 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/lookup.h"
|
||||
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#include "webfuse/mocks/mock_fuse.hpp"
|
||||
#include "webfuse/mocks/mock_operation_context.hpp"
|
||||
#include "webfuse/mocks/mock_jsonrpc_proxy.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using webfuse_test::MockJsonRpcProxy;
|
||||
using webfuse_test::MockOperationContext;
|
||||
using webfuse_test::FuseMock;
|
||||
using testing::_;
|
||||
using testing::Return;
|
||||
using testing::Invoke;
|
||||
using testing::StrEq;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void free_context(
|
||||
struct wf_jsonrpc_proxy * ,
|
||||
wf_jsonrpc_proxy_finished_fn * ,
|
||||
void * user_data,
|
||||
char const * ,
|
||||
char const *)
|
||||
{
|
||||
free(user_data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_lookup, invoke_proxy)
|
||||
{
|
||||
MockJsonRpcProxy proxy;
|
||||
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("lookup"),StrEq("sis"))).Times(1)
|
||||
.WillOnce(Invoke(free_context));
|
||||
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(reinterpret_cast<wf_jsonrpc_proxy*>(&proxy)));
|
||||
|
||||
wf_impl_operation_context op_context;
|
||||
op_context.name = nullptr;
|
||||
fuse_ctx fuse_context;
|
||||
fuse_context.gid = 0;
|
||||
fuse_context.uid = 0;
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_ctx(_)).Times(1).WillOnce(Return(&fuse_context));
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context));
|
||||
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
wf_impl_operation_lookup(request, inode, "some.file");
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_lookup, fail_rpc_null)
|
||||
{
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(nullptr));
|
||||
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_ctx(_)).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
wf_impl_operation_lookup(request, inode, "some.file");
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_lookup, finished_file)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_entry(_,_)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "inode", json_integer(42));
|
||||
json_object_set_new(result, "mode", json_integer(0755));
|
||||
json_object_set_new(result, "type", json_string("file"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_lookup_context*>(malloc(sizeof(wf_impl_operation_lookup_context)));
|
||||
context->timeout = 1.0;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_lookup_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_lookup, finished_dir)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_entry(_,_)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "inode", json_integer(42));
|
||||
json_object_set_new(result, "mode", json_integer(0755));
|
||||
json_object_set_new(result, "type", json_string("dir"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_lookup_context*>(malloc(sizeof(wf_impl_operation_lookup_context)));
|
||||
context->timeout = 1.0;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_lookup_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_lookup, finished_unknown_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_entry(_,_)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "inode", json_integer(42));
|
||||
json_object_set_new(result, "mode", json_integer(0755));
|
||||
json_object_set_new(result, "type", json_string("unknown"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_lookup_context*>(malloc(sizeof(wf_impl_operation_lookup_context)));
|
||||
context->timeout = 1.0;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_lookup_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_lookup, finished_fail_missing_inode)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "mode", json_integer(0755));
|
||||
json_object_set_new(result, "type", json_string("file"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_lookup_context*>(malloc(sizeof(wf_impl_operation_lookup_context)));
|
||||
context->timeout = 1.0;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_lookup_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_lookup, finished_fail_invalid_inode_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "inode", json_string("42"));
|
||||
json_object_set_new(result, "mode", json_string("0755"));
|
||||
json_object_set_new(result, "type", json_string("file"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_lookup_context*>(malloc(sizeof(wf_impl_operation_lookup_context)));
|
||||
context->timeout = 1.0;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_lookup_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_lookup, finished_fail_missing_mode)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "inode", json_integer(42));
|
||||
json_object_set_new(result, "type", json_string("file"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_lookup_context*>(malloc(sizeof(wf_impl_operation_lookup_context)));
|
||||
context->timeout = 1.0;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_lookup_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_lookup, finished_fail_invalid_mode_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "inode", json_integer(42));
|
||||
json_object_set_new(result, "mode", json_string("0755"));
|
||||
json_object_set_new(result, "type", json_string("file"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_lookup_context*>(malloc(sizeof(wf_impl_operation_lookup_context)));
|
||||
context->timeout = 1.0;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_lookup_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_lookup, finished_fail_type_mode)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "inode", json_integer(42));
|
||||
json_object_set_new(result, "mode", json_integer(0755));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_lookup_context*>(malloc(sizeof(wf_impl_operation_lookup_context)));
|
||||
context->timeout = 1.0;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_lookup_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_lookup, finished_fail_invalid_type_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "inode", json_integer(42));
|
||||
json_object_set_new(result, "mode", json_integer(0755));
|
||||
json_object_set_new(result, "type", json_integer(42));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_lookup_context*>(malloc(sizeof(wf_impl_operation_lookup_context)));
|
||||
context->timeout = 1.0;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_lookup_finished(context, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_lookup, finished_error)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * error = json_object();
|
||||
json_object_set_new(error, "code", json_integer(WF_BAD));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_lookup_context*>(malloc(sizeof(wf_impl_operation_lookup_context)));
|
||||
context->timeout = 1.0;
|
||||
context->gid = 0;
|
||||
context->uid = 0;
|
||||
wf_impl_operation_lookup_finished(context, nullptr, error);
|
||||
json_decref(error);
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/open.h"
|
||||
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#include "webfuse/mocks/mock_fuse.hpp"
|
||||
#include "webfuse/mocks/mock_operation_context.hpp"
|
||||
#include "webfuse/mocks/mock_jsonrpc_proxy.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using webfuse_test::MockJsonRpcProxy;
|
||||
using webfuse_test::MockOperationContext;
|
||||
using webfuse_test::FuseMock;
|
||||
using testing::_;
|
||||
using testing::Return;
|
||||
using testing::StrEq;
|
||||
|
||||
TEST(wf_impl_operation_open, invoke_proxy)
|
||||
{
|
||||
MockJsonRpcProxy proxy;
|
||||
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("open"),StrEq("sii"))).Times(1);
|
||||
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(reinterpret_cast<wf_jsonrpc_proxy*>(&proxy)));
|
||||
|
||||
wf_impl_operation_context op_context;
|
||||
op_context.name = nullptr;
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context));
|
||||
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
fuse_file_info file_info;
|
||||
file_info.flags = 0;
|
||||
wf_impl_operation_open(request, inode, &file_info);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_open, fail_rpc_null)
|
||||
{
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(nullptr));
|
||||
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
fuse_file_info * file_info = nullptr;
|
||||
wf_impl_operation_open(request, inode, file_info);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_open, finished)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "handle", json_integer(42));
|
||||
wf_impl_operation_open_finished(nullptr, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_open, finished_fail_error)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * error = json_object();
|
||||
json_object_set_new(error, "code", json_integer(WF_BAD));
|
||||
wf_impl_operation_open_finished(nullptr, nullptr, error);
|
||||
json_decref(error);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_open, finished_fail_no_handle)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
wf_impl_operation_open_finished(nullptr, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_open, finished_fail_invalid_handle_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_open(_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "handle", json_string("42"));
|
||||
wf_impl_operation_open_finished(nullptr, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/read.h"
|
||||
|
||||
#include "webfuse/mocks/mock_fuse.hpp"
|
||||
#include "webfuse/mocks/mock_operation_context.hpp"
|
||||
#include "webfuse/mocks/mock_jsonrpc_proxy.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using webfuse_test::MockJsonRpcProxy;
|
||||
using webfuse_test::MockOperationContext;
|
||||
using webfuse_test::FuseMock;
|
||||
using testing::_;
|
||||
using testing::Return;
|
||||
using testing::StrEq;
|
||||
|
||||
TEST(wf_impl_operation_read, invoke_proxy)
|
||||
{
|
||||
MockJsonRpcProxy proxy;
|
||||
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1);
|
||||
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(reinterpret_cast<wf_jsonrpc_proxy*>(&proxy)));
|
||||
|
||||
wf_impl_operation_context op_context;
|
||||
op_context.name = nullptr;
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context));
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
size_t size = 42;
|
||||
off_t offset = 0;
|
||||
fuse_file_info file_info;
|
||||
file_info.fh = 1;
|
||||
wf_impl_operation_read(request, inode, size, offset, &file_info);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, invoke_proxy_limit_size)
|
||||
{
|
||||
MockJsonRpcProxy proxy;
|
||||
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("read"),StrEq("siiii"))).Times(1);
|
||||
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(reinterpret_cast<wf_jsonrpc_proxy*>(&proxy)));
|
||||
|
||||
wf_impl_operation_context op_context;
|
||||
op_context.name = nullptr;
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context));
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
size_t size = 100 * 1024 * 1024;
|
||||
off_t offset = 0;
|
||||
fuse_file_info file_info;
|
||||
file_info.fh = 1;
|
||||
wf_impl_operation_read(request, inode, size, offset, &file_info);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, fail_rpc_null)
|
||||
{
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(nullptr));
|
||||
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
size_t size = 42;
|
||||
off_t offset = 0;
|
||||
fuse_file_info * file_info = nullptr;
|
||||
wf_impl_operation_read(request, inode, size, offset, file_info);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, fill_buffer_identity)
|
||||
{
|
||||
wf_status status;
|
||||
char * buffer = wf_impl_fill_buffer("brummni", 8, "identity", 8, &status);
|
||||
ASSERT_EQ(WF_GOOD, status);
|
||||
ASSERT_STREQ("brummni", buffer);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, fill_buffer_identity_fail_inconsistent_size)
|
||||
{
|
||||
wf_status status;
|
||||
char * buffer = wf_impl_fill_buffer("brummni", 8, "identity", 7, &status);
|
||||
ASSERT_NE(WF_GOOD, status);
|
||||
ASSERT_EQ(nullptr, buffer);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, fill_buffer_base64)
|
||||
{
|
||||
wf_status status;
|
||||
char * buffer = wf_impl_fill_buffer("YnJ1bW1uaQ==", 12, "base64", 7, &status);
|
||||
|
||||
ASSERT_EQ(WF_GOOD, status);
|
||||
ASSERT_EQ(0, strncmp("brummni", buffer, 7));
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, fill_buffer_base64_fail_invalid_data)
|
||||
{
|
||||
wf_status status;
|
||||
char * buffer = wf_impl_fill_buffer("YnJ1bW1uaQ=A", 12, "base64", 8, &status);
|
||||
ASSERT_NE(WF_GOOD, status);
|
||||
ASSERT_EQ(nullptr, buffer);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, fill_buffer_empty)
|
||||
{
|
||||
wf_status status;
|
||||
char * buffer = wf_impl_fill_buffer(nullptr, 0, "identity", 0, &status);
|
||||
|
||||
ASSERT_EQ(WF_GOOD, status);
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, fill_buffer_fail_invalid_format)
|
||||
{
|
||||
wf_status status;
|
||||
char * buffer = wf_impl_fill_buffer("some data", 9, "unknown", 9, &status);
|
||||
ASSERT_NE(WF_GOOD, status);
|
||||
ASSERT_EQ(nullptr, buffer);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, finished)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,7)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "data", json_string("brummni"));
|
||||
json_object_set_new(result, "format", json_string("identity"));
|
||||
json_object_set_new(result, "count", json_integer(7));
|
||||
wf_impl_operation_read_finished(nullptr, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, finished_fail_no_data)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "format", json_string("identity"));
|
||||
json_object_set_new(result, "count", json_integer(7));
|
||||
wf_impl_operation_read_finished(nullptr, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, finished_fail_invalid_data_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "data", json_integer(42));
|
||||
json_object_set_new(result, "format", json_string("identity"));
|
||||
json_object_set_new(result, "count", json_integer(7));
|
||||
wf_impl_operation_read_finished(nullptr, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, finished_fail_no_format)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "data", json_string("brummni"));
|
||||
json_object_set_new(result, "count", json_integer(7));
|
||||
wf_impl_operation_read_finished(nullptr, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, finished_fail_invalid_format_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "data", json_string("brummni"));
|
||||
json_object_set_new(result, "format", json_integer(42));
|
||||
json_object_set_new(result, "count", json_integer(7));
|
||||
wf_impl_operation_read_finished(nullptr, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, finished_fail_no_count)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "data", json_string("brummni"));
|
||||
json_object_set_new(result, "format", json_string("identity"));
|
||||
wf_impl_operation_read_finished(nullptr, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, finished_fail_invalid_count_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
json_object_set_new(result, "data", json_string("brummni"));
|
||||
json_object_set_new(result, "format", json_string("identity"));
|
||||
json_object_set_new(result, "count", json_string("7"));
|
||||
wf_impl_operation_read_finished(nullptr, result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_read, finished_fail_error)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, _)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * error = json_object();
|
||||
json_object_set_new(error, "code", json_integer(WF_BAD));
|
||||
wf_impl_operation_read_finished(nullptr, nullptr, error);
|
||||
json_decref(error);
|
||||
}
|
||||
@@ -1,265 +0,0 @@
|
||||
#include "webfuse/adapter/impl/operation/readdir.h"
|
||||
|
||||
#include "webfuse/core/status.h"
|
||||
|
||||
#include "webfuse/mocks/mock_fuse.hpp"
|
||||
#include "webfuse/mocks/mock_operation_context.hpp"
|
||||
#include "webfuse/mocks/mock_jsonrpc_proxy.hpp"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using webfuse_test::MockJsonRpcProxy;
|
||||
using webfuse_test::MockOperationContext;
|
||||
using webfuse_test::FuseMock;
|
||||
using testing::_;
|
||||
using testing::Return;
|
||||
using testing::Invoke;
|
||||
using testing::StrEq;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void free_context(
|
||||
struct wf_jsonrpc_proxy * ,
|
||||
wf_jsonrpc_proxy_finished_fn * ,
|
||||
void * user_data,
|
||||
char const * ,
|
||||
char const *)
|
||||
{
|
||||
free(user_data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_readdir, invoke_proxy)
|
||||
{
|
||||
MockJsonRpcProxy proxy;
|
||||
EXPECT_CALL(proxy, wf_jsonrpc_proxy_vinvoke(_,_,_,StrEq("readdir"),StrEq("si")))
|
||||
.Times(1).WillOnce(Invoke(free_context));
|
||||
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(reinterpret_cast<wf_jsonrpc_proxy*>(&proxy)));
|
||||
|
||||
wf_impl_operation_context op_context;
|
||||
op_context.name = nullptr;
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(&op_context));
|
||||
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
size_t size = 10;
|
||||
size_t offset = 0;
|
||||
fuse_file_info file_info;
|
||||
file_info.flags = 0;
|
||||
wf_impl_operation_readdir(request, inode, size, offset, &file_info);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_readdir, fail_rpc_null)
|
||||
{
|
||||
MockOperationContext context;
|
||||
EXPECT_CALL(context, wf_impl_operation_context_get_proxy(_)).Times(1)
|
||||
.WillOnce(Return(nullptr));
|
||||
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_req_userdata(_)).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
fuse_req_t request = nullptr;
|
||||
fuse_ino_t inode = 1;
|
||||
size_t size = 10;
|
||||
size_t offset = 0;
|
||||
fuse_file_info file_info;
|
||||
file_info.flags = 0;
|
||||
wf_impl_operation_readdir(request, inode, size, offset, &file_info);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_readdir, finished)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_array();
|
||||
json_t * item = json_object();
|
||||
json_object_set_new(item, "name", json_string("a.file"));
|
||||
json_object_set_new(item, "inode", json_integer(42));
|
||||
json_array_append_new(result, item);
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_readdir_context*>(malloc(sizeof(wf_impl_operation_readdir_context)));
|
||||
context->request = nullptr;
|
||||
context->size = 1;
|
||||
context->offset = 0;
|
||||
wf_impl_operation_readdir_finished(reinterpret_cast<void*>(context), result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_readdir, finished_many_items)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_array();
|
||||
for(int i = 0; i < 100; i++)
|
||||
{
|
||||
json_t * item = json_object();
|
||||
json_object_set_new(item, "name", json_sprintf("file_%d.txt", i));
|
||||
json_object_set_new(item, "inode", json_integer(1 + i));
|
||||
json_array_append_new(result, item);
|
||||
}
|
||||
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_readdir_context*>(malloc(sizeof(wf_impl_operation_readdir_context)));
|
||||
context->request = nullptr;
|
||||
context->size = 100;
|
||||
context->offset = 0;
|
||||
wf_impl_operation_readdir_finished(reinterpret_cast<void*>(context), result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_readdir, finished_read_after_end)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_array();
|
||||
json_t * item = json_object();
|
||||
json_object_set_new(item, "name", json_string("a.file"));
|
||||
json_object_set_new(item, "inode", json_integer(42));
|
||||
json_array_append_new(result, item);
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_readdir_context*>(malloc(sizeof(wf_impl_operation_readdir_context)));
|
||||
context->request = nullptr;
|
||||
context->size = 10;
|
||||
context->offset = 2;
|
||||
wf_impl_operation_readdir_finished(reinterpret_cast<void*>(context), result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_readdir, finished_fail_error)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * error = json_array();
|
||||
json_object_set_new(error, "code", json_integer(WF_BAD));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_readdir_context*>(malloc(sizeof(wf_impl_operation_readdir_context)));
|
||||
context->request = nullptr;
|
||||
context->size = 1;
|
||||
context->offset = 0;
|
||||
wf_impl_operation_readdir_finished(reinterpret_cast<void*>(context), nullptr, error);
|
||||
json_decref(error);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_readdir, finished_fail_invalid_result_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_object();
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_readdir_context*>(malloc(sizeof(wf_impl_operation_readdir_context)));
|
||||
context->request = nullptr;
|
||||
context->size = 1;
|
||||
context->offset = 0;
|
||||
wf_impl_operation_readdir_finished(reinterpret_cast<void*>(context), result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_readdir, finished_fail_missing_name)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_array();
|
||||
json_t * item = json_object();
|
||||
json_object_set_new(item, "inode", json_integer(42));
|
||||
json_array_append_new(result, item);
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_readdir_context*>(malloc(sizeof(wf_impl_operation_readdir_context)));
|
||||
context->request = nullptr;
|
||||
context->size = 1;
|
||||
context->offset = 0;
|
||||
wf_impl_operation_readdir_finished(reinterpret_cast<void*>(context), result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_readdir, finished_fail_invalid_name_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_array();
|
||||
json_t * item = json_object();
|
||||
json_object_set_new(item, "name", json_integer(42));
|
||||
json_object_set_new(item, "inode", json_integer(42));
|
||||
json_array_append_new(result, item);
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_readdir_context*>(malloc(sizeof(wf_impl_operation_readdir_context)));
|
||||
context->request = nullptr;
|
||||
context->size = 1;
|
||||
context->offset = 0;
|
||||
wf_impl_operation_readdir_finished(reinterpret_cast<void*>(context), result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_readdir, finished_fail_missing_inode)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_array();
|
||||
json_t * item = json_object();
|
||||
json_object_set_new(item, "name", json_string("a.file"));
|
||||
json_array_append_new(result, item);
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_readdir_context*>(malloc(sizeof(wf_impl_operation_readdir_context)));
|
||||
context->request = nullptr;
|
||||
context->size = 1;
|
||||
context->offset = 0;
|
||||
wf_impl_operation_readdir_finished(reinterpret_cast<void*>(context), result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_readdir, finished_fail_invalid_inode_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_array();
|
||||
json_t * item = json_object();
|
||||
json_object_set_new(item, "name", json_string("a.file"));
|
||||
json_object_set_new(item, "inode", json_string("42"));
|
||||
json_array_append_new(result, item);
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_readdir_context*>(malloc(sizeof(wf_impl_operation_readdir_context)));
|
||||
context->request = nullptr;
|
||||
context->size = 1;
|
||||
context->offset = 0;
|
||||
wf_impl_operation_readdir_finished(reinterpret_cast<void*>(context), result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
|
||||
TEST(wf_impl_operation_readdir, finished_fail_invalid_item_type)
|
||||
{
|
||||
FuseMock fuse;
|
||||
EXPECT_CALL(fuse, fuse_reply_buf(_,_,_)).Times(0);
|
||||
EXPECT_CALL(fuse, fuse_reply_err(_, ENOENT)).Times(1).WillOnce(Return(0));
|
||||
|
||||
json_t * result = json_array();
|
||||
json_array_append_new(result, json_string("item"));
|
||||
|
||||
auto * context = reinterpret_cast<wf_impl_operation_readdir_context*>(malloc(sizeof(wf_impl_operation_readdir_context)));
|
||||
context->request = nullptr;
|
||||
context->size = 1;
|
||||
context->offset = 0;
|
||||
wf_impl_operation_readdir_finished(reinterpret_cast<void*>(context), result, nullptr);
|
||||
json_decref(result);
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "webfuse/mocks/mock_authenticator.hpp"
|
||||
|
||||
#include "webfuse/adapter/impl/authenticator.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
|
||||
using ::testing::Return;
|
||||
using ::testing::_;
|
||||
using ::webfuse_test::Authenticator;
|
||||
using ::webfuse_test::MockAuthenticator;
|
||||
using ::webfuse_test::set_authenticator;
|
||||
using ::webfuse_test::authenticate;
|
||||
|
||||
|
||||
TEST(Authenticator, Authenticate)
|
||||
{
|
||||
MockAuthenticator mock;
|
||||
set_authenticator(&mock);
|
||||
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init(&creds, "username", nullptr);
|
||||
char dummy[] = "usr_data";
|
||||
void * user_data = reinterpret_cast<void*>(dummy);
|
||||
|
||||
EXPECT_CALL(mock, authenticate(&creds, user_data))
|
||||
.Times(1)
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
struct wf_impl_authenticator * authenticator = wf_impl_authenticator_create(
|
||||
"username",
|
||||
&authenticate,
|
||||
user_data);
|
||||
|
||||
bool result = wf_impl_authenticator_autenticate(authenticator, &creds);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
wf_impl_authenticator_dispose(authenticator);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Authenticator, SkipAuthenticationWithWrongType)
|
||||
{
|
||||
MockAuthenticator mock;
|
||||
set_authenticator(&mock);
|
||||
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init(&creds, "username", nullptr);
|
||||
EXPECT_CALL(mock, authenticate(_, _))
|
||||
.Times(0);
|
||||
|
||||
struct wf_impl_authenticator * authenticator = wf_impl_authenticator_create(
|
||||
"certificate",
|
||||
&authenticate,
|
||||
nullptr);
|
||||
|
||||
bool result = wf_impl_authenticator_autenticate(authenticator, &creds);
|
||||
ASSERT_FALSE(result);
|
||||
|
||||
wf_impl_authenticator_dispose(authenticator);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include "webfuse/mocks/mock_authenticator.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::webfuse_test::MockAuthenticator;
|
||||
using ::webfuse_test::set_authenticator;
|
||||
using ::webfuse_test::authenticate;
|
||||
using ::webfuse_test::authenticate_1;
|
||||
using ::webfuse_test::authenticate_2;
|
||||
|
||||
|
||||
TEST(Authenticators, CloneEmpty)
|
||||
{
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_authenticators clone;
|
||||
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
ASSERT_EQ(nullptr, authenticators.first);
|
||||
|
||||
wf_impl_authenticators_clone(&authenticators, &clone);
|
||||
ASSERT_EQ(nullptr, clone.first);
|
||||
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_authenticators_cleanup(&clone);
|
||||
}
|
||||
|
||||
TEST(Authenticators, Clone)
|
||||
{
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_authenticators clone;
|
||||
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
wf_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
ASSERT_NE(nullptr, authenticators.first);
|
||||
|
||||
wf_impl_authenticators_clone(&authenticators, &clone);
|
||||
ASSERT_NE(nullptr, clone.first);
|
||||
ASSERT_NE(nullptr, authenticators.first);
|
||||
ASSERT_NE(authenticators.first, clone.first);
|
||||
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_authenticators_cleanup(&clone);
|
||||
}
|
||||
|
||||
TEST(Authenticators, Move)
|
||||
{
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_authenticators clone;
|
||||
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
wf_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
ASSERT_NE(nullptr, authenticators.first);
|
||||
|
||||
wf_impl_authenticators_move(&authenticators, &clone);
|
||||
ASSERT_NE(nullptr, clone.first);
|
||||
ASSERT_EQ(nullptr, authenticators.first);
|
||||
ASSERT_NE(authenticators.first, clone.first);
|
||||
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_authenticators_cleanup(&clone);
|
||||
}
|
||||
|
||||
TEST(Authenticators, AuthenticateWithoutAuthenticators)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init(&creds, "username", nullptr);
|
||||
|
||||
struct wf_impl_authenticators authenticators;
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
|
||||
bool result = wf_impl_authenticators_authenticate(&authenticators, &creds);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
result = wf_impl_authenticators_authenticate(&authenticators, nullptr);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Authenticators, FailToAuthenticateWithoutCredentials)
|
||||
{
|
||||
MockAuthenticator mock;
|
||||
set_authenticator(&mock);
|
||||
|
||||
struct wf_impl_authenticators authenticators;
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
wf_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
|
||||
bool result = wf_impl_authenticators_authenticate(&authenticators, nullptr);
|
||||
ASSERT_FALSE(result);
|
||||
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
}
|
||||
|
||||
TEST(Authenticators, AuthenticateWithMultipleCredentials)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init(&creds, "username", nullptr);
|
||||
|
||||
MockAuthenticator username_mock;
|
||||
set_authenticator(1, &username_mock);
|
||||
EXPECT_CALL(username_mock, authenticate(&creds, nullptr))
|
||||
.Times(1)
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
MockAuthenticator certificate_mock;
|
||||
set_authenticator(2, &certificate_mock);
|
||||
EXPECT_CALL(certificate_mock, authenticate(_, _))
|
||||
.Times(0);
|
||||
|
||||
struct wf_impl_authenticators authenticators;
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
wf_impl_authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
|
||||
wf_impl_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
|
||||
|
||||
bool result = wf_impl_authenticators_authenticate(&authenticators, &creds);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Authenticators, FailedAuthenticateWithWrongType)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init(&creds, "token", nullptr);
|
||||
|
||||
MockAuthenticator username_mock;
|
||||
set_authenticator(1, &username_mock);
|
||||
EXPECT_CALL(username_mock, authenticate(&creds, nullptr))
|
||||
.Times(0);
|
||||
|
||||
MockAuthenticator certificate_mock;
|
||||
set_authenticator(2, &certificate_mock);
|
||||
EXPECT_CALL(certificate_mock, authenticate(_, _))
|
||||
.Times(0);
|
||||
|
||||
struct wf_impl_authenticators authenticators;
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
wf_impl_authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
|
||||
wf_impl_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
|
||||
|
||||
bool result = wf_impl_authenticators_authenticate(&authenticators, &creds);
|
||||
ASSERT_FALSE(result);
|
||||
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
@@ -1,579 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "webfuse/utils/adapter_client.hpp"
|
||||
#include "webfuse/adapter/client_tlsconfig.h"
|
||||
#include "webfuse/adapter/credentials.h"
|
||||
#include "webfuse/core/protocol_names.h"
|
||||
#include "webfuse/utils/ws_server2.hpp"
|
||||
#include "webfuse/mocks/mock_adapter_client_callback.hpp"
|
||||
#include "webfuse/mocks/mock_invokation_handler.hpp"
|
||||
#include "webfuse/utils/timeout_watcher.hpp"
|
||||
#include "webfuse/tests/integration/file.hpp"
|
||||
#include "webfuse/mocks/lookup_matcher.hpp"
|
||||
|
||||
using webfuse_test::AdapterClient;
|
||||
using webfuse_test::WsServer2;
|
||||
using webfuse_test::MockInvokationHander;
|
||||
using webfuse_test::MockAdapterClientCallback;
|
||||
using webfuse_test::TimeoutWatcher;
|
||||
using webfuse_test::File;
|
||||
using webfuse_test::Lookup;
|
||||
using testing::_;
|
||||
using testing::Invoke;
|
||||
using testing::AnyNumber;
|
||||
using testing::Return;
|
||||
using testing::Throw;
|
||||
using testing::StrEq;
|
||||
|
||||
#define TIMEOUT (std::chrono::milliseconds(30 * 1000))
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
void GetCredentials(wf_client *, int, void * arg)
|
||||
{
|
||||
auto * creds = reinterpret_cast<wf_credentials*>(arg);
|
||||
wf_credentials_set_type(creds, "username");
|
||||
wf_credentials_add(creds, "username", "Bob");
|
||||
wf_credentials_add(creds, "password", "secret");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(AdapterClient, CreateAndDispose)
|
||||
{
|
||||
MockAdapterClientCallback callback;
|
||||
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_INIT, nullptr)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CREATED, nullptr)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1);
|
||||
|
||||
wf_client * client = wf_client_create(
|
||||
callback.GetCallbackFn(), callback.GetUserData());
|
||||
|
||||
wf_client_dispose(client);
|
||||
}
|
||||
|
||||
TEST(AdapterClient, Connect)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(_,_)).Times(0);
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_INIT, nullptr)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CREATED, nullptr)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1);
|
||||
|
||||
bool connected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||
|
||||
client.Disconnect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
|
||||
TEST(AdapterClient, IgnoreNonJsonMessage)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(_,_)).Times(0);
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_INIT, nullptr)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CREATED, nullptr)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1);
|
||||
|
||||
bool connected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||
|
||||
server.SendMessage("brummni");
|
||||
|
||||
client.Disconnect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
|
||||
|
||||
TEST(AdapterClient, IgnoreInvalidJsonMessage)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(_,_)).Times(0);
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_INIT, nullptr)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CREATED, nullptr)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1);
|
||||
|
||||
bool connected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||
|
||||
json_t * invalid_request = json_object();
|
||||
server.SendMessage(invalid_request);
|
||||
|
||||
client.Disconnect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
|
||||
TEST(AdapterClient, ConnectWithTls)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER, 0, true);
|
||||
EXPECT_CALL(handler, Invoke(_,_)).Times(0);
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_INIT, nullptr)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CREATED, nullptr)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1)
|
||||
.WillOnce(Invoke([](wf_client *, int, void * arg) {
|
||||
auto * tls = reinterpret_cast<wf_client_tlsconfig*>(arg);
|
||||
wf_client_tlsconfig_set_keypath (tls, "client-key.pem");
|
||||
wf_client_tlsconfig_set_certpath(tls, "client-cert.pem");
|
||||
wf_client_tlsconfig_set_cafilepath(tls, "server-cert.pem");
|
||||
}));
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1);
|
||||
|
||||
bool connected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||
|
||||
client.Disconnect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
|
||||
TEST(AdapterClient, FailedToConnectInvalidPort)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_INIT, nullptr)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CREATED, nullptr)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_GET_TLS_CONFIG, _)).Times(1);
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CLEANUP, nullptr)).Times(1);
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), "ws://localhost:4/");
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
|
||||
|
||||
TEST(AdapterClient, Authenticate)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("authenticate"),_)).Times(1)
|
||||
.WillOnce(Return("{}"));
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
||||
|
||||
bool connected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATE_GET_CREDENTIALS, _)).Times(1)
|
||||
.WillOnce(Invoke(GetCredentials));
|
||||
|
||||
bool authenticated = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_AUTHENTICATED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { authenticated = true; }));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||
|
||||
client.Authenticate();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return authenticated; }));
|
||||
|
||||
client.Disconnect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
|
||||
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;
|
||||
}));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), "");
|
||||
|
||||
client.Authenticate();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return called; }));
|
||||
}
|
||||
|
||||
TEST(AdapterClient, AuthenticationFailed)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("authenticate"),_)).Times(1)
|
||||
.WillOnce(Throw(std::runtime_error("authentication failed")));
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
||||
|
||||
bool connected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
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;
|
||||
}));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||
|
||||
client.Authenticate();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return called; }));
|
||||
|
||||
client.Disconnect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
|
||||
TEST(AdapterClient, AddFileSystem)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
||||
.WillOnce(Return("{\"id\": \"test\"}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber())
|
||||
.WillRepeatedly(Throw(std::runtime_error("unknown")));
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
||||
|
||||
bool connected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
bool called = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_FILESYSTEM_ADDED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&called] (wf_client *, int, void *) mutable {
|
||||
called = true;
|
||||
}));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||
|
||||
client.AddFileSystem();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return called; }));
|
||||
|
||||
client.Disconnect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
|
||||
TEST(AdapterClient, FailToAddFileSystemTwice)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
||||
.WillOnce(Return("{\"id\": \"test\"}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber())
|
||||
.WillRepeatedly(Throw(std::runtime_error("unknown")));
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
||||
|
||||
bool connected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
bool filesystem_added = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_FILESYSTEM_ADDED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable {
|
||||
filesystem_added = true;
|
||||
}));
|
||||
|
||||
bool filesystem_add_failed = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_FILESYSTEM_ADD_FAILED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable {
|
||||
filesystem_add_failed = true;
|
||||
}));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||
|
||||
client.AddFileSystem();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return filesystem_added; }));
|
||||
|
||||
client.AddFileSystem();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return filesystem_add_failed; }));
|
||||
|
||||
client.Disconnect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
|
||||
TEST(AdapterClient, FailToAddFileSystemMissingId)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
||||
.WillOnce(Return("{}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber())
|
||||
.WillRepeatedly(Throw(std::runtime_error("unknown")));
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
||||
|
||||
bool connected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
bool filesystem_add_failed = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_FILESYSTEM_ADD_FAILED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable {
|
||||
filesystem_add_failed = true;
|
||||
}));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||
|
||||
client.AddFileSystem();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return filesystem_add_failed; }));
|
||||
|
||||
client.Disconnect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
|
||||
TEST(AdapterClient, FailToAddFileSystemIdNotString)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
||||
.WillOnce(Return("{\"id\": 42}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber())
|
||||
.WillRepeatedly(Throw(std::runtime_error("unknown")));
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
||||
|
||||
bool connected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
bool filesystem_add_failed = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_FILESYSTEM_ADD_FAILED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable {
|
||||
filesystem_add_failed = true;
|
||||
}));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||
|
||||
client.AddFileSystem();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return filesystem_add_failed; }));
|
||||
|
||||
client.Disconnect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
|
||||
|
||||
TEST(AdapterClient, AddFileSystemFailed)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
||||
.WillOnce(Throw(std::runtime_error("failed")));
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
||||
|
||||
bool connected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
bool called = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_FILESYSTEM_ADD_FAILED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&called] (wf_client *, int, void *) mutable {
|
||||
called = true;
|
||||
}));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||
|
||||
client.AddFileSystem();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return called; }));
|
||||
|
||||
client.Disconnect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
|
||||
TEST(AdapterClient, LookupFile)
|
||||
{
|
||||
TimeoutWatcher watcher(TIMEOUT);
|
||||
|
||||
MockInvokationHander handler;
|
||||
WsServer2 server(handler, WF_PROTOCOL_NAME_PROVIDER_SERVER);
|
||||
EXPECT_CALL(handler, Invoke(StrEq("add_filesystem"),_)).Times(1)
|
||||
.WillOnce(Return("{\"id\": \"test\"}"));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), _)).Times(AnyNumber())
|
||||
.WillRepeatedly(Throw(std::runtime_error("unknown")));
|
||||
EXPECT_CALL(handler, Invoke(StrEq("lookup"), Lookup(1, "Hello.txt"))).Times(AnyNumber())
|
||||
.WillRepeatedly(Return(
|
||||
"{"
|
||||
"\"inode\": 2,"
|
||||
"\"mode\": 420," //0644
|
||||
"\"type\": \"file\","
|
||||
"\"size\": 42,"
|
||||
"\"atime\": 0,"
|
||||
"\"mtime\": 0,"
|
||||
"\"ctime\": 0"
|
||||
"}"
|
||||
));
|
||||
|
||||
MockAdapterClientCallback callback;
|
||||
EXPECT_CALL(callback, Invoke(_, _, _)).Times(AnyNumber());
|
||||
|
||||
bool connected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_CONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { connected = true; }));
|
||||
|
||||
bool disconnected = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_DISCONNECTED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&] (wf_client *, int, void *) mutable { disconnected = true; }));
|
||||
|
||||
bool called = false;
|
||||
EXPECT_CALL(callback, Invoke(_, WF_CLIENT_FILESYSTEM_ADDED, nullptr)).Times(1)
|
||||
.WillOnce(Invoke([&called] (wf_client *, int, void *) mutable {
|
||||
called = true;
|
||||
}));
|
||||
|
||||
AdapterClient client(callback.GetCallbackFn(), callback.GetUserData(), server.GetUrl());
|
||||
|
||||
client.Connect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return connected; }));
|
||||
|
||||
client.AddFileSystem();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return called; }));
|
||||
|
||||
std::string file_name = client.GetDir() + "/Hello.txt";
|
||||
File file(file_name);
|
||||
ASSERT_TRUE(file.isFile());
|
||||
|
||||
client.Disconnect();
|
||||
ASSERT_TRUE(watcher.waitUntil([&]() mutable { return disconnected; }));
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse/adapter/client_tlsconfig.h"
|
||||
#include "webfuse/adapter/impl/client_tlsconfig.h"
|
||||
|
||||
TEST(ClientTlsConfig, InitAndCleanup)
|
||||
{
|
||||
wf_client_tlsconfig config;
|
||||
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
}
|
||||
|
||||
TEST(ClientTlsConfig, SetKeyPath)
|
||||
{
|
||||
wf_client_tlsconfig config;
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
|
||||
wf_client_tlsconfig_set_keypath(&config, "/path/to/key.pem");
|
||||
ASSERT_STREQ("/path/to/key.pem", config.key_path);
|
||||
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
}
|
||||
|
||||
TEST(ClientTlsConfig, SetCertPath)
|
||||
{
|
||||
wf_client_tlsconfig config;
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
|
||||
wf_client_tlsconfig_set_certpath(&config, "/path/to/cert.pem");
|
||||
ASSERT_STREQ("/path/to/cert.pem", config.cert_path);
|
||||
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
}
|
||||
|
||||
TEST(ClientTlsConfig, SetCafilePath)
|
||||
{
|
||||
wf_client_tlsconfig config;
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
|
||||
wf_client_tlsconfig_set_cafilepath(&config, "/path/to/cafile.pem");
|
||||
ASSERT_STREQ("/path/to/cafile.pem", config.cafile_path);
|
||||
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
}
|
||||
|
||||
TEST(ClientTslConfig, IsSet)
|
||||
{
|
||||
wf_client_tlsconfig config;
|
||||
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
ASSERT_FALSE(wf_impl_client_tlsconfig_isset(&config));
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
wf_client_tlsconfig_set_keypath(&config, "/path/to/key.pem");
|
||||
ASSERT_FALSE(wf_impl_client_tlsconfig_isset(&config));
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
wf_client_tlsconfig_set_certpath(&config, "/path/to/cert.pem");
|
||||
ASSERT_FALSE(wf_impl_client_tlsconfig_isset(&config));
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
|
||||
wf_impl_client_tlsconfig_init(&config);
|
||||
wf_client_tlsconfig_set_keypath(&config, "/path/to/key.pem");
|
||||
wf_client_tlsconfig_set_certpath(&config, "/path/to/cert.pem");
|
||||
ASSERT_TRUE(wf_impl_client_tlsconfig_isset(&config));
|
||||
wf_impl_client_tlsconfig_cleanup(&config);
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "webfuse/adapter/credentials.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include <jansson.h>
|
||||
|
||||
TEST(Credentials, Type)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
|
||||
wf_impl_credentials_init(&creds, "test", nullptr);
|
||||
ASSERT_STREQ("test", wf_credentials_type(&creds));
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Credentials, Get)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
json_t * data = json_object();
|
||||
json_object_set_new(data, "username", json_string("bob"));
|
||||
json_object_set_new(data, "password", json_string("<secret>"));
|
||||
|
||||
wf_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wf_credentials_type(&creds));
|
||||
ASSERT_STREQ("bob", wf_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ("<secret>", wf_credentials_get(&creds, "password"));
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
}
|
||||
|
||||
TEST(Credentials, FailedToGetNonexistingValue)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
json_t * data = json_object();
|
||||
|
||||
wf_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wf_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password"));
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
}
|
||||
|
||||
TEST(Credentials, FailedToGetWithoutData)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
|
||||
wf_impl_credentials_init(&creds, "username", nullptr);
|
||||
ASSERT_STREQ("username", wf_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password"));
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Credentials, FailedToGetWrongDataType)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
json_t * data = json_string("invalid_creds");
|
||||
|
||||
wf_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wf_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password"));
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
}
|
||||
|
||||
TEST(Credentials, FailedToGetWrongElementDataType)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
json_t * data = json_object();
|
||||
json_object_set_new(data, "username", json_integer(42));
|
||||
|
||||
wf_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wf_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_credentials_get(&creds, "password"));
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
}
|
||||
|
||||
TEST(Credentials, SetType)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init_default(&creds);
|
||||
|
||||
wf_credentials_set_type(&creds, "username");
|
||||
ASSERT_STREQ("username", wf_credentials_type(&creds));
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Credentials, Add)
|
||||
{
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init_default(&creds);
|
||||
|
||||
wf_credentials_add(&creds, "a.value", "a");
|
||||
ASSERT_STREQ("a", wf_credentials_get(&creds, "a.value"));
|
||||
|
||||
wf_credentials_add(&creds, "b.value", "b");
|
||||
ASSERT_STREQ("b", wf_credentials_get(&creds, "b.value"));
|
||||
|
||||
wf_credentials_add(&creds, "a.value", "A");
|
||||
ASSERT_STREQ("A", wf_credentials_get(&creds, "a.value"));
|
||||
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse/adapter/impl/fuse_wrapper.h"
|
||||
|
||||
TEST(libfuse, fuse_req_t_size)
|
||||
{
|
||||
ASSERT_EQ(sizeof(void*), sizeof(fuse_req_t));
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
#include "webfuse/adapter/mountpoint.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
class MockUserDataDisposer
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD1(dispose, void(void * mountpoint));
|
||||
};
|
||||
|
||||
MockUserDataDisposer * global_disposer = nullptr;
|
||||
|
||||
void ondispose(void * user_data)
|
||||
{
|
||||
global_disposer->dispose(user_data);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(mountpoint, get_path)
|
||||
{
|
||||
wf_mountpoint * mountpoint = wf_mountpoint_create("/some/path");
|
||||
ASSERT_NE(nullptr, mountpoint);
|
||||
|
||||
ASSERT_STREQ("/some/path", wf_mountpoint_get_path(mountpoint));
|
||||
|
||||
wf_mountpoint_dispose(mountpoint);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(mountpoint, ondispose)
|
||||
{
|
||||
MockUserDataDisposer disposer;
|
||||
global_disposer = &disposer;
|
||||
|
||||
wf_mountpoint * mountpoint = wf_mountpoint_create("/some/path");
|
||||
ASSERT_NE(nullptr, mountpoint);
|
||||
|
||||
int value = 42;
|
||||
void * user_data = reinterpret_cast<void*>(&value);
|
||||
wf_mountpoint_set_userdata(mountpoint, user_data, ondispose);
|
||||
EXPECT_CALL(disposer, dispose(user_data)).Times(1);
|
||||
|
||||
wf_mountpoint_dispose(mountpoint);
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "webfuse/adapter/server.h"
|
||||
#include "webfuse/adapter/server_config.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct wf_mountpoint *
|
||||
create_mountpoint(
|
||||
char const * filesystem,
|
||||
void * user_data)
|
||||
{
|
||||
(void) filesystem;
|
||||
(void) user_data;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(server, create_dispose)
|
||||
{
|
||||
mkdir("test", 0700);
|
||||
|
||||
struct wf_server_config * config = wf_server_config_create();
|
||||
wf_server_config_set_mountpoint_factory(config, &create_mountpoint, nullptr);
|
||||
struct wf_server * server = wf_server_create(config);
|
||||
ASSERT_NE(nullptr, server);
|
||||
|
||||
wf_server_dispose(server);
|
||||
wf_server_config_dispose(config);
|
||||
|
||||
rmdir("test");
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse/adapter/server_config.h"
|
||||
#include "webfuse/adapter/impl/server_config.h"
|
||||
#include "webfuse/adapter/impl/authenticator.h"
|
||||
#include "webfuse/utils/tempdir.hpp"
|
||||
|
||||
using webfuse_test::TempDir;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
wf_mountpoint * create_mountpoint(
|
||||
char const * filesystem,
|
||||
void * user_data)
|
||||
{
|
||||
(void) filesystem;
|
||||
(void) user_data;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool authenticate(
|
||||
wf_credentials const * credentials,
|
||||
void * user_data)
|
||||
{
|
||||
(void) credentials;
|
||||
(void) user_data;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST(server_config, create_dispose)
|
||||
{
|
||||
wf_server_config * config = wf_server_config_create();
|
||||
ASSERT_NE(nullptr, config);
|
||||
|
||||
wf_server_config_dispose(config);
|
||||
}
|
||||
|
||||
TEST(server_config, set_documentroot)
|
||||
{
|
||||
wf_server_config * config = wf_server_config_create();
|
||||
ASSERT_NE(nullptr, config);
|
||||
|
||||
ASSERT_EQ(nullptr, config->document_root);
|
||||
|
||||
wf_server_config_set_documentroot(config, "www");
|
||||
ASSERT_STREQ("www", config->document_root);
|
||||
|
||||
wf_server_config_set_documentroot(config, "/var/www");
|
||||
ASSERT_STREQ("/var/www", config->document_root);
|
||||
|
||||
wf_server_config_dispose(config);
|
||||
}
|
||||
|
||||
TEST(server_config, set_keypath)
|
||||
{
|
||||
wf_server_config * config = wf_server_config_create();
|
||||
ASSERT_NE(nullptr, config);
|
||||
|
||||
ASSERT_EQ(nullptr, config->key_path);
|
||||
|
||||
wf_server_config_set_keypath(config, "key.pem");
|
||||
ASSERT_STREQ("key.pem", config->key_path);
|
||||
|
||||
wf_server_config_set_keypath(config, "pki/self/key.pem");
|
||||
ASSERT_STREQ("pki/self/key.pem", config->key_path);
|
||||
|
||||
wf_server_config_dispose(config);
|
||||
}
|
||||
|
||||
TEST(server_config, set_certpath)
|
||||
{
|
||||
wf_server_config * config = wf_server_config_create();
|
||||
ASSERT_NE(nullptr, config);
|
||||
|
||||
ASSERT_EQ(nullptr, config->key_path);
|
||||
|
||||
wf_server_config_set_certpath(config, "cert.pem");
|
||||
ASSERT_STREQ("cert.pem", config->cert_path);
|
||||
|
||||
wf_server_config_set_certpath(config, "pki/self/cert.pem");
|
||||
ASSERT_STREQ("pki/self/cert.pem", config->cert_path);
|
||||
|
||||
wf_server_config_dispose(config);
|
||||
}
|
||||
|
||||
TEST(server_config, set_vhostname)
|
||||
{
|
||||
wf_server_config * config = wf_server_config_create();
|
||||
ASSERT_NE(nullptr, config);
|
||||
|
||||
ASSERT_EQ(nullptr, config->key_path);
|
||||
|
||||
wf_server_config_set_vhostname(config, "webfuse");
|
||||
ASSERT_STREQ("webfuse", config->vhost_name);
|
||||
|
||||
wf_server_config_set_vhostname(config, "localhost");
|
||||
ASSERT_STREQ("localhost", config->vhost_name);
|
||||
|
||||
wf_server_config_dispose(config);
|
||||
}
|
||||
|
||||
TEST(server_config, set_port)
|
||||
{
|
||||
wf_server_config * config = wf_server_config_create();
|
||||
ASSERT_NE(nullptr, config);
|
||||
|
||||
ASSERT_EQ(0, config->port);
|
||||
|
||||
wf_server_config_set_port(config, 8443);
|
||||
ASSERT_EQ(8443, config->port);
|
||||
|
||||
wf_server_config_set_port(config, 8080);
|
||||
ASSERT_EQ(8080, config->port);
|
||||
|
||||
wf_server_config_dispose(config);
|
||||
}
|
||||
|
||||
TEST(server_config, set_mounpoint_factory)
|
||||
{
|
||||
wf_server_config * config = wf_server_config_create();
|
||||
ASSERT_NE(nullptr, config);
|
||||
ASSERT_EQ(nullptr, config->mountpoint_factory.create_mountpoint);
|
||||
ASSERT_EQ(nullptr, config->mountpoint_factory.user_data);
|
||||
|
||||
int value = 42;
|
||||
void * user_data = reinterpret_cast<void*>(&value);
|
||||
wf_server_config_set_mountpoint_factory(config, &create_mountpoint, user_data);
|
||||
ASSERT_EQ(&create_mountpoint, config->mountpoint_factory.create_mountpoint);
|
||||
ASSERT_EQ(user_data, config->mountpoint_factory.user_data);
|
||||
|
||||
wf_server_config_dispose(config);
|
||||
}
|
||||
|
||||
TEST(server_config, add_authenticator)
|
||||
{
|
||||
wf_server_config * config = wf_server_config_create();
|
||||
ASSERT_NE(nullptr, config);
|
||||
ASSERT_EQ(nullptr, config->authenticators.first);
|
||||
|
||||
int value = 42;
|
||||
void * user_data = reinterpret_cast<void*>(&value);
|
||||
wf_server_config_add_authenticator(config, "username", &authenticate, user_data);
|
||||
|
||||
wf_impl_authenticator * authenticator = config->authenticators.first;
|
||||
ASSERT_STREQ("username", authenticator->type);
|
||||
ASSERT_EQ(&authenticate, authenticator->authenticate);
|
||||
ASSERT_EQ(user_data, authenticator->user_data);
|
||||
|
||||
wf_server_config_dispose(config);
|
||||
}
|
||||
Reference in New Issue
Block a user