mirror of
https://github.com/falk-werner/webfused
synced 2024-10-27 20:44:08 +00:00
Merge pull request #12 from falk-werner/reduce_dependency_versions
- make userdb optional - allow to specify mount options - fix invalid memory access of syslog logger
This commit is contained in:
commit
da174ebf22
4
deps.sh
4
deps.sh
@ -24,8 +24,8 @@ gtest_MD5=ecd1fa65e7de707cd5c00bdac56022cd
|
|||||||
gtest_DIR=googletest-release-${gtest_VERSION}
|
gtest_DIR=googletest-release-${gtest_VERSION}
|
||||||
gtest_TYPE=cmake
|
gtest_TYPE=cmake
|
||||||
|
|
||||||
webfuse_VERSION=0.5.1
|
webfuse_VERSION=0.7.0
|
||||||
webfuse_URL=https://github.com/falk-werner/webfuse/archive/v${webfuse_VERSION}.tar.gz
|
webfuse_URL=https://github.com/falk-werner/webfuse/archive/v${webfuse_VERSION}.tar.gz
|
||||||
webfuse_MD5=a2e0e9d24cf7bc2d2273b5c64788adca
|
webfuse_MD5=4f8b69196a634016da3c0e4f63e13590
|
||||||
webfuse_DIR=webfuse-${webfuse_VERSION}
|
webfuse_DIR=webfuse-${webfuse_VERSION}
|
||||||
webfuse_TYPE=meson
|
webfuse_TYPE=meson
|
||||||
|
@ -5,7 +5,7 @@ A config file is used to configure webfuse daemon.
|
|||||||
## Config file
|
## Config file
|
||||||
|
|
||||||
```
|
```
|
||||||
version = { major = 1, minor = 0 }
|
version = { major = 1, minor = 1 }
|
||||||
|
|
||||||
server:
|
server:
|
||||||
{
|
{
|
||||||
@ -35,7 +35,7 @@ authentication:
|
|||||||
|
|
||||||
filesystems:
|
filesystems:
|
||||||
(
|
(
|
||||||
{name = "test", mount_point = "/tmp/webfused" }
|
{name = "test", mount_point = "/tmp/webfused", mount_options = () }
|
||||||
)
|
)
|
||||||
|
|
||||||
log:
|
log:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
# Webfuse deamon configuration file
|
# Webfuse deamon configuration file
|
||||||
|
|
||||||
version = { major = 1, minor = 0 }
|
version = { major = 1, minor = 1 }
|
||||||
|
|
||||||
server:
|
server:
|
||||||
{
|
{
|
||||||
@ -36,7 +36,7 @@ authentication:
|
|||||||
|
|
||||||
filesystems:
|
filesystems:
|
||||||
(
|
(
|
||||||
{name = "test", mount_point = "/tmp/webfused" }
|
{name = "test", mount_point = "/tmp/webfused", mount_options = () }
|
||||||
)
|
)
|
||||||
|
|
||||||
log:
|
log:
|
||||||
|
59
meson.build
59
meson.build
@ -1,30 +1,43 @@
|
|||||||
project('webfused', 'c', 'cpp', version: '0.6.0', license: 'LGPL-3.0+')
|
project('webfused', 'c', 'cpp', version: '0.6.0', license: 'LGPL-3.0+',
|
||||||
|
default_options: ['c_std=gnu99', 'cpp_std=gnu++14'])
|
||||||
|
|
||||||
without_tests = get_option('without_tests')
|
without_tests = get_option('without_tests')
|
||||||
|
without_userdb = get_option('without_userdb')
|
||||||
|
|
||||||
c_compiler = meson.get_compiler('c')
|
c_compiler = meson.get_compiler('c')
|
||||||
|
|
||||||
openssl_dep = dependency('openssl', version: '>=1.1.1')
|
|
||||||
libconfig_dep = dependency('libconfig', version: '>=1.5')
|
libconfig_dep = dependency('libconfig', version: '>=1.5')
|
||||||
pam_dep = c_compiler.find_library('pam')
|
pam_dep = c_compiler.find_library('pam')
|
||||||
|
|
||||||
libwebsockets_dep = dependency('libwebsockets', version: '>=4.0.0')
|
libwebsockets_dep = dependency('libwebsockets', version: '>=4.0.0')
|
||||||
jansson_dep = dependency('jansson', version: '>=2.11')
|
libfuse_dep = dependency('fuse3', version: '>=3.1.0')
|
||||||
libfuse_dep = dependency('fuse3', version: '>=3.8.0')
|
|
||||||
|
|
||||||
webfuse_adapter_dep = dependency('webfuse', version: '>=0.5.0')
|
webfuse_adapter_dep = dependency('webfuse', version: '>=0.7.0')
|
||||||
|
|
||||||
inc_dir = include_directories('src')
|
inc_dir = include_directories('src')
|
||||||
|
|
||||||
libuserdb = static_library('userdb',
|
if not without_userdb
|
||||||
'src/userdb/userdb.c',
|
openssl_dep = dependency('openssl', version: '>=1.1.1')
|
||||||
include_directories: inc_dir,
|
jansson_dep = dependency('jansson', version: '>=2.7')
|
||||||
dependencies: [libconfig_dep, openssl_dep, jansson_dep])
|
|
||||||
|
|
||||||
libuserdb_dep = declare_dependency(
|
libuserdb = static_library('userdb',
|
||||||
|
'src/userdb/userdb_openssl.c',
|
||||||
|
include_directories: inc_dir,
|
||||||
|
dependencies: [openssl_dep, jansson_dep])
|
||||||
|
|
||||||
|
libuserdb_dep = declare_dependency(
|
||||||
include_directories: inc_dir,
|
include_directories: inc_dir,
|
||||||
link_with: libuserdb,
|
link_with: libuserdb,
|
||||||
dependencies: [libconfig_dep, openssl_dep, jansson_dep])
|
dependencies: [openssl_dep, jansson_dep])
|
||||||
|
else
|
||||||
|
libuserdb = static_library('userdb',
|
||||||
|
'src/userdb/userdb_none.c',
|
||||||
|
include_directories: inc_dir)
|
||||||
|
|
||||||
|
libuserdb_dep = declare_dependency(
|
||||||
|
include_directories: inc_dir,
|
||||||
|
link_with: libuserdb)
|
||||||
|
endif
|
||||||
|
|
||||||
libwebfused = static_library('webfused',
|
libwebfused = static_library('webfused',
|
||||||
'src/webfused/daemon.c',
|
'src/webfused/daemon.c',
|
||||||
@ -42,15 +55,15 @@ libwebfused = static_library('webfused',
|
|||||||
'src/webfused/log/manager.c',
|
'src/webfused/log/manager.c',
|
||||||
'src/webfused/log/stderr_logger.c',
|
'src/webfused/log/stderr_logger.c',
|
||||||
'src/webfused/log/syslog_logger.c',
|
'src/webfused/log/syslog_logger.c',
|
||||||
|
'src/webfused/util/string_list.c',
|
||||||
include_directories: inc_dir,
|
include_directories: inc_dir,
|
||||||
dependencies: [libuserdb_dep, webfuse_adapter_dep, pam_dep],
|
dependencies: [libuserdb_dep, webfuse_adapter_dep, libconfig_dep, pam_dep],
|
||||||
install: false)
|
install: false)
|
||||||
|
|
||||||
libwebfused_dep = declare_dependency(
|
libwebfused_dep = declare_dependency(
|
||||||
include_directories: inc_dir,
|
include_directories: inc_dir,
|
||||||
link_with: libwebfused,
|
link_with: libwebfused,
|
||||||
dependencies: [libuserdb_dep, webfuse_adapter_dep, pam_dep],
|
dependencies: [libuserdb_dep, webfuse_adapter_dep, libconfig_dep, pam_dep])
|
||||||
install: false)
|
|
||||||
|
|
||||||
webfused = executable('webfused',
|
webfused = executable('webfused',
|
||||||
'src/webfused/main.c',
|
'src/webfused/main.c',
|
||||||
@ -70,7 +83,7 @@ webfused_conf = configure_file(input: 'etc/webfused.conf' , output: 'webfu
|
|||||||
invalid_conf = configure_file(input: 'test/invalid.conf' , output: 'invalid.conf' , copy: true)
|
invalid_conf = configure_file(input: 'test/invalid.conf' , output: 'invalid.conf' , copy: true)
|
||||||
test_passwd_json = configure_file(input: 'test/test_passwd.json', output: 'test_passwd.json', copy: true)
|
test_passwd_json = configure_file(input: 'test/test_passwd.json', output: 'test_passwd.json', copy: true)
|
||||||
|
|
||||||
alltests = executable('alltests',
|
alltests_sources = [
|
||||||
'test/mock/config_builder.cc',
|
'test/mock/config_builder.cc',
|
||||||
'test/mock/logger.cc',
|
'test/mock/logger.cc',
|
||||||
'test/mock/credentials.cc',
|
'test/mock/credentials.cc',
|
||||||
@ -89,16 +102,26 @@ alltests = executable('alltests',
|
|||||||
'test/config/config.cc',
|
'test/config/config.cc',
|
||||||
'test/config/settings.cc',
|
'test/config/settings.cc',
|
||||||
'test/auth/factory.cc',
|
'test/auth/factory.cc',
|
||||||
'test/auth/file_authenticator.cc',
|
|
||||||
'test/auth/pam_authenticator.cc',
|
'test/auth/pam_authenticator.cc',
|
||||||
'test/log/log.cc',
|
'test/log/log.cc',
|
||||||
'test/log/log_manager.cc',
|
'test/log/log_manager.cc',
|
||||||
'test/log/stderr_logger.cc',
|
'test/log/stderr_logger.cc',
|
||||||
'test/log/syslog_logger.cc',
|
'test/log/syslog_logger.cc',
|
||||||
|
'test/util/string_list.cc',
|
||||||
'test/daemon.cc',
|
'test/daemon.cc',
|
||||||
'test/change_user.cc',
|
'test/change_user.cc',
|
||||||
'test/mountpoint_factory.cc',
|
'test/mountpoint_factory.cc'
|
||||||
'test/userdb.cc',
|
]
|
||||||
|
|
||||||
|
if not without_userdb
|
||||||
|
alltests_sources += [
|
||||||
|
'test/auth/file_authenticator.cc',
|
||||||
|
'test/userdb.cc'
|
||||||
|
]
|
||||||
|
endif
|
||||||
|
|
||||||
|
alltests = executable('alltests',
|
||||||
|
alltests_sources,
|
||||||
include_directories: ['src', 'test'],
|
include_directories: ['src', 'test'],
|
||||||
link_args: [
|
link_args: [
|
||||||
'-Wl,--wrap=wf_credentials_type',
|
'-Wl,--wrap=wf_credentials_type',
|
||||||
|
@ -1 +1,2 @@
|
|||||||
option('without_tests', type: 'boolean', value: false, description: 'disable unit tests')
|
option('without_tests', type: 'boolean', value: false, description: 'disable unit tests')
|
||||||
|
option('without_userdb', type: 'boolean', value: false, description: 'disable userdb')
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
#include <openssl/opensslv.h>
|
#include <openssl/opensslv.h>
|
||||||
#include <openssl/engine.h>
|
#include <openssl/engine.h>
|
||||||
#include <openssl/evp.h>
|
#include <openssl/evp.h>
|
||||||
#include <jansson.h>
|
|
||||||
#include <userdb/userdb.h>
|
#include <userdb/userdb.h>
|
||||||
|
|
||||||
|
|
||||||
|
74
src/userdb/userdb_none.c
Normal file
74
src/userdb/userdb_none.c
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
#include "userdb.h"
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
struct userdb * userdb_create(
|
||||||
|
char const * pepper)
|
||||||
|
{
|
||||||
|
(void) pepper;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void userdb_dispose(struct userdb * db)
|
||||||
|
{
|
||||||
|
(void) db;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool userdb_save(
|
||||||
|
struct userdb * db,
|
||||||
|
char const * filename)
|
||||||
|
{
|
||||||
|
(void) db;
|
||||||
|
(void) filename;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool userdb_load_file(
|
||||||
|
struct userdb * db,
|
||||||
|
char const * filename)
|
||||||
|
{
|
||||||
|
(void) db;
|
||||||
|
(void) filename;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool userdb_load_string(
|
||||||
|
struct userdb * db,
|
||||||
|
char const * contents)
|
||||||
|
{
|
||||||
|
(void) db;
|
||||||
|
(void) contents;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void userdb_add(
|
||||||
|
struct userdb * db,
|
||||||
|
char const * username,
|
||||||
|
char const * password)
|
||||||
|
{
|
||||||
|
(void) db;
|
||||||
|
(void) username;
|
||||||
|
(void) password;
|
||||||
|
}
|
||||||
|
|
||||||
|
void userdb_remove(
|
||||||
|
struct userdb * db,
|
||||||
|
char const * user)
|
||||||
|
{
|
||||||
|
(void) db;
|
||||||
|
(void) user;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool userdb_check(
|
||||||
|
struct userdb * db,
|
||||||
|
char const * username,
|
||||||
|
char const * password)
|
||||||
|
{
|
||||||
|
(void) db;
|
||||||
|
(void) username;
|
||||||
|
(void) password;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
@ -128,10 +128,11 @@ bool
|
|||||||
wfd_config_add_filesystem(
|
wfd_config_add_filesystem(
|
||||||
struct wfd_config * config,
|
struct wfd_config * config,
|
||||||
char const * name,
|
char const * name,
|
||||||
char const * mount_point)
|
char const * mount_point,
|
||||||
|
struct wfd_string_list const * mount_options)
|
||||||
{
|
{
|
||||||
return wfd_mountpoint_factory_add_filesystem(
|
return wfd_mountpoint_factory_add_filesystem(
|
||||||
config->mountpoint_factory, name, mount_point);
|
config->mountpoint_factory, name, mount_point, mount_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@ -174,4 +175,3 @@ wfd_config_get_group(
|
|||||||
{
|
{
|
||||||
return config->group;
|
return config->group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,12 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define WFD_CONFIG_VERSION_MAJOR 1
|
||||||
|
#define WFD_CONFIG_VERSION_MINOR 1
|
||||||
|
|
||||||
|
#define WFD_CONFIG_VERSION_STR_MAJOR "1"
|
||||||
|
#define WFD_CONFIG_VERSION_STR_MINOR "1"
|
||||||
|
|
||||||
struct wfd_config;
|
struct wfd_config;
|
||||||
struct wf_server_config;
|
struct wf_server_config;
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ extern "C"
|
|||||||
|
|
||||||
struct wfd_settings;
|
struct wfd_settings;
|
||||||
struct wfd_config;
|
struct wfd_config;
|
||||||
|
struct wfd_string_list;
|
||||||
|
|
||||||
extern struct wfd_config *
|
extern struct wfd_config *
|
||||||
wfd_config_create(void);
|
wfd_config_create(void);
|
||||||
@ -51,7 +52,8 @@ extern bool
|
|||||||
wfd_config_add_filesystem(
|
wfd_config_add_filesystem(
|
||||||
struct wfd_config * config,
|
struct wfd_config * config,
|
||||||
char const * name,
|
char const * name,
|
||||||
char const * mount_point);
|
char const * mount_point,
|
||||||
|
struct wfd_string_list const * mount_options);
|
||||||
|
|
||||||
extern bool
|
extern bool
|
||||||
wfd_config_set_logger(
|
wfd_config_set_logger(
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "webfused/config/config.h"
|
#include "webfused/config/config.h"
|
||||||
#include "webfused/config/settings_intern.h"
|
#include "webfused/config/settings_intern.h"
|
||||||
#include "webfused/log/log.h"
|
#include "webfused/log/log.h"
|
||||||
|
#include "webfused/util/string_list.h"
|
||||||
|
|
||||||
#include <libconfig.h>
|
#include <libconfig.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -10,13 +11,9 @@
|
|||||||
|
|
||||||
|
|
||||||
#if ((LIBCONFIG_VER_MAJOR != 1) || (LIBCONFIG_VER_MINOR < 5))
|
#if ((LIBCONFIG_VER_MAJOR != 1) || (LIBCONFIG_VER_MINOR < 5))
|
||||||
#error "linconfig 1.5 or higher needed"
|
#error "libconfig 1.5 or higher needed"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define WFD_CONFIG_VERSION_MAJOR 1
|
|
||||||
#define WFD_CONFIG_VERSION_MINOR 0
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
wfd_config_check_version(
|
wfd_config_check_version(
|
||||||
config_t * config)
|
config_t * config)
|
||||||
@ -217,6 +214,26 @@ wfd_config_read_authentication(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wfd_config_read_mountoptions(
|
||||||
|
config_setting_t * filesystem,
|
||||||
|
struct wfd_string_list * mount_options)
|
||||||
|
{
|
||||||
|
config_setting_t * list = config_setting_get_member(filesystem, "mount_options");
|
||||||
|
if ((NULL != list) && (CONFIG_TRUE == config_setting_is_list(list)))
|
||||||
|
{
|
||||||
|
int length = config_setting_length(list);
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
|
{
|
||||||
|
char const * option = config_setting_get_string_elem(list, i);
|
||||||
|
if (NULL != option)
|
||||||
|
{
|
||||||
|
wfd_string_list_add(mount_options, option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
wfd_config_read_filesystems(
|
wfd_config_read_filesystems(
|
||||||
config_t * config,
|
config_t * config,
|
||||||
@ -255,7 +272,12 @@ wfd_config_read_filesystems(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = wfd_config_add_filesystem(builder, name, mount_point);
|
struct wfd_string_list mount_options;
|
||||||
|
wfd_string_list_init(&mount_options);
|
||||||
|
wfd_config_read_mountoptions(fs, &mount_options);
|
||||||
|
|
||||||
|
result = wfd_config_add_filesystem(builder, name, mount_point, &mount_options);
|
||||||
|
wfd_string_list_cleanup(&mount_options);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -41,6 +43,7 @@ wfd_syslog_logger_close(
|
|||||||
void * user_data)
|
void * user_data)
|
||||||
{
|
{
|
||||||
closelog();
|
closelog();
|
||||||
|
free(user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wfd_syslog_facility
|
struct wfd_syslog_facility
|
||||||
@ -97,7 +100,7 @@ wfd_syslog_logger_init(
|
|||||||
int level,
|
int level,
|
||||||
struct wfd_settings * settings)
|
struct wfd_settings * settings)
|
||||||
{
|
{
|
||||||
char const * ident = wfd_settings_get_string_or_default(settings, "ident", "webfused");
|
char * ident = strdup(wfd_settings_get_string_or_default(settings, "ident", "webfused"));
|
||||||
char const * facility_str = wfd_settings_get_string_or_default(settings, "facility", "daemon");
|
char const * facility_str = wfd_settings_get_string_or_default(settings, "facility", "daemon");
|
||||||
bool log_pid = wfd_settings_get_bool(settings, "log_pid");
|
bool log_pid = wfd_settings_get_bool(settings, "log_pid");
|
||||||
|
|
||||||
@ -109,12 +112,13 @@ wfd_syslog_logger_init(
|
|||||||
wfd_logger_init(level,
|
wfd_logger_init(level,
|
||||||
&wfd_syslog_logger_log,
|
&wfd_syslog_logger_log,
|
||||||
&wfd_syslog_logger_close,
|
&wfd_syslog_logger_close,
|
||||||
NULL);
|
ident);
|
||||||
|
|
||||||
openlog(ident, options, facility);
|
openlog(ident, options, facility);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
free(ident);
|
||||||
WFD_ERROR("failed to init syslog logger: invalid log facility: \'%s\'", facility_str);
|
WFD_ERROR("failed to init syslog logger: invalid log facility: \'%s\'", facility_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "webfused/mountpoint_factory.h"
|
#include "webfused/mountpoint_factory.h"
|
||||||
|
#include "webfused/util/string_list.h"
|
||||||
#include "webfused/log/log.h"
|
#include "webfused/log/log.h"
|
||||||
|
|
||||||
#include <webfuse/mountpoint.h>
|
#include <webfuse/mountpoint.h>
|
||||||
@ -13,6 +14,7 @@ struct wfd_filesystem
|
|||||||
{
|
{
|
||||||
char * name;
|
char * name;
|
||||||
char * mount_point;
|
char * mount_point;
|
||||||
|
struct wfd_string_list mount_options;
|
||||||
bool in_use;
|
bool in_use;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,6 +70,7 @@ wfd_mountpoint_factory_dispose(
|
|||||||
struct wfd_filesystem * filesystem = &(factory->filesystems[i]);
|
struct wfd_filesystem * filesystem = &(factory->filesystems[i]);
|
||||||
free(filesystem->name);
|
free(filesystem->name);
|
||||||
free(filesystem->mount_point);
|
free(filesystem->mount_point);
|
||||||
|
wfd_string_list_cleanup(&filesystem->mount_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(factory->filesystems);
|
free(factory->filesystems);
|
||||||
@ -78,7 +81,8 @@ bool
|
|||||||
wfd_mountpoint_factory_add_filesystem(
|
wfd_mountpoint_factory_add_filesystem(
|
||||||
struct wfd_mountpoint_factory * factory,
|
struct wfd_mountpoint_factory * factory,
|
||||||
char const * name,
|
char const * name,
|
||||||
char const * mount_point)
|
char const * mount_point,
|
||||||
|
struct wfd_string_list const * mount_options)
|
||||||
{
|
{
|
||||||
bool result = (NULL == wfd_mountpoint_factory_find(factory, name));
|
bool result = (NULL == wfd_mountpoint_factory_find(factory, name));
|
||||||
if (!result)
|
if (!result)
|
||||||
@ -110,6 +114,7 @@ wfd_mountpoint_factory_add_filesystem(
|
|||||||
struct wfd_filesystem * actual = &(factory->filesystems[factory->count]);
|
struct wfd_filesystem * actual = &(factory->filesystems[factory->count]);
|
||||||
actual->name = strdup(name);
|
actual->name = strdup(name);
|
||||||
actual->mount_point = path;
|
actual->mount_point = path;
|
||||||
|
wfd_string_list_init_copy(&actual->mount_options, mount_options);
|
||||||
actual->in_use = false;
|
actual->in_use = false;
|
||||||
factory->count++;
|
factory->count++;
|
||||||
}
|
}
|
||||||
@ -140,6 +145,10 @@ wfd_mountpoint_factory_create_mountpoint(
|
|||||||
struct wf_mountpoint * result = wf_mountpoint_create(fs->mount_point);
|
struct wf_mountpoint * result = wf_mountpoint_create(fs->mount_point);
|
||||||
wf_mountpoint_set_userdata(result,
|
wf_mountpoint_set_userdata(result,
|
||||||
&fs->in_use, &wfd_mountpoint_factory_release_mountpoint);
|
&fs->in_use, &wfd_mountpoint_factory_release_mountpoint);
|
||||||
|
for (size_t i = 0; i < fs->mount_options.size; i++)
|
||||||
|
{
|
||||||
|
wf_mountpoint_add_mountoption(result, fs->mount_options.items[i]);
|
||||||
|
}
|
||||||
|
|
||||||
WFD_INFO("created mountpoint \'%s\' at path \'%s\'", filesystem, fs->mount_point);
|
WFD_INFO("created mountpoint \'%s\' at path \'%s\'", filesystem, fs->mount_point);
|
||||||
return result;
|
return result;
|
||||||
|
@ -13,6 +13,7 @@ extern "C"
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct wfd_mountpoint_factory;
|
struct wfd_mountpoint_factory;
|
||||||
|
struct wfd_string_list;
|
||||||
|
|
||||||
extern struct wfd_mountpoint_factory *
|
extern struct wfd_mountpoint_factory *
|
||||||
wfd_mountpoint_factory_create(void);
|
wfd_mountpoint_factory_create(void);
|
||||||
@ -25,7 +26,8 @@ extern bool
|
|||||||
wfd_mountpoint_factory_add_filesystem(
|
wfd_mountpoint_factory_add_filesystem(
|
||||||
struct wfd_mountpoint_factory * factory,
|
struct wfd_mountpoint_factory * factory,
|
||||||
char const * name,
|
char const * name,
|
||||||
char const * mount_point);
|
char const * mount_point,
|
||||||
|
struct wfd_string_list const * mount_options);
|
||||||
|
|
||||||
extern struct wf_mountpoint *
|
extern struct wf_mountpoint *
|
||||||
wfd_mountpoint_factory_create_mountpoint(
|
wfd_mountpoint_factory_create_mountpoint(
|
||||||
|
62
src/webfused/util/string_list.c
Normal file
62
src/webfused/util/string_list.c
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#include "webfused/util/string_list.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define WFD_STRING_LIST_INITIAL_CAPACITY 8
|
||||||
|
|
||||||
|
void
|
||||||
|
wfd_string_list_init(
|
||||||
|
struct wfd_string_list * list)
|
||||||
|
{
|
||||||
|
list->size = 0;
|
||||||
|
list->capacity = WFD_STRING_LIST_INITIAL_CAPACITY;
|
||||||
|
list->items = malloc(sizeof(char *) * list->capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wfd_string_list_init_copy(
|
||||||
|
struct wfd_string_list * list,
|
||||||
|
struct wfd_string_list const * other)
|
||||||
|
{
|
||||||
|
if (0 < other->size)
|
||||||
|
{
|
||||||
|
list->size = other->size;
|
||||||
|
list->capacity = other->capacity;
|
||||||
|
list->items = malloc(sizeof(char *) * list->capacity);
|
||||||
|
|
||||||
|
for(size_t i = 0; i < other->size; i++)
|
||||||
|
{
|
||||||
|
list->items[i] = strdup(other->items[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wfd_string_list_init(list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wfd_string_list_cleanup(
|
||||||
|
struct wfd_string_list * list)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < list->size; i++)
|
||||||
|
{
|
||||||
|
free(list->items[i]);
|
||||||
|
}
|
||||||
|
free(list->items);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
wfd_string_list_add(
|
||||||
|
struct wfd_string_list * list,
|
||||||
|
char const * item)
|
||||||
|
{
|
||||||
|
if (list->size >= list->capacity)
|
||||||
|
{
|
||||||
|
list->capacity *= 2;
|
||||||
|
list->items = realloc(list->items, sizeof(char *) * list->capacity);
|
||||||
|
}
|
||||||
|
|
||||||
|
list->items[list->size] = strdup(item);
|
||||||
|
list->size++;
|
||||||
|
}
|
44
src/webfused/util/string_list.h
Normal file
44
src/webfused/util/string_list.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#ifndef WFD_UTIL_STRING_LIST_H
|
||||||
|
#define WFD_UTIL_STRING_LIST_H
|
||||||
|
|
||||||
|
#ifndef __cplusplus
|
||||||
|
#include <stddef.h>
|
||||||
|
#else
|
||||||
|
#include <cstddef>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct wfd_string_list
|
||||||
|
{
|
||||||
|
size_t size;
|
||||||
|
size_t capacity;
|
||||||
|
char * * items;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void
|
||||||
|
wfd_string_list_init(
|
||||||
|
struct wfd_string_list * list);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
wfd_string_list_init_copy(
|
||||||
|
struct wfd_string_list * list,
|
||||||
|
struct wfd_string_list const * other);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
wfd_string_list_cleanup(
|
||||||
|
struct wfd_string_list * list);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
wfd_string_list_add(
|
||||||
|
struct wfd_string_list * list,
|
||||||
|
char const * item);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -5,7 +5,9 @@
|
|||||||
|
|
||||||
#include "webfused/log/logger.h"
|
#include "webfused/log/logger.h"
|
||||||
#include "webfused/log/log.h"
|
#include "webfused/log/log.h"
|
||||||
|
#include "webfused/util/string_list.h"
|
||||||
#include "mock/logger.hpp"
|
#include "mock/logger.hpp"
|
||||||
|
|
||||||
using ::webfused_test::MockLogger;
|
using ::webfused_test::MockLogger;
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
|
|
||||||
@ -77,7 +79,8 @@ TEST(config, add_filesystem)
|
|||||||
wfd_config * config = wfd_config_create();
|
wfd_config * config = wfd_config_create();
|
||||||
ASSERT_NE(nullptr, config);
|
ASSERT_NE(nullptr, config);
|
||||||
|
|
||||||
bool success = wfd_config_add_filesystem(config, "test", "/tmp/test");
|
struct wfd_string_list mount_options = {0, 0, nullptr};
|
||||||
|
bool success = wfd_config_add_filesystem(config, "test", "/tmp/test", &mount_options);
|
||||||
ASSERT_TRUE(success);
|
ASSERT_TRUE(success);
|
||||||
|
|
||||||
wfd_config_dispose(config);
|
wfd_config_dispose(config);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "webfused/config/config.h"
|
||||||
#include "webfused/config/factory.h"
|
#include "webfused/config/factory.h"
|
||||||
#include "webfused/log/logger.h"
|
#include "webfused/log/logger.h"
|
||||||
#include "webfused/log/log.h"
|
#include "webfused/log/log.h"
|
||||||
@ -23,7 +24,7 @@ TEST(configfile, is_loadable)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_server_vhostname(_,StrEq("localhost"))).Times(1);
|
EXPECT_CALL(builder, wfd_config_set_server_vhostname(_,StrEq("localhost"))).Times(1);
|
||||||
EXPECT_CALL(builder, wfd_config_set_server_port(_,8080)).Times(1);
|
EXPECT_CALL(builder, wfd_config_set_server_port(_,8080)).Times(1);
|
||||||
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(true));
|
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(true));
|
||||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_)).Times(1).WillOnce(Return(true));
|
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_,_)).Times(1).WillOnce(Return(true));
|
||||||
|
|
||||||
struct wfd_config * config = wfd_config_load_file("webfused.conf");
|
struct wfd_config * config = wfd_config_load_file("webfused.conf");
|
||||||
ASSERT_NE(nullptr, config);
|
ASSERT_NE(nullptr, config);
|
||||||
@ -38,7 +39,7 @@ TEST(configfile, minimal_config)
|
|||||||
StrictMock<MockConfigBuilder> builder;
|
StrictMock<MockConfigBuilder> builder;
|
||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
|
|
||||||
char const minimal[] = "version = { major = 1, minor = 0 }\n";
|
char const minimal[] = "version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n";
|
||||||
struct wfd_config * config = wfd_config_load_string(minimal);
|
struct wfd_config * config = wfd_config_load_string(minimal);
|
||||||
ASSERT_NE(nullptr, config);
|
ASSERT_NE(nullptr, config);
|
||||||
}
|
}
|
||||||
@ -53,7 +54,7 @@ TEST(configfile, invalid_config)
|
|||||||
EXPECT_CALL(builder, wfd_config_create).Times(0);
|
EXPECT_CALL(builder, wfd_config_create).Times(0);
|
||||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(0);
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(0);
|
||||||
|
|
||||||
char const syntax_error[] = "version.major = 1\n";
|
char const syntax_error[] = "version.major = " WFD_CONFIG_VERSION_STR_MAJOR "\n";
|
||||||
|
|
||||||
wfd_config * config = wfd_config_load_string(syntax_error);
|
wfd_config * config = wfd_config_load_string(syntax_error);
|
||||||
ASSERT_EQ(nullptr, config);
|
ASSERT_EQ(nullptr, config);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "webfused/config/config.h"
|
||||||
#include "webfused/config/factory.h"
|
#include "webfused/config/factory.h"
|
||||||
#include "webfused/log/logger.h"
|
#include "webfused/log/logger.h"
|
||||||
#include "webfused/log/log.h"
|
#include "webfused/log/log.h"
|
||||||
@ -26,7 +27,7 @@ TEST(config_auth, authentication)
|
|||||||
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(true));
|
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(true));
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"authentication:\n"
|
"authentication:\n"
|
||||||
"(\n"
|
"(\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
@ -51,7 +52,7 @@ TEST(config_auth, failed_create_authenticator)
|
|||||||
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(false));
|
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(false));
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"authentication:\n"
|
"authentication:\n"
|
||||||
"(\n"
|
"(\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
@ -75,7 +76,7 @@ TEST(config_auth, failed_missing_auth_provider)
|
|||||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"authentication:\n"
|
"authentication:\n"
|
||||||
"(\n"
|
"(\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
@ -98,7 +99,7 @@ TEST(config_auth, failed_missing_auth_settings)
|
|||||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"authentication:\n"
|
"authentication:\n"
|
||||||
"(\n"
|
"(\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
@ -124,7 +125,7 @@ TEST(config_auth, failed_auth_settings_get_elem)
|
|||||||
EXPECT_CALL(libconfig, config_setting_get_elem(_,_)).Times(1).WillOnce(Return(nullptr));
|
EXPECT_CALL(libconfig, config_setting_get_elem(_,_)).Times(1).WillOnce(Return(nullptr));
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR" }\n"
|
||||||
"authentication:\n"
|
"authentication:\n"
|
||||||
"(\n"
|
"(\n"
|
||||||
" {\n"
|
" {\n"
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "webfused/config/config.h"
|
||||||
#include "webfused/config/factory.h"
|
#include "webfused/config/factory.h"
|
||||||
|
#include "webfused/util/string_list.h"
|
||||||
#include "webfused/log/logger.h"
|
#include "webfused/log/logger.h"
|
||||||
#include "webfused/log/log.h"
|
#include "webfused/log/log.h"
|
||||||
#include "mock/logger.hpp"
|
#include "mock/logger.hpp"
|
||||||
#include "mock/config_builder.hpp"
|
#include "mock/config_builder.hpp"
|
||||||
#include "mock/libconfig.hpp"
|
#include "mock/libconfig.hpp"
|
||||||
|
|
||||||
|
using ::testing::Invoke;
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
using ::testing::Return;
|
using ::testing::Return;
|
||||||
using ::testing::StrictMock;
|
using ::testing::StrictMock;
|
||||||
@ -23,10 +26,10 @@ TEST(configfile_fs, filesystems)
|
|||||||
|
|
||||||
StrictMock<MockConfigBuilder> builder;
|
StrictMock<MockConfigBuilder> builder;
|
||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(1).WillOnce(Return(true));
|
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_,_)).Times(1).WillOnce(Return(true));
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"filesystems:\n"
|
"filesystems:\n"
|
||||||
"(\n"
|
"(\n"
|
||||||
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
|
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
|
||||||
@ -44,10 +47,10 @@ TEST(configfile_fs, filesystems_empty)
|
|||||||
|
|
||||||
StrictMock<MockConfigBuilder> builder;
|
StrictMock<MockConfigBuilder> builder;
|
||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
|
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_,_)).Times(0);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"filesystems:\n"
|
"filesystems:\n"
|
||||||
"(\n"
|
"(\n"
|
||||||
")\n"
|
")\n"
|
||||||
@ -65,13 +68,13 @@ TEST(configfile_fs, filesystems_failed_add)
|
|||||||
StrictMock<MockConfigBuilder> builder;
|
StrictMock<MockConfigBuilder> builder;
|
||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(1).WillOnce(Return(false));
|
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_,_)).Times(1).WillOnce(Return(false));
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"filesystems:\n"
|
"filesystems:\n"
|
||||||
"(\n"
|
"(\n"
|
||||||
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
|
" {name = \"foo\", mount_point = \"/tmp/test\", mount_options = () }\n"
|
||||||
")\n"
|
")\n"
|
||||||
;
|
;
|
||||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||||
@ -87,10 +90,10 @@ TEST(configfile_fs, filesystems_failed_missing_name)
|
|||||||
StrictMock<MockConfigBuilder> builder;
|
StrictMock<MockConfigBuilder> builder;
|
||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
|
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_,_)).Times(0);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"filesystems:\n"
|
"filesystems:\n"
|
||||||
"(\n"
|
"(\n"
|
||||||
" {mount_point = \"/tmp/test\" }\n"
|
" {mount_point = \"/tmp/test\" }\n"
|
||||||
@ -109,10 +112,10 @@ TEST(configfile_fs, filesystems_failed_missing_mountpoint)
|
|||||||
StrictMock<MockConfigBuilder> builder;
|
StrictMock<MockConfigBuilder> builder;
|
||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
|
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_,_)).Times(0);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"filesystems:\n"
|
"filesystems:\n"
|
||||||
"(\n"
|
"(\n"
|
||||||
" {name = \"foo\"}\n"
|
" {name = \"foo\"}\n"
|
||||||
@ -131,13 +134,13 @@ TEST(configfile_fs, filesystems_failed_missing_elem)
|
|||||||
StrictMock<MockConfigBuilder> builder;
|
StrictMock<MockConfigBuilder> builder;
|
||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||||
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
|
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_,_)).Times(0);
|
||||||
|
|
||||||
MockLibConfig libconfig;
|
MockLibConfig libconfig;
|
||||||
EXPECT_CALL(libconfig, config_setting_get_elem(_,_)).Times(1).WillOnce(Return(nullptr));
|
EXPECT_CALL(libconfig, config_setting_get_elem(_,_)).Times(1).WillOnce(Return(nullptr));
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"filesystems:\n"
|
"filesystems:\n"
|
||||||
"(\n"
|
"(\n"
|
||||||
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
|
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
|
||||||
@ -146,3 +149,51 @@ TEST(configfile_fs, filesystems_failed_missing_elem)
|
|||||||
struct wfd_config * config = wfd_config_load_string(config_text);
|
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||||
ASSERT_EQ(nullptr, config);
|
ASSERT_EQ(nullptr, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(configfile_fs, filesystems_failed_add_options)
|
||||||
|
{
|
||||||
|
MockLogger logger;
|
||||||
|
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||||
|
EXPECT_CALL(logger, onclose()).Times(1);
|
||||||
|
|
||||||
|
StrictMock<MockConfigBuilder> builder;
|
||||||
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||||
|
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_,_)).Times(1).WillOnce(Return(false));
|
||||||
|
|
||||||
|
char const config_text[] =
|
||||||
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
|
"filesystems:\n"
|
||||||
|
"(\n"
|
||||||
|
" {name = \"foo\", mount_point = \"/tmp/test\", mount_options = (\"-o\", \"allow_other\") }\n"
|
||||||
|
")\n"
|
||||||
|
;
|
||||||
|
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||||
|
ASSERT_EQ(nullptr, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(configfile_fs, with_mountoptions)
|
||||||
|
{
|
||||||
|
MockLogger logger;
|
||||||
|
EXPECT_CALL(logger, log(_, _, _)).Times(0);
|
||||||
|
EXPECT_CALL(logger, onclose()).Times(1);
|
||||||
|
|
||||||
|
StrictMock<MockConfigBuilder> builder;
|
||||||
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
|
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_,_,_)).Times(1).WillOnce(Invoke(
|
||||||
|
[](wfd_config * config, char const * name, char const * mountpoint, wfd_string_list const * mount_options) -> bool {
|
||||||
|
std::cout << mount_options->items[0] << std::endl;
|
||||||
|
std::cout << mount_options->items[1] << std::endl;
|
||||||
|
return (2 == mount_options->size);
|
||||||
|
}));
|
||||||
|
|
||||||
|
char const config_text[] =
|
||||||
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
|
"filesystems:\n"
|
||||||
|
"(\n"
|
||||||
|
" {name = \"foo\", mount_point = \"/tmp/test\", mount_options = (\"-o\", \"allow_user\") }\n"
|
||||||
|
")\n"
|
||||||
|
;
|
||||||
|
struct wfd_config * config = wfd_config_load_string(config_text);
|
||||||
|
ASSERT_NE(nullptr, config);
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "webfused/config/config.h"
|
||||||
#include "webfused/config/factory.h"
|
#include "webfused/config/factory.h"
|
||||||
#include "webfused/log/logger.h"
|
#include "webfused/log/logger.h"
|
||||||
#include "webfused/log/log.h"
|
#include "webfused/log/log.h"
|
||||||
@ -26,7 +27,7 @@ TEST(configfile_log, set_logger)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(true));
|
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(true));
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"log:\n"
|
"log:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" provider = \"stderr\"\n"
|
" provider = \"stderr\"\n"
|
||||||
@ -49,7 +50,7 @@ TEST(configfile_log, log_fail_set_logger)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(false));
|
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(false));
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"log:\n"
|
"log:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" provider = \"stderr\"\n"
|
" provider = \"stderr\"\n"
|
||||||
@ -72,7 +73,7 @@ TEST(configfile_log, log_fail_missing_provider)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
|
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"log:\n"
|
"log:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" level = \"all\"\n"
|
" level = \"all\"\n"
|
||||||
@ -94,7 +95,7 @@ TEST(configfile_log, log_fail_missing_level)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
|
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"log:\n"
|
"log:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" provider = \"stderr\"\n"
|
" provider = \"stderr\"\n"
|
||||||
@ -117,7 +118,7 @@ TEST(configfile_log, log_fail_invalid_level)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_logger(_, _, _, _)).Times(0);
|
EXPECT_CALL(builder, wfd_config_set_logger(_, _, _, _)).Times(0);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"log:\n"
|
"log:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" provider = \"stderr\"\n"
|
" provider = \"stderr\"\n"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "webfused/config/config.h"
|
||||||
#include "webfused/config/factory.h"
|
#include "webfused/config/factory.h"
|
||||||
#include "webfused/log/logger.h"
|
#include "webfused/log/logger.h"
|
||||||
#include "webfused/log/log.h"
|
#include "webfused/log/log.h"
|
||||||
@ -26,7 +27,7 @@ TEST(configfile_server, vhost_name)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_server_vhostname(_,StrEq("some.host"))).Times(1);
|
EXPECT_CALL(builder, wfd_config_set_server_vhostname(_,StrEq("some.host"))).Times(1);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"server:\n"
|
"server:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" vhost_name = \"some.host\"\n"
|
" vhost_name = \"some.host\"\n"
|
||||||
@ -47,7 +48,7 @@ TEST(configfile_server, port)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_server_port(_,54321)).Times(1);
|
EXPECT_CALL(builder, wfd_config_set_server_port(_,54321)).Times(1);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"server:\n"
|
"server:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" port = 54321\n"
|
" port = 54321\n"
|
||||||
@ -68,7 +69,7 @@ TEST(configfile_server, tls_certificate)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_server_cert(_, StrEq("/path/to/cert.pem"))).Times(1);
|
EXPECT_CALL(builder, wfd_config_set_server_cert(_, StrEq("/path/to/cert.pem"))).Times(1);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"server:\n"
|
"server:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" tls:\n"
|
" tls:\n"
|
||||||
@ -92,7 +93,7 @@ TEST(configfile_server, tls_key)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_server_key(_,StrEq("/path/to/key.pem"))).Times(1);
|
EXPECT_CALL(builder, wfd_config_set_server_key(_,StrEq("/path/to/key.pem"))).Times(1);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"server:\n"
|
"server:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" tls:\n"
|
" tls:\n"
|
||||||
@ -116,7 +117,7 @@ TEST(configfile_server, document_root)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_server_document_root(_,StrEq("/var/www"))).Times(1);
|
EXPECT_CALL(builder, wfd_config_set_server_document_root(_,StrEq("/var/www"))).Times(1);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"server:\n"
|
"server:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" document_root = \"/var/www\"\n"
|
" document_root = \"/var/www\"\n"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "webfused/config/config.h"
|
||||||
#include "webfused/config/factory.h"
|
#include "webfused/config/factory.h"
|
||||||
#include "webfused/log/logger.h"
|
#include "webfused/log/logger.h"
|
||||||
#include "webfused/log/log.h"
|
#include "webfused/log/log.h"
|
||||||
@ -26,7 +27,7 @@ TEST(configfile_user, set_user)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(1);
|
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(1);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"user:\n"
|
"user:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" name = \"webfused\"\n"
|
" name = \"webfused\"\n"
|
||||||
@ -49,7 +50,7 @@ TEST(configfile_user, set_user_fail_missing_name)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(0);
|
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(0);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"user:\n"
|
"user:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" group = \"webfused\"\n"
|
" group = \"webfused\"\n"
|
||||||
@ -71,7 +72,7 @@ TEST(configfile_user, set_user_fail_missing_group)
|
|||||||
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(0);
|
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(0);
|
||||||
|
|
||||||
char const config_text[] =
|
char const config_text[] =
|
||||||
"version = { major = 1, minor = 0 }\n"
|
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
|
||||||
"user:\n"
|
"user:\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" name = \"webfused\"\n"
|
" name = \"webfused\"\n"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "webfused/config/config.h"
|
||||||
#include "webfused/config/factory.h"
|
#include "webfused/config/factory.h"
|
||||||
#include "webfused/log/logger.h"
|
#include "webfused/log/logger.h"
|
||||||
#include "webfused/log/log.h"
|
#include "webfused/log/log.h"
|
||||||
@ -25,7 +26,7 @@ TEST(configfile_version, invalid_major_version_too_low)
|
|||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||||
|
|
||||||
char const too_low[] = "version = { major = 0, minor = 0 }\n";
|
char const too_low[] = "version = { major = 0, minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n";
|
||||||
|
|
||||||
struct wfd_config * config= wfd_config_load_string(too_low);
|
struct wfd_config * config= wfd_config_load_string(too_low);
|
||||||
ASSERT_EQ(nullptr, config);
|
ASSERT_EQ(nullptr, config);
|
||||||
@ -41,7 +42,7 @@ TEST(configfile_version, invalid_major_version_too_high)
|
|||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||||
|
|
||||||
char const too_high[] = "version = { major = 2, minor = 0 }\n";
|
char const too_high[] = "version = { major = 99, minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n";
|
||||||
|
|
||||||
struct wfd_config * config = wfd_config_load_string(too_high);
|
struct wfd_config * config = wfd_config_load_string(too_high);
|
||||||
ASSERT_EQ(nullptr, config);
|
ASSERT_EQ(nullptr, config);
|
||||||
@ -57,7 +58,7 @@ TEST(configfile_version, invalid_missing_major_version)
|
|||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||||
|
|
||||||
char const too_high[] = "version = { minor = 0 }\n";
|
char const too_high[] = "version = { minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n";
|
||||||
|
|
||||||
struct wfd_config * config = wfd_config_load_string(too_high);
|
struct wfd_config * config = wfd_config_load_string(too_high);
|
||||||
ASSERT_EQ(nullptr, config);
|
ASSERT_EQ(nullptr, config);
|
||||||
@ -73,7 +74,7 @@ TEST(configfile_version, invalid_missing_minor_version)
|
|||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
|
||||||
|
|
||||||
char const too_high[] = "version = { major = 1 }\n";
|
char const too_high[] = "version = { major = " WFD_CONFIG_VERSION_STR_MAJOR " }\n";
|
||||||
|
|
||||||
struct wfd_config * config = wfd_config_load_string(too_high);
|
struct wfd_config * config = wfd_config_load_string(too_high);
|
||||||
ASSERT_EQ(nullptr, config);
|
ASSERT_EQ(nullptr, config);
|
||||||
@ -88,7 +89,7 @@ TEST(configfile_version, valid_older_minor)
|
|||||||
StrictMock<MockConfigBuilder> builder;
|
StrictMock<MockConfigBuilder> builder;
|
||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
|
|
||||||
char const valid[] = "version = { major = 1, minor = -1 }\n";
|
char const valid[] = "version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = -1 }\n";
|
||||||
|
|
||||||
struct wfd_config * config = wfd_config_load_string(valid);
|
struct wfd_config * config = wfd_config_load_string(valid);
|
||||||
ASSERT_NE(nullptr, config);
|
ASSERT_NE(nullptr, config);
|
||||||
@ -103,7 +104,7 @@ TEST(configfile_version, valid_newer_minor)
|
|||||||
StrictMock<MockConfigBuilder> builder;
|
StrictMock<MockConfigBuilder> builder;
|
||||||
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
|
||||||
|
|
||||||
char const valid[] = "version = { major = 1, minor = 1 }\n";
|
char const valid[] = "version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = 99 }\n";
|
||||||
|
|
||||||
struct wfd_config * config = wfd_config_load_string(valid);
|
struct wfd_config * config = wfd_config_load_string(valid);
|
||||||
ASSERT_NE(nullptr, config);
|
ASSERT_NE(nullptr, config);
|
||||||
|
@ -13,7 +13,7 @@ WFD_WRAP_FUNC2(wfd_MockConfigBuilder, void, wfd_config_set_server_key, wfd_confi
|
|||||||
WFD_WRAP_FUNC2(wfd_MockConfigBuilder, void, wfd_config_set_server_cert, wfd_config *, char const *);
|
WFD_WRAP_FUNC2(wfd_MockConfigBuilder, void, wfd_config_set_server_cert, wfd_config *, char const *);
|
||||||
WFD_WRAP_FUNC2(wfd_MockConfigBuilder, void, wfd_config_set_server_document_root, wfd_config *, char const *);
|
WFD_WRAP_FUNC2(wfd_MockConfigBuilder, void, wfd_config_set_server_document_root, wfd_config *, char const *);
|
||||||
WFD_WRAP_FUNC3(wfd_MockConfigBuilder, bool, wfd_config_add_auth_provider, wfd_config *, char const *, wfd_settings *);
|
WFD_WRAP_FUNC3(wfd_MockConfigBuilder, bool, wfd_config_add_auth_provider, wfd_config *, char const *, wfd_settings *);
|
||||||
WFD_WRAP_FUNC3(wfd_MockConfigBuilder, bool, wfd_config_add_filesystem, wfd_config *, char const *, char const *);
|
WFD_WRAP_FUNC4(wfd_MockConfigBuilder, bool, wfd_config_add_filesystem, wfd_config *, char const *, char const *, wfd_string_list *);
|
||||||
WFD_WRAP_FUNC4(wfd_MockConfigBuilder, bool, wfd_config_set_logger, wfd_config *, char const *, int, wfd_settings *);
|
WFD_WRAP_FUNC4(wfd_MockConfigBuilder, bool, wfd_config_set_logger, wfd_config *, char const *, int, wfd_settings *);
|
||||||
WFD_WRAP_FUNC3(wfd_MockConfigBuilder, void, wfd_config_set_user, wfd_config *, char const *, char const *);
|
WFD_WRAP_FUNC3(wfd_MockConfigBuilder, void, wfd_config_set_user, wfd_config *, char const *, char const *);
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ public:
|
|||||||
virtual void wfd_config_set_server_cert(wfd_config * config, char const * cert_path) = 0;
|
virtual void wfd_config_set_server_cert(wfd_config * config, char const * cert_path) = 0;
|
||||||
virtual void wfd_config_set_server_document_root(wfd_config * config, char const * document_root) = 0;
|
virtual void wfd_config_set_server_document_root(wfd_config * config, char const * document_root) = 0;
|
||||||
virtual bool wfd_config_add_auth_provider(wfd_config * config, char const * provider, wfd_settings * settings) = 0;
|
virtual bool wfd_config_add_auth_provider(wfd_config * config, char const * provider, wfd_settings * settings) = 0;
|
||||||
virtual bool wfd_config_add_filesystem(wfd_config * config, char const * name, char const * mountpoint) = 0;
|
virtual bool wfd_config_add_filesystem(wfd_config * config, char const * name, char const * mountpoint, wfd_string_list const * mount_options) = 0;
|
||||||
virtual bool wfd_config_set_logger(wfd_config * config, char const * provider, int level, wfd_settings * settings) = 0;
|
virtual bool wfd_config_set_logger(wfd_config * config, char const * provider, int level, wfd_settings * settings) = 0;
|
||||||
virtual void wfd_config_set_user(wfd_config * config, char const * user, char const * group) = 0;
|
virtual void wfd_config_set_user(wfd_config * config, char const * user, char const * group) = 0;
|
||||||
};
|
};
|
||||||
@ -37,7 +37,7 @@ public:
|
|||||||
MOCK_METHOD2(wfd_config_set_server_cert, void (wfd_config * config, char const * cert_path));
|
MOCK_METHOD2(wfd_config_set_server_cert, void (wfd_config * config, char const * cert_path));
|
||||||
MOCK_METHOD2(wfd_config_set_server_document_root, void (wfd_config * config, char const * document_root));
|
MOCK_METHOD2(wfd_config_set_server_document_root, void (wfd_config * config, char const * document_root));
|
||||||
MOCK_METHOD3(wfd_config_add_auth_provider, bool (wfd_config * config, char const * provider, wfd_settings * settings));
|
MOCK_METHOD3(wfd_config_add_auth_provider, bool (wfd_config * config, char const * provider, wfd_settings * settings));
|
||||||
MOCK_METHOD3(wfd_config_add_filesystem, bool (wfd_config * config, char const * name, char const * mountpoint));
|
MOCK_METHOD4(wfd_config_add_filesystem, bool (wfd_config * config, char const * name, char const * mountpoint, wfd_string_list const * mount_options));
|
||||||
MOCK_METHOD4(wfd_config_set_logger, bool (wfd_config * config, char const * provider, int level, wfd_settings * settings));
|
MOCK_METHOD4(wfd_config_set_logger, bool (wfd_config * config, char const * provider, int level, wfd_settings * settings));
|
||||||
MOCK_METHOD3(wfd_config_set_user, void (wfd_config * config, char const * user, char const * group));
|
MOCK_METHOD3(wfd_config_set_user, void (wfd_config * config, char const * user, char const * group));
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include "webfused/mountpoint_factory.h"
|
#include "webfused/mountpoint_factory.h"
|
||||||
|
#include "webfused/util/string_list.h"
|
||||||
#include <webfuse/mountpoint.h>
|
#include <webfuse/mountpoint.h>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -17,7 +18,8 @@ TEST(mountpiont_factory, add_filesystem)
|
|||||||
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
||||||
ASSERT_NE(nullptr, factory);
|
ASSERT_NE(nullptr, factory);
|
||||||
|
|
||||||
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfused_test");
|
struct wfd_string_list mount_options = {0, 0, nullptr};
|
||||||
|
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfused_test", &mount_options);
|
||||||
ASSERT_TRUE(success);
|
ASSERT_TRUE(success);
|
||||||
|
|
||||||
wfd_mountpoint_factory_dispose(factory);
|
wfd_mountpoint_factory_dispose(factory);
|
||||||
@ -28,10 +30,11 @@ TEST(mountpiont_factory, add_filesystem_fail_to_add_twice)
|
|||||||
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
||||||
ASSERT_NE(nullptr, factory);
|
ASSERT_NE(nullptr, factory);
|
||||||
|
|
||||||
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfused_test");
|
struct wfd_string_list mount_options = {0, 0, nullptr};
|
||||||
|
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfused_test", &mount_options);
|
||||||
ASSERT_TRUE(success);
|
ASSERT_TRUE(success);
|
||||||
|
|
||||||
success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfused_test");
|
success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfused_test", &mount_options);
|
||||||
ASSERT_FALSE(success);
|
ASSERT_FALSE(success);
|
||||||
|
|
||||||
wfd_mountpoint_factory_dispose(factory);
|
wfd_mountpoint_factory_dispose(factory);
|
||||||
@ -47,7 +50,8 @@ TEST(mountpiont_factory, add_filesystem_multi)
|
|||||||
{
|
{
|
||||||
char name[10];
|
char name[10];
|
||||||
snprintf(name, 10, "test_%zu", i);
|
snprintf(name, 10, "test_%zu", i);
|
||||||
bool success = wfd_mountpoint_factory_add_filesystem(factory, name, "/tmp/webfused_test");
|
struct wfd_string_list mount_options = {0, 0, nullptr};
|
||||||
|
bool success = wfd_mountpoint_factory_add_filesystem(factory, name, "/tmp/webfused_test", &mount_options);
|
||||||
ASSERT_TRUE(success) << i;
|
ASSERT_TRUE(success) << i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +63,8 @@ TEST(mountpiont_factory, add_filesystem_fail_invalid_path)
|
|||||||
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
||||||
ASSERT_NE(nullptr, factory);
|
ASSERT_NE(nullptr, factory);
|
||||||
|
|
||||||
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/do/not/allow/nested/paths");
|
struct wfd_string_list mount_options = {0, 0, nullptr};
|
||||||
|
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/do/not/allow/nested/paths", &mount_options);
|
||||||
ASSERT_FALSE(success);
|
ASSERT_FALSE(success);
|
||||||
|
|
||||||
wfd_mountpoint_factory_dispose(factory);
|
wfd_mountpoint_factory_dispose(factory);
|
||||||
@ -70,7 +75,8 @@ TEST(mountpiont_factory, create_mountpoint)
|
|||||||
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
||||||
ASSERT_NE(nullptr, factory);
|
ASSERT_NE(nullptr, factory);
|
||||||
|
|
||||||
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test");
|
struct wfd_string_list mount_options = {0, 0, nullptr};
|
||||||
|
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test", &mount_options);
|
||||||
ASSERT_TRUE(success);
|
ASSERT_TRUE(success);
|
||||||
|
|
||||||
wf_mountpoint * mountpoint = wfd_mountpoint_factory_create_mountpoint("test", factory);
|
wf_mountpoint * mountpoint = wfd_mountpoint_factory_create_mountpoint("test", factory);
|
||||||
@ -86,7 +92,8 @@ TEST(mountpiont_factory, create_mountpoint_fail_already_in_use)
|
|||||||
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
||||||
ASSERT_NE(nullptr, factory);
|
ASSERT_NE(nullptr, factory);
|
||||||
|
|
||||||
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test");
|
struct wfd_string_list mount_options = {0, 0, nullptr};
|
||||||
|
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test", &mount_options);
|
||||||
ASSERT_TRUE(success);
|
ASSERT_TRUE(success);
|
||||||
|
|
||||||
wf_mountpoint * mountpoint = wfd_mountpoint_factory_create_mountpoint("test", factory);
|
wf_mountpoint * mountpoint = wfd_mountpoint_factory_create_mountpoint("test", factory);
|
||||||
@ -105,7 +112,8 @@ TEST(mountpiont_factory, create_mountpoint_fail_unknown_filesystem)
|
|||||||
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
||||||
ASSERT_NE(nullptr, factory);
|
ASSERT_NE(nullptr, factory);
|
||||||
|
|
||||||
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test");
|
struct wfd_string_list mount_options = {0, 0, nullptr};
|
||||||
|
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test", &mount_options);
|
||||||
ASSERT_TRUE(success);
|
ASSERT_TRUE(success);
|
||||||
|
|
||||||
wf_mountpoint * mountpoint = wfd_mountpoint_factory_create_mountpoint("unkown", factory);
|
wf_mountpoint * mountpoint = wfd_mountpoint_factory_create_mountpoint("unkown", factory);
|
||||||
@ -119,7 +127,8 @@ TEST(mountpiont_factory, create_mountpoint_multi)
|
|||||||
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
|
||||||
ASSERT_NE(nullptr, factory);
|
ASSERT_NE(nullptr, factory);
|
||||||
|
|
||||||
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test");
|
struct wfd_string_list mount_options = {0, 0, nullptr};
|
||||||
|
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test", &mount_options);
|
||||||
ASSERT_TRUE(success);
|
ASSERT_TRUE(success);
|
||||||
|
|
||||||
for(int i = 0; i < 5; i++)
|
for(int i = 0; i < 5; i++)
|
||||||
|
44
test/util/string_list.cc
Normal file
44
test/util/string_list.cc
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include "webfused/util/string_list.h"
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
TEST(string_list, init_cleanup)
|
||||||
|
{
|
||||||
|
wfd_string_list list;
|
||||||
|
wfd_string_list_init(&list);
|
||||||
|
|
||||||
|
ASSERT_EQ(0, list.size);
|
||||||
|
|
||||||
|
wfd_string_list_cleanup(&list);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(string_list, add)
|
||||||
|
{
|
||||||
|
wfd_string_list list;
|
||||||
|
wfd_string_list_init(&list);
|
||||||
|
wfd_string_list_add(&list, "value");
|
||||||
|
|
||||||
|
ASSERT_EQ(1, list.size);
|
||||||
|
ASSERT_STREQ("value", list.items[0]);
|
||||||
|
|
||||||
|
wfd_string_list_cleanup(&list);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(string_list, add_many)
|
||||||
|
{
|
||||||
|
wfd_string_list list;
|
||||||
|
wfd_string_list_init(&list);
|
||||||
|
|
||||||
|
constexpr size_t count = 256;
|
||||||
|
for (size_t i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
wfd_string_list_add(&list, "value");
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT_EQ(count, list.size);
|
||||||
|
for (size_t i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
ASSERT_STREQ("value", list.items[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
wfd_string_list_cleanup(&list);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user