~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/plugin/authentication_test.cc

  • Committer: Brian Aker
  • Date: 2009-10-15 00:22:33 UTC
  • mto: (1183.1.11 merge)
  • mto: This revision was merged to the branch mainline in revision 1198.
  • Revision ID: brian@gaz-20091015002233-fa4ao2mbc67wls91
First pass of information engine. OMG, ponies... is it so much easier to
deal with creating and engine.

The list table iterator though... its ass, needs to go. We should also
abstract out share. Very few engines need a custom one. Just say'in

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
25
 
#include <drizzled/security_context.h>
26
 
#include <gtest/gtest.h>
27
 
#include <string>
28
 
 
29
 
#include "plugin_stubs.h"
30
 
 
31
 
using namespace drizzled;
32
 
 
33
 
static void error_handler_func_stub(uint32_t my_err, const char *str, myf MyFlags)
34
 
{
35
 
  (void)my_err;
36
 
  (void)str;
37
 
  (void)MyFlags;
38
 
}
39
 
 
40
 
class AuthenticationTest : public ::testing::Test
41
 
{
42
 
public:
43
 
  SecurityContext sctx;
44
 
  std::string passwd;
45
 
  AuthenticationStub stub1;
46
 
  AuthenticationStub stub2;
47
 
 
48
 
  AuthenticationTest() :
49
 
    stub1("AuthenticationStub1"),
50
 
    stub2("AuthenticationStub2")
51
 
  {}
52
 
  
53
 
  virtual void SetUp ()
54
 
  {
55
 
    error_handler_hook = error_handler_func_stub;
56
 
  }
57
 
 
58
 
  void addOnePlugin()
59
 
  {
60
 
    plugin::Authentication::addPlugin(&stub1);
61
 
  }
62
 
 
63
 
  void removeOnePlugin()
64
 
  {
65
 
    plugin::Authentication::removePlugin(&stub1);
66
 
  }
67
 
 
68
 
  void addTwoPlugins()
69
 
  {
70
 
    plugin::Authentication::addPlugin(&stub1);
71
 
    plugin::Authentication::addPlugin(&stub2);
72
 
  }
73
 
 
74
 
  void removeTwoPlugins()
75
 
  {
76
 
    plugin::Authentication::removePlugin(&stub1);
77
 
    plugin::Authentication::removePlugin(&stub2);
78
 
  }
79
 
  
80
 
};
81
 
 
82
 
TEST_F(AuthenticationTest, isAuthenticated_noPluginsLoaded_shouldReturn_True)
83
 
{
84
 
  bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
85
 
 
86
 
  ASSERT_TRUE(authenticated);
87
 
}
88
 
 
89
 
TEST_F(AuthenticationTest, isAuthenticated_OnePluginReturnigFalse_ShouldReturn_False)
90
 
{
91
 
 
92
 
  addOnePlugin();
93
 
  bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
94
 
  removeOnePlugin();
95
 
 
96
 
  ASSERT_FALSE(authenticated);
97
 
}
98
 
 
99
 
TEST_F(AuthenticationTest, isAuthenticated_OnePluginReturnigTrue_ShouldReturn_True)
100
 
{
101
 
 
102
 
  stub1.set_authenticate_return(true);
103
 
  
104
 
  addOnePlugin();
105
 
  bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
106
 
  removeOnePlugin();
107
 
  
108
 
  ASSERT_TRUE(authenticated);
109
 
}
110
 
 
111
 
TEST_F(AuthenticationTest, isAuthenticated_TwoPluginsBothReturnigFalse_ShouldReturn_False)
112
 
{
113
 
 
114
 
  addTwoPlugins();
115
 
  bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
116
 
  removeTwoPlugins();
117
 
  
118
 
  ASSERT_FALSE(authenticated);
119
 
}
120
 
 
121
 
TEST_F(AuthenticationTest, isAuthenticated_TwoPluginsOnlyOneReturnigTrue_ShouldReturn_True)
122
 
{
123
 
  stub2.set_authenticate_return(true);
124
 
  
125
 
  addTwoPlugins();
126
 
  bool authenticated = plugin::Authentication::isAuthenticated(sctx, passwd);
127
 
  removeTwoPlugins();
128
 
  
129
 
  ASSERT_TRUE(authenticated);
130
 
}
131
 
 
132