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

changed credentials API

This commit is contained in:
Falk Werner 2020-02-25 22:05:48 +01:00
parent 767bafcd01
commit c6ca2e14bd
12 changed files with 140 additions and 66 deletions

View File

@ -9,6 +9,7 @@ add_library(webfuse-provider-static STATIC
lib/webfuse/provider/impl/provider.c lib/webfuse/provider/impl/provider.c
lib/webfuse/provider/impl/request.c lib/webfuse/provider/impl/request.c
lib/webfuse/provider/impl/dirbuffer.c lib/webfuse/provider/impl/dirbuffer.c
lib/webfuse/provider/impl/credentials.c
lib/webfuse/provider/impl/operation/lookup.c lib/webfuse/provider/impl/operation/lookup.c
lib/webfuse/provider/impl/operation/getattr.c lib/webfuse/provider/impl/operation/getattr.c
lib/webfuse/provider/impl/operation/readdir.c lib/webfuse/provider/impl/operation/readdir.c

View File

@ -14,6 +14,7 @@
#include <webfuse/provider/operation/open.h> #include <webfuse/provider/operation/open.h>
#include <webfuse/provider/operation/close.h> #include <webfuse/provider/operation/close.h>
#include <webfuse/provider/operation/read.h> #include <webfuse/provider/operation/read.h>
#include <webfuse/provider/credentials.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -228,25 +229,15 @@ extern WFP_API void wfp_client_config_set_onread(
wfp_read_fn * handler); wfp_read_fn * handler);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/// \brief Enabled authentication with username and password. /// \brief Enabled authentication.
///
/// Sets username and password for built-in username authentication.
/// ///
/// \param config pointer to client configuration /// \param config pointer to client configuration
/// \param username pointer to username /// \param get_credentials pointer to function providing credentials when
/// \param password pointer to password // needed.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_username_credentials( extern WFP_API void wfp_client_config_enable_authentication(
struct wfp_client_config * config, struct wfp_client_config * config,
char const * username, wfp_get_credentials_fn * get_credentials);
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 #ifdef __cplusplus
} }

View File

@ -0,0 +1,30 @@
#ifndef WF_PROVIDER_CREDENTIALS_H
#define WF_PROVIDER_CREDENTIALS_H
#include <webfuse/provider/api.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_credentials;
typedef void wfp_get_credentials_fn(
struct wfp_credentials * credentials,
void * user_data);
extern WFP_API void wfp_credentials_set_type(
struct wfp_credentials * credentials,
char const * type);
extern WFP_API void wfp_credentials_add(
struct wfp_credentials * credentials,
char const * key,
char const * value);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -14,6 +14,7 @@
#include <webfuse/provider/client_config.h> #include <webfuse/provider/client_config.h>
#include <webfuse/provider/client_protocol.h> #include <webfuse/provider/client_protocol.h>
#include <webfuse/provider/dirbuffer.h> #include <webfuse/provider/dirbuffer.h>
#include <webfuse/provider/credentials.h>
#include <webfuse/provider/operation/error.h> #include <webfuse/provider/operation/error.h>
#include <webfuse/provider/operation/lookup.h> #include <webfuse/provider/operation/lookup.h>

View File

@ -11,6 +11,7 @@
#include "webfuse/provider/impl/client_config.h" #include "webfuse/provider/impl/client_config.h"
#include "webfuse/provider/impl/client.h" #include "webfuse/provider/impl/client.h"
#include "webfuse/provider/impl/dirbuffer.h" #include "webfuse/provider/impl/dirbuffer.h"
#include "webfuse/provider/impl/credentials.h"
// respond // respond
@ -155,23 +156,13 @@ void wfp_client_config_set_onread(
wfp_impl_client_config_set_onread(config, handler); wfp_impl_client_config_set_onread(config, handler);
} }
void wfp_client_config_set_username_credentials( void wfp_client_config_enable_authentication(
struct wfp_client_config * config, struct wfp_client_config * config,
char const * username, wfp_get_credentials_fn * get_credentials)
char const * password)
{ {
wfp_impl_client_config_set_username_credentials(config, username, password); wfp_impl_client_config_enable_authentication(config, get_credentials);
} }
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 // protocol
@ -257,3 +248,20 @@ void wfp_dirbuffer_add(
{ {
wfp_impl_dirbuffer_add(buffer, name, inode); wfp_impl_dirbuffer_add(buffer, name, inode);
} }
// credentials
void wfp_credentials_set_type(
struct wfp_credentials * credentials,
char const * type)
{
wfp_impl_credentials_set_type(credentials, type);
}
void wfp_credentials_add(
struct wfp_credentials * credentials,
char const * key,
char const * value)
{
wfp_impl_credentials_add(credentials, key, value);
}

View File

@ -111,28 +111,9 @@ void wfp_impl_client_config_set_onread(
config->provider.read = handler; config->provider.read = handler;
} }
void wfp_impl_client_config_enable_authentication(
void wfp_impl_client_config_set_username_credentials(
struct wfp_client_config * config, struct wfp_client_config * config,
char const * username, wfp_get_credentials_fn * get_credentials)
char const * password)
{ {
(void) config; config->provider.get_credentials = get_credentials;
(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
} }

View File

@ -70,15 +70,9 @@ extern void wfp_impl_client_config_set_onread(
struct wfp_client_config * config, struct wfp_client_config * config,
wfp_read_fn * handler); wfp_read_fn * handler);
extern void wfp_impl_client_config_set_username_credentials( extern void wfp_impl_client_config_enable_authentication(
struct wfp_client_config * config, struct wfp_client_config * config,
char const * username, wfp_get_credentials_fn * get_credentials);
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 #ifdef __cplusplus
} }

