1
0
mirror of https://github.com/falk-werner/webfused synced 2024-10-27 20:44:08 +00:00

Compare commits

..

No commits in common. "master" and "v0.3.0" have entirely different histories.

44 changed files with 237 additions and 630 deletions

View File

@ -36,9 +36,7 @@ env:
before_install:
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib/x86_64-linux-gnu
- sudo pip3 install --system meson
- bash <(curl -s https://raw.githubusercontent.com/falk-werner/install_deps/main/install_deps.sh) -s
before_script:
- meson -Dbuildtype=$BUILD_TYPE -Db_coverage=$COVERAGE build
@ -46,7 +44,7 @@ before_script:
- ninja
script:
- meson test --print-errorlogs -t 10 $CHECK_OPTS
- meson test $CHECK_OPTS
after_success:
- bash <(curl -s https://codecov.io/bash)

View File

@ -5,10 +5,6 @@
Reference implementation of webfuse daemon (webfused).
**Note:** This repository refers to [webfuse-legacy](https://github.com/falk-werner/webfuse/tree/webfuse-legacy).
Since `webfuse-legacy` is out-dated, the repository is archived and will be removed in future.
_Please leave an issue if you are still interested in this code._
## Further information
- [Build Instructions](doc/build.md)

View File

@ -1,42 +0,0 @@
# webfused changelog
## 0.7.0 _(unknown)_
* __Chore:__ added changelog
## 0.6.0 _(Sat Nov 14 2020)_
* __Feature:__ allow to specify mount options via config file
* __Feature:__ make userdb optional
* __Feature:__ reduce versions of depencies to required minimum
* __Chore:__ updated dependencies (libwebsockets 4.1.3, libjansson 2.13.1, libfuse 3.10.0, webfuse 0.7.0)
* __Chore:__ remove meson subprojects (use install_deps to fetch depedencies)
* __Fix:__ ensure that syslog ident is valid while logger is active (invalid memory access)
## 0.5.0 _(Sun Jul 19 2020)_
* __Chore:__ updated depedencies (webfuse 0.5.0)
## 0.4.1 _(Sun Jul 05 2020)_
* __Fix:__ removed gtest dependency, when built without tests
## 0.4.0 _(Sun Jul 05 2020)_
* __Feature:__ allow to build without tests
* __Chore:__ updated dependencies (libwebsockets 4.0.0, webfuse 0.4.0)
## 0.3.0 _(Sat Jun 06 2020)_
* __Chore:__ switched build system to meson
## 0.2.0 _(Fri Mar 20 2020)_
* __Feature:__ enabled authentication (pam, userdb)
* __Feature:__ use config file
* __Feature:__ added syslog logger
## 0.1.0 _(Mon Mar 09 2020)_
* __Feature:__ initial version

31
deps.sh
View File

@ -1,31 +0,0 @@
PACKAGES="fuse3 libwebsockets jansson gtest webfuse"
fuse3_VERSION=3.10.0
fuse3_URL=https://github.com/libfuse/libfuse/archive/fuse-${fuse3_VERSION}.tar.gz
fuse3_MD5=22aec9bc9008eea6b17e203653d1b938
fuse3_DIR=libfuse-fuse-${fuse3_VERSION}
fuse3_TYPE=meson
libwebsockets_VERSION=4.1.3
libwebsockets_URL=https://github.com/warmcat/libwebsockets/archive/v${libwebsockets_VERSION}.tar.gz
libwebsockets_MD5=413cbe790ccb089001f53b2ee167b9c2
libwebsockets_DIR=libwebsockets-${libwebsockets_VERSION}
libwebsockets_TYPE=cmake
jansson_VERSION=2.13.1
jansson_URL=https://github.com/akheron/jansson/archive/v${jansson_VERSION}.tar.gz
jansson_MD5=3d589a62053874893715453a46a32a0e
jansson_DIR=jansson-${jansson_VERSION}
jansson_TYPE=cmake
gtest_VERSION=1.10.0
gtest_URL=https://github.com/google/googletest/archive/release-${gtest_VERSION}.tar.gz
gtest_MD5=ecd1fa65e7de707cd5c00bdac56022cd
gtest_DIR=googletest-release-${gtest_VERSION}
gtest_TYPE=cmake
webfuse_VERSION=0.7.0
webfuse_URL=https://github.com/falk-werner/webfuse/archive/v${webfuse_VERSION}.tar.gz
webfuse_MD5=4f8b69196a634016da3c0e4f63e13590
webfuse_DIR=webfuse-${webfuse_VERSION}
webfuse_TYPE=meson

View File

@ -12,7 +12,7 @@ To install dependecies, see below.
- [webfuse](https://github.com/falk-werner/webfuse)
- [libfuse](https://github.com/libfuse/libfuse/)
- [libwebsockets](https://libwebsockets.org/)
- [jansson](https://github.com/akheron/jansson)
- [jansson](https://github.com/akheron/jansson)
- [openssl](https://www.openssl.org/)
- [libconfig](https://hyperrealm.github.io/libconfig/)
- [linux-pam](http://www.linux-pam.org/)
@ -37,9 +37,9 @@ To install libfuse, meson is needed. Please refer to [meson quick guide](https:/
### libwebsockets
wget https://github.com/warmcat/libwebsockets/archive/v4.0.13.tar.gz -O libwebsockets.tar.gz
wget https://github.com/warmcat/libwebsockets/archive/v3.2.0.tar.gz -O libwebsockets.tar.gz
tar -xf libwebsockets.tar.gz
cd libwebsockets-4.0.13
cd libwebsockets-3.2.0
mkdir .build
cd .build
cmake ..

View File

@ -5,7 +5,7 @@ A config file is used to configure webfuse daemon.
## Config file
```
version = { major = 1, minor = 1 }
version = { major = 1, minor = 0 }
server:
{
@ -35,7 +35,7 @@ authentication:
filesystems:
(
{name = "test", mount_point = "/tmp/webfused", mount_options = () }
{name = "test", mount_point = "/tmp/webfused" }
)
log:

View File

@ -1,12 +1,12 @@
# Webfuse deamon configuration file
version = { major = 1, minor = 1 }
version = { major = 1, minor = 0 }
server:
{
vhost_name = "localhost"
port = 8080
# tls:
# {
# certificate = "/etc/webfused/cert.pem"
@ -36,7 +36,7 @@ authentication:
filesystems:
(
{name = "test", mount_point = "/tmp/webfused", mount_options = () }
{name = "test", mount_point = "/tmp/webfused" }
)
log:

View File

@ -1,43 +1,38 @@
project('webfused', 'c', 'cpp', version: '0.7.0', license: 'LGPL-3.0+',
default_options: ['c_std=gnu99', 'cpp_std=gnu++14'])
project('webfused', 'c', 'cpp', version: '0.3.0', license: 'LGPL-3.0+')
without_tests = get_option('without_tests')
without_userdb = get_option('without_userdb')
c_compiler = meson.get_compiler('c')
openssl_dep = dependency('openssl', version: '>=1.1.1')
libconfig_dep = dependency('libconfig', version: '>=1.5')
pam_dep = c_compiler.find_library('pam')
libwebsockets_dep = dependency('libwebsockets', version: '>=4.0.0')
libfuse_dep = dependency('fuse3', version: '>=3.1.0')
libwebsockets_dep = dependency('libwebsockets', version: '>=4.0.13', required: false)
if not libwebsockets_dep.found()
cmake = import('cmake')
libwebsockets = cmake.subproject('libwebsockets')
libwebsockets_dep = libwebsockets.dependency('websockets_shared')
endif
webfuse_adapter_dep = dependency('webfuse', version: '>=0.7.0')
jansson_dep = dependency('jansson', version: '>=2.11', fallback: ['jansson', 'jansson_dep'])
libfuse_dep = dependency('fuse3', version: '>=3.8.0', fallback: ['fuse3', 'libfuse_dep'])
gtest_dep = dependency('gtest', version: '>=1.10.0', fallback: ['gtest', 'gtest_dep'])
gmock_main_dep = dependency('gmock_main', version: '>=1.10.0', fallback: ['gtest', 'gmock_main_dep'])
webfuse_adapter_dep = dependency('webfuse_adapter', version: '>=0.3.0',
fallback: ['webfuse', 'webfuse_adapter_dep'], default_options: ['without_provider=true'])
inc_dir = include_directories('src')
if not without_userdb
openssl_dep = dependency('openssl', version: '>=1.1.1')
jansson_dep = dependency('jansson', version: '>=2.7')
libuserdb = static_library('userdb',
'src/userdb/userdb.c',
include_directories: inc_dir,
dependencies: [libconfig_dep, openssl_dep, jansson_dep])
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,
link_with: libuserdb,
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
libuserdb_dep = declare_dependency(
include_directories: inc_dir,
link_with: libuserdb,
dependencies: [libconfig_dep, openssl_dep, jansson_dep])
libwebfused = static_library('webfused',
'src/webfused/daemon.c',
@ -55,15 +50,15 @@ libwebfused = static_library('webfused',
'src/webfused/log/manager.c',
'src/webfused/log/stderr_logger.c',
'src/webfused/log/syslog_logger.c',
'src/webfused/util/string_list.c',
include_directories: inc_dir,
dependencies: [libuserdb_dep, webfuse_adapter_dep, libconfig_dep, pam_dep],
dependencies: [libuserdb_dep, webfuse_adapter_dep, pam_dep],
install: false)
libwebfused_dep = declare_dependency(
include_directories: inc_dir,
link_with: libwebfused,
dependencies: [libuserdb_dep, webfuse_adapter_dep, libconfig_dep, pam_dep])
dependencies: [libuserdb_dep, webfuse_adapter_dep, pam_dep],
install: false)
webfused = executable('webfused',
'src/webfused/main.c',
@ -83,15 +78,15 @@ webfused_conf = configure_file(input: 'etc/webfused.conf' , output: 'webfu
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)
alltests_sources = [
'test/mock/config_builder.cc',
'test/mock/logger.cc',
'test/mock/credentials.cc',
'test/mock/settings.cc',
'test/mock/pam.cc',
'test/mock/libconfig.cc',
'test/mock/linux.cc',
'test/mock/server.cc',
alltests = executable('alltests',
'test/mock/config_builder.cc',
'test/mock/logger.cc',
'test/mock/credentials.cc',
'test/mock/settings.cc',
'test/mock/pam.cc',
'test/mock/libconfig.cc',
'test/mock/linux.cc',
'test/mock/server.cc',
'test/config/configfile.cc',
'test/config/configfile_version.cc',
'test/config/configfile_server.cc',
@ -99,29 +94,19 @@ alltests_sources = [
'test/config/configfile_filesystem.cc',
'test/config/configfile_log.cc',
'test/config/configfile_user.cc',
'test/config/config.cc',
'test/config/settings.cc',
'test/auth/factory.cc',
'test/auth/pam_authenticator.cc',
'test/log/log.cc',
'test/log/log_manager.cc',
'test/log/stderr_logger.cc',
'test/log/syslog_logger.cc',
'test/util/string_list.cc',
'test/daemon.cc',
'test/change_user.cc',
'test/mountpoint_factory.cc'
]
if not without_userdb
alltests_sources += [
'test/auth/file_authenticator.cc',
'test/userdb.cc'
]
endif
alltests = executable('alltests',
alltests_sources,
'test/config/config.cc',
'test/config/settings.cc',
'test/auth/factory.cc',
'test/auth/file_authenticator.cc',
'test/auth/pam_authenticator.cc',
'test/log/log.cc',
'test/log/log_manager.cc',
'test/log/stderr_logger.cc',
'test/log/syslog_logger.cc',
'test/daemon.cc',
'test/change_user.cc',
'test/mountpoint_factory.cc',
'test/userdb.cc',
include_directories: ['src', 'test'],
link_args: [
'-Wl,--wrap=wf_credentials_type',

View File

@ -1,2 +1 @@
option('without_tests', type: 'boolean', value: false, description: 'disable unit tests')
option('without_userdb', type: 'boolean', value: false, description: 'disable userdb')
option('without_tests', type: 'boolean', value: false, description: 'disable unit tests')

View File

@ -10,6 +10,7 @@
#include <openssl/opensslv.h>
#include <openssl/engine.h>
#include <openssl/evp.h>
#include <jansson.h>
#include <userdb/userdb.h>
@ -130,7 +131,7 @@ static int parse_args(struct args * args, int argc, char * argv[])
fprintf(stderr, "error: missing command\n");
args->show_help = true;
result = EXIT_FAILURE;
}
}
}
return result;
@ -300,4 +301,4 @@ int main(int argc, char * argv[])
args_cleanup(&args);
openssl_cleanup();
return result;
}
}

View File

@ -1,74 +0,0 @@
#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;
}

View File

@ -1,7 +1,7 @@
#ifndef WFD_AUTH_AUTHENTICATOR_H
#define WFD_AUTH_AUTHENTICATOR_H
#include "webfuse/authenticate.h"
#include "webfuse/adapter/authenticate.h"
#ifdef __cplusplus
extern "C"

View File

@ -4,7 +4,7 @@
#include "userdb/userdb.h"
#include "webfused/log/log.h"
#include <webfuse/credentials.h>
#include <webfuse/adapter/credentials.h>
#include <stdlib.h>
#include <string.h>
@ -26,7 +26,7 @@ wfd_file_authenticator_dispose(
static bool
wfd_file_authenticator_authenticate(
struct wf_credentials const * credentials,
struct wf_credentials * credentials,
void * user_data)
{
bool result = false;

View File

@ -3,7 +3,7 @@
#include "webfused/config/settings.h"
#include "webfused/log/log.h"
#include <webfuse/credentials.h>
#include "webfuse/adapter/credentials.h"
#include <security/pam_appl.h>
#include <stdlib.h>
@ -73,7 +73,7 @@ wfd_pam_authenticator_dispose(
static bool
wfd_pam_authenticator_authenticate(
struct wf_credentials const * credentials,
struct wf_credentials * credentials,
void * user_data)
{
bool result = false;

View File

@ -1,12 +1,11 @@
#include "webfused/config/config.h"
#include "webfused/config/config_intern.h"
#include "webfuse/adapter/server_config.h"
#include "webfused/auth/factory.h"
#include "webfused/auth/authenticator.h"
#include "webfused/mountpoint_factory.h"
#include "webfused/log/manager.h"
#include <webfuse/server_config.h>
#include <stdlib.h>
#include <string.h>
@ -112,8 +111,8 @@ wfd_config_add_auth_provider(
if (result)
{
wf_server_config_add_authenticator(
config->server,
wfd_authenticator_get_type(config->authenticator),
config->server,
wfd_authenticator_get_type(config->authenticator),
config->authenticator.vtable->authenticate,
config->authenticator.data);
@ -128,11 +127,10 @@ bool
wfd_config_add_filesystem(
struct wfd_config * config,
char const * name,
char const * mount_point,
struct wfd_string_list const * mount_options)
char const * mount_point)
{
return wfd_mountpoint_factory_add_filesystem(
config->mountpoint_factory, name, mount_point, mount_options);
config->mountpoint_factory, name, mount_point);
}
bool
@ -175,3 +173,4 @@ wfd_config_get_group(
{
return config->group;
}

View File

@ -13,12 +13,6 @@ extern "C"
{
#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 wf_server_config;

View File

@ -12,7 +12,6 @@ extern "C"
struct wfd_settings;
struct wfd_config;
struct wfd_string_list;
extern struct wfd_config *
wfd_config_create(void);
@ -52,8 +51,7 @@ extern bool
wfd_config_add_filesystem(
struct wfd_config * config,
char const * name,
char const * mount_point,
struct wfd_string_list const * mount_options);
char const * mount_point);
extern bool
wfd_config_set_logger(

View File

@ -3,7 +3,6 @@
#include "webfused/config/config.h"
#include "webfused/config/settings_intern.h"
#include "webfused/log/log.h"
#include "webfused/util/string_list.h"
#include <libconfig.h>
#include <stdlib.h>
@ -11,9 +10,13 @@
#if ((LIBCONFIG_VER_MAJOR != 1) || (LIBCONFIG_VER_MINOR < 5))
#error "libconfig 1.5 or higher needed"
#error "linconfig 1.5 or higher needed"
#endif
#define WFD_CONFIG_VERSION_MAJOR 1
#define WFD_CONFIG_VERSION_MINOR 0
static bool
wfd_config_check_version(
config_t * config)
@ -28,7 +31,7 @@ wfd_config_check_version(
if (WFD_CONFIG_VERSION_MAJOR != version_major)
{
WFD_ERROR("failed to load config: "
WFD_ERROR("failed to load config: "
"incompatible versions: expected %d, but war %d",
WFD_CONFIG_VERSION_MAJOR, version_major);
return false;
@ -160,7 +163,7 @@ wfd_config_read_authenticator(
}
char const * provider_name = NULL;
if (result)
if (result)
{
int rc = config_setting_lookup_string(authenticator, "provider", &provider_name);
if (CONFIG_TRUE != rc)
@ -210,30 +213,10 @@ wfd_config_read_authentication(
result = wfd_config_read_authenticator(authenticator, builder);
}
}
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
wfd_config_read_filesystems(
config_t * config,
@ -272,12 +255,7 @@ wfd_config_read_filesystems(
break;
}
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);
result = wfd_config_add_filesystem(builder, name, mount_point);
if (!result)
{
break;
@ -294,7 +272,7 @@ wfd_config_read_user(
struct wfd_config * builder)
{
bool result = true;
bool has_user = (NULL != config_lookup(config, "user"));
if (has_user)
{
@ -340,12 +318,12 @@ wfd_config_load(
&& wfd_config_read_filesystems(config, result)
&& wfd_config_read_user(config, result)
;
if (success)
{
wfd_config_read_server(config, result);
}
if (!success)
{
wfd_config_dispose(result);
@ -370,13 +348,13 @@ wfd_config_load_file(
}
else
{
WFD_ERROR("failed to load config: %s: %d: %s",
WFD_ERROR("failed to load config: %s: %d: %s",
config_error_file(&config),
config_error_line(&config),
config_error_text(&config));
}
config_destroy(&config);
return result;
}
@ -396,12 +374,12 @@ wfd_config_load_string(
}
else
{
WFD_ERROR("failed to load config: %d: %s",
WFD_ERROR("failed to load config: %d: %s",
config_error_line(&config),
config_error_text(&config));
}
config_destroy(&config);
return result;
}

View File

@ -10,7 +10,7 @@
#include <unistd.h>
#include <getopt.h>
#include <webfuse/webfuse.h>
#include <webfuse_adapter.h>
#include "webfused/config/config.h"
#include "webfused/config/factory.h"
#include "webfused/log/log.h"

View File

@ -6,8 +6,6 @@
#include <syslog.h>
#include <strings.h>
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
static int
@ -25,7 +23,7 @@ wfd_syslog_logger_to_priority(
}
}
static void
static void
wfd_syslog_logger_log(
void * user_data,
int level,
@ -43,7 +41,6 @@ wfd_syslog_logger_close(
void * user_data)
{
closelog();
free(user_data);
}
struct wfd_syslog_facility
@ -100,7 +97,7 @@ wfd_syslog_logger_init(
int level,
struct wfd_settings * settings)
{
char * ident = strdup(wfd_settings_get_string_or_default(settings, "ident", "webfused"));
char const * ident = wfd_settings_get_string_or_default(settings, "ident", "webfused");
char const * facility_str = wfd_settings_get_string_or_default(settings, "facility", "daemon");
bool log_pid = wfd_settings_get_bool(settings, "log_pid");
@ -109,18 +106,17 @@ wfd_syslog_logger_init(
if (result)
{
int options = (log_pid) ? LOG_PID : 0;
wfd_logger_init(level,
&wfd_syslog_logger_log,
&wfd_syslog_logger_close,
ident);
wfd_logger_init(level,
&wfd_syslog_logger_log,
&wfd_syslog_logger_close,
NULL);
openlog(ident, options, facility);
}
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);
}
return result;
}
}

View File

@ -1,8 +1,7 @@
#include "webfused/mountpoint_factory.h"
#include "webfused/util/string_list.h"
#include "webfused/log/log.h"
#include <webfuse/mountpoint.h>
#include <webfuse/adapter/mountpoint.h>
#include <sys/stat.h>
#include <stdlib.h>
@ -14,7 +13,6 @@ struct wfd_filesystem
{
char * name;
char * mount_point;
struct wfd_string_list mount_options;
bool in_use;
};
@ -42,7 +40,7 @@ wfd_mountpoint_factory_find(
return NULL;
}
static void
static void
wfd_mountpoint_factory_release_mountpoint(
void * user_data)
{
@ -70,7 +68,6 @@ wfd_mountpoint_factory_dispose(
struct wfd_filesystem * filesystem = &(factory->filesystems[i]);
free(filesystem->name);
free(filesystem->mount_point);
wfd_string_list_cleanup(&filesystem->mount_options);
}
free(factory->filesystems);
@ -81,8 +78,7 @@ bool
wfd_mountpoint_factory_add_filesystem(
struct wfd_mountpoint_factory * factory,
char const * name,
char const * mount_point,
struct wfd_string_list const * mount_options)
char const * mount_point)
{
bool result = (NULL == wfd_mountpoint_factory_find(factory, name));
if (!result)
@ -107,14 +103,13 @@ wfd_mountpoint_factory_add_filesystem(
if (factory->count >= factory->capacity)
{
factory->capacity *= 2;
factory->filesystems = realloc(factory->filesystems,
factory->filesystems = realloc(factory->filesystems,
sizeof(struct wfd_filesystem) * factory->capacity);
}
struct wfd_filesystem * actual = &(factory->filesystems[factory->count]);
actual->name = strdup(name);
actual->mount_point = path;
wfd_string_list_init_copy(&actual->mount_options, mount_options);
actual->in_use = false;
factory->count++;
}
@ -145,10 +140,6 @@ wfd_mountpoint_factory_create_mountpoint(
struct wf_mountpoint * result = wf_mountpoint_create(fs->mount_point);
wf_mountpoint_set_userdata(result,
&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);
return result;

View File

@ -1,7 +1,7 @@
#ifndef WFD_MOUNTPOINT_FACTORY_H
#define WFD_MOUNTPOINT_FACTORY_H
#include "webfuse/mountpoint_factory.h"
#include "webfuse/adapter/mountpoint_factory.h"
#ifndef __cplusplus
#include <stdbool.h>
@ -13,7 +13,6 @@ extern "C"
#endif
struct wfd_mountpoint_factory;
struct wfd_string_list;
extern struct wfd_mountpoint_factory *
wfd_mountpoint_factory_create(void);
@ -26,8 +25,7 @@ extern bool
wfd_mountpoint_factory_add_filesystem(
struct wfd_mountpoint_factory * factory,
char const * name,
char const * mount_point,
struct wfd_string_list const * mount_options);
char const * mount_point);
extern struct wf_mountpoint *
wfd_mountpoint_factory_create_mountpoint(

View File

@ -1,62 +0,0 @@
#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++;
}

View File

@ -1,44 +0,0 @@
#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

7
subprojects/fuse3.wrap Normal file
View File

@ -0,0 +1,7 @@
[wrap-file]
directory = libfuse-fuse-3.8.0
source_url = https://github.com/libfuse/libfuse/archive/fuse-3.8.0.tar.gz
source_filename = fuse-3.8.0.tar.gz
source_hash = 1781225ba4d11d76eb105e02e54976939974547eb40bab4b4e91167854224024

10
subprojects/gtest.wrap Normal file
View File

@ -0,0 +1,10 @@
[wrap-file]
directory = googletest-release-1.10.0
source_url = https://github.com/google/googletest/archive/release-1.10.0.zip
source_filename = gtest-1.10.0.zip
source_hash = 94c634d499558a76fa649edb13721dce6e98fb1e7018dfaeba3cd7a083945e91
patch_url = https://wrapdb.mesonbuild.com/v1/projects/gtest/1.10.0/1/get_zip
patch_filename = gtest-1.10.0-1-wrap.zip
patch_hash = 04ff14e8880e4e465f6260221e9dfd56fea6bc7cce4c4aff0dc528e4a2c8f514

10
subprojects/jansson.wrap Normal file
View File

@ -0,0 +1,10 @@
[wrap-file]
directory = jansson-2.11
source_url = http://www.digip.org/jansson/releases/jansson-2.11.tar.bz2
source_filename = jansson-2.11.tar.bz2
source_hash = 783132e2fc970feefc2fa54199ef65ee020bd8e0e991a78ea44b8586353a0947
patch_url = https://wrapdb.mesonbuild.com/v1/projects/jansson/2.11/3/get_zip
patch_filename = jansson-2.11-3-wrap.zip
patch_hash = 0bcac510994890048d42658c674e33dd7d88715fc1e3bf49d10012f57b0e0020

View File

@ -0,0 +1,6 @@
[wrap-file]
directory = libwebsockets-4.0.13
source_url = https://github.com/warmcat/libwebsockets/archive/v4.0.13.zip
source_filename = v4.0.13.zip
source_hash = 0914ea3fdec496daf6b6a5c00f7ba1b52eb8cc3d55b66685df92920b232fd7a5

7
subprojects/webfuse.wrap Normal file
View File

@ -0,0 +1,7 @@
[wrap-file]
directory = webfuse-0.3.1
source_url = https://github.com/falk-werner/webfuse/archive/v0.3.1.tar.gz
source_filename = v0.3.1.tar.gz
source_hash = 46624b5f29e8f87dd1aebfce3b13ca87e766bc59546b6e5f49665d2f8c555d62

View File

@ -5,9 +5,7 @@
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
#include "webfused/util/string_list.h"
#include "mock/logger.hpp"
using ::webfused_test::MockLogger;
using ::testing::_;
@ -79,8 +77,7 @@ TEST(config, add_filesystem)
wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config);
struct wfd_string_list mount_options = {0, 0, nullptr};
bool success = wfd_config_add_filesystem(config, "test", "/tmp/test", &mount_options);
bool success = wfd_config_add_filesystem(config, "test", "/tmp/test");
ASSERT_TRUE(success);
wfd_config_dispose(config);
@ -107,4 +104,4 @@ TEST(config, do_set_user)
ASSERT_STREQ("some.group", wfd_config_get_group(config));
wfd_config_dispose(config);
}
}

View File

@ -1,6 +1,5 @@
#include <gtest/gtest.h>
#include "webfused/config/config.h"
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
@ -24,7 +23,7 @@ TEST(configfile, is_loadable)
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_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");
ASSERT_NE(nullptr, config);
@ -39,7 +38,7 @@ TEST(configfile, minimal_config)
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
char const minimal[] = "version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n";
char const minimal[] = "version = { major = 1, minor = 0 }\n";
struct wfd_config * config = wfd_config_load_string(minimal);
ASSERT_NE(nullptr, config);
}
@ -54,10 +53,10 @@ TEST(configfile, invalid_config)
EXPECT_CALL(builder, wfd_config_create).Times(0);
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(0);
char const syntax_error[] = "version.major = " WFD_CONFIG_VERSION_STR_MAJOR "\n";
char const syntax_error[] = "version.major = 1\n";
wfd_config * config = wfd_config_load_string(syntax_error);
ASSERT_EQ(nullptr, config);
ASSERT_EQ(nullptr, config);
}
TEST(configfile, invalid_config_file)

View File

@ -1,6 +1,5 @@
#include <gtest/gtest.h>
#include "webfused/config/config.h"
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
@ -24,10 +23,10 @@ TEST(config_auth, authentication)
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
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[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
@ -49,10 +48,10 @@ TEST(config_auth, failed_create_authenticator)
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_auth_provider(_,_, _)).Times(1).WillOnce(Return(false));
EXPECT_CALL(builder, wfd_config_add_auth_provider(_,_, _)).Times(1).WillOnce(Return(false));
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
@ -75,8 +74,8 @@ TEST(config_auth, failed_missing_auth_provider)
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
@ -98,8 +97,8 @@ TEST(config_auth, failed_missing_auth_settings)
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"
@ -124,8 +123,8 @@ TEST(config_auth, failed_auth_settings_get_elem)
MockLibConfig libconfig;
EXPECT_CALL(libconfig, config_setting_get_elem(_,_)).Times(1).WillOnce(Return(nullptr));
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR" }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"authentication:\n"
"(\n"
" {\n"

View File

@ -1,15 +1,12 @@
#include <gtest/gtest.h>
#include "webfused/config/config.h"
#include "webfused/config/factory.h"
#include "webfused/util/string_list.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
#include "mock/logger.hpp"
#include "mock/config_builder.hpp"
#include "mock/libconfig.hpp"
using ::testing::Invoke;
using ::testing::_;
using ::testing::Return;
using ::testing::StrictMock;
@ -26,10 +23,10 @@ TEST(configfile_fs, filesystems)
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(Return(true));
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(1).WillOnce(Return(true));
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
@ -47,10 +44,10 @@ TEST(configfile_fs, filesystems_empty)
StrictMock<MockConfigBuilder> builder;
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[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
")\n"
@ -68,13 +65,13 @@ TEST(configfile_fs, filesystems_failed_add)
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));
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"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {name = \"foo\", mount_point = \"/tmp/test\", mount_options = () }\n"
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
")\n"
;
struct wfd_config * config = wfd_config_load_string(config_text);
@ -90,10 +87,10 @@ TEST(configfile_fs, filesystems_failed_missing_name)
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(0);
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {mount_point = \"/tmp/test\" }\n"
@ -112,10 +109,10 @@ TEST(configfile_fs, filesystems_failed_missing_mountpoint)
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(0);
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {name = \"foo\"}\n"
@ -134,13 +131,13 @@ TEST(configfile_fs, filesystems_failed_missing_elem)
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(0);
EXPECT_CALL(builder, wfd_config_add_filesystem(_,_, _)).Times(0);
MockLibConfig libconfig;
EXPECT_CALL(libconfig, config_setting_get_elem(_,_)).Times(1).WillOnce(Return(nullptr));
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"filesystems:\n"
"(\n"
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
@ -149,51 +146,3 @@ TEST(configfile_fs, filesystems_failed_missing_elem)
struct wfd_config * config = wfd_config_load_string(config_text);
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);
}

View File

@ -1,6 +1,5 @@
#include <gtest/gtest.h>
#include "webfused/config/config.h"
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
@ -24,10 +23,10 @@ TEST(configfile_log, set_logger)
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
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[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" provider = \"stderr\"\n"
@ -47,10 +46,10 @@ TEST(configfile_log, log_fail_set_logger)
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_set_logger(_,_, _, _)).Times(1).WillOnce(Return(false));
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(1).WillOnce(Return(false));
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" provider = \"stderr\"\n"
@ -72,8 +71,8 @@ TEST(configfile_log, log_fail_missing_provider)
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" level = \"all\"\n"
@ -94,8 +93,8 @@ TEST(configfile_log, log_fail_missing_level)
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_logger(_,_, _, _)).Times(0);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" provider = \"stderr\"\n"
@ -117,8 +116,8 @@ TEST(configfile_log, log_fail_invalid_level)
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_logger(_, _, _, _)).Times(0);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"log:\n"
"{\n"
" provider = \"stderr\"\n"

View File

@ -1,6 +1,5 @@
#include <gtest/gtest.h>
#include "webfused/config/config.h"
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
@ -26,8 +25,8 @@ TEST(configfile_server, vhost_name)
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_vhostname(_,StrEq("some.host"))).Times(1);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" vhost_name = \"some.host\"\n"
@ -47,8 +46,8 @@ TEST(configfile_server, port)
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_port(_,54321)).Times(1);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" port = 54321\n"
@ -64,12 +63,12 @@ TEST(configfile_server, tls_certificate)
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_cert(_, StrEq("/path/to/cert.pem"))).Times(1);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" tls:\n"
@ -88,12 +87,12 @@ TEST(configfile_server, tls_key)
EXPECT_CALL(logger, log(_, _, _)).Times(0);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_server_key(_,StrEq("/path/to/key.pem"))).Times(1);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" tls:\n"
@ -114,10 +113,10 @@ TEST(configfile_server, document_root)
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
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[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"server:\n"
"{\n"
" document_root = \"/var/www\"\n"

View File

@ -1,6 +1,5 @@
#include <gtest/gtest.h>
#include "webfused/config/config.h"
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
@ -24,10 +23,10 @@ TEST(configfile_user, set_user)
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(1);
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(1);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"user:\n"
"{\n"
" name = \"webfused\"\n"
@ -49,8 +48,8 @@ TEST(configfile_user, set_user_fail_missing_name)
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(0);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"user:\n"
"{\n"
" group = \"webfused\"\n"
@ -71,8 +70,8 @@ TEST(configfile_user, set_user_fail_missing_group)
EXPECT_CALL(builder, wfd_config_dispose(_)).Times(1);
EXPECT_CALL(builder, wfd_config_set_user(_, _, _)).Times(0);
char const config_text[] =
"version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n"
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
"user:\n"
"{\n"
" name = \"webfused\"\n"

View File

@ -1,6 +1,5 @@
#include <gtest/gtest.h>
#include "webfused/config/config.h"
#include "webfused/config/factory.h"
#include "webfused/log/logger.h"
#include "webfused/log/log.h"
@ -26,7 +25,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_dispose(_)).Times(1);
char const too_low[] = "version = { major = 0, minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n";
char const too_low[] = "version = { major = 0, minor = 0 }\n";
struct wfd_config * config= wfd_config_load_string(too_low);
ASSERT_EQ(nullptr, config);
@ -42,7 +41,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_dispose(_)).Times(1);
char const too_high[] = "version = { major = 99, minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n";
char const too_high[] = "version = { major = 2, minor = 0 }\n";
struct wfd_config * config = wfd_config_load_string(too_high);
ASSERT_EQ(nullptr, config);
@ -58,7 +57,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_dispose(_)).Times(1);
char const too_high[] = "version = { minor = " WFD_CONFIG_VERSION_STR_MINOR " }\n";
char const too_high[] = "version = { minor = 0 }\n";
struct wfd_config * config = wfd_config_load_string(too_high);
ASSERT_EQ(nullptr, config);
@ -74,7 +73,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_dispose(_)).Times(1);
char const too_high[] = "version = { major = " WFD_CONFIG_VERSION_STR_MAJOR " }\n";
char const too_high[] = "version = { major = 1 }\n";
struct wfd_config * config = wfd_config_load_string(too_high);
ASSERT_EQ(nullptr, config);
@ -85,11 +84,11 @@ TEST(configfile_version, valid_older_minor)
MockLogger logger;
EXPECT_CALL(logger, log(WFD_LOGLEVEL_INFO, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
char const valid[] = "version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = -1 }\n";
char const valid[] = "version = { major = 1, minor = -1 }\n";
struct wfd_config * config = wfd_config_load_string(valid);
ASSERT_NE(nullptr, config);
@ -104,7 +103,7 @@ TEST(configfile_version, valid_newer_minor)
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, wfd_config_create).Times(1).WillOnce(Return(builder.getBuilder()));
char const valid[] = "version = { major = " WFD_CONFIG_VERSION_STR_MAJOR ", minor = 99 }\n";
char const valid[] = "version = { major = 1, minor = 1 }\n";
struct wfd_config * config = wfd_config_load_string(valid);
ASSERT_NE(nullptr, config);

View File

@ -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_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_FUNC4(wfd_MockConfigBuilder, bool, wfd_config_add_filesystem, wfd_config *, char const *, char const *, wfd_string_list *);
WFD_WRAP_FUNC3(wfd_MockConfigBuilder, bool, wfd_config_add_filesystem, wfd_config *, char const *, char const *);
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 *);
}
@ -23,7 +23,7 @@ namespace webfused_test
MockConfigBuilder::MockConfigBuilder()
{
wfd_MockConfigBuilder = this;
wfd_MockConfigBuilder = this;
}
MockConfigBuilder::~MockConfigBuilder()
@ -37,4 +37,4 @@ struct wfd_config * MockConfigBuilder::getBuilder()
return reinterpret_cast<wfd_config *>(config_builder);
}
}
}

View File

@ -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_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_filesystem(wfd_config * config, char const * name, char const * mountpoint, wfd_string_list const * mount_options) = 0;
virtual bool wfd_config_add_filesystem(wfd_config * config, char const * name, char const * mountpoint) = 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;
};
@ -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_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_METHOD4(wfd_config_add_filesystem, bool (wfd_config * config, char const * name, char const * mountpoint, wfd_string_list const * mount_options));
MOCK_METHOD3(wfd_config_add_filesystem, bool (wfd_config * config, char const * name, char const * mountpoint));
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));

View File

@ -2,7 +2,7 @@
#define WFD_MOCK_CREDENTIALS_HPP
#include <gmock/gmock.h>
#include "webfuse/credentials.h"
#include "webfuse/adapter/credentials.h"
namespace webfused_test
{

View File

@ -1,7 +1,7 @@
#ifndef WFD_MOCK_SERVER_HPP
#define WFD_MOCK_SERVER_HPP
#include <webfuse/server.h>
#include <webfuse/adapter/server.h>
#include <gmock/gmock.h>
namespace webfused_test

View File

@ -1,7 +1,6 @@
#include <gtest/gtest.h>
#include "webfused/mountpoint_factory.h"
#include "webfused/util/string_list.h"
#include <webfuse/mountpoint.h>
#include <webfuse/adapter/mountpoint.h>
#include <cstring>
@ -18,8 +17,7 @@ TEST(mountpiont_factory, add_filesystem)
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
ASSERT_NE(nullptr, factory);
struct wfd_string_list mount_options = {0, 0, nullptr};
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfused_test", &mount_options);
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfused_test");
ASSERT_TRUE(success);
wfd_mountpoint_factory_dispose(factory);
@ -30,11 +28,10 @@ TEST(mountpiont_factory, add_filesystem_fail_to_add_twice)
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
ASSERT_NE(nullptr, factory);
struct wfd_string_list mount_options = {0, 0, nullptr};
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfused_test", &mount_options);
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfused_test");
ASSERT_TRUE(success);
success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfused_test", &mount_options);
success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfused_test");
ASSERT_FALSE(success);
wfd_mountpoint_factory_dispose(factory);
@ -50,8 +47,7 @@ TEST(mountpiont_factory, add_filesystem_multi)
{
char name[10];
snprintf(name, 10, "test_%zu", i);
struct wfd_string_list mount_options = {0, 0, nullptr};
bool success = wfd_mountpoint_factory_add_filesystem(factory, name, "/tmp/webfused_test", &mount_options);
bool success = wfd_mountpoint_factory_add_filesystem(factory, name, "/tmp/webfused_test");
ASSERT_TRUE(success) << i;
}
@ -63,8 +59,7 @@ TEST(mountpiont_factory, add_filesystem_fail_invalid_path)
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
ASSERT_NE(nullptr, factory);
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);
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/do/not/allow/nested/paths");
ASSERT_FALSE(success);
wfd_mountpoint_factory_dispose(factory);
@ -75,8 +70,7 @@ TEST(mountpiont_factory, create_mountpoint)
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
ASSERT_NE(nullptr, factory);
struct wfd_string_list mount_options = {0, 0, nullptr};
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test", &mount_options);
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test");
ASSERT_TRUE(success);
wf_mountpoint * mountpoint = wfd_mountpoint_factory_create_mountpoint("test", factory);
@ -92,8 +86,7 @@ TEST(mountpiont_factory, create_mountpoint_fail_already_in_use)
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
ASSERT_NE(nullptr, factory);
struct wfd_string_list mount_options = {0, 0, nullptr};
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test", &mount_options);
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test");
ASSERT_TRUE(success);
wf_mountpoint * mountpoint = wfd_mountpoint_factory_create_mountpoint("test", factory);
@ -112,8 +105,7 @@ TEST(mountpiont_factory, create_mountpoint_fail_unknown_filesystem)
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
ASSERT_NE(nullptr, factory);
struct wfd_string_list mount_options = {0, 0, nullptr};
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test", &mount_options);
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test");
ASSERT_TRUE(success);
wf_mountpoint * mountpoint = wfd_mountpoint_factory_create_mountpoint("unkown", factory);
@ -127,8 +119,7 @@ TEST(mountpiont_factory, create_mountpoint_multi)
wfd_mountpoint_factory * factory = wfd_mountpoint_factory_create();
ASSERT_NE(nullptr, factory);
struct wfd_string_list mount_options = {0, 0, nullptr};
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test", &mount_options);
bool success = wfd_mountpoint_factory_add_filesystem(factory, "test", "/tmp/webfuse_test");
ASSERT_TRUE(success);
for(int i = 0; i < 5; i++)
@ -139,6 +130,6 @@ TEST(mountpiont_factory, create_mountpoint_multi)
wf_mountpoint_dispose(mountpoint);
}
wfd_mountpoint_factory_dispose(factory);
}

View File

@ -1,44 +0,0 @@
#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);
}