mirror of
https://github.com/falk-werner/webfused
synced 2024-10-27 20:44:08 +00:00
use wrap utility
This commit is contained in:
parent
90fc495d95
commit
ea56c6e86c
@ -59,8 +59,8 @@ TEST(file_authenticator, authenticate)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_TRUE(is_authenticated);
|
||||
@ -78,8 +78,8 @@ TEST(file_authenticator, authenticate_fail_wrong_passwd)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("unkown"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("unkown"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -97,8 +97,8 @@ TEST(file_authenticator, authenticate_fail_no_passwd_file)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secred"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secred"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -116,8 +116,8 @@ TEST(file_authenticator, authenticate_fail_missing_username)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("unkown"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("unkown"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -135,8 +135,8 @@ TEST(file_authenticator, authenticate_fail_missing_password)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return(nullptr));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
|
@ -61,8 +61,8 @@ TEST(pam_authenticator, authenticate)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_TRUE(is_authenticated);
|
||||
@ -87,8 +87,8 @@ TEST(pam_authenticator, authenticate_with_custom_service_name)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_TRUE(is_authenticated);
|
||||
@ -144,8 +144,8 @@ TEST(pam_authenticator, conversation_with_valid_messages)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_TRUE(is_authenticated);
|
||||
@ -190,8 +190,8 @@ TEST(pam_authenticator, conversation_with_invalid_messages)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -211,8 +211,8 @@ TEST(pam_authenticator, authenticate_fail_authenticate)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -233,8 +233,8 @@ TEST(pam_authenticator, authenticate_fail_acct_mgmt)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -251,8 +251,8 @@ TEST(pam_authenticator, authenticate_fail_missing_username)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return("secret"));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
@ -269,8 +269,8 @@ TEST(pam_authenticator, authenticate_fail_missing_password)
|
||||
ASSERT_TRUE(success);
|
||||
|
||||
MockCredentials creds;
|
||||
EXPECT_CALL(creds, get(StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, get(StrEq("password"))).Times(1).WillOnce(Return(nullptr));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("username"))).Times(1).WillOnce(Return("bob"));
|
||||
EXPECT_CALL(creds, wf_credentials_get(_,StrEq("password"))).Times(1).WillOnce(Return(nullptr));
|
||||
|
||||
bool is_authenticated = wfd_authenticator_authenticate(authenticator, nullptr);
|
||||
ASSERT_FALSE(is_authenticated);
|
||||
|
@ -1,50 +1,12 @@
|
||||
#include "mock/credentials.hpp"
|
||||
|
||||
#include "util/wrap.hpp"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
using webfused_test::ICredentials;
|
||||
|
||||
static ICredentials * wfd_mock_credentials = nullptr;
|
||||
|
||||
extern char const *
|
||||
__real_wf_credentials_type(
|
||||
struct wf_credentials const * credentials);
|
||||
|
||||
char const *
|
||||
__wrap_wf_credentials_type(
|
||||
struct wf_credentials const * credentials)
|
||||
{
|
||||
if (nullptr == wfd_mock_credentials)
|
||||
{
|
||||
return __real_wf_credentials_type(credentials);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_credentials->type();
|
||||
}
|
||||
}
|
||||
|
||||
extern char const * __real_wf_credentials_get(
|
||||
struct wf_credentials const * credentials,
|
||||
char const * key);
|
||||
|
||||
|
||||
char const * __wrap_wf_credentials_get(
|
||||
struct wf_credentials const * credentials,
|
||||
char const * key)
|
||||
{
|
||||
if (nullptr == wfd_mock_credentials)
|
||||
{
|
||||
return __real_wf_credentials_get(credentials, key);
|
||||
}
|
||||
else
|
||||
{
|
||||
return wfd_mock_credentials->get(key);
|
||||
}
|
||||
}
|
||||
|
||||
static webfused_test::ICredentials * wfd_MockCredentials = nullptr;
|
||||
|
||||
WFD_WRAP_FUNC1(wfd_MockCredentials, char const *, wf_credentials_type, struct wf_credentials const *);
|
||||
WFD_WRAP_FUNC2(wfd_MockCredentials, char const *, wf_credentials_get, struct wf_credentials const *, char const *);
|
||||
}
|
||||
|
||||
|
||||
@ -53,12 +15,12 @@ namespace webfused_test
|
||||
|
||||
MockCredentials::MockCredentials()
|
||||
{
|
||||
wfd_mock_credentials = this;
|
||||
wfd_MockCredentials = this;
|
||||
}
|
||||
|
||||
MockCredentials::~MockCredentials()
|
||||
{
|
||||
wfd_mock_credentials = nullptr;
|
||||
wfd_MockCredentials = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ class ICredentials
|
||||
{
|
||||
public:
|
||||
virtual ~ICredentials() = default;
|
||||
virtual char const * type() = 0;
|
||||
virtual char const * get(char const * key) = 0;
|
||||
virtual char const * wf_credentials_type(struct wf_credentials const * credentials) = 0;
|
||||
virtual char const * wf_credentials_get(struct wf_credentials const * credentials, char const * key) = 0;
|
||||
};
|
||||
|
||||
class MockCredentials: public ICredentials
|
||||
@ -20,8 +20,8 @@ class MockCredentials: public ICredentials
|
||||
public:
|
||||
MockCredentials();
|
||||
virtual ~MockCredentials();
|
||||
MOCK_METHOD0(type, char const*());
|
||||
MOCK_METHOD1(get, char const *(char const * key));
|
||||
MOCK_METHOD1(wf_credentials_type, char const*(struct wf_credentials const * credentials));
|
||||
MOCK_METHOD2(wf_credentials_get, char const *(struct wf_credentials const * credentials, char const * key));
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user