View File

@ -0,0 +1,34 @@
#include "webfuse/provider/impl/credentials.h"
#include <stdlib.h>
#include <string.h>
void wfp_impl_credentials_init(
struct wfp_credentials * credentials)
{
credentials->type = NULL;
credentials->contents = json_object();
}
void wfp_impl_credentials_cleanup(
struct wfp_credentials * credentials)
{
free(credentials->type);
json_decref(credentials->contents);
}
void wfp_impl_credentials_set_type(
struct wfp_credentials * credentials,
char const * type)
{
free(credentials->type);
credentials->type = strdup(type);
}
void wfp_impl_credentials_add(
struct wfp_credentials * credentials,
char const * key,
char const * value)
{
json_object_set_new(credentials->contents, key, json_string(value));
}

View File

@ -0,0 +1,38 @@
#ifndef WF_PROVIDER_IMPL_CREDENTIALS_H
#define WF_PROVIDER_IMPL_CREDENTIALS_H
#include "webfuse/provider/credentials.h"
#include <jansson.h>
#ifdef __cplusplus
extern "C"
{
#endif
struct wfp_credentials
{
char * type;
json_t * contents;
};
extern void wfp_impl_credentials_init(
struct wfp_credentials * credentials);
extern void wfp_impl_credentials_cleanup(
struct wfp_credentials * credentials);
extern void wfp_impl_credentials_set_type(
struct wfp_credentials * credentials,
char const * type);
extern void wfp_impl_credentials_add(
struct wfp_credentials * credentials,
char const * key,
char const * value);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -67,6 +67,7 @@ void wfp_impl_provider_init(
provider->connected = &wfp_impl_connected_default; provider->connected = &wfp_impl_connected_default;
provider->disconnected = &wfp_impl_disconnected_default; provider->disconnected = &wfp_impl_disconnected_default;
provider->ontimer = &wfp_impl_ontimer_default; provider->ontimer = &wfp_impl_ontimer_default;
provider->get_credentials = NULL;
} }
void wfp_impl_provider_init_from_prototype( void wfp_impl_provider_init_from_prototype(
@ -82,6 +83,7 @@ void wfp_impl_provider_init_from_prototype(
provider->connected = prototype->connected; provider->connected = prototype->connected;
provider->disconnected = prototype->disconnected; provider->disconnected = prototype->disconnected;
provider->ontimer = prototype->ontimer; provider->ontimer = prototype->ontimer;
provider->get_credentials = prototype->get_credentials;
} }
void wfp_impl_provider_invoke( void wfp_impl_provider_invoke(

View File

@ -20,6 +20,7 @@ struct wfp_provider
wfp_open_fn * open; wfp_open_fn * open;
wfp_close_fn * close; wfp_close_fn * close;
wfp_read_fn * read; wfp_read_fn * read;
wfp_get_credentials_fn * get_credentials;
}; };
struct wfp_impl_invokation_context struct wfp_impl_invokation_context

View File

@ -45,13 +45,6 @@ public:
wfp_client_config_dispose(config); 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() void Connect()
{ {
wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/"); wfp_client_protocol_connect(protocol, server->getContext(), "ws://localhost:54321/");
@ -169,7 +162,7 @@ TEST(client_protocol, connect_with_username_authentication)
{ {
MockProviderClient provider; MockProviderClient provider;
ClientProtocolFixture fixture(provider); ClientProtocolFixture fixture(provider);
fixture.SetUsernameCredentials("bob", "secret"); // ToDo: enable authentication
EXPECT_CALL(provider, OnConnected()).Times(AtMost(1)); EXPECT_CALL(provider, OnConnected()).Times(AtMost(1));
EXPECT_CALL(provider, OnDisconnected()).Times(1); EXPECT_CALL(provider, OnDisconnected()).Times(1);