mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
added first idea of API
This commit is contained in:
parent
3e563f00d6
commit
767bafcd01
@ -227,6 +227,27 @@ extern WFP_API void wfp_client_config_set_onread(
|
||||
struct wfp_client_config * config,
|
||||
wfp_read_fn * handler);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// \brief Enabled authentication with username and password.
|
||||
///
|
||||
/// Sets username and password for built-in username authentication.
|
||||
///
|
||||
/// \param config pointer to client configuration
|
||||
/// \param username pointer to username
|
||||
/// \param password pointer to password
|
||||
//------------------------------------------------------------------------------
|
||||
extern WFP_API void wfp_client_config_set_username_credentials(
|
||||
struct wfp_client_config * config,
|
||||
char const * username,
|
||||
char const * password);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
//------------------------------------------------------------------------------
|
||||
extern WFP_API void wfp_client_config_set_generic_credentials(
|
||||
struct wfp_client_config * config,
|
||||
char const * credentials_type,
|
||||
char const * contents[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -155,6 +155,23 @@ void wfp_client_config_set_onread(
|
||||
wfp_impl_client_config_set_onread(config, handler);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_username_credentials(
|
||||
struct wfp_client_config * config,
|
||||
char const * username,
|
||||
char const * password)
|
||||
{
|
||||
wfp_impl_client_config_set_username_credentials(config, username, password);
|
||||
}
|
||||
|
||||
void wfp_client_config_set_generic_credentials(
|
||||
struct wfp_client_config * config,
|
||||
char const * credentials_type,
|
||||
char const * contents[])
|
||||
{
|
||||
wfp_impl_client_config_set_generic_credentials(config, credentials_type, contents);
|
||||
}
|
||||
|
||||
|
||||
// protocol
|
||||
|
||||
|
||||
|
@ -110,3 +110,29 @@ void wfp_impl_client_config_set_onread(
|
||||
{
|
||||
config->provider.read = handler;
|
||||
}
|
||||
|
||||
|
||||
void wfp_impl_client_config_set_username_credentials(
|
||||
struct wfp_client_config * config,
|
||||
char const * username,
|
||||
char const * password)
|
||||
{
|
||||
(void) config;
|
||||
(void) username;
|
||||
(void) password;
|
||||
|
||||
// ToDo: implement me
|
||||
}
|
||||
|
||||
void wfp_impl_client_config_set_generic_credentials(
|
||||
struct wfp_client_config * config,
|
||||
char const * credentials_type,
|
||||
char const * contents[])
|
||||
{
|
||||
(void) config;
|
||||
(void) credentials_type;
|
||||
(void) contents;
|
||||
|
||||
// ToDo: implement me
|
||||
|
||||
}
|
||||
|
@ -70,6 +70,16 @@ extern void wfp_impl_client_config_set_onread(
|
||||
struct wfp_client_config * config,
|
||||
wfp_read_fn * handler);
|
||||
|
||||
extern void wfp_impl_client_config_set_username_credentials(
|
||||
struct wfp_client_config * config,
|
||||
char const * username,
|
||||
char const * password);
|
||||
|
||||
extern void wfp_impl_client_config_set_generic_credentials(
|
||||
struct wfp_client_config * config,
|
||||
char const * credentials_type,
|
||||
char const * contents[]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -45,6 +45,13 @@ public:
|
||||
wfp_client_config_dispose(config);
|
||||
}
|
||||
|
||||
void SetUsernameCredentials(
|
||||
std::string const & username,
|
||||
std::string const & password)
|
||||
{
|
||||
wfp_client_config_set_username_credentials(config, username.c_str(), password.c_str());
|
||||
}
|
||||
|
||||
void Connect()
|
||||
{
|
||||
wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/");
|
||||
@ -61,6 +68,47 @@ public:
|
||||
return server->receiveMessage();
|
||||
}
|
||||
|
||||
void AwaitAuthentication(
|
||||
std::string const & expected_username,
|
||||
std::string const & expected_password)
|
||||
{
|
||||
json_t * request = server->receiveMessage();
|
||||
ASSERT_TRUE(json_is_object(request));
|
||||
|
||||
json_t * method = json_object_get(request, "method");
|
||||
ASSERT_TRUE(json_is_string(method));
|
||||
ASSERT_STREQ("authenticate", json_string_value(method));
|
||||
|
||||
json_t * id = json_object_get(request, "id");
|
||||
ASSERT_TRUE(json_is_integer(id));
|
||||
|
||||
json_t * params = json_object_get(request, "params");
|
||||
ASSERT_TRUE(json_is_array(params));
|
||||
ASSERT_EQ(2, json_array_size(params));
|
||||
|
||||
json_t * type = json_array_get(params, 0);
|
||||
ASSERT_TRUE(json_is_string(type));
|
||||
ASSERT_STREQ("username", json_string_value(type));
|
||||
|
||||
json_t * credentials = json_array_get(params, 1);
|
||||
ASSERT_TRUE(json_is_object(credentials));
|
||||
|
||||
json_t * username = json_object_get(credentials, "username");
|
||||
ASSERT_TRUE(json_is_string(username));
|
||||
ASSERT_STREQ(expected_username.c_str(), json_string_value(username));
|
||||
|
||||
json_t * password = json_object_get(credentials, "password");
|
||||
ASSERT_TRUE(json_is_string(password));
|
||||
ASSERT_STREQ(expected_password.c_str(), json_string_value(password));
|
||||
|
||||
json_t * response = json_object();
|
||||
json_object_set_new(response, "result", json_object());
|
||||
json_object_set(response, "id", id);
|
||||
server->sendMessage(response);
|
||||
|
||||
json_decref(request);
|
||||
}
|
||||
|
||||
void AwaitAddFilesystem(std::string& filesystemName)
|
||||
{
|
||||
json_t * addFilesystemRequest = server->receiveMessage();
|
||||
@ -91,7 +139,6 @@ public:
|
||||
server->sendMessage(response);
|
||||
|
||||
json_decref(addFilesystemRequest);
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
@ -100,10 +147,8 @@ private:
|
||||
wfp_client_protocol * protocol;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST(client_protocol, connect)
|
||||
{
|
||||
MockProviderClient provider;
|
||||
@ -120,6 +165,27 @@ TEST(client_protocol, connect)
|
||||
if (HasFatalFailure()) { return; }
|
||||
}
|
||||
|
||||
TEST(client_protocol, connect_with_username_authentication)
|
||||
{
|
||||
MockProviderClient provider;
|
||||
ClientProtocolFixture fixture(provider);
|
||||
fixture.SetUsernameCredentials("bob", "secret");
|
||||
|
||||
EXPECT_CALL(provider, OnConnected()).Times(AtMost(1));
|
||||
EXPECT_CALL(provider, OnDisconnected()).Times(1);
|
||||
|
||||
fixture.Connect();
|
||||
if (HasFatalFailure()) { return; }
|
||||
|
||||
fixture.AwaitAuthentication("bob", "secret");
|
||||
if (HasFatalFailure()) { return; }
|
||||
|
||||
std::string filesystem;
|
||||
fixture.AwaitAddFilesystem(filesystem);
|
||||
if (HasFatalFailure()) { return; }
|
||||
|
||||
}
|
||||
|
||||
TEST(client_protocol, getattr)
|
||||
{
|
||||
MockProviderClient provider;
|
||||
|
Loading…
Reference in New Issue
Block a user