Browse code
unauthenticated returns auth err
Greg Wiley authored on 18/04/2017 21:21:27
Showing 2 changed files
Showing 2 changed files
... | ... |
@@ -30,7 +30,7 @@ int impl::authenticate(pam_handle *handle, int flags, const std::vector<const st |
30 | 30 |
if (validator_->validate(user, token)) { |
31 | 31 |
return PAM_SUCCESS; |
32 | 32 |
} |
33 |
- return 1212; |
|
33 |
+ return PAM_AUTH_ERR; |
|
34 | 34 |
} |
35 | 35 |
|
36 | 36 |
dual_control create_dual_control(const dual_control_configuration &configuration) { |
... | ... |
@@ -61,7 +61,43 @@ int authenticate_validates_with_received_token() { |
61 | 61 |
int actual = dc->authenticate(handle, 0, arguments); |
62 | 62 |
|
63 | 63 |
// then |
64 |
- check(actual == PAM_SUCCESS, "should be valid"); |
|
64 |
+ check(actual == PAM_SUCCESS, "should be success"); |
|
65 |
+ succeed(); |
|
66 |
+} |
|
67 |
+ |
|
68 |
+int authenticate_fails_with_wrong_user() { |
|
69 |
+ // given |
|
70 |
+ dual_control_configuration configuration; |
|
71 |
+ std::string token("token"); |
|
72 |
+ configuration.validator = validator(new fake_validator("user", token)); |
|
73 |
+ configuration.conversations = conversations(new fake_conversations("wrong user", token)); |
|
74 |
+ dual_control dc(create_dual_control(configuration)); |
|
75 |
+ pam_handle_t *handle = (pam_handle_t*)""; |
|
76 |
+ std::vector<const std::string> arguments; |
|
77 |
+ |
|
78 |
+ // when |
|
79 |
+ int actual = dc->authenticate(handle, 0, arguments); |
|
80 |
+ |
|
81 |
+ // then |
|
82 |
+ check(actual == PAM_AUTH_ERR, "should be auth err"); |
|
83 |
+ succeed(); |
|
84 |
+} |
|
85 |
+ |
|
86 |
+int authenticate_fails_with_wrong_token() { |
|
87 |
+ // given |
|
88 |
+ dual_control_configuration configuration; |
|
89 |
+ std::string user("user"); |
|
90 |
+ configuration.validator = validator(new fake_validator(user, "token")); |
|
91 |
+ configuration.conversations = conversations(new fake_conversations(user, "wrong token")); |
|
92 |
+ dual_control dc(create_dual_control(configuration)); |
|
93 |
+ pam_handle_t *handle = (pam_handle_t*)""; |
|
94 |
+ std::vector<const std::string> arguments; |
|
95 |
+ |
|
96 |
+ // when |
|
97 |
+ int actual = dc->authenticate(handle, 0, arguments); |
|
98 |
+ |
|
99 |
+ // then |
|
100 |
+ check(actual == PAM_AUTH_ERR, "should be auth err"); |
|
65 | 101 |
succeed(); |
66 | 102 |
} |
67 | 103 |
|
... | ... |
@@ -72,6 +108,8 @@ RESET_VARS_END |
72 | 108 |
int runtests() { |
73 | 109 |
test(setcred_returns_success); |
74 | 110 |
test(authenticate_validates_with_received_token); |
111 |
+ test(authenticate_fails_with_wrong_user); |
|
112 |
+ test(authenticate_fails_with_wrong_token); |
|
75 | 113 |
succeed(); |
76 | 114 |
} |
77 | 115 |
|