2020-03-15 21:35:57 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "webfused/config/config.h"
|
2020-03-19 16:25:26 +00:00
|
|
|
#include "webfused/config/config_intern.h"
|
2020-03-20 12:48:58 +00:00
|
|
|
#include "mock/settings.hpp"
|
2020-03-17 15:49:17 +00:00
|
|
|
|
2020-03-17 20:51:04 +00:00
|
|
|
#include "webfused/log/logger.h"
|
|
|
|
#include "webfused/log/log.h"
|
2020-03-20 12:48:58 +00:00
|
|
|
#include "mock/logger.hpp"
|
2020-03-17 20:51:04 +00:00
|
|
|
using ::webfused_test::MockLogger;
|
|
|
|
using ::testing::_;
|
|
|
|
|
2020-03-18 09:17:17 +00:00
|
|
|
using ::webfused_test::MockSettings;
|
2020-03-17 15:49:17 +00:00
|
|
|
using ::testing::Return;
|
|
|
|
using ::testing::StrEq;
|
2020-03-15 21:35:57 +00:00
|
|
|
|
|
|
|
TEST(config, server_config)
|
|
|
|
{
|
|
|
|
wfd_config * config = wfd_config_create();
|
|
|
|
ASSERT_NE(nullptr, config);
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
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");
|
2020-03-15 21:35:57 +00:00
|
|
|
|
|
|
|
wf_server_config * server_config = wfd_config_get_server_config(config);
|
|
|
|
ASSERT_NE(nullptr, server_config);
|
|
|
|
|
2020-03-17 15:49:17 +00:00
|
|
|
wfd_config_dispose(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(config, auth_config)
|
|
|
|
{
|
|
|
|
wfd_config * config = wfd_config_create();
|
|
|
|
ASSERT_NE(nullptr, config);
|
|
|
|
|
2020-03-18 09:17:17 +00:00
|
|
|
MockSettings settings;
|
2020-03-18 16:33:31 +00:00
|
|
|
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
2020-03-17 15:49:17 +00:00
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
bool success = wfd_config_add_auth_provider(config, "file", nullptr);
|
2020-03-17 15:49:17 +00:00
|
|
|
ASSERT_TRUE(success);
|
|
|
|
|
|
|
|
wfd_config_dispose(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(config, auth_config_failed_to_add_second_provider)
|
|
|
|
{
|
|
|
|
wfd_config * config = wfd_config_create();
|
|
|
|
ASSERT_NE(nullptr, config);
|
|
|
|
|
2020-03-18 09:17:17 +00:00
|
|
|
MockSettings settings;
|
2020-03-18 16:33:31 +00:00
|
|
|
EXPECT_CALL(settings, getString(StrEq("file"))).Times(1).WillOnce(Return("/any/path"));
|
2020-03-17 15:49:17 +00:00
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
bool success = wfd_config_add_auth_provider(config, "file", nullptr);
|
2020-03-17 15:49:17 +00:00
|
|
|
ASSERT_TRUE(success);
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
success = wfd_config_add_auth_provider(config, "file", nullptr);
|
2020-03-17 15:49:17 +00:00
|
|
|
ASSERT_FALSE(success);
|
|
|
|
|
|
|
|
wfd_config_dispose(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(config, auth_config_failed_to_add_unknown_provider)
|
|
|
|
{
|
|
|
|
wfd_config * config = wfd_config_create();
|
|
|
|
ASSERT_NE(nullptr, config);
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
bool success = wfd_config_add_auth_provider(config, "unknown", nullptr);
|
2020-03-17 15:49:17 +00:00
|
|
|
ASSERT_FALSE(success);
|
|
|
|
|
2020-03-17 20:51:04 +00:00
|
|
|
wfd_config_dispose(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(config, add_filesystem)
|
|
|
|
{
|
|
|
|
wfd_config * config = wfd_config_create();
|
|
|
|
ASSERT_NE(nullptr, config);
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
bool success = wfd_config_add_filesystem(config, "test", "/tmp/test");
|
2020-03-17 20:51:04 +00:00
|
|
|
ASSERT_TRUE(success);
|
|
|
|
|
2020-03-18 16:33:31 +00:00
|
|
|
wfd_config_dispose(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(config, set_logger)
|
|
|
|
{
|
|
|
|
wfd_config * config = wfd_config_create();
|
|
|
|
ASSERT_NE(nullptr, config);
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
bool success = wfd_config_set_logger(config, "stderr", WFD_LOGLEVEL_ALL, nullptr);
|
2020-03-18 16:33:31 +00:00
|
|
|
ASSERT_TRUE(success);
|
|
|
|
|
2020-03-19 11:42:47 +00:00
|
|
|
wfd_config_dispose(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(config, do_set_user)
|
|
|
|
{
|
|
|
|
wfd_config * config = wfd_config_create();
|
|
|
|
ASSERT_NE(nullptr, config);
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
wfd_config_set_user(config, "some.user", "some.group");
|
2020-03-19 11:42:47 +00:00
|
|
|
ASSERT_STREQ("some.user", wfd_config_get_user(config));
|
|
|
|
ASSERT_STREQ("some.group", wfd_config_get_group(config));
|
|
|
|
|
2020-03-15 21:35:57 +00:00
|
|
|
wfd_config_dispose(config);
|
|
|
|
}
|