Browse code
happy log failure
Greg Wiley authored on 26/04/2017 17:58:08
Showing 2 changed files
Showing 2 changed files
... | ... |
@@ -10,6 +10,7 @@ |
10 | 10 |
*/ |
11 | 11 |
|
12 | 12 |
#include <syslog.h> |
13 |
+#include <security/pam_modules.h> |
|
13 | 14 |
|
14 | 15 |
#include "sys_syslog.h" |
15 | 16 |
#include "logger.h" |
... | ... |
@@ -22,7 +23,8 @@ namespace { |
22 | 23 |
impl(const sys_syslog &sys_syslog) : syslog_(sys_syslog) {} |
23 | 24 |
void log (int result, const std::string &user_name, |
24 | 25 |
const std::string &token) { |
25 |
- std::string message(user_name + " " + token + " success"); |
|
26 |
+ std::string pam_result = result == PAM_SUCCESS ? "success" : "fail"; |
|
27 |
+ std::string message(user_name + " " + token + " " + pam_result); |
|
26 | 28 |
|
27 | 29 |
syslog_.openlog("dual-control", 0, LOG_AUTHPRIV); |
28 | 30 |
syslog_.syslog(LOG_NOTICE, message.c_str()); |
... | ... |
@@ -64,12 +64,34 @@ int logs_success() { |
64 | 64 |
succeed(); |
65 | 65 |
} |
66 | 66 |
|
67 |
+int logs_failure() { |
|
68 |
+ //given |
|
69 |
+ mock_syslog *capture = new mock_syslog; |
|
70 |
+ sys_syslog::delegate test_delegate(capture); |
|
71 |
+ sys_syslog test_syslog(test_delegate); |
|
72 |
+ logger logger = logger::create(test_syslog); |
|
73 |
+ std::string user("user"); |
|
74 |
+ std::string token("token"); |
|
75 |
+ |
|
76 |
+ //when |
|
77 |
+ logger.log(PAM_AUTH_ERR, user, token); |
|
78 |
+ |
|
79 |
+ //then |
|
80 |
+ check(capture->facility == LOG_AUTHPRIV, "facility does not match"); |
|
81 |
+ check(capture->message == user + " " + token + " " + "fail", "message does not match"); |
|
82 |
+ check(capture->priority == LOG_NOTICE, "priority does not match"); |
|
83 |
+ check(capture->closed, "syslog not closed"); |
|
84 |
+ check(capture->ident == "dual-control", "dual-control"); |
|
85 |
+ succeed(); |
|
86 |
+} |
|
87 |
+ |
|
67 | 88 |
RESET_VARS_START |
68 | 89 |
RESET_VARS_END |
69 | 90 |
|
70 | 91 |
int run_tests() |
71 | 92 |
{ |
72 | 93 |
test (logs_success); |
94 |
+ test (logs_failure); |
|
73 | 95 |
succeed(); |
74 | 96 |
} |
75 | 97 |
|