You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
falk-werner_webfuse/test/test_credentials.cc

71 lines
2.1 KiB

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
6 years ago
#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);
}