1
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Pawel Blokus
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include <drizzled/error.h>
24
#include <drizzled/plugin/authentication.h>
25
#include <drizzled/identifier.h>
26
#include <gtest/gtest.h>
29
#include "plugin_stubs.h"
31
using namespace drizzled;
33
static void error_handler_func_stub(drizzled::error_t my_err, const char *str, myf MyFlags)
40
class AuthenticationTest : public ::testing::Test
43
identifier::User::const_shared_ptr sctx;
45
AuthenticationStub stub1;
46
AuthenticationStub stub2;
48
AuthenticationTest() :
49
sctx(drizzled::identifier::User::make_shared()),
50
stub1("AuthenticationStub1"),
51
stub2("AuthenticationStub2")
57
error_handler_hook = error_handler_func_stub;
62
plugin::Authentication::addPlugin(&stub1);
65
void removeOnePlugin()
67
plugin::Authentication::removePlugin(&stub1);
72
plugin::Authentication::addPlugin(&stub1);
73
plugin::Authentication::addPlugin(&stub2);
76
void removeTwoPlugins()
78
plugin::Authentication::removePlugin(&stub1);
79
plugin::Authentication::removePlugin(&stub2);
84
TEST_F(AuthenticationTest, isAuthenticated_noPluginsLoaded_shouldReturn_True)
86
bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
88
ASSERT_TRUE(authenticated);
91
TEST_F(AuthenticationTest, isAuthenticated_OnePluginReturnigFalse_ShouldReturn_False)
95
bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
98
ASSERT_FALSE(authenticated);
101
TEST_F(AuthenticationTest, isAuthenticated_OnePluginReturnigTrue_ShouldReturn_True)
104
stub1.set_authenticate_return(true);
107
bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
110
ASSERT_TRUE(authenticated);
113
TEST_F(AuthenticationTest, isAuthenticated_TwoPluginsBothReturnigFalse_ShouldReturn_False)
117
bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
120
ASSERT_FALSE(authenticated);
123
TEST_F(AuthenticationTest, isAuthenticated_TwoPluginsOnlyOneReturnigTrue_ShouldReturn_True)
125
stub2.set_authenticate_return(true);
128
bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
131
ASSERT_TRUE(authenticated);