1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00
falk-werner_webfuse-provider/test/test_credentials.cc

71 lines
2.1 KiB
C++
Raw Normal View History

Feature/authentication (#14) * makes wsfs_server_config opaque * feature: try to create mount point, if not present * fixes server start failure due to existing mountpoint * added basic authentication infrastructure * makes wsfs_server_config opaque * feature: try to create mount point, if not present * fixes server start failure due to existing mountpoint * added basic authentication infrastructure * added unit tests for credentials * added unit tests for authenticators * propagates authenticators to server protocol * enabled username authentication in daemon example * adds example to compute password hash * adds infrastructure to execute commands * added userdb to encapsulate authentication stuff * adds session and session_manager * fixes warning about unused param * moves some logic from server_protocol to session * makes wsfs_server_config opaque * feature: try to create mount point, if not present * fixes server start failure due to existing mountpoint * added basic authentication infrastructure * makes wsfs_server_config opaque * added unit tests for credentials * added unit tests for authenticators * propagates authenticators to server protocol * enabled username authentication in daemon example * adds example to compute password hash * adds infrastructure to execute commands * added userdb to encapsulate authentication stuff * adds session and session_manager * fixes warning about unused param * moves some logic from server_protocol to session * updates libcrypto to version 1.1.0
2019-03-23 21:53:14 +00:00
#include <gtest/gtest.h>
#include "wsfs/adapter/credentials_intern.h"
#include <jansson.h>
TEST(Credentials, Type)
{
struct wsfs_credentials creds;
wsfs_credentials_init(&creds, "test", nullptr);
ASSERT_STREQ("test", wsfs_credentials_type(&creds));
wsfs_credentials_cleanup(&creds);
}
TEST(Credentials, Get)
{
struct wsfs_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_credentials_init(&creds, "username", data);
ASSERT_STREQ("username", wsfs_credentials_type(&creds));
ASSERT_STREQ("bob", wsfs_credentials_get(&creds, "username"));
ASSERT_STREQ("<secret>", wsfs_credentials_get(&creds, "password"));
wsfs_credentials_cleanup(&creds);
json_decref(data);
}
TEST(Credentials, FailedToGetNonexistingValue)
{
struct wsfs_credentials creds;
json_t * data = json_object();
wsfs_credentials_init(&creds, "username", data);
ASSERT_STREQ("username", wsfs_credentials_type(&creds));
ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "username"));
ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "password"));
wsfs_credentials_cleanup(&creds);
json_decref(data);
}
TEST(Credentials, FailedToGetWithoutData)
{
struct wsfs_credentials creds;
wsfs_credentials_init(&creds, "username", nullptr);
ASSERT_STREQ("username", wsfs_credentials_type(&creds));
ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "username"));
ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "password"));
wsfs_credentials_cleanup(&creds);
}
TEST(Credentials, FailedToGetWrongDataType)
{
struct wsfs_credentials creds;
json_t * data = json_string("invalid_creds");
wsfs_credentials_init(&creds, "username", data);
ASSERT_STREQ("username", wsfs_credentials_type(&creds));
ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "username"));
ASSERT_STREQ(nullptr, wsfs_credentials_get(&creds, "password"));
wsfs_credentials_cleanup(&creds);
json_decref(data);
}