2019-03-23 21:53:14 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
2020-02-20 16:15:13 +00:00
|
|
|
#include "webfuse/mocks/mock_authenticator.hpp"
|
2019-03-23 21:53:14 +00:00
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
#include "webfuse/adapter/impl/authenticator.h"
|
|
|
|
#include "webfuse/adapter/impl/credentials.h"
|
2019-03-23 21:53:14 +00:00
|
|
|
|
|
|
|
using ::testing::Return;
|
|
|
|
using ::testing::_;
|
2019-03-26 22:04:53 +00:00
|
|
|
using ::webfuse_test::Authenticator;
|
|
|
|
using ::webfuse_test::MockAuthenticator;
|
|
|
|
using ::webfuse_test::set_authenticator;
|
|
|
|
using ::webfuse_test::authenticate;
|
2019-03-23 21:53:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(Authenticator, Authenticate)
|
|
|
|
{
|
|
|
|
MockAuthenticator mock;
|
|
|
|
set_authenticator(&mock);
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
struct wf_credentials creds;
|
|
|
|
wf_impl_credentials_init(&creds, "username", nullptr);
|
2019-03-23 21:53:14 +00:00
|
|
|
char dummy[] = "usr_data";
|
|
|
|
void * user_data = reinterpret_cast<void*>(dummy);
|
|
|
|
|
|
|
|
EXPECT_CALL(mock, authenticate(&creds, user_data))
|
|
|
|
.Times(1)
|
|
|
|
.WillRepeatedly(Return(true));
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
struct wf_impl_authenticator * authenticator = wf_impl_authenticator_create(
|
2019-03-23 21:53:14 +00:00
|
|
|
"username",
|
|
|
|
&authenticate,
|
|
|
|
user_data);
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
bool result = wf_impl_authenticator_autenticate(authenticator, &creds);
|
2019-03-23 21:53:14 +00:00
|
|
|
ASSERT_TRUE(result);
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
wf_impl_authenticator_dispose(authenticator);
|
|
|
|
wf_impl_credentials_cleanup(&creds);
|
2019-03-23 21:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Authenticator, SkipAuthenticationWithWrongType)
|
|
|
|
{
|
|
|
|
MockAuthenticator mock;
|
|
|
|
set_authenticator(&mock);
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
struct wf_credentials creds;
|
|
|
|
wf_impl_credentials_init(&creds, "username", nullptr);
|
2019-03-23 21:53:14 +00:00
|
|
|
EXPECT_CALL(mock, authenticate(_, _))
|
|
|
|
.Times(0);
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
struct wf_impl_authenticator * authenticator = wf_impl_authenticator_create(
|
2019-03-23 21:53:14 +00:00
|
|
|
"certificate",
|
|
|
|
&authenticate,
|
|
|
|
nullptr);
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
bool result = wf_impl_authenticator_autenticate(authenticator, &creds);
|
2019-03-23 21:53:14 +00:00
|
|
|
ASSERT_FALSE(result);
|
|
|
|
|
2019-03-26 22:04:53 +00:00
|
|
|
wf_impl_authenticator_dispose(authenticator);
|
|
|
|
wf_impl_credentials_cleanup(&creds);
|
2019-03-23 21:53:14 +00:00
|
|
|
}
|