2019-03-23 21:53:14 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <gmock/gmock.h>
|
|
|
|
|
|
|
|
#include "mock_authenticator.hpp"
|
|
|
|
|
2019-03-26 14:35:33 +00:00
|
|
|
#include "wsfs/adapter/impl/authenticator.h"
|
|
|
|
#include "wsfs/adapter/impl/credentials.h"
|
2019-03-23 21:53:14 +00:00
|
|
|
|
|
|
|
using ::testing::Return;
|
|
|
|
using ::testing::_;
|
|
|
|
using ::wsfs_test::Authenticator;
|
|
|
|
using ::wsfs_test::MockAuthenticator;
|
|
|
|
using ::wsfs_test::set_authenticator;
|
|
|
|
using ::wsfs_test::authenticate;
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Authenticator, Authenticate)
|
|
|
|
{
|
|
|
|
MockAuthenticator mock;
|
|
|
|
set_authenticator(&mock);
|
|
|
|
|
|
|
|
struct wsfs_credentials creds;
|
2019-03-26 14:35:33 +00:00
|
|
|
wsfs_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 14:35:33 +00:00
|
|
|
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(
|
2019-03-23 21:53:14 +00:00
|
|
|
"username",
|
|
|
|
&authenticate,
|
|
|
|
user_data);
|
|
|
|
|
2019-03-26 14:35:33 +00:00
|
|
|
bool result = wsfs_impl_authenticator_autenticate(authenticator, &creds);
|
2019-03-23 21:53:14 +00:00
|
|
|
ASSERT_TRUE(result);
|
|
|
|
|
2019-03-26 14:35:33 +00:00
|
|
|
wsfs_impl_authenticator_dispose(authenticator);
|
|
|
|
wsfs_impl_credentials_cleanup(&creds);
|
2019-03-23 21:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Authenticator, SkipAuthenticationWithWrongType)
|
|
|
|
{
|
|
|
|
MockAuthenticator mock;
|
|
|
|
set_authenticator(&mock);
|
|
|
|
|
|
|
|
struct wsfs_credentials creds;
|
2019-03-26 14:35:33 +00:00
|
|
|
wsfs_impl_credentials_init(&creds, "username", nullptr);
|
2019-03-23 21:53:14 +00:00
|
|
|
EXPECT_CALL(mock, authenticate(_, _))
|
|
|
|
.Times(0);
|
|
|
|
|
2019-03-26 14:35:33 +00:00
|
|
|
struct wsfs_impl_authenticator * authenticator = wsfs_impl_authenticator_create(
|
2019-03-23 21:53:14 +00:00
|
|
|
"certificate",
|
|
|
|
&authenticate,
|
|
|
|
nullptr);
|
|
|
|
|
2019-03-26 14:35:33 +00:00
|
|
|
bool result = wsfs_impl_authenticator_autenticate(authenticator, &creds);
|
2019-03-23 21:53:14 +00:00
|
|
|
ASSERT_FALSE(result);
|
|
|
|
|
2019-03-26 14:35:33 +00:00
|
|
|
wsfs_impl_authenticator_dispose(authenticator);
|
|
|
|
wsfs_impl_credentials_cleanup(&creds);
|
2019-03-23 21:53:14 +00:00
|
|
|
}
|