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/change_user.c
src/webfused/config/config.c src/webfused/config/config.c
src/webfused/config/factory.c src/webfused/config/factory.c
src/webfused/config/builder.c
src/webfused/config/settings.c src/webfused/config/settings.c
src/webfused/auth/authenticator.c src/webfused/auth/authenticator.c
src/webfused/auth/factory.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 target_link_libraries(alltests PRIVATE
-Wl,--wrap=wf_credentials_type -Wl,--wrap=wf_credentials_type
-Wl,--wrap=wf_credentials_get -Wl,--wrap=wf_credentials_get
-Wl,--wrap=wfd_settings_get_string -Wl,--wrap=wfd_settings_get_string
-Wl,--wrap=wfd_settings_get_string_or_default -Wl,--wrap=wfd_settings_get_string_or_default
-Wl,--wrap=wfd_settings_get_bool -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 webfused-static
userdb userdb
${LIBCONFIG_LIBRARIES} ${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.h"
#include "webfused/config/config_intern.h"
#include "webfuse/adapter/server_config.h" #include "webfuse/adapter/server_config.h"
#include "webfused/auth/factory.h" #include "webfused/auth/factory.h"
#include "webfused/auth/authenticator.h" #include "webfused/auth/authenticator.h"
@ -21,125 +22,6 @@ struct wfd_config
char * group; 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 * struct wfd_config *
wfd_config_create(void) wfd_config_create(void)
{ {
@ -175,17 +57,100 @@ wfd_config_dispose(
free(config); free(config);
} }
struct wfd_config_builder void
wfd_config_get_builder( wfd_config_set_server_vhostname(
struct wfd_config * config) struct wfd_config * config,
char const * vhost_name)
{ {
struct wfd_config_builder builder = wf_server_config_set_vhostname(config->server, vhost_name);
{ }
&wfd_config_vtable_config_builder,
config
};
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 * struct wf_server_config *

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
#define WFD_MOCK_CONFIG_BUILDER_HPP #define WFD_MOCK_CONFIG_BUILDER_HPP
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include "webfused/config/builder.h" #include "webfused/config/config_intern.h"
namespace webfused_test namespace webfused_test
{ {
@ -11,6 +11,8 @@ class IConfigBuilder
{ {
public: public:
virtual ~IConfigBuilder() = default; 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 setServerVhostname(char const * vhostname) = 0;
virtual void setServerPort(int port) = 0; virtual void setServerPort(int port) = 0;
virtual void setServerKey(char const * key_path) = 0; virtual void setServerKey(char const * key_path) = 0;
@ -25,7 +27,10 @@ public:
class MockConfigBuilder: public IConfigBuilder class MockConfigBuilder: public IConfigBuilder
{ {
public: 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(setServerVhostname, void (char const * vhostname));
MOCK_METHOD1(setServerPort, void (int port)); MOCK_METHOD1(setServerPort, void (int port));
MOCK_METHOD1(setServerKey, void (char const * key_path)); 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_METHOD3(setLogger, bool (char const * provider, int level, wfd_settings * settings));
MOCK_METHOD2(setUser, void (char const * user, char const * group)); 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 <gtest/gtest.h>
#include "webfused/config/config.h" #include "webfused/config/config.h"
#include "webfused/config/config_intern.h"
#include "mock_settings.hpp" #include "mock_settings.hpp"
#include "webfused/log/logger.h" #include "webfused/log/logger.h"
@ -17,12 +18,11 @@ TEST(config, server_config)
wfd_config * config = wfd_config_create(); wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config); ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config); wfd_config_set_server_vhostname(config, "localhost");
wfd_config_builder_set_server_vhostname(builder, "localhost"); wfd_config_set_server_port(config, 8443);
wfd_config_builder_set_server_port(builder, 8443); wfd_config_set_server_key(config, "/path/to/key.pem");
wfd_config_builder_set_server_key(builder, "/path/to/key.pem"); wfd_config_set_server_cert(config, "/path/to/cert.pem");
wfd_config_builder_set_server_cert(builder, "/path/to/cert.pem"); wfd_config_set_server_document_root(config, "/var/www");
wfd_config_builder_set_server_document_root(builder, "/var/www");
wf_server_config * server_config = wfd_config_get_server_config(config); wf_server_config * server_config = wfd_config_get_server_config(config);
ASSERT_NE(nullptr, server_config); ASSERT_NE(nullptr, server_config);
@ -35,12 +35,10 @@ TEST(config, auth_config)
wfd_config * config = wfd_config_create(); wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config); ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config);
MockSettings settings; MockSettings settings;
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("/any/path")); 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); ASSERT_TRUE(success);
wfd_config_dispose(config); wfd_config_dispose(config);
@ -51,15 +49,13 @@ TEST(config, auth_config_failed_to_add_second_provider)
wfd_config * config = wfd_config_create(); wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config); ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config);
MockSettings settings; MockSettings settings;
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("/any/path")); 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); 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); ASSERT_FALSE(success);
wfd_config_dispose(config); wfd_config_dispose(config);
@ -70,9 +66,7 @@ TEST(config, auth_config_failed_to_add_unknown_provider)
wfd_config * config = wfd_config_create(); wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config); ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config); bool success = wfd_config_add_auth_provider(config, "unknown", nullptr);
bool success = wfd_config_builder_add_auth_provider(builder, "unknown", nullptr);
ASSERT_FALSE(success); ASSERT_FALSE(success);
wfd_config_dispose(config); wfd_config_dispose(config);
@ -83,9 +77,7 @@ TEST(config, add_filesystem)
wfd_config * config = wfd_config_create(); wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config); ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config); bool success = wfd_config_add_filesystem(config, "test", "/tmp/test");
bool success = wfd_config_builder_add_filesystem(builder, "test", "/tmp/test");
ASSERT_TRUE(success); ASSERT_TRUE(success);
wfd_config_dispose(config); wfd_config_dispose(config);
@ -96,9 +88,7 @@ TEST(config, set_logger)
wfd_config * config = wfd_config_create(); wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config); ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config); bool success = wfd_config_set_logger(config, "stderr", WFD_LOGLEVEL_ALL, nullptr);
bool success = wfd_config_builder_set_logger(builder, "stderr", WFD_LOGLEVEL_ALL, nullptr);
ASSERT_TRUE(success); ASSERT_TRUE(success);
wfd_config_dispose(config); wfd_config_dispose(config);
@ -109,9 +99,7 @@ TEST(config, do_set_user)
wfd_config * config = wfd_config_create(); wfd_config * config = wfd_config_create();
ASSERT_NE(nullptr, config); ASSERT_NE(nullptr, config);
wfd_config_builder builder = wfd_config_get_builder(config); wfd_config_set_user(config, "some.user", "some.group");
wfd_config_builder_set_user(builder, "some.user", "some.group");
ASSERT_STREQ("some.user", wfd_config_get_user(config)); ASSERT_STREQ("some.user", wfd_config_get_user(config));
ASSERT_STREQ("some.group", wfd_config_get_group(config)); ASSERT_STREQ("some.group", wfd_config_get_group(config));

View File

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