~drizzle-trunk/drizzle/development

1377.8.42 by Paweł Blokus
authentication plugin tests
1
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
*
4
*  Copyright (C) 2010 Pawel Blokus
5
*
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.
10
*
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.
15
*
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
19
*/
20
21
#include "config.h"
22
23
#include <drizzled/error.h>
24
#include <drizzled/plugin/authentication.h>
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
25
#include <drizzled/identifier.h>
1377.8.42 by Paweł Blokus
authentication plugin tests
26
#include <gtest/gtest.h>
27
#include <string>
28
29
#include "plugin_stubs.h"
30
31
using namespace drizzled;
32
2087.3.1 by Brian Aker
Entire convert over to time_t.
33
static void error_handler_func_stub(drizzled::error_t my_err, const char *str, myf MyFlags)
1377.8.42 by Paweł Blokus
authentication plugin tests
34
{
35
  (void)my_err;
36
  (void)str;
37
  (void)MyFlags;
38
}
39
40
class AuthenticationTest : public ::testing::Test
41
{
42
public:
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
43
  identifier::User::const_shared_ptr sctx;
1377.8.42 by Paweł Blokus
authentication plugin tests
44
  std::string passwd;
45
  AuthenticationStub stub1;
46
  AuthenticationStub stub2;
47
48
  AuthenticationTest() :
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
49
    sctx(drizzled::identifier::User::make_shared()),
1377.8.42 by Paweł Blokus
authentication plugin tests
50
    stub1("AuthenticationStub1"),
51
    stub2("AuthenticationStub2")
2008.1.1 by Brian Aker
Adding user identifier that makes use of a shared ptr to handle concurrency
52
  {
53
  }
1377.8.42 by Paweł Blokus
authentication plugin tests
54
  
55
  virtual void SetUp ()
56
  {
57
    error_handler_hook = error_handler_func_stub;
58
  }
59
60
  void addOnePlugin()
61
  {
62
    plugin::Authentication::addPlugin(&stub1);
63
  }
64
65
  void removeOnePlugin()
66
  {
67
    plugin::Authentication::removePlugin(&stub1);
68
  }
69
70
  void addTwoPlugins()
71
  {
72
    plugin::Authentication::addPlugin(&stub1);
73
    plugin::Authentication::addPlugin(&stub2);
74
  }
75
76
  void removeTwoPlugins()
77
  {
78
    plugin::Authentication::removePlugin(&stub1);
79
    plugin::Authentication::removePlugin(&stub2);
80
  }
81
  
82
};
83
84
TEST_F(AuthenticationTest, isAuthenticated_noPluginsLoaded_shouldReturn_True)
85
{
86
  bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
87
88
  ASSERT_TRUE(authenticated);
89
}
90
91
TEST_F(AuthenticationTest, isAuthenticated_OnePluginReturnigFalse_ShouldReturn_False)
92
{
93
94
  addOnePlugin();
95
  bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
96
  removeOnePlugin();
97
98
  ASSERT_FALSE(authenticated);
99
}
100
101
TEST_F(AuthenticationTest, isAuthenticated_OnePluginReturnigTrue_ShouldReturn_True)
102
{
103
104
  stub1.set_authenticate_return(true);
105
  
106
  addOnePlugin();
107
  bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
108
  removeOnePlugin();
109
  
110
  ASSERT_TRUE(authenticated);
111
}
112
113
TEST_F(AuthenticationTest, isAuthenticated_TwoPluginsBothReturnigFalse_ShouldReturn_False)
114
{
115
116
  addTwoPlugins();
117
  bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
118
  removeTwoPlugins();
119
  
120
  ASSERT_FALSE(authenticated);
121
}
122
123
TEST_F(AuthenticationTest, isAuthenticated_TwoPluginsOnlyOneReturnigTrue_ShouldReturn_True)
124
{
125
  stub2.set_authenticate_return(true);
126
  
127
  addTwoPlugins();
128
  bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
129
  removeTwoPlugins();
130
  
131
  ASSERT_TRUE(authenticated);
132
}
133
134