git.fiddlerwoaroof.com
Browse code

empty answer and no colon cases

Greg Wiley authored on 20/04/2017 21:55:22
Showing 1 changed files
... ...
@@ -165,6 +165,64 @@ bool returns_user_and_token_from_pam_conversation()
165 165
     succeed();
166 166
 }
167 167
 
168
+int returns_empty_user_and_token_when_no_colon() {
169
+    // given
170
+    pam_handle *handle = reinterpret_cast<pam_handle *> (29039);
171
+    pam_message prompt;
172
+    prompt.msg_style = PAM_PROMPT_ECHO_OFF;
173
+    prompt.msg = const_cast<char *> ("Dual control token: ");
174
+    pam_response response;
175
+    response.resp_retcode = 0;
176
+    std::string response_text ("this_has_no_colon");
177
+    response.resp = const_cast<char *> (response_text.c_str());
178
+    conversation_data conversation_data = {
179
+        std::vector<pam_message> (&prompt, &prompt + 1),
180
+        std::vector<pam_response> (&response, &response + 1),
181
+        PAM_SUCCESS
182
+    };
183
+    pam pam (share (new fake_pam (handle, conversation_data)));
184
+    pam_request request (handle, 0, 0, 0);
185
+
186
+    conversation conversation (create_conversation (pam));
187
+
188
+    // when
189
+    conversation_result actual = conversation.initiate (request);
190
+
191
+    // then
192
+    check (actual.user_name == "", "user name does not match");
193
+    check (actual.token == "", "token does not match");
194
+    succeed();
195
+ }
196
+
197
+int returns_empty_user_and_token_when_empty_answer() {
198
+    // given
199
+    pam_handle *handle = reinterpret_cast<pam_handle *> (29039);
200
+    pam_message prompt;
201
+    prompt.msg_style = PAM_PROMPT_ECHO_OFF;
202
+    prompt.msg = const_cast<char *> ("Dual control token: ");
203
+    pam_response response;
204
+    response.resp_retcode = 0;
205
+    std::string response_text ("");
206
+    response.resp = const_cast<char *> (response_text.c_str());
207
+    conversation_data conversation_data = {
208
+        std::vector<pam_message> (&prompt, &prompt + 1),
209
+        std::vector<pam_response> (&response, &response + 1),
210
+        PAM_SUCCESS
211
+    };
212
+    pam pam (share (new fake_pam (handle, conversation_data)));
213
+    pam_request request (handle, 0, 0, 0);
214
+
215
+    conversation conversation (create_conversation (pam));
216
+
217
+    // when
218
+    conversation_result actual = conversation.initiate (request);
219
+
220
+    // then
221
+    check (actual.user_name == "", "user name does not match");
222
+    check (actual.token == "", "token does not match");
223
+    succeed();
224
+ }
225
+
168 226
 RESET_VARS_START
169 227
 RESET_VARS_END
170 228
 
... ...
@@ -172,6 +230,8 @@ int run_tests()
172 230
 {
173 231
     test (returns_user_and_token);
174 232
     test (returns_user_and_token_from_pam_conversation);
233
+    test (returns_empty_user_and_token_when_no_colon);
234
+    test (returns_empty_user_and_token_when_empty_answer);
175 235
     succeed();
176 236
 }
177 237
 
... ...
@@ -181,9 +241,6 @@ int main (int argc, char **argv)
181 241
 }
182 242
 
183 243
 /*
184
- * int returns_correct_token()
185
-int returns_correct_user_name()
186
-int returns_empty_user_and_token_when_no_colon()
187 244
 int returns_empty_user_and_token_when_empty_answer()
188 245
 int returns_empty_token_when_colon_end()
189 246
 int returns_empty_user_when_colon_begin()