mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
renamed to webfuse
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
#include "mock_authenticator.hpp"
|
||||
|
||||
#define WSFS_AUTHENTICTOR_COUNT 3
|
||||
#define WF_AUTHENTICATOR_COUNT 3
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
wsfs_test::Authenticator * g_authenticators[WSFS_AUTHENTICTOR_COUNT];
|
||||
webfuse_test::Authenticator * g_authenticators[WF_AUTHENTICATOR_COUNT];
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace wsfs_test
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
void set_authenticator(Authenticator * authenticator)
|
||||
@@ -23,17 +23,17 @@ void set_authenticator(size_t i, Authenticator * authenticator)
|
||||
g_authenticators[i] = authenticator;
|
||||
}
|
||||
|
||||
bool authenticate(struct wsfs_credentials * creds, void * user_data)
|
||||
bool authenticate(struct wf_credentials * creds, void * user_data)
|
||||
{
|
||||
return g_authenticators[0]->authenticate(creds, user_data);
|
||||
}
|
||||
|
||||
bool authenticate_1(struct wsfs_credentials * creds, void * user_data)
|
||||
bool authenticate_1(struct wf_credentials * creds, void * user_data)
|
||||
{
|
||||
return g_authenticators[1]->authenticate(creds, user_data);
|
||||
}
|
||||
|
||||
bool authenticate_2(struct wsfs_credentials * creds, void * user_data)
|
||||
bool authenticate_2(struct wf_credentials * creds, void * user_data)
|
||||
{
|
||||
return g_authenticators[2]->authenticate(creds, user_data);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#define MOCK_AUTHENTICATOR_H
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "wsfs/adapter/impl/authenticator.h"
|
||||
#include "webfuse/adapter/impl/authenticator.h"
|
||||
|
||||
namespace wsfs_test
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
class Authenticator
|
||||
@@ -12,22 +12,22 @@ class Authenticator
|
||||
public:
|
||||
virtual ~Authenticator() { }
|
||||
virtual bool authenticate(
|
||||
struct wsfs_credentials * credentials,
|
||||
struct wf_credentials * credentials,
|
||||
void * user_data) = 0;
|
||||
};
|
||||
|
||||
class MockAuthenticator: public Authenticator
|
||||
{
|
||||
public:
|
||||
MOCK_METHOD2(authenticate, bool (struct wsfs_credentials * credentials, void * user_data));
|
||||
MOCK_METHOD2(authenticate, bool (struct wf_credentials * credentials, void * user_data));
|
||||
};
|
||||
|
||||
void set_authenticator(Authenticator * authenticator);
|
||||
void set_authenticator(size_t index, Authenticator * authenticator);
|
||||
|
||||
bool authenticate(struct wsfs_credentials * creds, void * user_data);
|
||||
bool authenticate_1(struct wsfs_credentials * creds, void * user_data);
|
||||
bool authenticate_2(struct wsfs_credentials * creds, void * user_data);
|
||||
bool authenticate(struct wf_credentials * creds, void * user_data);
|
||||
bool authenticate_1(struct wf_credentials * creds, void * user_data);
|
||||
bool authenticate_2(struct wf_credentials * creds, void * user_data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "msleep.hpp"
|
||||
#include <ctime>
|
||||
|
||||
namespace wsfs_test
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
void msleep(long millis)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef WSFS_TEST_MSLEEP_HPP
|
||||
#define WSFS_TEST_MSLEEP_HPP
|
||||
#ifndef WF_TEST_MSLEEP_HPP
|
||||
#define WF_TEST_MSLEEP_HPP
|
||||
|
||||
namespace wsfs_test
|
||||
namespace webfuse_test
|
||||
{
|
||||
|
||||
extern void msleep(long millis);
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
|
||||
#include "mock_authenticator.hpp"
|
||||
|
||||
#include "wsfs/adapter/impl/authenticator.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
#include "webfuse/adapter/impl/authenticator.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
|
||||
using ::testing::Return;
|
||||
using ::testing::_;
|
||||
using ::wsfs_test::Authenticator;
|
||||
using ::wsfs_test::MockAuthenticator;
|
||||
using ::wsfs_test::set_authenticator;
|
||||
using ::wsfs_test::authenticate;
|
||||
using ::webfuse_test::Authenticator;
|
||||
using ::webfuse_test::MockAuthenticator;
|
||||
using ::webfuse_test::set_authenticator;
|
||||
using ::webfuse_test::authenticate;
|
||||
|
||||
|
||||
TEST(Authenticator, Authenticate)
|
||||
@@ -19,8 +19,8 @@ TEST(Authenticator, Authenticate)
|
||||
MockAuthenticator mock;
|
||||
set_authenticator(&mock);
|
||||
|
||||
struct wsfs_credentials creds;
|
||||
wsfs_impl_credentials_init(&creds, "username", nullptr);
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init(&creds, "username", nullptr);
|
||||
char dummy[] = "usr_data";
|
||||
void * user_data = reinterpret_cast<void*>(dummy);
|
||||
|
||||
@@ -28,16 +28,16 @@ TEST(Authenticator, Authenticate)
|
||||
.Times(1)
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(
|
||||
struct wf_impl_authenticator * authenticator = wf_impl_authenticator_create(
|
||||
"username",
|
||||
&authenticate,
|
||||
user_data);
|
||||
|
||||
bool result = wsfs_impl_authenticator_autenticate(authenticator, &creds);
|
||||
bool result = wf_impl_authenticator_autenticate(authenticator, &creds);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
wsfs_impl_authenticator_dispose(authenticator);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
wf_impl_authenticator_dispose(authenticator);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Authenticator, SkipAuthenticationWithWrongType)
|
||||
@@ -45,19 +45,19 @@ TEST(Authenticator, SkipAuthenticationWithWrongType)
|
||||
MockAuthenticator mock;
|
||||
set_authenticator(&mock);
|
||||
|
||||
struct wsfs_credentials creds;
|
||||
wsfs_impl_credentials_init(&creds, "username", nullptr);
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init(&creds, "username", nullptr);
|
||||
EXPECT_CALL(mock, authenticate(_, _))
|
||||
.Times(0);
|
||||
|
||||
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(
|
||||
struct wf_impl_authenticator * authenticator = wf_impl_authenticator_create(
|
||||
"certificate",
|
||||
&authenticate,
|
||||
nullptr);
|
||||
|
||||
bool result = wsfs_impl_authenticator_autenticate(authenticator, &creds);
|
||||
bool result = wf_impl_authenticator_autenticate(authenticator, &creds);
|
||||
ASSERT_FALSE(result);
|
||||
|
||||
wsfs_impl_authenticator_dispose(authenticator);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
wf_impl_authenticator_dispose(authenticator);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
@@ -1,86 +1,86 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "wsfs/adapter/impl/authenticators.h"
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include "mock_authenticator.hpp"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::Return;
|
||||
using ::wsfs_test::MockAuthenticator;
|
||||
using ::wsfs_test::set_authenticator;
|
||||
using ::wsfs_test::authenticate;
|
||||
using ::wsfs_test::authenticate_1;
|
||||
using ::wsfs_test::authenticate_2;
|
||||
using ::webfuse_test::MockAuthenticator;
|
||||
using ::webfuse_test::set_authenticator;
|
||||
using ::webfuse_test::authenticate;
|
||||
using ::webfuse_test::authenticate_1;
|
||||
using ::webfuse_test::authenticate_2;
|
||||
|
||||
|
||||
TEST(Authenticators, CloneEmpty)
|
||||
{
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
struct wsfs_impl_authenticators clone;
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_authenticators clone;
|
||||
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
ASSERT_EQ(nullptr, authenticators.first);
|
||||
|
||||
wsfs_impl_authenticators_clone(&authenticators, &clone);
|
||||
wf_impl_authenticators_clone(&authenticators, &clone);
|
||||
ASSERT_EQ(nullptr, clone.first);
|
||||
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_authenticators_cleanup(&clone);
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_authenticators_cleanup(&clone);
|
||||
}
|
||||
|
||||
TEST(Authenticators, Clone)
|
||||
{
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
struct wsfs_impl_authenticators clone;
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_authenticators clone;
|
||||
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
wsfs_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
wf_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
ASSERT_NE(nullptr, authenticators.first);
|
||||
|
||||
wsfs_impl_authenticators_clone(&authenticators, &clone);
|
||||
wf_impl_authenticators_clone(&authenticators, &clone);
|
||||
ASSERT_NE(nullptr, clone.first);
|
||||
ASSERT_NE(nullptr, authenticators.first);
|
||||
ASSERT_NE(authenticators.first, clone.first);
|
||||
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_authenticators_cleanup(&clone);
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_authenticators_cleanup(&clone);
|
||||
}
|
||||
|
||||
TEST(Authenticators, Move)
|
||||
{
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
struct wsfs_impl_authenticators clone;
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_authenticators clone;
|
||||
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
wsfs_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
wf_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
ASSERT_NE(nullptr, authenticators.first);
|
||||
|
||||
wsfs_impl_authenticators_move(&authenticators, &clone);
|
||||
wf_impl_authenticators_move(&authenticators, &clone);
|
||||
ASSERT_NE(nullptr, clone.first);
|
||||
ASSERT_EQ(nullptr, authenticators.first);
|
||||
ASSERT_NE(authenticators.first, clone.first);
|
||||
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_authenticators_cleanup(&clone);
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_authenticators_cleanup(&clone);
|
||||
}
|
||||
|
||||
TEST(Authenticators, AuthenticateWithoutAuthenticators)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
wsfs_impl_credentials_init(&creds, "username", nullptr);
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init(&creds, "username", nullptr);
|
||||
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
struct wf_impl_authenticators authenticators;
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
|
||||
bool result = wsfs_impl_authenticators_authenticate(&authenticators, &creds);
|
||||
bool result = wf_impl_authenticators_authenticate(&authenticators, &creds);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
result = wsfs_impl_authenticators_authenticate(&authenticators, nullptr);
|
||||
result = wf_impl_authenticators_authenticate(&authenticators, nullptr);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Authenticators, FailToAuthenticateWithoutCredentials)
|
||||
@@ -88,20 +88,20 @@ TEST(Authenticators, FailToAuthenticateWithoutCredentials)
|
||||
MockAuthenticator mock;
|
||||
set_authenticator(&mock);
|
||||
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
wsfs_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
struct wf_impl_authenticators authenticators;
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
wf_impl_authenticators_add(&authenticators, "username", &authenticate, nullptr);
|
||||
|
||||
bool result = wsfs_impl_authenticators_authenticate(&authenticators, nullptr);
|
||||
bool result = wf_impl_authenticators_authenticate(&authenticators, nullptr);
|
||||
ASSERT_FALSE(result);
|
||||
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
}
|
||||
|
||||
TEST(Authenticators, AuthenticateWithMultipleCredentials)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
wsfs_impl_credentials_init(&creds, "username", nullptr);
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init(&creds, "username", nullptr);
|
||||
|
||||
MockAuthenticator username_mock;
|
||||
set_authenticator(1, &username_mock);
|
||||
@@ -114,22 +114,22 @@ TEST(Authenticators, AuthenticateWithMultipleCredentials)
|
||||
EXPECT_CALL(certificate_mock, authenticate(_, _))
|
||||
.Times(0);
|
||||
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
wsfs_impl_authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
|
||||
wsfs_impl_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
|
||||
struct wf_impl_authenticators authenticators;
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
wf_impl_authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
|
||||
wf_impl_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
|
||||
|
||||
bool result = wsfs_impl_authenticators_authenticate(&authenticators, &creds);
|
||||
bool result = wf_impl_authenticators_authenticate(&authenticators, &creds);
|
||||
ASSERT_TRUE(result);
|
||||
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Authenticators, FailedAuthenticateWithWrongType)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
wsfs_impl_credentials_init(&creds, "token", nullptr);
|
||||
struct wf_credentials creds;
|
||||
wf_impl_credentials_init(&creds, "token", nullptr);
|
||||
|
||||
MockAuthenticator username_mock;
|
||||
set_authenticator(1, &username_mock);
|
||||
@@ -141,14 +141,14 @@ TEST(Authenticators, FailedAuthenticateWithWrongType)
|
||||
EXPECT_CALL(certificate_mock, authenticate(_, _))
|
||||
.Times(0);
|
||||
|
||||
struct wsfs_impl_authenticators authenticators;
|
||||
wsfs_impl_authenticators_init(&authenticators);
|
||||
wsfs_impl_authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
|
||||
wsfs_impl_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
|
||||
struct wf_impl_authenticators authenticators;
|
||||
wf_impl_authenticators_init(&authenticators);
|
||||
wf_impl_authenticators_add(&authenticators, "username", &authenticate_1, nullptr);
|
||||
wf_impl_authenticators_add(&authenticators, "certificate", &authenticate_2, nullptr);
|
||||
|
||||
bool result = wsfs_impl_authenticators_authenticate(&authenticators, &creds);
|
||||
bool result = wf_impl_authenticators_authenticate(&authenticators, &creds);
|
||||
ASSERT_FALSE(result);
|
||||
|
||||
wsfs_impl_authenticators_cleanup(&authenticators);
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
wf_impl_authenticators_cleanup(&authenticators);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
@@ -1,70 +1,70 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wsfs/adapter/impl/credentials.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include <jansson.h>
|
||||
|
||||
TEST(Credentials, Type)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
struct wf_credentials creds;
|
||||
|
||||
wsfs_impl_credentials_init(&creds, "test", nullptr);
|
||||
ASSERT_STREQ("test", wsfs_impl_credentials_type(&creds));
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
wf_impl_credentials_init(&creds, "test", nullptr);
|
||||
ASSERT_STREQ("test", wf_impl_credentials_type(&creds));
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Credentials, Get)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
struct wf_credentials creds;
|
||||
json_t * data = json_object();
|
||||
json_object_set_new(data, "username", json_string("bob"));
|
||||
json_object_set_new(data, "password", json_string("<secret>"));
|
||||
|
||||
wsfs_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ("bob", wsfs_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ("<secret>", wsfs_impl_credentials_get(&creds, "password"));
|
||||
wf_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wf_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ("bob", wf_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ("<secret>", wf_impl_credentials_get(&creds, "password"));
|
||||
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
}
|
||||
|
||||
TEST(Credentials, FailedToGetNonexistingValue)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
struct wf_credentials creds;
|
||||
json_t * data = json_object();
|
||||
|
||||
wsfs_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "password"));
|
||||
wf_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wf_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password"));
|
||||
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
}
|
||||
|
||||
TEST(Credentials, FailedToGetWithoutData)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
struct wf_credentials creds;
|
||||
|
||||
wsfs_impl_credentials_init(&creds, "username", nullptr);
|
||||
ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "password"));
|
||||
wf_impl_credentials_init(&creds, "username", nullptr);
|
||||
ASSERT_STREQ("username", wf_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password"));
|
||||
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
}
|
||||
|
||||
TEST(Credentials, FailedToGetWrongDataType)
|
||||
{
|
||||
struct wsfs_credentials creds;
|
||||
struct wf_credentials creds;
|
||||
json_t * data = json_string("invalid_creds");
|
||||
|
||||
wsfs_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wsfs_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wsfs_impl_credentials_get(&creds, "password"));
|
||||
wf_impl_credentials_init(&creds, "username", data);
|
||||
ASSERT_STREQ("username", wf_impl_credentials_type(&creds));
|
||||
ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "username"));
|
||||
ASSERT_STREQ(nullptr, wf_impl_credentials_get(&creds, "password"));
|
||||
|
||||
wsfs_impl_credentials_cleanup(&creds);
|
||||
wf_impl_credentials_cleanup(&creds);
|
||||
json_decref(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "wsfs/adapter/fuse_wrapper.h"
|
||||
#include "webfuse/adapter/fuse_wrapper.h"
|
||||
|
||||
TEST(libfuse, fuse_req_t_size)
|
||||
{
|
||||
|
||||
@@ -1,60 +1,60 @@
|
||||
#include <string>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wsfs/adapter/impl/jsonrpc/response.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/response.h"
|
||||
|
||||
|
||||
static void response_parse_str(
|
||||
std::string const & buffer,
|
||||
struct wsfs_impl_jsonrpc_response * response)
|
||||
struct wf_impl_jsonrpc_response * response)
|
||||
{
|
||||
wsfs_impl_jsonrpc_response_init(response, buffer.c_str(), buffer.size());
|
||||
wf_impl_jsonrpc_response_init(response, buffer.c_str(), buffer.size());
|
||||
}
|
||||
|
||||
TEST(response_parser, test)
|
||||
{
|
||||
struct wsfs_impl_jsonrpc_response response;
|
||||
struct wf_impl_jsonrpc_response response;
|
||||
|
||||
// invalid json
|
||||
response_parse_str("", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_NE(WF_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// invalid json
|
||||
response_parse_str("invalid_json", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_NE(WF_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// no object
|
||||
response_parse_str("[]", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_NE(WF_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// empty
|
||||
response_parse_str("{}", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_NE(WF_GOOD, response.status);
|
||||
ASSERT_EQ(-1, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// no data
|
||||
response_parse_str("{\"id\":42}", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_NE(WF_GOOD, response.status);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// custom error code
|
||||
response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response);
|
||||
ASSERT_NE(WSFS_GOOD, response.status);
|
||||
ASSERT_NE(WF_GOOD, response.status);
|
||||
ASSERT_EQ(42, response.status);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_EQ(nullptr, response.result);
|
||||
|
||||
// valid response
|
||||
response_parse_str("{\"result\": true, \"id\": 42}", &response);
|
||||
ASSERT_EQ(WSFS_GOOD, response.status);
|
||||
ASSERT_EQ(WF_GOOD, response.status);
|
||||
ASSERT_EQ(42, response.id);
|
||||
ASSERT_NE(nullptr, response.result);
|
||||
json_decref(response.result);
|
||||
|
||||
@@ -5,21 +5,21 @@
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wsfs/adapter/server.h"
|
||||
#include "wsfs/adapter/server_config.h"
|
||||
#include "webfuse/adapter/server.h"
|
||||
#include "webfuse/adapter/server_config.h"
|
||||
|
||||
|
||||
TEST(server, create_dispose)
|
||||
{
|
||||
mkdir("test", 0700);
|
||||
|
||||
struct wsfs_server_config * config = wsfs_server_config_create();
|
||||
wsfs_server_config_set_mountpoint(config, "test");
|
||||
struct wsfs_server * server = wsfs_server_create(config);
|
||||
struct wf_server_config * config = wf_server_config_create();
|
||||
wf_server_config_set_mountpoint(config, "test");
|
||||
struct wf_server * server = wf_server_create(config);
|
||||
ASSERT_NE(nullptr, server);
|
||||
|
||||
wsfs_server_dispose(server);
|
||||
wsfs_server_config_dispose(config);
|
||||
wf_server_dispose(server);
|
||||
wf_server_config_dispose(config);
|
||||
|
||||
rmdir("test");
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "msleep.hpp"
|
||||
#include "wsfs/adapter/impl/time/timepoint.h"
|
||||
#include "webfuse/adapter/impl/time/timepoint.h"
|
||||
|
||||
using wsfs_test::msleep;
|
||||
using webfuse_test::msleep;
|
||||
|
||||
TEST(timepoint, now)
|
||||
{
|
||||
wsfs_impl_timepoint start = wsfs_impl_timepoint_now();
|
||||
wf_impl_timepoint start = wf_impl_timepoint_now();
|
||||
msleep(42);
|
||||
wsfs_impl_timepoint end = wsfs_impl_timepoint_now();
|
||||
wf_impl_timepoint end = wf_impl_timepoint_now();
|
||||
|
||||
ASSERT_LT(start, end);
|
||||
ASSERT_LT(end, start + 500);
|
||||
@@ -17,20 +17,20 @@ TEST(timepoint, now)
|
||||
|
||||
TEST(timepoint, in_msec)
|
||||
{
|
||||
wsfs_impl_timepoint now = wsfs_impl_timepoint_now();
|
||||
wsfs_impl_timepoint later = wsfs_impl_timepoint_in_msec(42);
|
||||
wf_impl_timepoint now = wf_impl_timepoint_now();
|
||||
wf_impl_timepoint later = wf_impl_timepoint_in_msec(42);
|
||||
|
||||
ASSERT_LT(now, later);
|
||||
ASSERT_LT(later, now + 500);
|
||||
}
|
||||
|
||||
TEST(wsfs_impl_timepoint, elapsed)
|
||||
TEST(wf_impl_timepoint, elapsed)
|
||||
{
|
||||
wsfs_impl_timepoint now;
|
||||
wf_impl_timepoint now;
|
||||
|
||||
now = wsfs_impl_timepoint_now();
|
||||
ASSERT_TRUE(wsfs_impl_timepoint_is_elapsed(now - 1));
|
||||
now = wf_impl_timepoint_now();
|
||||
ASSERT_TRUE(wf_impl_timepoint_is_elapsed(now - 1));
|
||||
|
||||
now =wsfs_impl_timepoint_now();
|
||||
ASSERT_FALSE(wsfs_impl_timepoint_is_elapsed(now + 500));
|
||||
now =wf_impl_timepoint_now();
|
||||
ASSERT_FALSE(wf_impl_timepoint_is_elapsed(now + 500));
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
#include <cstddef>
|
||||
|
||||
#include "msleep.hpp"
|
||||
#include "wsfs/adapter/impl/time/timer.h"
|
||||
#include "wsfs/adapter/impl/time/timeout_manager.h"
|
||||
#include "webfuse/adapter/impl/time/timer.h"
|
||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||
|
||||
using std::size_t;
|
||||
using wsfs_test::msleep;
|
||||
using webfuse_test::msleep;
|
||||
|
||||
namespace
|
||||
{
|
||||
void on_timeout(struct wsfs_impl_timer * timer)
|
||||
void on_timeout(struct wf_impl_timer * timer)
|
||||
{
|
||||
bool * triggered = reinterpret_cast<bool*>(timer->user_data);
|
||||
*triggered = true;
|
||||
@@ -20,82 +20,82 @@ namespace
|
||||
|
||||
TEST(timer, init)
|
||||
{
|
||||
struct wsfs_impl_timeout_manager manager;
|
||||
struct wsfs_impl_timer timer;
|
||||
struct wf_impl_timeout_manager manager;
|
||||
struct wf_impl_timer timer;
|
||||
|
||||
wsfs_impl_timeout_manager_init(&manager);
|
||||
wsfs_impl_timer_init(&timer, &manager);
|
||||
wf_impl_timeout_manager_init(&manager);
|
||||
wf_impl_timer_init(&timer, &manager);
|
||||
|
||||
wsfs_impl_timer_cleanup(&timer);
|
||||
wsfs_impl_timeout_manager_cleanup(&manager);
|
||||
wf_impl_timer_cleanup(&timer);
|
||||
wf_impl_timeout_manager_cleanup(&manager);
|
||||
}
|
||||
|
||||
TEST(timer, trigger)
|
||||
{
|
||||
struct wsfs_impl_timeout_manager manager;
|
||||
struct wsfs_impl_timer timer;
|
||||
struct wf_impl_timeout_manager manager;
|
||||
struct wf_impl_timer timer;
|
||||
|
||||
wsfs_impl_timeout_manager_init(&manager);
|
||||
wsfs_impl_timer_init(&timer, &manager);
|
||||
wf_impl_timeout_manager_init(&manager);
|
||||
wf_impl_timer_init(&timer, &manager);
|
||||
|
||||
bool triggered = false;
|
||||
wsfs_impl_timer_start(&timer, wsfs_impl_timepoint_in_msec(250), &on_timeout, reinterpret_cast<void*>(&triggered));
|
||||
wf_impl_timer_start(&timer, wf_impl_timepoint_in_msec(250), &on_timeout, reinterpret_cast<void*>(&triggered));
|
||||
msleep(500);
|
||||
wsfs_impl_timeout_manager_check(&manager);
|
||||
wf_impl_timeout_manager_check(&manager);
|
||||
|
||||
ASSERT_TRUE(triggered);
|
||||
|
||||
wsfs_impl_timer_cleanup(&timer);
|
||||
wsfs_impl_timeout_manager_cleanup(&manager);
|
||||
wf_impl_timer_cleanup(&timer);
|
||||
wf_impl_timeout_manager_cleanup(&manager);
|
||||
}
|
||||
|
||||
TEST(timer, cancel)
|
||||
{
|
||||
struct wsfs_impl_timeout_manager manager;
|
||||
struct wsfs_impl_timer timer;
|
||||
struct wf_impl_timeout_manager manager;
|
||||
struct wf_impl_timer timer;
|
||||
|
||||
wsfs_impl_timeout_manager_init(&manager);
|
||||
wsfs_impl_timer_init(&timer, &manager);
|
||||
wf_impl_timeout_manager_init(&manager);
|
||||
wf_impl_timer_init(&timer, &manager);
|
||||
|
||||
bool triggered = false;
|
||||
wsfs_impl_timer_start(&timer, wsfs_impl_timepoint_in_msec(250), &on_timeout, &triggered);
|
||||
wf_impl_timer_start(&timer, wf_impl_timepoint_in_msec(250), &on_timeout, &triggered);
|
||||
msleep(500);
|
||||
wsfs_impl_timer_cancel(&timer);
|
||||
wsfs_impl_timeout_manager_check(&manager);
|
||||
wf_impl_timer_cancel(&timer);
|
||||
wf_impl_timeout_manager_check(&manager);
|
||||
|
||||
ASSERT_FALSE(triggered);
|
||||
|
||||
wsfs_impl_timer_cleanup(&timer);
|
||||
wsfs_impl_timeout_manager_cleanup(&manager);
|
||||
wf_impl_timer_cleanup(&timer);
|
||||
wf_impl_timeout_manager_cleanup(&manager);
|
||||
}
|
||||
|
||||
TEST(timer, multiple_timers)
|
||||
{
|
||||
static size_t const count = 5;
|
||||
struct wsfs_impl_timeout_manager manager;
|
||||
struct wsfs_impl_timer timer[count];
|
||||
struct wf_impl_timeout_manager manager;
|
||||
struct wf_impl_timer timer[count];
|
||||
bool triggered[count];
|
||||
|
||||
wsfs_impl_timeout_manager_init(&manager);
|
||||
wf_impl_timeout_manager_init(&manager);
|
||||
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
wsfs_impl_timer_init(&timer[i], &manager);
|
||||
wf_impl_timer_init(&timer[i], &manager);
|
||||
triggered[i] = false;
|
||||
wsfs_impl_timer_start(&timer[i], wsfs_impl_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]);
|
||||
wf_impl_timer_start(&timer[i], wf_impl_timepoint_in_msec(300 - (50 * i)), &on_timeout, &triggered[i]);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
msleep(100);
|
||||
wsfs_impl_timeout_manager_check(&manager);
|
||||
wf_impl_timeout_manager_check(&manager);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i < count; i++)
|
||||
{
|
||||
ASSERT_TRUE(triggered[i]);
|
||||
wsfs_impl_timer_cleanup(&timer[i]);
|
||||
wf_impl_timer_cleanup(&timer[i]);
|
||||
}
|
||||
|
||||
wsfs_impl_timeout_manager_cleanup(&manager);
|
||||
wf_impl_timeout_manager_cleanup(&manager);
|
||||
}
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wsfs/provider/impl/url.h"
|
||||
#include "webfuse/provider/impl/url.h"
|
||||
|
||||
TEST(url, ParseWs)
|
||||
{
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://localhost/");
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "ws://localhost/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(80, url.port);
|
||||
ASSERT_FALSE(url.use_tls);
|
||||
ASSERT_STREQ("localhost", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
wfp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParswWss)
|
||||
{
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "wss://localhost/");
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "wss://localhost/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(443, url.port);
|
||||
ASSERT_TRUE(url.use_tls);
|
||||
ASSERT_STREQ("localhost", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
wfp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParseIPAdress)
|
||||
{
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://127.0.0.1/");
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "ws://127.0.0.1/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(80, url.port);
|
||||
ASSERT_STREQ("127.0.0.1", url.host);
|
||||
ASSERT_STREQ("/", url.path);
|
||||
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
wfp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParsePort)
|
||||
{
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://localhost:54321/");
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "ws://localhost:54321/");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_EQ(54321, url.port);
|
||||
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
wfp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, ParseNonEmptyPath)
|
||||
{
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://localhost/some_path?query");
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "ws://localhost/some_path?query");
|
||||
ASSERT_TRUE(result);
|
||||
ASSERT_STREQ("/some_path?query", url.path);
|
||||
|
||||
wsfsp_impl_url_cleanup(&url);
|
||||
wfp_impl_url_cleanup(&url);
|
||||
}
|
||||
|
||||
TEST(url, FailToParseUnknownProtocol)
|
||||
{
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "unknown://localhost/");
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "unknown://localhost/");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
@@ -72,8 +72,8 @@ TEST(url, FailToParseUnknownProtocol)
|
||||
|
||||
TEST(url, FailToParseMissingProtocol)
|
||||
{
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "unknown");
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "unknown");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
@@ -82,8 +82,8 @@ TEST(url, FailToParseMissingProtocol)
|
||||
|
||||
TEST(url, FailToParseMissingPath)
|
||||
{
|
||||
struct wsfsp_impl_url url;
|
||||
bool result = wsfsp_impl_url_init(&url, "ws://localhost");
|
||||
struct wfp_impl_url url;
|
||||
bool result = wfp_impl_url_init(&url, "ws://localhost");
|
||||
ASSERT_FALSE(result);
|
||||
ASSERT_EQ(0, url.port);
|
||||
ASSERT_EQ(nullptr, url.path);
|
||||
|
||||
Reference in New Issue
Block a user