git.fiddlerwoaroof.com
Browse code

logs pam auth error

Greg Wiley authored on 18/04/2017 22:15:04
Showing 1 changed files
... ...
@@ -147,84 +147,45 @@ int logs_authentication() {
147 147
     succeed();
148 148
 }
149 149
 
150
-RESET_VARS_START
151
-RESET_VARS_END
150
+int logs_authentication_failure() {
151
+    //given
152
+    dual_control_configuration configuration;
153
+    std::string user("user");
154
+    std::string token("token");
155
+    configuration.validator = validator(new fake_validator(user, "not_token"));
156
+    configuration.conversations = conversations(new fake_conversations(user, token));
157
+    mock_logger *test_logger = new mock_logger;
158
+    configuration.logger = logger(test_logger);
159
+    dual_control dc(create_dual_control(configuration));
160
+    pam_handle_t *handle = (pam_handle_t*)"";
161
+    std::vector<const std::string> arguments;
152 162
 
153
-int runtests() {
154
-//    test(setcred_returns_success);
155
-//    test(authenticate_validates_with_received_token);
156
-//    test(authenticate_fails_with_wrong_user);
157
-//    test(authenticate_fails_with_wrong_token);
158
-    test(logs_authentication);
159
-    succeed();
160
-}
163
+    //when
164
+    dc->authenticate(handle, 0, arguments);
161 165
 
162
-int main(int argc, char* argv[]) {
163
-   return !runtests();
166
+    //then
167
+    check (test_logger->logged_result() == PAM_AUTH_ERR, "logged result should be success");
168
+    check (test_logger->logged_user_name() == user, "logged user name should be user");
169
+    check (test_logger->logged_token() == token, "logged token should be token");
170
+    succeed();
164 171
 }
165 172
 
166 173
 
167
-
168
-// DELETE BELOW HERE
169
-
170
-/*
171
-const char *validated_user = "";
172
-const char *validated_token = "";
173
-const char *token_to_return = "";
174
-int validation_to_return = 0;
175
-int log_success_invoked = 0;
176
-int log_failure_invoked = 0;
177
-int at_least_one_failed_test = 0;
178
-pam_handle_t *passed_pam_handle = NULL;
179
-
180 174
 RESET_VARS_START
181
-validated_user = "";
182
-validated_token = "";
183
-validation_to_return = 1;
184
-passed_pam_handle = NULL;
185
-log_success_invoked = 0;
186
-log_failure_invoked = 0;
187 175
 RESET_VARS_END
188 176
 
189
-const char *ask_for_token(pam_handle_t *pamh) {
190
-    passed_pam_handle = pamh;
191
-    return token_to_return;
192
-}
193
-
194
-
195
-int validate_token(const char *user, const char *token) {
196
-    validated_user = user;
197
-    validated_token = token;
198
-    return validation_to_return;
199
-}
200
-
201
-void log_success() {
202
-    log_success_invoked = 1;
203
-}
204
-
205
-void log_failure() {
206
-    log_failure_invoked = 1;
207
-}
208
-
209
-int pam_sm_authenticate_success_invokes_log_success() {
210
-    // given
211
-    validation_to_return = 1;
212
-
213
-    //when
214
-   pam_sm_authenticate(NULL, 0, 0, NULL);
215
-   return log_success_invoked;
177
+int runtests() {
178
+    test(setcred_returns_success);
179
+    test(authenticate_validates_with_received_token);
180
+    test(authenticate_fails_with_wrong_user);
181
+    test(authenticate_fails_with_wrong_token);
182
+    test(logs_authentication);
183
+    test(logs_authentication_failure);
184
+    succeed();
216 185
 }
217 186
 
218
-int pam_sm_authenticate_fail_invokes_log_failure() {
219
-    // given
220
-    validation_to_return = 0;
221
-
222
-    //when
223
-   pam_sm_authenticate(NULL, 0, 0, NULL);
224
-   check(log_failure_invoked, "log failure should be invoked");
225
-   succeed();
187
+int main(int argc, char* argv[]) {
188
+   return !runtests();
226 189
 }
227 190
 
228
-*/
229
-
230 191