git.fiddlerwoaroof.com
Browse code

refactor

Greg Wiley authored on 18/04/2017 22:23:31
Showing 4 changed files
... ...
@@ -24,12 +24,12 @@ class conversation_result {
24 24
 class conversations_ifc {
25 25
     public:
26 26
         virtual ~conversations_ifc() {}
27
-        virtual conversation_result initiate_conversation() = 0;
27
+        virtual conversation_result initiate_conversation() {
28
+            return conversation_result("","");
29
+        }
28 30
 };
29 31
 typedef std::shared_ptr<conversations_ifc> conversations;
30 32
 
31
-
32
-
33 33
 class token_conversation {
34 34
     public:
35 35
         virtual ~token_conversation() {}
... ...
@@ -16,7 +16,6 @@ class dual_control_ifc {
16 16
         virtual int authenticate(pam_handle_t *handle, int flags, const std::vector<const std::string> &arguments ) = 0;
17 17
         virtual int setcred(pam_handle_t *handle, int flags, const std::vector<const std::string> &arguments) = 0;
18 18
 };
19
-
20 19
 typedef std::shared_ptr<dual_control_ifc> dual_control;
21 20
 
22 21
 struct dual_control_configuration {
... ...
@@ -24,12 +23,11 @@ struct dual_control_configuration {
24 23
     conversations conversations;
25 24
     logger logger;
26 25
     dual_control_configuration()
27
-        : logger(new logger_ifc) {}
26
+        : validator(new validator_ifc),
27
+          conversations(new conversations_ifc),
28
+          logger(new logger_ifc) {}
28 29
 };
29
-
30 30
 dual_control create_dual_control(const dual_control_configuration &configuration);
31 31
 
32
-
33
-
34 32
 #endif
35 33
 
... ...
@@ -77,7 +77,7 @@ int authenticate_validates_with_received_token() {
77 77
     configuration.validator = validator(new fake_validator(user, token));
78 78
     configuration.conversations = conversations(new fake_conversations(user, token));
79 79
     dual_control dc(create_dual_control(configuration));
80
-    pam_handle_t *handle = (pam_handle_t*)"";
80
+    pam_handle_t *handle(0);
81 81
     std::vector<const std::string> arguments;
82 82
 
83 83
     // when
... ...
@@ -95,7 +95,7 @@ int authenticate_fails_with_wrong_user() {
95 95
     configuration.validator = validator(new fake_validator("user", token));
96 96
     configuration.conversations = conversations(new fake_conversations("wrong user", token));
97 97
     dual_control dc(create_dual_control(configuration));
98
-    pam_handle_t *handle = (pam_handle_t*)"";
98
+    pam_handle_t *handle(0);
99 99
     std::vector<const std::string> arguments;
100 100
 
101 101
     // when
... ...
@@ -113,7 +113,7 @@ int authenticate_fails_with_wrong_token() {
113 113
     configuration.validator = validator(new fake_validator(user, "token"));
114 114
     configuration.conversations = conversations(new fake_conversations(user, "wrong token"));
115 115
     dual_control dc(create_dual_control(configuration));
116
-    pam_handle_t *handle = (pam_handle_t*)"";
116
+    pam_handle_t *handle(0);
117 117
     std::vector<const std::string> arguments;
118 118
 
119 119
     // when
... ...
@@ -134,7 +134,7 @@ int logs_authentication() {
134 134
     mock_logger *test_logger = new mock_logger;
135 135
     configuration.logger = logger(test_logger);
136 136
     dual_control dc(create_dual_control(configuration));
137
-    pam_handle_t *handle = (pam_handle_t*)"";
137
+    pam_handle_t *handle(0);
138 138
     std::vector<const std::string> arguments;
139 139
 
140 140
     //when
... ...
@@ -152,12 +152,12 @@ int logs_authentication_failure() {
152 152
     dual_control_configuration configuration;
153 153
     std::string user("user");
154 154
     std::string token("token");
155
-    configuration.validator = validator(new fake_validator(user, "not_token"));
155
+    configuration.validator = validator(new fake_validator(user, "not the received token"));
156 156
     configuration.conversations = conversations(new fake_conversations(user, token));
157 157
     mock_logger *test_logger = new mock_logger;
158 158
     configuration.logger = logger(test_logger);
159 159
     dual_control dc(create_dual_control(configuration));
160
-    pam_handle_t *handle = (pam_handle_t*)"";
160
+    pam_handle_t *handle(0);
161 161
     std::vector<const std::string> arguments;
162 162
 
163 163
     //when
... ...
@@ -10,12 +10,13 @@
10 10
 class validator_ifc {
11 11
     public:
12 12
         virtual ~validator_ifc() {}
13
-        virtual bool validate(const std::string &user, const std::string &token) = 0;
13
+        virtual bool validate(const std::string &user, const std::string &token) {
14
+           return false;
15
+        }
14 16
 };
15 17
 
16 18
 typedef std::shared_ptr<validator_ifc> validator;
17 19
 
18
-
19 20
 class old_validator {
20 21
     private:
21 22
         directory_p directory_;
... ...
@@ -27,5 +28,4 @@ class old_validator {
27 28
         bool validate(const std::string &user, const std::string &token);
28 29
 };
29 30
 
30
-
31 31
 #endif