Browse code
pam conversation handles conversation answer fail
Greg Wiley authored on 17/04/2017 21:50:39
Showing 2 changed files
Showing 2 changed files
... | ... |
@@ -24,6 +24,10 @@ pam_token_conversation::pam_token_conversation(pam_handle_t *pamh, const pam_p p |
24 | 24 |
if (conversation_result) { |
25 | 25 |
return; |
26 | 26 |
} |
27 |
+ |
|
28 |
+ if (answers[0]->resp_retcode) { |
|
29 |
+ return; |
|
30 |
+ } |
|
27 | 31 |
std::string answer(answers[0]->resp); |
28 | 32 |
std::string::iterator delim = std::find(answer.begin(), answer.end(), ':'); |
29 | 33 |
if (delim == answer.end()) { |
... | ... |
@@ -34,6 +34,24 @@ class fake_failing_conversation: public pam_conversation { |
34 | 34 |
} |
35 | 35 |
}; |
36 | 36 |
|
37 |
+class fake_failing_answer_conversation: public pam_conversation { |
|
38 |
+ private: |
|
39 |
+ pam_response response_; |
|
40 |
+ std::string answer_; |
|
41 |
+ public: |
|
42 |
+ fake_failing_answer_conversation() : answer_("ok:1") {} |
|
43 |
+ int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers) { |
|
44 |
+ if (prompts.size() != 1) { |
|
45 |
+ throw std::string("test only supports one prompt"); |
|
46 |
+ } |
|
47 |
+ response_.resp_retcode = 13; |
|
48 |
+ response_.resp = const_cast<char *>(answer_.c_str()); |
|
49 |
+ answers.resize(1); |
|
50 |
+ answers[0] = &response_; |
|
51 |
+ return 0; |
|
52 |
+ } |
|
53 |
+}; |
|
54 |
+ |
|
37 | 55 |
class match_prompt_text_conversation : public pam_conversation { |
38 | 56 |
private: |
39 | 57 |
pam_response response_; |
... | ... |
@@ -242,6 +260,20 @@ int returns_empty_user_and_token_when_conversation_fails() { |
242 | 260 |
succeed(); |
243 | 261 |
} |
244 | 262 |
|
263 |
+int returns_empty_user_and_token_when_conversation_answer_fails() { |
|
264 |
+ //given |
|
265 |
+ pam_handle_t *pamh; |
|
266 |
+ pam_conversation_p fake_conversation = (pam_conversation_p) new fake_failing_answer_conversation; |
|
267 |
+ pam_p pam = (pam_p) new fake_pam(fake_conversation); |
|
268 |
+ |
|
269 |
+ //when |
|
270 |
+ pam_token_conversation conversation(pamh, pam); |
|
271 |
+ |
|
272 |
+ //then |
|
273 |
+ check(conversation.user_name() == "", "did not return empty user name"); |
|
274 |
+ check(conversation.token() == "", "did not return empty token"); |
|
275 |
+ succeed(); |
|
276 |
+} |
|
245 | 277 |
|
246 | 278 |
RESET_VARS_START |
247 | 279 |
RESET_VARS_END |
... | ... |
@@ -257,6 +289,7 @@ int run_tests() { |
257 | 289 |
test(prompts_user_with_correct_text); |
258 | 290 |
test(prompts_user_with_correct_style); |
259 | 291 |
test(returns_empty_user_and_token_when_conversation_fails); |
292 |
+ test(returns_empty_user_and_token_when_conversation_answer_fails); |
|
260 | 293 |
succeed(); |
261 | 294 |
} |
262 | 295 |
|