commit
3e563f00d6
@ -0,0 +1,21 @@
|
|||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/// \file protocol_names.h
|
||||||
|
/// \brief Names of websocket protocol.
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
#ifndef WF_PROTOCOL_NAMES_H
|
||||||
|
#define WF_PROTOCOL_NAMES_H
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/// \def WF_PROTOCOL_NAME_ADAPTER_SERVER
|
||||||
|
/// \brief Name of the websocket protocol an adapter server is running.
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
#define WF_PROTOCOL_NAME_ADAPTER_SERVER ("webfuse-adapter-server")
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
/// \def WF_PROTOCOL_NAME_PROVIDER_CLIENT
|
||||||
|
/// \brief Name of the websocket protocol an provider client is running.
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
#define WF_PROTOCOL_NAME_PROVIDER_CLIENT ("webfuse-provider-client")
|
||||||
|
|
||||||
|
#endif
|
@ -1,114 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
/// \file provider/static_filesystem.h
|
|
||||||
/// \brief Reference implementation of static filesystem.
|
|
||||||
///
|
|
||||||
/// This header is used by integration tests. It may be removed from the
|
|
||||||
/// library.
|
|
||||||
///
|
|
||||||
/// \todo Remove this header from library
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef WFP_STATIC_FILESYSTEM_H
|
|
||||||
#define WFP_STATIC_FILESYSTEM_H
|
|
||||||
|
|
||||||
#ifndef __cplusplus
|
|
||||||
#include <stddef.h>
|
|
||||||
#else
|
|
||||||
#include <cstddef>
|
|
||||||
using ::std::size_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <webfuse/provider/api.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct wfp_client_config;
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// \deprecated This will be removed. Dont use it.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
struct wfp_static_filesystem;
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// \deprecated This will be removed. Dont use it.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
typedef size_t
|
|
||||||
wfp_static_filesystem_read_fn(
|
|
||||||
size_t offset,
|
|
||||||
char * buffer,
|
|
||||||
size_t buffer_size,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// \deprecated This will be removed. Dont use it.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
typedef void
|
|
||||||
wfp_static_filesystem_get_info_fn(
|
|
||||||
void * user_data,
|
|
||||||
int * result_mode,
|
|
||||||
size_t * result_size);
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// \deprecated This will be removed. Dont use it.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
extern WFP_API struct wfp_static_filesystem *
|
|
||||||
wfp_static_filesystem_create(
|
|
||||||
struct wfp_client_config * config);
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// \deprecated This will be removed. Dont use it.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
extern WFP_API void
|
|
||||||
wfp_static_filesystem_dispose(
|
|
||||||
struct wfp_static_filesystem * filesystem);
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// \deprecated This will be removed. Dont use it.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
extern WFP_API void
|
|
||||||
wfp_static_filesystem_add(
|
|
||||||
struct wfp_static_filesystem * filesystem,
|
|
||||||
char const * path,
|
|
||||||
int mode,
|
|
||||||
char const * content,
|
|
||||||
size_t length);
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// \deprecated This will be removed. Dont use it.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
extern WFP_API void
|
|
||||||
wfp_static_filesystem_add_text(
|
|
||||||
struct wfp_static_filesystem * filesystem,
|
|
||||||
char const * path,
|
|
||||||
int mode,
|
|
||||||
char const * content);
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// \deprecated This will be removed. Dont use it.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
extern WFP_API void
|
|
||||||
wfp_static_filesystem_add_file(
|
|
||||||
struct wfp_static_filesystem * filesystem,
|
|
||||||
char const * path,
|
|
||||||
char const * filename);
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/// \deprecated This will be removed. Dont use it.
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
extern WFP_API void
|
|
||||||
wfp_static_filesystem_add_generic(
|
|
||||||
struct wfp_static_filesystem * filesystem,
|
|
||||||
char const * path,
|
|
||||||
wfp_static_filesystem_read_fn * read,
|
|
||||||
wfp_static_filesystem_get_info_fn * get_info,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,52 +0,0 @@
|
|||||||
#ifndef WFP_IMPL_STATIC_FILESYSTEM_H
|
|
||||||
#define WFP_IMPL_STATIC_FILESYSTEM_H
|
|
||||||
|
|
||||||
#include "webfuse/provider/static_filesystem.h"
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern struct wfp_static_filesystem *
|
|
||||||
wfp_impl_static_filesystem_create(
|
|
||||||
struct wfp_client_config * config);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wfp_impl_static_filesystem_dispose(
|
|
||||||
struct wfp_static_filesystem * filesystem);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wfp_impl_static_filesystem_add(
|
|
||||||
struct wfp_static_filesystem * filesystem,
|
|
||||||
char const * path,
|
|
||||||
int mode,
|
|
||||||
char const * content,
|
|
||||||
size_t length);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wfp_impl_static_filesystem_add_text(
|
|
||||||
struct wfp_static_filesystem * filesystem,
|
|
||||||
char const * path,
|
|
||||||
int mode,
|
|
||||||
char const * content);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wfp_impl_static_filesystem_add_file(
|
|
||||||
struct wfp_static_filesystem * filesystem,
|
|
||||||
char const * path,
|
|
||||||
char const * filename);
|
|
||||||
|
|
||||||
extern void
|
|
||||||
wfp_impl_static_filesystem_add_generic(
|
|
||||||
struct wfp_static_filesystem * filesystem,
|
|
||||||
char const * path,
|
|
||||||
wfp_static_filesystem_read_fn * read,
|
|
||||||
wfp_static_filesystem_get_info_fn * get_info,
|
|
||||||
void * user_data);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,58 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include "webfuse/core/path.h"
|
|
||||||
|
|
||||||
TEST(wf_path, empty)
|
|
||||||
{
|
|
||||||
struct wf_path * path = wf_path_create("");
|
|
||||||
ASSERT_EQ(0, wf_path_element_count(path));
|
|
||||||
ASSERT_EQ(nullptr, wf_path_get_element(path, 0));
|
|
||||||
|
|
||||||
wf_path_dispose(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wf_path, relative_file)
|
|
||||||
{
|
|
||||||
struct wf_path * path = wf_path_create("some.file");
|
|
||||||
ASSERT_EQ(1, wf_path_element_count(path));
|
|
||||||
ASSERT_STREQ("some.file", wf_path_get_element(path, 0));
|
|
||||||
|
|
||||||
wf_path_dispose(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wf_path, absolute_file)
|
|
||||||
{
|
|
||||||
struct wf_path * path = wf_path_create("/absolute.file");
|
|
||||||
ASSERT_EQ(1, wf_path_element_count(path));
|
|
||||||
ASSERT_STREQ("absolute.file", wf_path_get_element(path, 0));
|
|
||||||
|
|
||||||
wf_path_dispose(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wf_path, nested_path)
|
|
||||||
{
|
|
||||||
struct wf_path * path = wf_path_create("/a/nested/path");
|
|
||||||
ASSERT_EQ(3, wf_path_element_count(path));
|
|
||||||
ASSERT_STREQ("a", wf_path_get_element(path, 0));
|
|
||||||
ASSERT_STREQ("nested", wf_path_get_element(path, 1));
|
|
||||||
ASSERT_STREQ("path", wf_path_get_element(path, 2));
|
|
||||||
|
|
||||||
wf_path_dispose(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wf_path, deep_nested_path)
|
|
||||||
{
|
|
||||||
struct wf_path * path = wf_path_create("/this/is/a/very/deep/nested/path/to/some/file");
|
|
||||||
ASSERT_EQ(10, wf_path_element_count(path));
|
|
||||||
ASSERT_STREQ("this", wf_path_get_element(path, 0));
|
|
||||||
ASSERT_STREQ("is", wf_path_get_element(path, 1));
|
|
||||||
ASSERT_STREQ("a", wf_path_get_element(path, 2));
|
|
||||||
ASSERT_STREQ("very", wf_path_get_element(path, 3));
|
|
||||||
ASSERT_STREQ("deep", wf_path_get_element(path, 4));
|
|
||||||
ASSERT_STREQ("nested", wf_path_get_element(path, 5));
|
|
||||||
ASSERT_STREQ("path", wf_path_get_element(path, 6));
|
|
||||||
ASSERT_STREQ("to", wf_path_get_element(path, 7));
|
|
||||||
ASSERT_STREQ("some", wf_path_get_element(path, 8));
|
|
||||||
ASSERT_STREQ("file", wf_path_get_element(path, 9));
|
|
||||||
|
|
||||||
wf_path_dispose(path);
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
#ifndef WF_TEST_FAKE_SERVER_HPP
|
|
||||||
#define WF_TEST_FAKE_SERVER_HPP
|
|
||||||
|
|
||||||
#include <libwebsockets.h>
|
|
||||||
|
|
||||||
namespace webfuse_test
|
|
||||||
{
|
|
||||||
|
|
||||||
class FakeAdapterServer
|
|
||||||
{
|
|
||||||
FakeAdapterServer(FakeAdapterServer const &) = delete;
|
|
||||||
FakeAdapterServer & operator=(FakeAdapterServer const &) = delete;
|
|
||||||
public:
|
|
||||||
explicit FakeAdapterServer(int port);
|
|
||||||
~FakeAdapterServer();
|
|
||||||
void waitForConnection();
|
|
||||||
private:
|
|
||||||
class Private;
|
|
||||||
Private * d;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
@ -1,72 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
#include <gmock/gmock.h>
|
|
||||||
|
|
||||||
#include <webfuse/provider/client_protocol.h>
|
|
||||||
#include <webfuse/provider/client_config.h>
|
|
||||||
#include "fake_adapter_server.hpp"
|
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <thread>
|
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
using webfuse_test::FakeAdapterServer;
|
|
||||||
using testing::_;
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
|
|
||||||
struct Context
|
|
||||||
{
|
|
||||||
lws_context * context;
|
|
||||||
std::atomic<bool> isShutdownRequested;
|
|
||||||
};
|
|
||||||
|
|
||||||
void run(Context * context)
|
|
||||||
{
|
|
||||||
while (!context->isShutdownRequested)
|
|
||||||
{
|
|
||||||
lws_service(context->context, 100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
TEST(client_protocol, connect)
|
|
||||||
{
|
|
||||||
FakeAdapterServer server(54321);
|
|
||||||
|
|
||||||
wfp_client_config * config = wfp_client_config_create();
|
|
||||||
wfp_client_protocol * protocol = wfp_client_protocol_create(config);
|
|
||||||
|
|
||||||
struct lws_protocols protocols[2];
|
|
||||||
memset(protocols, 0, sizeof(struct lws_protocols) * 2);
|
|
||||||
protocols[0].name = "fs";
|
|
||||||
wfp_client_protocol_init_lws(protocol, &protocols[0]);
|
|
||||||
|
|
||||||
struct lws_context_creation_info info;
|
|
||||||
memset(&info, 0, sizeof(struct lws_context_creation_info));
|
|
||||||
info.port = CONTEXT_PORT_NO_LISTEN;
|
|
||||||
info.protocols = protocols;
|
|
||||||
info.uid = -1;
|
|
||||||
info.gid = -1;
|
|
||||||
|
|
||||||
struct lws_context * context = lws_create_context(&info);
|
|
||||||
wfp_client_protocol_connect(protocol, context, "ws://localhost:54321/");
|
|
||||||
|
|
||||||
Context ctx;
|
|
||||||
ctx.context = context;
|
|
||||||
ctx.isShutdownRequested = false;
|
|
||||||
std::thread client_thread(run, &ctx);
|
|
||||||
|
|
||||||
server.waitForConnection();
|
|
||||||
|
|
||||||
ctx.isShutdownRequested = true;
|
|
||||||
client_thread.join();
|
|
||||||
|
|
||||||
lws_context_destroy(context);
|
|
||||||
|
|
||||||
wfp_client_protocol_dispose(protocol);
|
|
||||||
wfp_client_config_dispose(config);
|
|
||||||
}
|
|
@ -1,61 +0,0 @@
|
|||||||
#include <gtest/gtest.h>
|
|
||||||
|
|
||||||
#include "webfuse/provider/impl/static_filesystem.h"
|
|
||||||
#include "webfuse/provider/client_config.h"
|
|
||||||
#include "webfuse/provider/impl/client_config.h"
|
|
||||||
|
|
||||||
#include "mock_request.hpp"
|
|
||||||
|
|
||||||
using webfuse_test::request_create;
|
|
||||||
using webfuse_test::MockRequest;
|
|
||||||
using webfuse_test::GetAttrMatcher;
|
|
||||||
using webfuse_test::ReaddirMatcher;
|
|
||||||
using testing::_;
|
|
||||||
|
|
||||||
TEST(wfp_static_filesystem, has_root_dir)
|
|
||||||
{
|
|
||||||
struct wfp_client_config * config = wfp_client_config_create();
|
|
||||||
struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config);
|
|
||||||
|
|
||||||
MockRequest mock;
|
|
||||||
struct wfp_request * request = request_create(&mock, 42);
|
|
||||||
EXPECT_CALL(mock, respond(GetAttrMatcher(1, 0555, "dir"), 42)).Times(1);
|
|
||||||
|
|
||||||
config->provider.getattr(request, 1, config->user_data);
|
|
||||||
|
|
||||||
wfp_impl_static_filesystem_dispose(filesystem);
|
|
||||||
wfp_client_config_dispose(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wfp_static_filesystem, contains_default_dirs)
|
|
||||||
{
|
|
||||||
struct wfp_client_config * config = wfp_client_config_create();
|
|
||||||
struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config);
|
|
||||||
|
|
||||||
MockRequest mock;
|
|
||||||
struct wfp_request * request = request_create(&mock, 23);
|
|
||||||
char const * default_dirs[] = {".", "..", nullptr};
|
|
||||||
EXPECT_CALL(mock, respond(ReaddirMatcher(default_dirs), 23)).Times(1);
|
|
||||||
|
|
||||||
config->provider.readdir(request, 1, config->user_data);
|
|
||||||
|
|
||||||
wfp_impl_static_filesystem_dispose(filesystem);
|
|
||||||
wfp_client_config_dispose(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wfp_static_filesystem, add_text)
|
|
||||||
{
|
|
||||||
struct wfp_client_config * config = wfp_client_config_create();
|
|
||||||
struct wfp_static_filesystem * filesystem = wfp_impl_static_filesystem_create(config);
|
|
||||||
wfp_impl_static_filesystem_add_text(filesystem, "text.file", 666, "some text");
|
|
||||||
|
|
||||||
MockRequest mock;
|
|
||||||
struct wfp_request * request = request_create(&mock, 23);
|
|
||||||
char const * contained_elements[] = {"text.file", nullptr};
|
|
||||||
EXPECT_CALL(mock, respond(ReaddirMatcher(contained_elements), 23)).Times(1);
|
|
||||||
|
|
||||||
config->provider.readdir(request, 1, config->user_data);
|
|
||||||
|
|
||||||
wfp_impl_static_filesystem_dispose(filesystem);
|
|
||||||
wfp_client_config_dispose(config);
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
#include "mock_authenticator.hpp"
|
#include "webfuse/mocks/mock_authenticator.hpp"
|
||||||
|
|
||||||
#define WF_AUTHENTICATOR_COUNT 3
|
#define WF_AUTHENTICATOR_COUNT 3
|
||||||
|
|
@ -0,0 +1,204 @@
|
|||||||
|
#include "webfuse/mocks/mock_provider_client.hpp"
|
||||||
|
#include "webfuse/provider/operation/error.h"
|
||||||
|
#include "webfuse/provider/dirbuffer.h"
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
using webfuse_test::IProviderClient;
|
||||||
|
using webfuse_test::ProviderClientException;
|
||||||
|
|
||||||
|
static void webfuse_test_iproviderclient_onconnected(
|
||||||
|
void * user_data)
|
||||||
|
{
|
||||||
|
auto * self = reinterpret_cast<IProviderClient*>(user_data);
|
||||||
|
self->OnConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void webfuse_test_iproviderclient_ondisconnected(
|
||||||
|
void * user_data)
|
||||||
|
{
|
||||||
|
auto * self = reinterpret_cast<IProviderClient*>(user_data);
|
||||||
|
self->OnDisconnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void webfuse_test_iproviderclient_ontimer(
|
||||||
|
void * user_data)
|
||||||
|
{
|
||||||
|
auto * self = reinterpret_cast<IProviderClient*>(user_data);
|
||||||
|
self->OnTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void webfuse_test_iproviderclient_onlookup(
|
||||||
|
struct wfp_request * request,
|
||||||
|
ino_t parent,
|
||||||
|
char const * name,
|
||||||
|
void * user_data)
|
||||||
|
{
|
||||||
|
auto * self = reinterpret_cast<IProviderClient*>(user_data);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
struct stat buffer;
|
||||||
|
self->Lookup(parent, name, &buffer);
|
||||||
|
wfp_respond_lookup(request, &buffer);
|
||||||
|
}
|
||||||
|
catch (ProviderClientException& ex)
|
||||||
|
{
|
||||||
|
wfp_respond_error(request, ex.GetErrorCode());
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
wfp_respond_error(request, WF_BAD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void webfuse_test_iproviderclient_ongetattr(
|
||||||
|
struct wfp_request * request,
|
||||||
|
ino_t inode,
|
||||||
|
void * user_data)
|
||||||
|
{
|
||||||
|
auto * self = reinterpret_cast<IProviderClient*>(user_data);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
struct stat buffer;
|
||||||
|
memset(&buffer, 0, sizeof(struct stat));
|
||||||
|
self->GetAttr(inode, &buffer);
|
||||||
|
wfp_respond_getattr(request,&buffer);
|
||||||
|
}
|
||||||
|
catch (ProviderClientException& ex)
|
||||||
|
{
|
||||||
|
wfp_respond_error(request, ex.GetErrorCode());
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
wfp_respond_error(request, WF_BAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void webfuse_test_iproviderclient_onreaddir(
|
||||||
|
struct wfp_request * request,
|
||||||
|
ino_t directory,
|
||||||
|
void * user_data)
|
||||||
|
{
|
||||||
|
auto * self = reinterpret_cast<IProviderClient*>(user_data);
|
||||||
|
wfp_dirbuffer * buffer = wfp_dirbuffer_create();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
self->ReadDir(directory, buffer);
|
||||||
|
wfp_respond_readdir(request, buffer);
|
||||||
|
}
|
||||||
|
catch (ProviderClientException& ex)
|
||||||
|
{
|
||||||
|
wfp_respond_error(request, ex.GetErrorCode());
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
wfp_respond_error(request, WF_BAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
wfp_dirbuffer_dispose(buffer);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void webfuse_test_iproviderclient_onopen(
|
||||||
|
struct wfp_request * request,
|
||||||
|
ino_t inode,
|
||||||
|
int flags,
|
||||||
|
void * user_data)
|
||||||
|
{
|
||||||
|
auto * self = reinterpret_cast<IProviderClient*>(user_data);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uint32_t handle = 0;
|
||||||
|
self->Open(inode, flags, &handle);
|
||||||
|
wfp_respond_open(request, handle);
|
||||||
|
}
|
||||||
|
catch (ProviderClientException& ex)
|
||||||
|
{
|
||||||
|
wfp_respond_error(request, ex.GetErrorCode());
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
wfp_respond_error(request, WF_BAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void webfuse_test_iproviderclient_onclose(
|
||||||
|
ino_t inode,
|
||||||
|
uint32_t handle,
|
||||||
|
int flags,
|
||||||
|
void * user_data)
|
||||||
|
{
|
||||||
|
auto * self = reinterpret_cast<IProviderClient*>(user_data);
|
||||||
|
self->Close(inode, handle, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void webfuse_test_iproviderclient_onread(
|
||||||
|
struct wfp_request * request,
|
||||||
|
ino_t inode,
|
||||||
|
uint32_t handle,
|
||||||
|
size_t offset,
|
||||||
|
size_t length,
|
||||||
|
void * user_data)
|
||||||
|
{
|
||||||
|
auto * self = reinterpret_cast<IProviderClient*>(user_data);
|
||||||
|
char * data = new char[length];
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
size_t bytes_read = 0;
|
||||||
|
self->Read(inode, handle, offset, length, data, &bytes_read);
|
||||||
|
wfp_respond_read(request, data, bytes_read);
|
||||||
|
}
|
||||||
|
catch (ProviderClientException& ex)
|
||||||
|
{
|
||||||
|
wfp_respond_error(request, ex.GetErrorCode());
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
wfp_respond_error(request, WF_BAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete[] data;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
ProviderClientException::ProviderClientException(wf_status error_code)
|
||||||
|
: runtime_error("ProviderClientException")
|
||||||
|
, error_code_(error_code)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
wf_status ProviderClientException::GetErrorCode()
|
||||||
|
{
|
||||||
|
return error_code_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void IProviderClient::AttachTo(wfp_client_config * config)
|
||||||
|
{
|
||||||
|
void * self = reinterpret_cast<void *>(this);
|
||||||
|
wfp_client_config_set_userdata(config, self);
|
||||||
|
wfp_client_config_set_onconnected(config, &webfuse_test_iproviderclient_onconnected);
|
||||||
|
wfp_client_config_set_ondisconnected(config, &webfuse_test_iproviderclient_ondisconnected);
|
||||||
|
wfp_client_config_set_ontimer(config, &webfuse_test_iproviderclient_ontimer);
|
||||||
|
|
||||||
|
wfp_client_config_set_onlookup(config, &webfuse_test_iproviderclient_onlookup);
|
||||||
|
wfp_client_config_set_ongetattr(config, &webfuse_test_iproviderclient_ongetattr);
|
||||||
|
wfp_client_config_set_onreaddir(config, &webfuse_test_iproviderclient_onreaddir);
|
||||||
|
wfp_client_config_set_onopen(config, &webfuse_test_iproviderclient_onopen);
|
||||||
|
wfp_client_config_set_onclose(config, &webfuse_test_iproviderclient_onclose);
|
||||||
|
wfp_client_config_set_onread(config, &webfuse_test_iproviderclient_onread);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
#ifndef WF_MOCK_PROVIDER_CLIENT_HPP
|
||||||
|
#define WF_MOCK_PROVIDER_CLIENT_HPP
|
||||||
|
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
#include "webfuse/provider/client_config.h"
|
||||||
|
#include "webfuse/core/status.h"
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
class ProviderClientException: public std::runtime_error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ProviderClientException(wf_status error_code);
|
||||||
|
wf_status GetErrorCode();
|
||||||
|
private:
|
||||||
|
wf_status error_code_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class IProviderClient
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IProviderClient() = default;
|
||||||
|
virtual void OnConnected() = 0;
|
||||||
|
virtual void OnDisconnected() = 0;
|
||||||
|
virtual void OnTimer() = 0;
|
||||||
|
virtual void Lookup(ino_t parent, char const * name, struct stat * result) = 0;
|
||||||
|
virtual void GetAttr(ino_t inode, struct stat * buffer) = 0;
|
||||||
|
virtual void ReadDir(ino_t directory, wfp_dirbuffer * buffer) = 0;
|
||||||
|
virtual void Open(ino_t inode, int flags, uint32_t * handle) = 0;
|
||||||
|
virtual void Close(ino_t inode, uint32_t handle, int flags) = 0;
|
||||||
|
virtual void Read(ino_t inode, uint32_t handle, size_t offset, size_t length, char * buffer, size_t * bytes_read) = 0;
|
||||||
|
|
||||||
|
void AttachTo(wfp_client_config * config);
|
||||||
|
};
|
||||||
|
|
||||||
|
class MockProviderClient: public IProviderClient
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
~MockProviderClient() override = default;
|
||||||
|
MOCK_METHOD0( OnConnected, void());
|
||||||
|
MOCK_METHOD0( OnDisconnected, void());
|
||||||
|
MOCK_METHOD0( OnTimer, void());
|
||||||
|
MOCK_METHOD3( Lookup, void(ino_t parent, char const * name, struct stat * result));
|
||||||
|
MOCK_METHOD2( GetAttr, void(ino_t inode, struct stat * buffer));
|
||||||
|
MOCK_METHOD2( ReadDir, void(ino_t directory, wfp_dirbuffer * buffer));
|
||||||
|
MOCK_METHOD3( Open, void(ino_t inode, int flags, uint32_t * handle));
|
||||||
|
MOCK_METHOD3( Close, void(ino_t inode, uint32_t handle, int flags));
|
||||||
|
MOCK_METHOD6( Read, void(ino_t inode, uint32_t handle, size_t offset, size_t length, char * buffer, size_t * bytes_read));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -1,4 +1,4 @@
|
|||||||
#include "mock_request.hpp"
|
#include "webfuse/mocks/mock_request.hpp"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace
|
namespace
|
@ -1,7 +1,7 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||||
#include "msleep.hpp"
|
#include "webfuse/utils/msleep.hpp"
|
||||||
|
|
||||||
using webfuse_test::msleep;
|
using webfuse_test::msleep;
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
#include "mock_authenticator.hpp"
|
#include "webfuse/mocks/mock_authenticator.hpp"
|
||||||
|
|
||||||
#include "webfuse/adapter/impl/authenticator.h"
|
#include "webfuse/adapter/impl/authenticator.h"
|
||||||
#include "webfuse/adapter/impl/credentials.h"
|
#include "webfuse/adapter/impl/credentials.h"
|
@ -1,6 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "msleep.hpp"
|
#include "webfuse/utils/msleep.hpp"
|
||||||
#include "webfuse/adapter/impl/time/timepoint.h"
|
#include "webfuse/adapter/impl/time/timepoint.h"
|
||||||
|
|
||||||
using webfuse_test::msleep;
|
using webfuse_test::msleep;
|
@ -1,7 +1,7 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include "tempdir.hpp"
|
#include "webfuse/utils/tempdir.hpp"
|
||||||
#include "file_utils.hpp"
|
#include "webfuse/utils/file_utils.hpp"
|
||||||
#include "webfuse_adapter.h"
|
#include "webfuse_adapter.h"
|
||||||
#include "webfuse/adapter/impl/uuid_mountpoint.h"
|
#include "webfuse/adapter/impl/uuid_mountpoint.h"
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include "webfuse_adapter.h"
|
#include "webfuse_adapter.h"
|
||||||
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
|
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
|
||||||
#include "tempdir.hpp"
|
#include "webfuse/utils/tempdir.hpp"
|
||||||
#include "file_utils.hpp"
|
#include "webfuse/utils/file_utils.hpp"
|
||||||
|
|
||||||
using webfuse_test::TempDir;
|
using webfuse_test::TempDir;
|
||||||
using webfuse_test::is_dir;
|
using webfuse_test::is_dir;
|
@ -1,10 +1,11 @@
|
|||||||
#include "integration/provider.hpp"
|
#include "webfuse/tests/integration/provider.hpp"
|
||||||
#include "webfuse_provider.h"
|
#include "webfuse_provider.h"
|
||||||
#include "webfuse/provider/impl/client.h"
|
#include "webfuse/provider/impl/client.h"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "msleep.hpp"
|
#include "webfuse/utils/msleep.hpp"
|
||||||
|
#include "webfuse/utils/static_filesystem.h"
|
||||||
|
|
||||||
namespace webfuse_test
|
namespace webfuse_test
|
||||||
{
|
{
|
@ -0,0 +1,152 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <gmock/gmock.h>
|
||||||
|
|
||||||
|
#include <webfuse/provider/client_protocol.h>
|
||||||
|
#include <webfuse/provider/client_config.h>
|
||||||
|
#include "webfuse/utils/ws_server.hpp"
|
||||||
|
#include "webfuse/mocks/mock_provider_client.hpp"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
using webfuse_test::WebsocketServer;
|
||||||
|
using webfuse_test::MockProviderClient;
|
||||||
|
using webfuse_test::IProviderClient;
|
||||||
|
using testing::_;
|
||||||
|
using testing::AtMost;
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
|
||||||
|
class ClientProtocolFixture
|
||||||
|
{
|
||||||
|
ClientProtocolFixture(ClientProtocolFixture const &) = delete;
|
||||||
|
ClientProtocolFixture& operator=(ClientProtocolFixture const &) = delete;
|
||||||
|
public:
|
||||||
|
explicit ClientProtocolFixture(IProviderClient& client)
|
||||||
|
{
|
||||||
|
config = wfp_client_config_create();
|
||||||
|
client.AttachTo(config);
|
||||||
|
|
||||||
|
protocol = wfp_client_protocol_create(config);
|
||||||
|
|
||||||
|
struct lws_protocols client_protocol;
|
||||||
|
memset(&client_protocol, 0, sizeof(struct lws_protocols));
|
||||||
|
wfp_client_protocol_init_lws(protocol, &client_protocol);
|
||||||
|
|
||||||
|
server = new WebsocketServer(54321, &client_protocol, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
~ClientProtocolFixture()
|
||||||
|
{
|
||||||
|
delete server;
|
||||||
|
wfp_client_protocol_dispose(protocol);
|
||||||
|
wfp_client_config_dispose(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Connect()
|
||||||
|
{
|
||||||
|
wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/");
|
||||||
|
server->waitForConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SendToClient(json_t * request)
|
||||||
|
{
|
||||||
|
server->sendMessage(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
json_t * ReceiveMessageFromClient()
|
||||||
|
{
|
||||||
|
return server->receiveMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AwaitAddFilesystem(std::string& filesystemName)
|
||||||
|
{
|
||||||
|
json_t * addFilesystemRequest = server->receiveMessage();
|
||||||
|
ASSERT_NE(nullptr, addFilesystemRequest);
|
||||||
|
ASSERT_TRUE(json_is_object(addFilesystemRequest));
|
||||||
|
|
||||||
|
json_t * method = json_object_get(addFilesystemRequest, "method");
|
||||||
|
ASSERT_TRUE(json_is_string(method));
|
||||||
|
ASSERT_STREQ("add_filesystem", json_string_value(method));
|
||||||
|
|
||||||
|
json_t * params = json_object_get(addFilesystemRequest, "params");
|
||||||
|
ASSERT_TRUE(json_is_array(params));
|
||||||
|
ASSERT_EQ(1, json_array_size(params));
|
||||||
|
|
||||||
|
json_t * filesystem = json_array_get(params, 0);
|
||||||
|
ASSERT_TRUE(json_is_string(filesystem));
|
||||||
|
filesystemName = json_string_value(filesystem);
|
||||||
|
|
||||||
|
json_t * id = json_object_get(addFilesystemRequest, "id");
|
||||||
|
ASSERT_TRUE(json_is_integer(id));
|
||||||
|
|
||||||
|
json_t * response = json_object();
|
||||||
|
json_t * result = json_object();
|
||||||
|
json_object_set(result, "id", filesystem);
|
||||||
|
json_object_set_new(response, "result", result);
|
||||||
|
json_object_set(response, "id", id);
|
||||||
|
|
||||||
|
server->sendMessage(response);
|
||||||
|
|
||||||
|
json_decref(addFilesystemRequest);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
WebsocketServer * server;
|
||||||
|
wfp_client_config * config;
|
||||||
|
wfp_client_protocol * protocol;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TEST(client_protocol, connect)
|
||||||
|
{
|
||||||
|
MockProviderClient provider;
|
||||||
|
ClientProtocolFixture fixture(provider);
|
||||||
|
|
||||||
|
EXPECT_CALL(provider, OnConnected()).Times(AtMost(1));
|
||||||
|
EXPECT_CALL(provider, OnDisconnected()).Times(1);
|
||||||
|
|
||||||
|
fixture.Connect();
|
||||||
|
if (HasFatalFailure()) { return; }
|
||||||
|
|
||||||
|
std::string filesystem;
|
||||||
|
fixture.AwaitAddFilesystem(filesystem);
|
||||||
|
if (HasFatalFailure()) { return; }
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(client_protocol, getattr)
|
||||||
|
{
|
||||||
|
MockProviderClient provider;
|
||||||
|
ClientProtocolFixture fixture(provider);
|
||||||
|
|
||||||
|
EXPECT_CALL(provider, OnConnected()).Times(1);
|
||||||
|
EXPECT_CALL(provider, OnDisconnected()).Times(1);
|
||||||
|
EXPECT_CALL(provider, GetAttr(1, _)).Times(1);
|
||||||
|
|
||||||
|
fixture.Connect();
|
||||||
|
if (HasFatalFailure()) { return; }
|
||||||
|
|
||||||
|
std::string filesystem;
|
||||||
|
fixture.AwaitAddFilesystem(filesystem);
|
||||||
|
if (HasFatalFailure()) { return; }
|
||||||
|
|
||||||
|
json_t * params = json_array();
|
||||||
|
json_array_append_new(params, json_string(filesystem.c_str()));
|
||||||
|
json_array_append_new(params, json_integer(1));
|
||||||
|
json_t * request = json_object();
|
||||||
|
json_object_set_new(request, "method", json_string("getattr"));
|
||||||
|
json_object_set_new(request, "params", params);
|
||||||
|
json_object_set_new(request, "id", json_integer(42));
|
||||||
|
|
||||||
|
fixture.SendToClient(request);
|
||||||
|
json_t * response = fixture.ReceiveMessageFromClient();
|
||||||
|
ASSERT_TRUE(json_is_object(response));
|
||||||
|
|
||||||
|
json_decref(response);
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
#include "die_if.hpp"
|
#include "webfuse/utils/die_if.hpp"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace webfuse_test
|
namespace webfuse_test
|
@ -1,4 +1,4 @@
|
|||||||
#include "file_utils.hpp"
|
#include "webfuse/utils/file_utils.hpp"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
@ -1,4 +1,4 @@
|
|||||||
#include "msleep.hpp"
|
#include "webfuse/utils/msleep.hpp"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
namespace webfuse_test
|
namespace webfuse_test
|
@ -1,4 +1,4 @@
|
|||||||
#include "webfuse/core/path.h"
|
#include "webfuse/utils/path.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -0,0 +1,63 @@
|
|||||||
|
#ifndef WFP_STATIC_FILESYSTEM_H
|
||||||
|
#define WFP_STATIC_FILESYSTEM_H
|
||||||
|
|
||||||
|
#ifndef __cplusplus
|
||||||
|
#include <stddef.h>
|
||||||
|
#else
|
||||||
|
#include <cstddef>
|
||||||
|
using ::std::size_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <webfuse/provider/api.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wfp_client_config;
|
||||||
|
|
||||||
|
struct wfp_static_filesystem;
|
||||||
|
|
||||||
|
typedef size_t
|
||||||
|
wfp_static_filesystem_read_fn(
|
||||||
|
size_t offset,
|
||||||
|
char * buffer,
|
||||||
|
size_t buffer_size,
|
||||||
|
void * user_data);
|
||||||
|
|
||||||
|
typedef void
|
||||||
|
wfp_static_filesystem_get_info_fn(
|
||||||
|
void * user_data,
|
||||||
|
int * result_mode,
|
||||||
|
size_t * result_size);
|
||||||
|
|
||||||
|
|
||||||
|
extern WFP_API struct wfp_static_filesystem *
|
||||||
|
wfp_static_filesystem_create(
|
||||||
|
struct wfp_client_config * config);
|
||||||
|
|
||||||
|
extern WFP_API void
|
||||||
|
wfp_static_filesystem_dispose(
|
||||||
|
struct wfp_static_filesystem * filesystem);
|
||||||
|
|
||||||
|
extern WFP_API void
|
||||||
|
wfp_static_filesystem_add(
|
||||||
|
struct wfp_static_filesystem * filesystem,
|
||||||
|
char const * path,
|
||||||
|
int mode,
|
||||||
|
char const * content,
|
||||||
|
size_t length);
|
||||||
|
|
||||||
|
extern WFP_API void
|
||||||
|
wfp_static_filesystem_add_text(
|
||||||
|
struct wfp_static_filesystem * filesystem,
|
||||||
|
char const * path,
|
||||||
|
int mode,
|
||||||
|
char const * content);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -1,5 +1,5 @@
|
|||||||
#include "webfuse/core/string.h"
|
#include "webfuse/core/string.h"
|
||||||
#include "tempdir.hpp"
|
#include "webfuse/utils/tempdir.hpp"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
@ -1,4 +1,4 @@
|
|||||||
#include "timeout_watcher.hpp"
|
#include "webfuse/utils/timeout_watcher.hpp"
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
using std::chrono::milliseconds;
|
using std::chrono::milliseconds;
|
@ -0,0 +1,29 @@
|
|||||||
|
#ifndef WF_TEST_UTILS_WS_SERVER_HPP
|
||||||
|
#define WF_TEST_UTILS_WS_SERVER_HPP
|
||||||
|
|
||||||
|
#include <libwebsockets.h>
|
||||||
|
#include <jansson.h>
|
||||||
|
|
||||||
|
namespace webfuse_test
|
||||||
|
{
|
||||||
|
|
||||||
|
class WebsocketServer
|
||||||
|
{
|
||||||
|
WebsocketServer(WebsocketServer const &) = delete;
|
||||||
|
WebsocketServer & operator=(WebsocketServer const &) = delete;
|
||||||
|
public:
|
||||||
|
explicit WebsocketServer(int port);
|
||||||
|
WebsocketServer(int port, struct lws_protocols * additionalProtocols, std::size_t additionalProtocolsCount);
|
||||||
|
~WebsocketServer();
|
||||||
|
struct lws_context * getContext();
|
||||||
|
void waitForConnection();
|
||||||
|
void sendMessage(json_t * message);
|
||||||
|
json_t * receiveMessage();
|
||||||
|
private:
|
||||||
|
class Private;
|
||||||
|
Private * d;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in new issue