parent
fab2545df1
commit
2e81b8c23d
@ -0,0 +1,8 @@
|
||||
#include "webfused/auth/authenticator.h"
|
||||
|
||||
void
|
||||
wfd_authenticator_dispose(
|
||||
struct wfd_authenticator authenticator)
|
||||
{
|
||||
authenticator.vtable->dispose(authenticator.data);
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
#ifndef WFD_AUTH_AUTHENTICATOR_H
|
||||
#define WFD_AUTH_AUTHENTICATOR_H
|
||||
|
||||
#include "webfuse/adapter/authenticate.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef void
|
||||
wfd_authenticator_dispose_fn(
|
||||
void * data);
|
||||
|
||||
struct wfd_authenticator_vtable
|
||||
{
|
||||
wfd_authenticator_dispose_fn * dispose;
|
||||
wf_authenticate_fn * authenticate;
|
||||
};
|
||||
|
||||
struct wfd_authenticator
|
||||
{
|
||||
struct wfd_authenticator_vtable const * vtable;
|
||||
void * data;
|
||||
};
|
||||
|
||||
extern void
|
||||
wfd_authenticator_dispose(
|
||||
struct wfd_authenticator authenticator);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,25 @@
|
||||
#include "webfused/auth/factory.h"
|
||||
#include "webfused/auth/settings.h"
|
||||
#include "webfused/auth/file_authenticator.h"
|
||||
#include "webfused/log/log.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
bool
|
||||
wfd_authenticator_create(
|
||||
struct wfd_auth_settings * settings,
|
||||
struct wfd_authenticator * authenticator)
|
||||
{
|
||||
bool result = false;
|
||||
char const * provider_name = wfd_auth_settings_get_provider(settings);
|
||||
if (0 == strcmp("file", provider_name))
|
||||
{
|
||||
result = wfd_file_authenticator_create(settings, authenticator);
|
||||
}
|
||||
else
|
||||
{
|
||||
WFD_ERROR("failed to create authenticator: unknown type \"%s\"", provider_name);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
#ifndef WFD_AUTHENTICATION_FACTORY_H
|
||||
#define WFD_AUTHENTICATION_FACTORY_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfd_authenticator;
|
||||
struct wfd_auth_settings;
|
||||
|
||||
extern bool
|
||||
wfd_authenticator_create(
|
||||
struct wfd_auth_settings * settings,
|
||||
struct wfd_authenticator * authenticator);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,9 @@
|
||||
#include "webfused/auth/file_authenticator.h"
|
||||
|
||||
bool
|
||||
wfd_file_authenticator_create(
|
||||
struct wfd_auth_settings * settings,
|
||||
struct wfd_authenticator * authenticator)
|
||||
{
|
||||
return false;
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
#ifndef WFD_AUTH_FILE_AUTHENTICATOR_H
|
||||
#define WFD_AUTH_FILE_AUTHENTICATOR_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfd_authenticator;
|
||||
struct wfd_auth_settings;
|
||||
|
||||
extern bool
|
||||
wfd_file_authenticator_create(
|
||||
struct wfd_auth_settings * settings,
|
||||
struct wfd_authenticator * authenticator);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,28 +0,0 @@
|
||||
#ifndef WFD_AUTH_SETTINGS_BUILDER_H
|
||||
#define WFD_AUTH_SETTINGS_BUILDER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#endif
|
||||
|
||||
extern struct wfd_auth_settings *
|
||||
wfd_auth_settings_create(void);
|
||||
|
||||
extern void
|
||||
wfd_auth_settings_dispose(
|
||||
struct wfd_auth_settings * settings);
|
||||
|
||||
extern void
|
||||
wfd_auth_settings_set_provider(
|
||||
struct wfd_auth_settings * settings,
|
||||
char const * provider);
|
||||
|
||||
extern void
|
||||
wfd_auth_settings_add(
|
||||
struct wfd_auth_settings * settings,
|
||||
char const * key,
|
||||
char const * value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,51 @@
|
||||
#include "webfused/auth/settings.h"
|
||||
#include "webfused/config/auth_settings.h"
|
||||
|
||||
#include <libconfig.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
struct wfd_auth_settings
|
||||
{
|
||||
char * provider_name;
|
||||
struct config_setting_t * settings;
|
||||
};
|
||||
|
||||
struct wfd_auth_settings *
|
||||
wfd_auth_settings_create(
|
||||
char const * provider_name,
|
||||
struct config_setting_t * settings)
|
||||
{
|
||||
struct wfd_auth_settings * auth_settings = malloc(sizeof(struct wfd_auth_settings));
|
||||
auth_settings->provider_name = strdup(provider_name);
|
||||
auth_settings->settings = settings;
|
||||
|
||||
return auth_settings;
|
||||
}
|
||||
|
||||
void
|
||||
wfd_auth_settings_dispose(
|
||||
struct wfd_auth_settings * settings)
|
||||
{
|
||||
free(settings->provider_name);
|
||||
free(settings);
|
||||
}
|
||||
|
||||
char const *
|
||||
wfd_auth_settings_get_provider(
|
||||
struct wfd_auth_settings * settings)
|
||||
{
|
||||
return settings->provider_name;
|
||||
}
|
||||
|
||||
char const *
|
||||
wfd_auth_settings_get(
|
||||
struct wfd_auth_settings * settings,
|
||||
char const * key)
|
||||
{
|
||||
char const * result;
|
||||
int rc = config_setting_lookup_string(settings->settings, key, &result);
|
||||
|
||||
return (CONFIG_TRUE == rc) ? result : NULL;
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
#ifndef WFD_CONFIG_AUTH_SETTINGS_H
|
||||
#define WFD_CONFIG_AUTH_SETTINGS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wfd_auth_settings;
|
||||
struct config_setting_t;
|
||||
|
||||
extern struct wfd_auth_settings *
|
||||
wfd_auth_settings_create(
|
||||
char const * provider_name,
|
||||
struct config_setting_t * settings);
|
||||
|
||||
extern void
|
||||
wfd_auth_settings_dispose(
|
||||
struct wfd_auth_settings * settings);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -0,0 +1,4 @@
|
||||
# This config file is invalid,
|
||||
# since "." is not allowed as separator
|
||||
|
||||
version.major = 1
|
@ -0,0 +1,26 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfused/auth/factory.h"
|
||||
#include "webfused/auth/authenticator.h"
|
||||
#include "webfused/config/auth_settings.h"
|
||||
#include "webfused/log/log.h"
|
||||
#include "mock_logger.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
using ::webfused_test::MockLogger;
|
||||
|
||||
|
||||
TEST(auth_factory, fail_unknown_provider)
|
||||
{
|
||||
MockLogger logger;
|
||||
EXPECT_CALL(logger, log(WFD_LOGLEVEL_ERROR, _, _)).Times(1);
|
||||
EXPECT_CALL(logger, onclose()).Times(1);
|
||||
|
||||
wfd_auth_settings * auth_settings = wfd_auth_settings_create(
|
||||
"unknown", NULL);
|
||||
|
||||
wfd_authenticator authenticator;
|
||||
bool result = wfd_authenticator_create(auth_settings, &authenticator);
|
||||
ASSERT_FALSE(result);
|
||||
|
||||
wfd_auth_settings_dispose(auth_settings);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "webfused/auth/settings.h"
|
||||
#include "webfused/config/auth_settings.h"
|
||||
#include <libconfig.h>
|
||||
|
||||
TEST(auth_settings, auth_settings)
|
||||
{
|
||||
char const settings_text[] =
|
||||
"settings:\n"
|
||||
"{\n"
|
||||
" string_value = \"some.string\"\n"
|
||||
" int_value = 42\n"
|
||||
"}\n"
|
||||
;
|
||||
config_t config;
|
||||
config_init(&config);
|
||||
int rc = config_read_string(&config, settings_text);
|
||||
ASSERT_TRUE(CONFIG_TRUE == rc);
|
||||
|
||||
config_setting_t * settings = config_lookup(&config, "settings");
|
||||
ASSERT_NE(nullptr, settings);
|
||||
|
||||
wfd_auth_settings * auth_settings = wfd_auth_settings_create("test_provider", settings);
|
||||
ASSERT_STREQ("test_provider", wfd_auth_settings_get_provider(auth_settings));
|
||||
ASSERT_STREQ("some.string", wfd_auth_settings_get(auth_settings, "string_value"));
|
||||
ASSERT_EQ(nullptr, wfd_auth_settings_get(auth_settings, "int_value"));
|
||||
ASSERT_EQ(nullptr, wfd_auth_settings_get(auth_settings, "invalid_value"));
|
||||
|
||||
wfd_auth_settings_dispose(auth_settings);
|
||||
config_destroy(&config);
|
||||
}
|
Loading…
Reference in new issue