Merge pull request #45 from falk-werner/mountpoint_provider
In order to give the (library) user some control of where the remote filesystem is mounted, a mounpoint factory is introduced to preplace the global root mount point and the uuid logic. To keep compatiblity, uuid stuff is not removed now (, but should be removed in near future...).pull/48/head
commit
cd144a3143
@ -0,0 +1,38 @@
|
||||
#ifndef WF_ADAPTER_MOUNTPOINT_H
|
||||
#define WF_ADAPTER_MOUNTPOINT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_mountpoint;
|
||||
|
||||
typedef void
|
||||
wf_mountpoint_userdata_dispose_fn(
|
||||
void * user_data);
|
||||
|
||||
extern struct wf_mountpoint *
|
||||
wf_mountpoint_create(
|
||||
char const * path);
|
||||
|
||||
extern void
|
||||
wf_mountpoint_dispose(
|
||||
struct wf_mountpoint * mountpoint);
|
||||
|
||||
extern char const *
|
||||
wf_mountpoint_get_path(
|
||||
struct wf_mountpoint const * mountpoint);
|
||||
|
||||
extern void
|
||||
wf_mountpoint_set_userdata(
|
||||
struct wf_mountpoint * mointpoint,
|
||||
void * user_data,
|
||||
wf_mountpoint_userdata_dispose_fn * dispose);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,24 @@
|
||||
#ifndef WF_ADAPTER_MOUNTPOINT_FACTORY_H
|
||||
#define WF_ADAPTER_MOUNTPOINT_FACTORY_H
|
||||
|
||||
#include <webfuse/adapter/api.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_mountpoint;
|
||||
|
||||
typedef struct wf_mountpoint *
|
||||
wf_create_mountpoint_fn(
|
||||
char const * filesystem,
|
||||
void * user_data);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
@ -0,0 +1,53 @@
|
||||
#include "webfuse/adapter/impl/mountpoint.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wf_mountpoint
|
||||
{
|
||||
char * path;
|
||||
void * user_data;
|
||||
wf_mountpoint_userdata_dispose_fn * dispose;
|
||||
};
|
||||
|
||||
struct wf_mountpoint *
|
||||
wf_impl_mountpoint_create(
|
||||
char const * path)
|
||||
{
|
||||
struct wf_mountpoint * mountpoint = malloc(sizeof(struct wf_mountpoint));
|
||||
mountpoint->path = strdup(path);
|
||||
mountpoint->user_data = NULL;
|
||||
mountpoint->dispose = NULL;
|
||||
|
||||
return mountpoint;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_mountpoint_dispose(
|
||||
struct wf_mountpoint * mountpoint)
|
||||
{
|
||||
if (NULL != mountpoint->dispose)
|
||||
{
|
||||
mountpoint->dispose(mountpoint->user_data);
|
||||
}
|
||||
|
||||
free(mountpoint->path);
|
||||
free(mountpoint);
|
||||
}
|
||||
|
||||
char const *
|
||||
wf_impl_mountpoint_get_path(
|
||||
struct wf_mountpoint const * mountpoint)
|
||||
{
|
||||
return mountpoint->path;
|
||||
}
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_set_userdata(
|
||||
struct wf_mountpoint * mountpoint,
|
||||
void * user_data,
|
||||
wf_mountpoint_userdata_dispose_fn * dispose)
|
||||
{
|
||||
mountpoint->user_data = user_data;
|
||||
mountpoint->dispose = dispose;
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
#ifndef WF_IMPL_MOUNTPOINT_H
|
||||
#define WF_IMPL_MOUNTPOINT_H
|
||||
|
||||
#include "webfuse/adapter/mountpoint.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern struct wf_mountpoint *
|
||||
wf_impl_mountpoint_create(
|
||||
char const * path);
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_dispose(
|
||||
struct wf_mountpoint * mountpoint);
|
||||
|
||||
extern char const *
|
||||
wf_impl_mountpoint_get_path(
|
||||
struct wf_mountpoint const * mountpoint);
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_set_userdata(
|
||||
struct wf_mountpoint * mountpoint,
|
||||
void * user_data,
|
||||
wf_mountpoint_userdata_dispose_fn * dispose);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,67 @@
|
||||
#include "webfuse/adapter/impl/mountpoint_factory.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void
|
||||
wf_impl_mountpoint_factory_init_default(
|
||||
struct wf_impl_mountpoint_factory * factory)
|
||||
{
|
||||
factory->create_mountpoint = NULL;
|
||||
factory->user_data = NULL;
|
||||
factory->dispose = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_mountpoint_factory_init(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
wf_create_mountpoint_fn * create_mountpoint,
|
||||
void * user_data,
|
||||
wf_impl_mountpoint_factory_dispose_fn * dispose)
|
||||
{
|
||||
factory->create_mountpoint = create_mountpoint;
|
||||
factory->user_data = user_data;
|
||||
factory->dispose = dispose;
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_mountpoint_factory_move(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
struct wf_impl_mountpoint_factory * other)
|
||||
{
|
||||
other->create_mountpoint = factory->create_mountpoint;
|
||||
other->user_data = factory->user_data;
|
||||
other->dispose = factory->dispose;
|
||||
|
||||
factory->create_mountpoint = NULL;
|
||||
factory->dispose = NULL;
|
||||
factory->user_data = NULL;
|
||||
}
|
||||
|
||||
bool
|
||||
wf_impl_mountpoint_factory_isvalid(
|
||||
struct wf_impl_mountpoint_factory * factory)
|
||||
{
|
||||
return (NULL != factory->create_mountpoint);
|
||||
}
|
||||
|
||||
void
|
||||
wf_impl_mountpoint_factory_cleanup(
|
||||
struct wf_impl_mountpoint_factory * factory)
|
||||
{
|
||||
if (NULL != factory->dispose)
|
||||
{
|
||||
factory->dispose(factory->user_data);
|
||||
}
|
||||
|
||||
factory->create_mountpoint = NULL;
|
||||
factory->dispose = NULL;
|
||||
factory->user_data = NULL;
|
||||
}
|
||||
|
||||
struct wf_mountpoint *
|
||||
wf_impl_mountpoint_factory_create_mountpoint(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
char const * filesystem)
|
||||
{
|
||||
return factory->create_mountpoint(filesystem, factory->user_data);
|
||||
}
|
||||
|
@ -0,0 +1,61 @@
|
||||
#ifndef WF_ADAPTER_IMPL_MOUNTPOINT_FACTORY_H
|
||||
#define WF_ADAPTER_IMPL_MOUNTPOINT_FACTORY_H
|
||||
|
||||
#include "webfuse/adapter/mountpoint_factory.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef void
|
||||
wf_impl_mountpoint_factory_dispose_fn(
|
||||
void * user_data);
|
||||
|
||||
struct wf_impl_mountpoint_factory
|
||||
{
|
||||
wf_create_mountpoint_fn * create_mountpoint;
|
||||
wf_impl_mountpoint_factory_dispose_fn * dispose;
|
||||
void * user_data;
|
||||
};
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_factory_init_default(
|
||||
struct wf_impl_mountpoint_factory * factory);
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_factory_init(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
wf_create_mountpoint_fn * create_mountpoint,
|
||||
void * user_data,
|
||||
wf_impl_mountpoint_factory_dispose_fn * dispose);
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_factory_move(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
struct wf_impl_mountpoint_factory * other);
|
||||
|
||||
extern bool
|
||||
wf_impl_mountpoint_factory_isvalid(
|
||||
struct wf_impl_mountpoint_factory * factory);
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_factory_init_from(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
struct wf_impl_mountpoint_factory * other);
|
||||
|
||||
extern void
|
||||
wf_impl_mountpoint_factory_cleanup(
|
||||
struct wf_impl_mountpoint_factory * factory);
|
||||
|
||||
extern struct wf_mountpoint *
|
||||
wf_impl_mountpoint_factory_create_mountpoint(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
char const * filesystem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,123 @@
|
||||
#include "webfuse/adapter/impl/uuid_mountpoint.h"
|
||||
#include "webfuse/adapter/impl/mountpoint.h"
|
||||
|
||||
#include "webfuse/core/string.h"
|
||||
|
||||
#include <uuid/uuid.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct wf_impl_uuid_mountpoint_data
|
||||
{
|
||||
char * id;
|
||||
char * filesystem_path;
|
||||
char * default_path;
|
||||
char * full_path;
|
||||
};
|
||||
|
||||
static char * wf_impl_uuid_mountpoint_create_id(void)
|
||||
{
|
||||
uuid_t uuid;
|
||||
uuid_generate(uuid);
|
||||
char id[UUID_STR_LEN];
|
||||
uuid_unparse(uuid, id);
|
||||
|
||||
return strdup(id);
|
||||
}
|
||||
|
||||
static bool wf_impl_uuid_mountpoint_is_link_broken(char const * path, char const * id)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
char buffer[UUID_STR_LEN];
|
||||
ssize_t count = readlink(path, buffer, UUID_STR_LEN);
|
||||
if ((0 < count) && (count < UUID_STR_LEN))
|
||||
{
|
||||
buffer[count] = '\0';
|
||||
result = (0 == strcmp(buffer, id));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool wf_impl_uuid_mountpoint_link_first_subdir(
|
||||
char const * link_path,
|
||||
char const * path)
|
||||
{
|
||||
bool result = false;
|
||||
DIR * dir = opendir(path);
|
||||
if (NULL != dir)
|
||||
{
|
||||
struct dirent * entry = readdir(dir);
|
||||
while (NULL != entry)
|
||||
{
|
||||
if ((DT_DIR == entry->d_type) && ('.' != entry->d_name[0]))
|
||||
{
|
||||
symlink(entry->d_name, link_path);
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
|
||||
entry = readdir(dir);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
wf_impl_uuid_mountpoint_data_dispose(
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_impl_uuid_mountpoint_data * data = user_data;
|
||||
|
||||
rmdir(data->full_path);
|
||||
|
||||
if (wf_impl_uuid_mountpoint_is_link_broken(data->default_path, data->id))
|
||||
{
|
||||
unlink(data->default_path);
|
||||
|
||||
bool const success = wf_impl_uuid_mountpoint_link_first_subdir(data->default_path, data->filesystem_path);
|
||||
if (!success)
|
||||
{
|
||||
rmdir(data->filesystem_path);
|
||||
}
|
||||
}
|
||||
|
||||
free(data->id);
|
||||
free(data->filesystem_path);
|
||||
free(data->default_path);
|
||||
free(data->full_path);
|
||||
free(data);
|
||||
}
|
||||
|
||||
struct wf_mountpoint *
|
||||
wf_impl_uuid_mountpoint_create(
|
||||
char const * root_path,
|
||||
char const * filesystem)
|
||||
{
|
||||
struct wf_impl_uuid_mountpoint_data * data = malloc(sizeof(struct wf_impl_uuid_mountpoint_data));
|
||||
data->filesystem_path = wf_create_string("%s/%s", root_path, filesystem);
|
||||
mkdir(data->filesystem_path, 0755);
|
||||
|
||||
data->id = wf_impl_uuid_mountpoint_create_id();
|
||||
data->full_path = wf_create_string("%s/%s/%s", root_path, filesystem, data->id);
|
||||
mkdir(data->full_path, 0755);
|
||||
|
||||
data->default_path = wf_create_string("%s/%s/default", root_path, filesystem);
|
||||
symlink(data->id, data->default_path);
|
||||
|
||||
struct wf_mountpoint * mountpoint = wf_impl_mountpoint_create(data->full_path);
|
||||
wf_impl_mountpoint_set_userdata(mountpoint, data, &wf_impl_uuid_mountpoint_data_dispose);
|
||||
|
||||
return mountpoint;
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
#ifndef WF_IMPL_UUID_MOUNTPOINT_H
|
||||
#define WF_IMPL_UUID_MOUNTPOINT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_mountpoint;
|
||||
|
||||
extern struct wf_mountpoint *
|
||||
wf_impl_uuid_mountpoint_create(
|
||||
char const * root_path,
|
||||
char const * filesystem);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,84 @@
|
||||
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
|
||||
#include "webfuse/adapter/impl/uuid_mountpoint.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct wf_impl_uuid_mountpoint_factory
|
||||
{
|
||||
char * root_path;
|
||||
bool root_created;
|
||||
};
|
||||
|
||||
static void *
|
||||
wf_impl_uuid_mountpoint_factory_create_context(
|
||||
char const * root_path)
|
||||
{
|
||||
struct wf_impl_uuid_mountpoint_factory * factory = NULL;
|
||||
bool root_created = false;
|
||||
|
||||
struct stat info;
|
||||
int rc = stat(root_path, &info);
|
||||
if ((0 != rc) || (!S_ISDIR(info.st_mode)))
|
||||
{
|
||||
rc = mkdir(root_path, 0755);
|
||||
root_created = true;
|
||||
}
|
||||
|
||||
if (0 == rc)
|
||||
{
|
||||
factory = malloc(sizeof(struct wf_impl_uuid_mountpoint_factory));
|
||||
factory->root_path = strdup(root_path);
|
||||
factory->root_created = root_created;
|
||||
}
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
||||
static void
|
||||
wf_impl_uuid_mountpoint_factory_dispose(
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_impl_uuid_mountpoint_factory * factory = user_data;
|
||||
|
||||
if (factory->root_created)
|
||||
{
|
||||
rmdir(factory->root_path);
|
||||
}
|
||||
|
||||
free(factory->root_path);
|
||||
free(factory);
|
||||
}
|
||||
|
||||
static struct wf_mountpoint *
|
||||
wf_impl_uuid_mountpoint_factory_create_mountpoint(
|
||||
char const * filesystem,
|
||||
void * user_data)
|
||||
{
|
||||
struct wf_impl_uuid_mountpoint_factory * factory = user_data;
|
||||
|
||||
return wf_impl_uuid_mountpoint_create(factory->root_path, filesystem);
|
||||
}
|
||||
|
||||
bool
|
||||
wf_impl_uuid_mountpoint_factory_init(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
char const * root_path)
|
||||
{
|
||||
void * context = wf_impl_uuid_mountpoint_factory_create_context(root_path);
|
||||
bool const result = (NULL != context);
|
||||
|
||||
if (result)
|
||||
{
|
||||
factory->create_mountpoint = &wf_impl_uuid_mountpoint_factory_create_mountpoint;
|
||||
factory->user_data = context;
|
||||
factory->dispose = &wf_impl_uuid_mountpoint_factory_dispose;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#ifndef WF_IMPL_UUID_MOUNTPOINT_FACTORY_H
|
||||
#define WF_IMPL_UUID_MOUNTPOINT_FACTORY_H
|
||||
|
||||
#include "webfuse/adapter/impl/mountpoint_factory.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern bool
|
||||
wf_impl_uuid_mountpoint_factory_init(
|
||||
struct wf_impl_mountpoint_factory * factory,
|
||||
char const * root_path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,47 @@
|
||||
#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);
|
||||
}
|
@ -0,0 +1,175 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse/adapter/server_config.h"
|
||||
#include "webfuse/adapter/impl/server_config.h"
|
||||
#include "webfuse/adapter/impl/authenticator.h"
|
||||
#include "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 * 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_mountpoint)
|
||||
{
|
||||
TempDir temp("server_config");
|
||||
|
||||
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);
|
||||
ASSERT_EQ(nullptr, config->mountpoint_factory.dispose);
|
||||
|
||||
wf_server_config_set_mountpoint(config, temp.path());
|
||||
ASSERT_NE(nullptr, config->mountpoint_factory.create_mountpoint);
|
||||
ASSERT_NE(nullptr, config->mountpoint_factory.user_data);
|
||||
ASSERT_NE(nullptr, config->mountpoint_factory.dispose);
|
||||
|
||||
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);
|
||||
ASSERT_EQ(nullptr, config->mountpoint_factory.dispose);
|
||||
|
||||
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);
|
||||
ASSERT_EQ(nullptr, config->mountpoint_factory.dispose);
|
||||
|
||||
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);
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tempdir.hpp"
|
||||
#include "file_utils.hpp"
|
||||
#include "webfuse_adapter.h"
|
||||
#include "webfuse/adapter/impl/uuid_mountpoint.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
using webfuse_test::TempDir;
|
||||
using webfuse_test::is_dir;
|
||||
using webfuse_test::is_symlink;
|
||||
using webfuse_test::is_same_path;
|
||||
|
||||
TEST(uuid_mountpoint, create)
|
||||
{
|
||||
TempDir temp("uuid_mountpoint");
|
||||
|
||||
std::string filesystem_path = std::string(temp.path()) + "/dummy";
|
||||
std::string default_path = std::string(temp.path()) + "/dummy/default";
|
||||
|
||||
wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_create(temp.path(), "dummy");
|
||||
std::string path = wf_mountpoint_get_path(mountpoint);
|
||||
ASSERT_NE(nullptr, mountpoint);
|
||||
ASSERT_TRUE(is_dir(filesystem_path));
|
||||
ASSERT_TRUE(is_symlink(default_path));
|
||||
ASSERT_TRUE(is_dir(default_path));
|
||||
ASSERT_TRUE(is_dir(path));
|
||||
ASSERT_TRUE(is_same_path(default_path, path));
|
||||
|
||||
wf_mountpoint_dispose(mountpoint);
|
||||
ASSERT_FALSE(is_dir(filesystem_path));
|
||||
ASSERT_FALSE(is_symlink(default_path));
|
||||
ASSERT_FALSE(is_dir(default_path));
|
||||
ASSERT_FALSE(is_dir(path));
|
||||
}
|
||||
|
||||
TEST(uuid_mountpoint, relink_default)
|
||||
{
|
||||
TempDir temp("uuid_mountpoint");
|
||||
|
||||
std::string filesystem_path = std::string(temp.path()) + "/dummy";
|
||||
std::string default_path = std::string(temp.path()) + "/dummy/default";
|
||||
|
||||
wf_mountpoint * mountpoint_a = wf_impl_uuid_mountpoint_create(temp.path(), "dummy");
|
||||
std::string path_a = wf_mountpoint_get_path(mountpoint_a);
|
||||
|
||||
wf_mountpoint * mountpoint_b = wf_impl_uuid_mountpoint_create(temp.path(), "dummy");
|
||||
std::string path_b = wf_mountpoint_get_path(mountpoint_b);
|
||||
|
||||
ASSERT_TRUE(is_dir(filesystem_path));
|
||||
ASSERT_TRUE(is_symlink(default_path));
|
||||
ASSERT_TRUE(is_dir(default_path));
|
||||
ASSERT_TRUE(is_dir(path_a));
|
||||
ASSERT_TRUE(is_dir(path_b));
|
||||
ASSERT_TRUE(is_same_path(default_path, path_a));
|
||||
|
||||
wf_mountpoint_dispose(mountpoint_a);
|
||||
ASSERT_TRUE(is_dir(filesystem_path));
|
||||
ASSERT_TRUE(is_symlink(default_path));
|
||||
ASSERT_TRUE(is_dir(default_path));
|
||||
ASSERT_FALSE(is_dir(path_a));
|
||||
ASSERT_TRUE(is_dir(path_b));
|
||||
ASSERT_TRUE(is_same_path(default_path, path_b));
|
||||
|
||||
wf_mountpoint_dispose(mountpoint_b);
|
||||
ASSERT_FALSE(is_dir(filesystem_path));
|
||||
ASSERT_FALSE(is_symlink(default_path));
|
||||
ASSERT_FALSE(is_dir(default_path));
|
||||
ASSERT_FALSE(is_dir(path_a));
|
||||
ASSERT_FALSE(is_dir(path_b));
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfuse_adapter.h"
|
||||
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
|
||||
#include "tempdir.hpp"
|
||||
#include "file_utils.hpp"
|
||||
|
||||
using webfuse_test::TempDir;
|
||||
using webfuse_test::is_dir;
|
||||
|
||||
TEST(uuid_mountpoint_factory, create_existing_dir)
|
||||
{
|
||||
TempDir temp("uuid_mountpoint_factory");
|
||||
|
||||
struct wf_impl_mountpoint_factory factory;
|
||||
bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, temp.path());
|
||||
ASSERT_TRUE(factory_created);
|
||||
ASSERT_TRUE(is_dir(temp.path()));
|
||||
|
||||
wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(&factory, "dummy");
|
||||
std::string path = wf_mountpoint_get_path(mountpoint);
|
||||
ASSERT_TRUE(is_dir(path));
|
||||
|
||||
wf_mountpoint_dispose(mountpoint);
|
||||
ASSERT_FALSE(is_dir(path));
|
||||
|
||||
wf_impl_mountpoint_factory_cleanup(&factory);
|
||||
// keep dir not created by factory
|
||||
ASSERT_TRUE(is_dir(temp.path()));
|
||||
}
|
||||
|
||||
TEST(uuid_mountpoint_factory, create_nonexisting_dir)
|
||||
{
|
||||
TempDir temp("uuid_mountpoint_factory");
|
||||
std::string root_path = std::string(temp.path()) + "/root";
|
||||
|
||||
struct wf_impl_mountpoint_factory factory;
|
||||
bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, root_path.c_str());
|
||||
ASSERT_TRUE(factory_created);
|
||||
ASSERT_TRUE(is_dir(root_path));
|
||||
|
||||
wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(&factory, "dummy");
|
||||
std::string path = wf_mountpoint_get_path(mountpoint);
|
||||
ASSERT_TRUE(is_dir(path));
|
||||
|
||||
wf_mountpoint_dispose(mountpoint);
|
||||
ASSERT_FALSE(is_dir(path));
|
||||
|
||||
wf_impl_mountpoint_factory_cleanup(&factory);
|
||||
// remove dir, created by factory
|
||||
ASSERT_FALSE(is_dir(root_path));
|
||||
}
|
||||
|
||||
TEST(uuid_mountpoint_factory, fail_to_created_nested_dir)
|
||||
{
|
||||
TempDir temp("uuid_mountpoint_factory");
|
||||
std::string root_path = std::string(temp.path()) + "/nested/root";
|
||||
|
||||
struct wf_impl_mountpoint_factory factory;
|
||||
bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, root_path.c_str());
|
||||
ASSERT_FALSE(factory_created);
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
#include "file_utils.hpp"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
bool is_dir(std::string const & path)
|
||||
{
|
||||
struct stat info;
|
||||
int rc = stat(path.c_str(), &info);
|
||||
|
||||
return (0 == rc) && (S_ISDIR(info.st_mode));
|
||||
}
|
||||
|
||||
bool is_symlink(std::string const & path)
|
||||
{
|
||||
struct stat info;
|
||||
int rc = lstat(path.c_str(), &info);
|
||||
|
||||
return (0 == rc) && (S_ISLNK(info.st_mode));
|
||||
}
|
||||
|
||||
bool is_same_path(std::string const & path, std::string const & other)
|
||||
{
|
||||
struct stat info;
|
||||
int rc = stat(path.c_str(), &info);
|
||||
|
||||
struct stat info_other;
|
||||
int rc_other = stat(other.c_str(), &info_other);
|
||||
|
||||
return (0 == rc) && (0 == rc_other) && (info.st_ino == info_other.st_ino);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
#ifndef WF_TEST_FILE_UTILS_HPP
|
||||
#define WF_TEST_FILE_UTILS_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
bool is_dir(std::string const & path);
|
||||
|
||||
bool is_symlink(std::string const & path);
|
||||
|
||||
bool is_same_path(std::string const & path, std::string const & other);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,33 @@
|
||||
#include "webfuse/core/string.h"
|
||||
#include "tempdir.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
TempDir::TempDir(char const * prefix)
|
||||
: path_(wf_create_string("/tmp/%s_XXXXXX", prefix))
|
||||
{
|
||||
char * result = mkdtemp(path_);
|
||||
if (NULL == result)
|
||||
{
|
||||
throw std::runtime_error("unable to create temp dir");
|
||||
}
|
||||
}
|
||||
|
||||
TempDir::~TempDir()
|
||||
{
|
||||
rmdir(path_);
|
||||
free(path_);
|
||||
}
|
||||
|
||||
char const * TempDir::path()
|
||||
{
|
||||
return path_;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
#ifndef WF_TEST_TEMPDIR_HPP
|
||||
#define WF_TEST_TEMPDIR_HPP
|
||||
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
class TempDir
|
||||
{
|
||||
TempDir(TempDir const &) = delete;
|
||||
TempDir & operator=(TempDir const &) = delete;
|
||||
public:
|
||||
explicit TempDir(char const * prefix);
|
||||
~TempDir();
|
||||
char const * path();
|
||||
private:
|
||||
char * path_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in new issue