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

Merge pull request #3 from falk-werner/refactor_config_builder

refacator: merged wfd_config_builder into wfd_config
This commit is contained in:
Falk Werner 2020-03-19 17:34:16 +01:00 committed by GitHub
commit 35e63bb182
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 572 additions and 570 deletions

View File

@ -54,7 +54,6 @@ add_library(webfused-static STATIC
src/webfused/change_user.c
src/webfused/config/config.c
src/webfused/config/factory.c
src/webfused/config/builder.c
src/webfused/config/settings.c
src/webfused/auth/authenticator.c
src/webfused/auth/factory.c
@ -144,9 +143,23 @@ target_compile_options(alltests PRIVATE ${GMOCK_CFLAGS} ${GTEST_CFLAGS} "-pthrea
target_link_libraries(alltests PRIVATE
-Wl,--wrap=wf_credentials_type
-Wl,--wrap=wf_credentials_get
-Wl,--wrap=wfd_settings_get_string
-Wl,--wrap=wfd_settings_get_string_or_default
-Wl,--wrap=wfd_settings_get_bool
-Wl,--wrap=wfd_config_create
-Wl,--wrap=wfd_config_dispose
-Wl,--wrap=wfd_config_set_server_vhostname
-Wl,--wrap=wfd_config_set_server_port
-Wl,--wrap=wfd_config_set_server_key
-Wl,--wrap=wfd_config_set_server_cert
-Wl,--wrap=wfd_config_set_server_document_root
-Wl,--wrap=wfd_config_add_auth_provider
-Wl,--wrap=wfd_config_add_filesystem
-Wl,--wrap=wfd_config_set_logger
-Wl,--wrap=wfd_config_set_user
webfused-static
userdb
${LIBCONFIG_LIBRARIES}

View File

@ -1,81 +0,0 @@
#include "webfused/config/builder.h"
void
wfd_config_builder_set_server_vhostname(
struct wfd_config_builder builder,
char const * vhost_name)
{
builder.vtable->set_server_vhostname(builder.data, vhost_name);
}
void
wfd_config_builder_set_server_port(
struct wfd_config_builder builder,
int port)
{
builder.vtable->set_server_port(builder.data, port);
}
void
wfd_config_builder_set_server_key(
struct wfd_config_builder builder,
char const * key_path)
{
builder.vtable->set_server_key(builder.data, key_path);
}
void
wfd_config_builder_set_server_cert(
struct wfd_config_builder builder,
char const * cert_path)
{
builder.vtable->set_server_cert(builder.data, cert_path);
}
void
wfd_config_builder_set_server_document_root(
struct wfd_config_builder builder,
char const * document_root)
{
builder.vtable->set_server_document_root(builder.data, document_root);
}
bool
wfd_config_builder_add_auth_provider(
struct wfd_config_builder builder,
char const * provider,
struct wfd_settings * settings)
{
return builder.vtable->add_auth_provider(builder.data, provider, settings);
}
bool
wfd_config_builder_add_filesystem(
struct wfd_config_builder builder,
char const * name,
char const * mount_point)
{
return builder.vtable->add_filesystem(builder.data, name, mount_point);
}
bool
wfd_config_builder_set_logger(
struct wfd_config_builder builder,
char const * provider,
int level,
struct wfd_settings * settings)
{
return builder.vtable->set_logger(builder.data, provider, level, settings);
}
void
wfd_config_builder_set_user(
struct wfd_config_builder builder,
char const * user,
char const * group)
{
return builder.vtable->set_user(builder.data, user, group);
}

View File

@ -1,138 +0,0 @@
#ifndef WFD_CONFIG_BUILDER_H
#define WFD_CONFIG_BUILDER_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
struct wfd_settings;
typedef void
wfd_config_builder_set_server_vhostname_fn(
void * data,
char const * vhost_name);
typedef void
wfd_config_builder_set_server_port_fn(
void * data,
int port);
typedef void
wfd_config_builder_set_server_key_fn(
void * data,
char const * key_path);
typedef void
wfd_config_builder_set_server_cert_fn(
void * data,
char const * cert_path);
typedef void
wfd_config_builder_set_server_document_root_fn(
void * data,
char const * document_root);
typedef bool
wfd_config_builder_add_auth_provider_fn(
void * data,
char const * provider,
struct wfd_settings * settings);
typedef bool
wfd_config_builder_add_filesystem_fn(
void * data,
char const * name,
char const * mount_point);
typedef bool
wfd_config_builder_set_logger_fn(
void * data,
char const * provider,
int level,
struct wfd_settings * settings);
typedef void
wfd_config_builder_set_user_fn(
void * data,
char const * user,
char const * group);
struct wfd_config_builder_vtable
{
wfd_config_builder_set_server_vhostname_fn * set_server_vhostname;
wfd_config_builder_set_server_port_fn * set_server_port;
wfd_config_builder_set_server_key_fn * set_server_key;
wfd_config_builder_set_server_cert_fn * set_server_cert;
wfd_config_builder_set_server_document_root_fn * set_server_document_root;
wfd_config_builder_add_auth_provider_fn * add_auth_provider;
wfd_config_builder_add_filesystem_fn * add_filesystem;
wfd_config_builder_set_logger_fn * set_logger;
wfd_config_builder_set_user_fn * set_user;
};
struct wfd_config_builder
{
struct wfd_config_builder_vtable const * vtable;
void * data;
};
extern void
wfd_config_builder_set_server_vhostname(
struct wfd_config_builder builder,
char const * vhost_name);
extern void
wfd_config_builder_set_server_port(
struct wfd_config_builder builder,
int port);
extern void
wfd_config_builder_set_server_key(
struct wfd_config_builder builder,
char const * key_path);
extern void
wfd_config_builder_set_server_cert(
struct wfd_config_builder builder,
char const * cert_path);
extern void
wfd_config_builder_set_server_document_root(
struct wfd_config_builder builder,
char const * document_root);
extern bool
wfd_config_builder_add_auth_provider(
struct wfd_config_builder builder,
char const * provider,
struct wfd_settings * settings);
extern bool
wfd_config_builder_add_filesystem(
struct wfd_config_builder builder,
char const * name,
char const * mount_point);
extern bool
wfd_config_builder_set_logger(
struct wfd_config_builder builder,
char const * provider,
int level,
struct wfd_settings * settings);
extern void
wfd_config_builder_set_user(
struct wfd_config_builder builder,
char const * user,
char const * group);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,4 +1,5 @@
#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"
@ -21,125 +22,6 @@ struct wfd_config
char * group;
};
static void
wfd_config_set_server_vhostname(
void * data,
char const * vhost_name)
{
struct wfd_config * config = data;
wf_server_config_set_vhostname(config->server, vhost_name);
}
static void
wfd_config_set_server_port(
void * data,
int port)
{
struct wfd_config * config = data;
wf_server_config_set_port(config->server, port);
}
static void
wfd_config_set_server_key(
void * data,
char const * key_path)
{
struct wfd_config * config = data;
wf_server_config_set_keypath(config->server, key_path);
}
static void
wfd_config_set_server_cert(
void * data,
char const * cert_path)
{
struct wfd_config * config = data;
wf_server_config_set_certpath(config->server, cert_path);
}
static void
wfd_config_set_server_document_root(
void * data,
char const * document_root)
{
struct wfd_config * config = data;
wf_server_config_set_documentroot(config->server, document_root);
}
static bool
wfd_config_add_auth_provider(
void * data,
char const * provider,
struct wfd_settings * settings)
{
bool result = false;
struct wfd_config * config = data;
if (!config->has_authenticator)
{
result = wfd_authenticator_create(provider, settings, &config->authenticator);
if (result)
{
wf_server_config_add_authenticator(
config->server,
wfd_authenticator_get_type(config->authenticator),
config->authenticator.vtable->authenticate,
config->authenticator.data);
config->has_authenticator = true;
}
}
return result;
}
static bool
wfd_config_add_filesystem(
void * data,
char const * name,
char const * mount_point)
{
struct wfd_config * config = data;
return wfd_mountpoint_factory_add_filesystem(
config->mountpoint_factory, name, mount_point);
}
static bool
wfd_config_set_logger(
void * data,
char const * provider,
int level,
struct wfd_settings * settings)
{
struct wfd_config * config = data;
return wfd_log_manager_set_logger(provider, level, settings);
}
static void
wfd_config_set_user(
void * data,
char const * user,
char const * group)
{
struct wfd_config * config = data;
config->user = strdup(user);
config->group = strdup(group);
}
static const struct wfd_config_builder_vtable
wfd_config_vtable_config_builder =
{
.set_server_vhostname = &wfd_config_set_server_vhostname,
.set_server_port = &wfd_config_set_server_port,
.set_server_key = &wfd_config_set_server_key,
.set_server_cert = &wfd_config_set_server_cert,
.set_server_document_root = &wfd_config_set_server_document_root,
.add_auth_provider = &wfd_config_add_auth_provider,
.add_filesystem = &wfd_config_add_filesystem,
.set_logger = &wfd_config_set_logger,
.set_user = &wfd_config_set_user
};
struct wfd_config *
wfd_config_create(void)
{
@ -175,17 +57,100 @@ wfd_config_dispose(
free(config);
}
struct wfd_config_builder
wfd_config_get_builder(
struct wfd_config * config)
void
wfd_config_set_server_vhostname(
struct wfd_config * config,
char const * vhost_name)
{
struct wfd_config_builder builder =
{
&wfd_config_vtable_config_builder,
config
};
wf_server_config_set_vhostname(config->server, vhost_name);
}
return builder;
void
wfd_config_set_server_port(
struct wfd_config * config,
int port)
{
wf_server_config_set_port(config->server, port);
}
void
wfd_config_set_server_key(
struct wfd_config * config,
char const * key_path)
{
wf_server_config_set_keypath(config->server, key_path);
}
void
wfd_config_set_server_cert(
struct wfd_config * config,
char const * cert_path)
{
wf_server_config_set_certpath(config->server, cert_path);
}
void
wfd_config_set_server_document_root(
struct wfd_config * config,
char const * document_root)
{
wf_server_config_set_documentroot(config->server, document_root);
}
bool
wfd_config_add_auth_provider(
struct wfd_config * config,
char const * provider,
struct wfd_settings * settings)
{
bool result = false;
if (!config->has_authenticator)
{
result = wfd_authenticator_create(provider, settings, &config->authenticator);
if (result)
{
wf_server_config_add_authenticator(
config->server,
wfd_authenticator_get_type(config->authenticator),
config->authenticator.vtable->authenticate,
config->authenticator.data);
config->has_authenticator = true;
}
}
return result;
}
bool
wfd_config_add_filesystem(
struct wfd_config * config,
char const * name,
char const * mount_point)
{
return wfd_mountpoint_factory_add_filesystem(
config->mountpoint_factory, name, mount_point);
}
bool
wfd_config_set_logger(
struct wfd_config * config,
char const * provider,
int level,
struct wfd_settings * settings)
{
return wfd_log_manager_set_logger(provider, level, settings);
}
void
wfd_config_set_user(
struct wfd_config * config,
char const * user,
char const * group)
{
config->user = strdup(user);
config->group = strdup(group);
}
struct wf_server_config *

View File

@ -1,8 +1,6 @@
#ifndef WFD_CONFIG_H
#define WFD_CONFIG_H
#include "webfused/config/builder.h"
#ifndef __cplusplus
#include <stdbool.h>
#include <stddef.h>
@ -18,17 +16,10 @@ extern "C"
struct wfd_config;
struct wf_server_config;
extern struct wfd_config *
wfd_config_create(void);
extern void
wfd_config_dispose(
struct wfd_config * config);
extern struct wfd_config_builder
wfd_config_get_builder(
struct wfd_config * config);
extern struct wf_server_config *
wfd_config_get_server_config(
struct wfd_config * config);

View File

@ -0,0 +1,73 @@
#ifndef WFD_CONFIG_INTERN_H
#define WFD_CONFIG_INTERN_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
struct wfd_settings;
struct wfd_config;
extern struct wfd_config *
wfd_config_create(void);
extern void
wfd_config_set_server_vhostname(
struct wfd_config * config,
char const * vhost_name);
extern void
wfd_config_set_server_port(
struct wfd_config * config,
int port);
extern void
wfd_config_set_server_key(
struct wfd_config * config,
char const * key_path);
extern void
wfd_config_set_server_cert(
struct wfd_config * config,
char const * cert_path);
extern void
wfd_config_set_server_document_root(
struct wfd_config * config,
char const * document_root);
extern bool
wfd_config_add_auth_provider(
struct wfd_config * config,
char const * provider,
struct wfd_settings * settings);
extern bool
wfd_config_add_filesystem(
struct wfd_config * config,
char const * name,
char const * mount_point);
extern bool
wfd_config_set_logger(
struct wfd_config * config,
char const * provider,
int level,
struct wfd_settings * settings);
extern void
wfd_config_set_user(
struct wfd_config * config,
char const * user,
char const * group);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,4 +1,6 @@
#include "webfused/config/factory.h"
#include "webfused/config/config_intern.h"
#include "webfused/config/config.h"
#include "webfused/config/settings_intern.h"
#include "webfused/log/log.h"
@ -58,7 +60,7 @@ wfd_config_check_version(
static bool
wfd_config_read_logger(
config_t * config,
struct wfd_config_builder builder)
struct wfd_config * builder)
{
bool result = true;
@ -100,7 +102,7 @@ wfd_config_read_logger(
config_setting_t * setting = config_lookup(config, "log.settings");
struct wfd_settings settings;
wfd_settings_init(&settings, setting);
result = wfd_config_builder_set_logger(builder, provider, level, &settings);
result = wfd_config_set_logger(builder, provider, level, &settings);
wfd_settings_cleanup(&settings);
}
}
@ -111,41 +113,41 @@ wfd_config_read_logger(
static bool
wfd_config_read_server(
config_t * config,
struct wfd_config_builder builder)
struct wfd_config * builder)
{
char const * vhost_name;
int rc = config_lookup_string(config, "server.vhost_name", &vhost_name);
if (CONFIG_TRUE == rc)
{
wfd_config_builder_set_server_vhostname(builder, vhost_name);
wfd_config_set_server_vhostname(builder, vhost_name);
}
int port;
rc = config_lookup_int(config, "server.port", &port);
if (CONFIG_TRUE == rc)
{
wfd_config_builder_set_server_port(builder, port);
wfd_config_set_server_port(builder, port);
}
char const * cert;
rc = config_lookup_string(config, "server.tls.certificate", &cert);
if (CONFIG_TRUE == rc)
{
wfd_config_builder_set_server_cert(builder, cert);
wfd_config_set_server_cert(builder, cert);
}
char const * key;
rc = config_lookup_string(config, "server.tls.key", &key);
if (CONFIG_TRUE == rc)
{
wfd_config_builder_set_server_key(builder, key);
wfd_config_set_server_key(builder, key);
}
char const * doc_root;
rc = config_lookup_string(config, "server.document_root", &doc_root);
if (CONFIG_TRUE == rc)
{
wfd_config_builder_set_server_document_root(builder, doc_root);
wfd_config_set_server_document_root(builder, doc_root);
}
return true;
@ -154,7 +156,7 @@ wfd_config_read_server(
static bool
wfd_config_read_authenticator(
config_setting_t * authenticator,
struct wfd_config_builder builder)
struct wfd_config * builder)
{
bool result = (NULL != authenticator);
@ -185,7 +187,7 @@ wfd_config_read_authenticator(
struct wfd_settings auth_settings;
wfd_settings_init(&auth_settings, settings);
result = wfd_config_builder_add_auth_provider(builder, provider_name, &auth_settings);
result = wfd_config_add_auth_provider(builder, provider_name, &auth_settings);
wfd_settings_cleanup(&auth_settings);
}
@ -195,7 +197,7 @@ wfd_config_read_authenticator(
static bool
wfd_config_read_authentication(
config_t * config,
struct wfd_config_builder builder)
struct wfd_config * builder)
{
bool result = true;
@ -216,7 +218,7 @@ wfd_config_read_authentication(
static bool
wfd_config_read_filesystems(
config_t * config,
struct wfd_config_builder builder)
struct wfd_config * builder)
{
bool result = true;
config_setting_t * filesystems = config_lookup(config, "filesystems");
@ -251,7 +253,7 @@ wfd_config_read_filesystems(
break;
}
result = wfd_config_builder_add_filesystem(builder, name, mount_point);
result = wfd_config_add_filesystem(builder, name, mount_point);
if (!result)
{
break;
@ -265,7 +267,7 @@ wfd_config_read_filesystems(
static bool
wfd_config_read_user(
config_t * config,
struct wfd_config_builder builder)
struct wfd_config * builder)
{
bool result = true;
@ -295,43 +297,48 @@ wfd_config_read_user(
if (result)
{
wfd_config_builder_set_user(builder, user, group);
wfd_config_set_user(builder, user, group);
}
}
return result;
}
static bool
static struct wfd_config *
wfd_config_load(
struct wfd_config_builder builder,
config_t * config)
{
struct wfd_config * result = wfd_config_create();
bool result = wfd_config_check_version(config)
&& wfd_config_read_logger(config, builder)
&& wfd_config_read_server(config, builder)
&& wfd_config_read_authentication(config, builder)
&& wfd_config_read_filesystems(config, builder)
&& wfd_config_read_user(config, builder)
bool success = wfd_config_check_version(config)
&& wfd_config_read_logger(config, result)
&& wfd_config_read_server(config, result)
&& wfd_config_read_authentication(config, result)
&& wfd_config_read_filesystems(config, result)
&& wfd_config_read_user(config, result)
;
if (!success)
{
wfd_config_dispose(result);
result = NULL;
}
return result;
}
bool
struct wfd_config *
wfd_config_load_file(
struct wfd_config_builder builder,
char const * filename)
{
bool result = false;
struct wfd_config * result = NULL;
config_t config;
config_init(&config);
int rc = config_read_file(&config, filename);
if (CONFIG_TRUE == rc)
{
result = wfd_config_load(builder, &config);
result = wfd_config_load(&config);
}
else
{
@ -346,19 +353,18 @@ wfd_config_load_file(
return result;
}
bool
struct wfd_config *
wfd_config_load_string(
struct wfd_config_builder builder,
char const * contents)
{
bool result = false;
struct wfd_config * result = NULL;
config_t config;
config_init(&config);
int rc = config_read_string(&config, contents);
if (CONFIG_TRUE == rc)
{
result = wfd_config_load(builder, &config);
result = wfd_config_load(&config);
}
else
{

View File

@ -1,25 +1,19 @@
#ifndef WFD_CONFIG_FACTORY_H
#define WFD_CONFIG_FACTORY_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "webfused/config/builder.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern bool
struct wfd_config;
extern struct wfd_config *
wfd_config_load_file(
struct wfd_config_builder builder,
char const * filename);
extern bool
extern struct wfd_config *
wfd_config_load_string(
struct wfd_config_builder builder,
char const * contents);
#ifdef __cplusplus

View File

@ -109,9 +109,9 @@ int wfd_daemon_run(int argc, char * argv[])
{
signal(SIGINT, on_interrupt);
struct wfd_config * config = wfd_config_create();
struct wfd_config_builder builder = wfd_config_get_builder(config);
bool success = wfd_config_load_file(builder, args.config_file);
struct wfd_config * config = wfd_config_load_file(args.config_file);
bool success = (NULL != config);
if (!success)
{
fprintf(stderr, "fatal: failed to load server config\n");
@ -145,7 +145,10 @@ int wfd_daemon_run(int argc, char * argv[])
}
}
wfd_config_dispose(config);
if (NULL != config)
{
wfd_config_dispose(config);
}
}
else
{

View File

@ -4,118 +4,251 @@ extern "C"
{
using webfused_test::IConfigBuilder;
static void
wfd_MockConfigBuilder_set_server_vhostname(
void * data,
static IConfigBuilder * wfd_MockConfigBuilder = nullptr;
extern struct wfd_config *
__real_wfd_config_create(void);
extern void
__real_wfd_config_dispose(
struct wfd_config * config);
extern void
__real_wfd_config_set_server_vhostname(
struct wfd_config * config,
char const * vhost_name);
extern void
__real_wfd_config_set_server_port(
struct wfd_config * config,
int port);
extern void
__real_wfd_config_set_server_key(
struct wfd_config * config,
char const * key_path);
extern void
__real_wfd_config_set_server_cert(
struct wfd_config * config,
char const * cert_path);
extern void
__real_wfd_config_set_server_document_root(
struct wfd_config * config,
char const * document_root);
extern bool
__real_wfd_config_add_auth_provider(
struct wfd_config * config,
char const * provider,
struct wfd_settings * settings);
extern bool
__real_wfd_config_add_filesystem(
struct wfd_config * config,
char const * name,
char const * mount_point);
extern bool
__real_wfd_config_set_logger(
struct wfd_config * config,
char const * provider,
int level,
struct wfd_settings * settings);
extern void
__real_wfd_config_set_user(
struct wfd_config * config,
char const * user,
char const * group);
struct wfd_config *
__wrap_wfd_config_create(void)
{
if (nullptr == wfd_MockConfigBuilder)
{
return __real_wfd_config_create();
}
else
{
return wfd_MockConfigBuilder->create();
}
}
void
__wrap_wfd_config_dispose(
struct wfd_config * config)
{
if (nullptr == wfd_MockConfigBuilder)
{
__real_wfd_config_dispose(config);
}
else
{
wfd_MockConfigBuilder->dispose(config);
}
}
void
__wrap_wfd_config_set_server_vhostname(
struct wfd_config * config,
char const * vhost_name)
{
auto * builder = reinterpret_cast<IConfigBuilder*>(data);
builder->setServerVhostname(vhost_name);
if (nullptr == wfd_MockConfigBuilder)
{
__real_wfd_config_set_server_vhostname(config, vhost_name);
}
else
{
wfd_MockConfigBuilder->setServerVhostname(vhost_name);
}
}
static void
wfd_MockConfigBuilder_set_server_port(
void * data,
void
__wrap_wfd_config_set_server_port(
struct wfd_config * config,
int port)
{
auto * builder = reinterpret_cast<IConfigBuilder*>(data);
builder->setServerPort(port);
if (nullptr == wfd_MockConfigBuilder)
{
__real_wfd_config_set_server_port(config, port);
}
else
{
wfd_MockConfigBuilder->setServerPort(port);
}
}
static void
wfd_MockConfigBuilder_set_server_key(
void * data,
void
__wrap_wfd_config_set_server_key(
struct wfd_config * config,
char const * key_path)
{
auto * builder = reinterpret_cast<IConfigBuilder*>(data);
builder->setServerKey(key_path);
if (nullptr == wfd_MockConfigBuilder)
{
__real_wfd_config_set_server_key(config, key_path);
}
else
{
wfd_MockConfigBuilder->setServerKey(key_path);
}
}
static void
wfd_MockConfigBuilder_set_server_cert(
void * data,
void
__wrap_wfd_config_set_server_cert(
struct wfd_config * config,
char const * cert_path)
{
auto * builder = reinterpret_cast<IConfigBuilder*>(data);
builder->setServerCert(cert_path);
if (nullptr == wfd_MockConfigBuilder)
{
__real_wfd_config_set_server_cert(config, cert_path);
}
else
{
wfd_MockConfigBuilder->setServerCert(cert_path);
}
}
static void
wfd_MockConfigBuilder_set_server_document_root(
void * data,
void
__wrap_wfd_config_set_server_document_root(
struct wfd_config * config,
char const * document_root)
{
auto * builder = reinterpret_cast<IConfigBuilder*>(data);
builder->setServerDocumentRoot(document_root);
if (nullptr == wfd_MockConfigBuilder)
{
__real_wfd_config_set_server_document_root(config, document_root);
}
else
{
wfd_MockConfigBuilder->setServerDocumentRoot(document_root);
}
}
static bool
wfd_MockConfigBuilder_add_auth_provider(
void * data,
bool
__wrap_wfd_config_add_auth_provider(
struct wfd_config * config,
char const * provider,
struct wfd_settings * settings)
{
auto * builder = reinterpret_cast<IConfigBuilder*>(data);
return builder->addAuthProvider(provider, settings);
if (nullptr == wfd_MockConfigBuilder)
{
return __real_wfd_config_add_auth_provider(config, provider, settings);
}
else
{
return wfd_MockConfigBuilder->addAuthProvider(provider, settings);
}
}
static bool
wfd_MockConfigBuilder_add_filesystem(
void * data,
bool
__wrap_wfd_config_add_filesystem(
struct wfd_config * config,
char const * name,
char const * mountpoint)
char const * mount_point)
{
auto * builder = reinterpret_cast<IConfigBuilder*>(data);
return builder->addFilesystem(name, mountpoint);
if (nullptr == wfd_MockConfigBuilder)
{
return __real_wfd_config_add_filesystem(config, name, mount_point);
}
else
{
return wfd_MockConfigBuilder->addFilesystem(name, mount_point);
}
}
static bool
wfd_MockConfigBuilder_set_logger(
void * data,
bool
__wrap_wfd_config_set_logger(
struct wfd_config * config,
char const * provider,
int level,
struct wfd_settings * settings)
{
auto * builder = reinterpret_cast<IConfigBuilder*>(data);
return builder->setLogger(provider, level, settings);
if (nullptr == wfd_MockConfigBuilder)
{
return __real_wfd_config_set_logger(config, provider, level, settings);
}
else
{
return wfd_MockConfigBuilder->setLogger(provider, level, settings);
}
}
static void
wfd_MockConfigBuilder_set_user(
void * data,
void
__wrap_wfd_config_set_user(
struct wfd_config * config,
char const * user,
char const * group)
{
auto * builder = reinterpret_cast<IConfigBuilder*>(data);
return builder->setUser(user, group);
if (nullptr == wfd_MockConfigBuilder)
{
__real_wfd_config_set_user(config, user, group);
}
else
{
wfd_MockConfigBuilder->setUser(user, group);
}
}
static const wfd_config_builder_vtable wfd_MockConfigBuilder_vtable =
{
&wfd_MockConfigBuilder_set_server_vhostname,
&wfd_MockConfigBuilder_set_server_port,
&wfd_MockConfigBuilder_set_server_key,
&wfd_MockConfigBuilder_set_server_cert,
&wfd_MockConfigBuilder_set_server_document_root,
&wfd_MockConfigBuilder_add_auth_provider,
&wfd_MockConfigBuilder_add_filesystem,
&wfd_MockConfigBuilder_set_logger,
&wfd_MockConfigBuilder_set_user
};
}
namespace webfused_test
{
struct wfd_config_builder MockConfigBuilder::getBuilder()
{
IConfigBuilder * config_builder = this;
wfd_config_builder builder = {
&wfd_MockConfigBuilder_vtable,
reinterpret_cast<void*>(config_builder)
};
MockConfigBuilder::MockConfigBuilder()
{
wfd_MockConfigBuilder = this;
}
return builder;
}
MockConfigBuilder::~MockConfigBuilder()
{
wfd_MockConfigBuilder = nullptr;
}
struct wfd_config * MockConfigBuilder::getBuilder()
{
IConfigBuilder * config_builder = this;
return reinterpret_cast<wfd_config *>(config_builder);
}
}

View File

@ -2,7 +2,7 @@
#define WFD_MOCK_CONFIG_BUILDER_HPP
#include <gmock/gmock.h>
#include "webfused/config/builder.h"
#include "webfused/config/config_intern.h"
namespace webfused_test
{
@ -11,6 +11,8 @@ class IConfigBuilder
{
public:
virtual ~IConfigBuilder() = default;
virtual wfd_config * create(void) = 0;
virtual void dispose(wfd_config * config) = 0;
virtual void setServerVhostname(char const * vhostname) = 0;
virtual void setServerPort(int port) = 0;
virtual void setServerKey(char const * key_path) = 0;
@ -25,7 +27,10 @@ public:
class MockConfigBuilder: public IConfigBuilder
{
public:
~MockConfigBuilder() override = default;
MockConfigBuilder();
~MockConfigBuilder() override;
MOCK_METHOD0(create, wfd_config * (void));
MOCK_METHOD1(dispose, void (wfd_config * config));
MOCK_METHOD1(setServerVhostname, void (char const * vhostname));
MOCK_METHOD1(setServerPort, void (int port));
MOCK_METHOD1(setServerKey, void (char const * key_path));
@ -36,7 +41,7 @@ public:
MOCK_METHOD3(setLogger, bool (char const * provider, int level, wfd_settings * settings));
MOCK_METHOD2(setUser, void (char const * user, char const * group));
struct wfd_config_builder getBuilder();
struct wfd_config * getBuilder();
};
}

View File

@ -1,5 +1,6 @@
#include <gtest/gtest.h>
#include "webfused/config/config.h"
#include "webfused/config/config_intern.h"
#include "mock_settings.hpp"
#include "webfused/log/logger.h"
@ -17,12 +18,11 @@ TEST(config, server_config)
wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config);
wfd_config_builder_set_server_vhostname(builder, "localhost");
wfd_config_builder_set_server_port(builder, 8443);
wfd_config_builder_set_server_key(builder, "/path/to/key.pem");
wfd_config_builder_set_server_cert(builder, "/path/to/cert.pem");
wfd_config_builder_set_server_document_root(builder, "/var/www");
wfd_config_set_server_vhostname(config, "localhost");
wfd_config_set_server_port(config, 8443);
wfd_config_set_server_key(config, "/path/to/key.pem");
wfd_config_set_server_cert(config, "/path/to/cert.pem");
wfd_config_set_server_document_root(config, "/var/www");
wf_server_config * server_config = wfd_config_get_server_config(config);
ASSERT_NE(nullptr, server_config);
@ -35,12 +35,10 @@ TEST(config, auth_config)
wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config);
MockSettings settings;
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
bool success = wfd_config_builder_add_auth_provider(builder, "file", nullptr);
bool success = wfd_config_add_auth_provider(config, "file", nullptr);
ASSERT_TRUE(success);
wfd_config_dispose(config);
@ -51,15 +49,13 @@ TEST(config, auth_config_failed_to_add_second_provider)
wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config);
MockSettings settings;
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
bool success = wfd_config_builder_add_auth_provider(builder, "file", nullptr);
bool success = wfd_config_add_auth_provider(config, "file", nullptr);
ASSERT_TRUE(success);
success = wfd_config_builder_add_auth_provider(builder, "file", nullptr);
success = wfd_config_add_auth_provider(config, "file", nullptr);
ASSERT_FALSE(success);
wfd_config_dispose(config);
@ -70,9 +66,7 @@ TEST(config, auth_config_failed_to_add_unknown_provider)
wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config);
bool success = wfd_config_builder_add_auth_provider(builder, "unknown", nullptr);
bool success = wfd_config_add_auth_provider(config, "unknown", nullptr);
ASSERT_FALSE(success);
wfd_config_dispose(config);
@ -83,9 +77,7 @@ TEST(config, add_filesystem)
wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config);
bool success = wfd_config_builder_add_filesystem(builder, "test", "/tmp/test");
bool success = wfd_config_add_filesystem(config, "test", "/tmp/test");
ASSERT_TRUE(success);
wfd_config_dispose(config);
@ -96,9 +88,7 @@ TEST(config, set_logger)
wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config);
bool success = wfd_config_builder_set_logger(builder, "stderr", WFD_LOGLEVEL_ALL, nullptr);
bool success = wfd_config_set_logger(config, "stderr", WFD_LOGLEVEL_ALL, nullptr);
ASSERT_TRUE(success);
wfd_config_dispose(config);
@ -109,9 +99,7 @@ TEST(config, do_set_user)
wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config);
wfd_config_builder_set_user(builder, "some.user", "some.group");
wfd_config_set_user(config, "some.user", "some.group");
ASSERT_STREQ("some.user", wfd_config_get_user(config));
ASSERT_STREQ("some.group", wfd_config_get_group(config));

View File

@ -17,14 +17,15 @@ using ::webfused_test::MockConfigBuilder;
TEST(config, is_loadable)
{
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, setLogger(_,_,_)).Times(1).WillOnce(Return(true));
EXPECT_CALL(builder, setServerVhostname(StrEq("localhost"))).Times(1);
EXPECT_CALL(builder, setServerPort(8080)).Times(1);
EXPECT_CALL(builder, addAuthProvider(_, _)).Times(1).WillOnce(Return(true));
EXPECT_CALL(builder, addFilesystem(_,_)).Times(1).WillOnce(Return(true));
bool result = wfd_config_load_file(builder.getBuilder(), "webfused.conf");
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_file("webfused.conf");
ASSERT_NE(nullptr, config);
}
TEST(config, minimal_config)
@ -34,10 +35,11 @@ TEST(config, minimal_config)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
char const minimal[] = "version = { major = 1, minor = 0 }\n";
bool result = wfd_config_load_string(builder.getBuilder(), minimal);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(minimal);
ASSERT_NE(nullptr, config);
}
TEST(config, invalid_config)
@ -46,12 +48,14 @@ TEST(config, invalid_config)
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(0);
EXPECT_CALL(builder, dispose(_)).Times(0);
char const syntax_error[] = "version.major = 1\n";
bool result = wfd_config_load_string(builder.getBuilder(), syntax_error);
ASSERT_FALSE(result);
wfd_config * config = wfd_config_load_string(syntax_error);
ASSERT_EQ(nullptr, config);
}
TEST(config, invalid_config_file)
@ -60,10 +64,12 @@ TEST(config, invalid_config_file)
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(0);
EXPECT_CALL(builder, dispose(_)).Times(0);
bool result = wfd_config_load_file(builder.getBuilder(), "invalid.conf");
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_file("invalid.conf");
ASSERT_EQ(nullptr, config);
}
TEST(config, invalid_major_version_too_low)
@ -72,12 +78,14 @@ TEST(config, invalid_major_version_too_low)
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
char const too_low[] = "version = { major = 0, minor = 0 }\n";
bool result = wfd_config_load_string(builder.getBuilder(), too_low);
ASSERT_FALSE(result);
struct wfd_config * config= wfd_config_load_string(too_low);
ASSERT_EQ(nullptr, config);
}
TEST(config, invalid_major_version_too_high)
@ -86,12 +94,14 @@ TEST(config, invalid_major_version_too_high)
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
char const too_high[] = "version = { major = 2, minor = 0 }\n";
bool result = wfd_config_load_string(builder.getBuilder(), too_high);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(too_high);
ASSERT_EQ(nullptr, config);
}
TEST(config, invalid_missing_major_version)
@ -100,12 +110,14 @@ TEST(config, invalid_missing_major_version)
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
char const too_high[] = "version = { minor = 0 }\n";
bool result = wfd_config_load_string(builder.getBuilder(), too_high);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(too_high);
ASSERT_EQ(nullptr, config);
}
TEST(config, invalid_missing_minor_version)
@ -114,12 +126,14 @@ TEST(config, invalid_missing_minor_version)
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
char const too_high[] = "version = { major = 1 }\n";
bool result = wfd_config_load_string(builder.getBuilder(), too_high);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(too_high);
ASSERT_EQ(nullptr, config);
}
TEST(config, valid_older_minor)
@ -128,12 +142,13 @@ TEST(config, valid_older_minor)
EXPECT_CALL(logger, log(WFD_LOGLEVEL_INFO, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
char const valid[] = "version = { major = 1, minor = -1 }\n";
bool result = wfd_config_load_string(builder.getBuilder(), valid);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(valid);
ASSERT_NE(nullptr, config);
}
TEST(config, valid_newer_minor)
@ -142,12 +157,13 @@ TEST(config, valid_newer_minor)
EXPECT_CALL(logger, log(WFD_LOGLEVEL_WARN, _, _)).Times(1);
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
char const valid[] = "version = { major = 1, minor = 1 }\n";
bool result = wfd_config_load_string(builder.getBuilder(), valid);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(valid);
ASSERT_NE(nullptr, config);
}
TEST(config, vhost_name)
@ -157,6 +173,7 @@ TEST(config, vhost_name)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, setServerVhostname(StrEq("some.host"))).Times(1);
char const config_text[] =
@ -166,8 +183,8 @@ TEST(config, vhost_name)
" vhost_name = \"some.host\"\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, port)
@ -177,6 +194,7 @@ TEST(config, port)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, setServerPort(54321)).Times(1);
char const config_text[] =
@ -186,8 +204,8 @@ TEST(config, port)
" port = 54321\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, tls_certificate)
@ -197,6 +215,7 @@ TEST(config, tls_certificate)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, setServerCert(StrEq("/path/to/cert.pem"))).Times(1);
char const config_text[] =
@ -209,8 +228,8 @@ TEST(config, tls_certificate)
" }\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, tls_key)
@ -220,6 +239,7 @@ TEST(config, tls_key)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, setServerKey(StrEq("/path/to/key.pem"))).Times(1);
char const config_text[] =
@ -232,8 +252,8 @@ TEST(config, tls_key)
" }\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, document_root)
@ -243,6 +263,7 @@ TEST(config, document_root)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, setServerDocumentRoot(StrEq("/var/www"))).Times(1);
char const config_text[] =
@ -252,8 +273,8 @@ TEST(config, document_root)
" document_root = \"/var/www\"\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, authentication)
@ -263,6 +284,7 @@ TEST(config, authentication)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, addAuthProvider(_, _)).Times(1).WillOnce(Return(true));
char const config_text[] =
@ -275,8 +297,8 @@ TEST(config, authentication)
" }\n"
")\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, failed_create_authenticator)
@ -286,6 +308,8 @@ TEST(config, failed_create_authenticator)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
EXPECT_CALL(builder, addAuthProvider(_, _)).Times(1).WillOnce(Return(false));
char const config_text[] =
@ -298,8 +322,8 @@ TEST(config, failed_create_authenticator)
" }\n"
")\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, failed_missing_auth_provider)
@ -309,6 +333,8 @@ TEST(config, failed_missing_auth_provider)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
@ -319,8 +345,8 @@ TEST(config, failed_missing_auth_provider)
" }\n"
")\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, failed_missing_auth_settings)
@ -330,6 +356,8 @@ TEST(config, failed_missing_auth_settings)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
char const config_text[] =
"version = { major = 1, minor = 0 }\n"
@ -340,8 +368,8 @@ TEST(config, failed_missing_auth_settings)
" }\n"
")\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, filesystems)
@ -351,6 +379,7 @@ TEST(config, filesystems)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, addFilesystem(_, _)).Times(1).WillOnce(Return(true));
char const config_text[] =
@ -360,8 +389,8 @@ TEST(config, filesystems)
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
")\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, filesystems_empty)
@ -371,6 +400,7 @@ TEST(config, filesystems_empty)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, addFilesystem(_, _)).Times(0);
char const config_text[] =
@ -379,8 +409,8 @@ TEST(config, filesystems_empty)
"(\n"
")\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, filesystems_failed_add)
@ -390,6 +420,8 @@ TEST(config, filesystems_failed_add)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
EXPECT_CALL(builder, addFilesystem(_, _)).Times(1).WillOnce(Return(false));
char const config_text[] =
@ -399,8 +431,8 @@ TEST(config, filesystems_failed_add)
" {name = \"foo\", mount_point = \"/tmp/test\" }\n"
")\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, filesystems_failed_missing_name)
@ -410,6 +442,8 @@ TEST(config, filesystems_failed_missing_name)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
EXPECT_CALL(builder, addFilesystem(_, _)).Times(0);
char const config_text[] =
@ -419,8 +453,8 @@ TEST(config, filesystems_failed_missing_name)
" {mount_point = \"/tmp/test\" }\n"
")\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, filesystems_failed_missing_mountpoint)
@ -430,6 +464,8 @@ TEST(config, filesystems_failed_missing_mountpoint)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
EXPECT_CALL(builder, addFilesystem(_, _)).Times(0);
char const config_text[] =
@ -439,8 +475,8 @@ TEST(config, filesystems_failed_missing_mountpoint)
" {name = \"foo\"}\n"
")\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, log)
@ -450,6 +486,7 @@ TEST(config, log)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, setLogger(_, _, _)).Times(1).WillOnce(Return(true));
char const config_text[] =
@ -460,8 +497,8 @@ TEST(config, log)
" level = \"all\"\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, log_fail_set_logger)
@ -471,6 +508,8 @@ TEST(config, log_fail_set_logger)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
EXPECT_CALL(builder, setLogger(_, _, _)).Times(1).WillOnce(Return(false));
char const config_text[] =
@ -481,8 +520,8 @@ TEST(config, log_fail_set_logger)
" level = \"all\"\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, log_fail_missing_provider)
@ -492,6 +531,8 @@ TEST(config, log_fail_missing_provider)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
EXPECT_CALL(builder, setLogger(_, _, _)).Times(0);
char const config_text[] =
@ -501,8 +542,8 @@ TEST(config, log_fail_missing_provider)
" level = \"all\"\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, log_fail_missing_level)
@ -512,6 +553,8 @@ TEST(config, log_fail_missing_level)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
EXPECT_CALL(builder, setLogger(_, _, _)).Times(0);
char const config_text[] =
@ -522,8 +565,8 @@ TEST(config, log_fail_missing_level)
" level = \"fancy\"\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, log_fail_invalid_level)
@ -533,6 +576,8 @@ TEST(config, log_fail_invalid_level)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
EXPECT_CALL(builder, setLogger(_, _, _)).Times(0);
char const config_text[] =
@ -542,8 +587,8 @@ TEST(config, log_fail_invalid_level)
" provider = \"stderr\"\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, set_user)
@ -553,6 +598,7 @@ TEST(config, set_user)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, setUser(_, _)).Times(1);
char const config_text[] =
@ -563,8 +609,8 @@ TEST(config, set_user)
" group = \"webfused\"\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_TRUE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_NE(nullptr, config);
}
TEST(config, set_user_fail_missing_name)
@ -574,6 +620,8 @@ TEST(config, set_user_fail_missing_name)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
EXPECT_CALL(builder, setUser(_, _)).Times(0);
char const config_text[] =
@ -583,8 +631,8 @@ TEST(config, set_user_fail_missing_name)
" group = \"webfused\"\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}
TEST(config, set_user_fail_missing_group)
@ -594,6 +642,8 @@ TEST(config, set_user_fail_missing_group)
EXPECT_CALL(logger, onclose()).Times(1);
StrictMock<MockConfigBuilder> builder;
EXPECT_CALL(builder, create).Times(1).WillOnce(Return(builder.getBuilder()));
EXPECT_CALL(builder, dispose(_)).Times(1);
EXPECT_CALL(builder, setUser(_, _)).Times(0);
char const config_text[] =
@ -603,6 +653,6 @@ TEST(config, set_user_fail_missing_group)
" name = \"webfused\"\n"
"}\n"
;
bool result = wfd_config_load_string(builder.getBuilder(), config_text);
ASSERT_FALSE(result);
struct wfd_config * config = wfd_config_load_string(config_text);
ASSERT_EQ(nullptr, config);
}