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/security_context.h>
26
#include <gtest/gtest.h>
29
#include "plugin_stubs.h"
31
using namespace drizzled;
33
static void error_handler_func_stub(uint32_t my_err, const char *str, myf MyFlags)
40
class AuthenticationTest : public ::testing::Test
45
AuthenticationStub stub1;
46
AuthenticationStub stub2;
48
AuthenticationTest() :
49
stub1("AuthenticationStub1"),
50
stub2("AuthenticationStub2")
55
error_handler_hook = error_handler_func_stub;
60
plugin::Authentication::addPlugin(&stub1);
63
void removeOnePlugin()
65
plugin::Authentication::removePlugin(&stub1);
70
plugin::Authentication::addPlugin(&stub1);
71
plugin::Authentication::addPlugin(&stub2);
74
void removeTwoPlugins()
76
plugin::Authentication::removePlugin(&stub1);
77
plugin::Authentication::removePlugin(&stub2);
82
TEST_F(AuthenticationTest, isAuthenticated_noPluginsLoaded_shouldReturn_True)
84
bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
86
ASSERT_TRUE(authenticated);
89
TEST_F(AuthenticationTest, isAuthenticated_OnePluginReturnigFalse_ShouldReturn_False)
93
bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
96
ASSERT_FALSE(authenticated);
99
TEST_F(AuthenticationTest, isAuthenticated_OnePluginReturnigTrue_ShouldReturn_True)
102
stub1.set_authenticate_return(true);
105
bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
108
ASSERT_TRUE(authenticated);
111
TEST_F(AuthenticationTest, isAuthenticated_TwoPluginsBothReturnigFalse_ShouldReturn_False)
115
bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
118
ASSERT_FALSE(authenticated);
121
TEST_F(AuthenticationTest, isAuthenticated_TwoPluginsOnlyOneReturnigTrue_ShouldReturn_True)
123
stub2.set_authenticate_return(true);
126
bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
129
ASSERT_TRUE(authenticated);