Browse code
handles empty user and empty token
Greg Wiley authored on 20/04/2017 22:09:58
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -97,9 +97,7 @@ std::shared_ptr<T> share (T *t) |
97 | 97 |
return std::shared_ptr<T> (t); |
98 | 98 |
} |
99 | 99 |
|
100 |
-conversation make_conversation (pam_handle *expected_handle, |
|
101 |
- const std::string &answer) |
|
102 |
-{ |
|
100 |
+conversation make_conversation(pam_handle *expected_handle, const std::string &answer) { |
|
103 | 101 |
pam_message prompt; |
104 | 102 |
prompt.msg_style = PAM_PROMPT_ECHO_OFF; |
105 | 103 |
prompt.msg = const_cast<char *> ("Dual control token: "); |
... | ... |
@@ -124,7 +122,7 @@ bool returns_user_and_token() |
124 | 122 |
pam_handle *handle = reinterpret_cast<pam_handle *> (29039); |
125 | 123 |
std::string user ("user"); |
126 | 124 |
std::string token ("token"); |
127 |
- conversation conversation (make_conversation (handle, user + ":" + token)); |
|
125 |
+ conversation conversation (make_conversation(handle, user + ":" + token)); |
|
128 | 126 |
pam_request request (handle, 0, 0, 0); |
129 | 127 |
|
130 | 128 |
// when |
... | ... |
@@ -137,12 +135,11 @@ bool returns_user_and_token() |
137 | 135 |
succeed(); |
138 | 136 |
} |
139 | 137 |
|
140 |
-int returns_empty_user_and_token_when_no_colon() |
|
141 |
-{ |
|
138 |
+int returns_empty_user_and_token_when_no_colon() { |
|
142 | 139 |
|
143 | 140 |
// given |
144 | 141 |
pam_handle *handle = reinterpret_cast<pam_handle *> (29039); |
145 |
- conversation conversation (make_conversation (handle, "nocolon")); |
|
142 |
+ conversation conversation (make_conversation(handle, "nocolon")); |
|
146 | 143 |
pam_request request (handle, 0, 0, 0); |
147 | 144 |
|
148 | 145 |
// when |
... | ... |
@@ -152,13 +149,12 @@ int returns_empty_user_and_token_when_no_colon() |
152 | 149 |
check (actual.user_name == "", "user name does not match"); |
153 | 150 |
check (actual.token == "", "token does not match"); |
154 | 151 |
succeed(); |
155 |
-} |
|
152 |
+ } |
|
156 | 153 |
|
157 |
-int returns_empty_user_and_token_when_empty_answer() |
|
158 |
-{ |
|
154 |
+int returns_empty_user_and_token_when_empty_answer() { |
|
159 | 155 |
// given |
160 | 156 |
pam_handle *handle = reinterpret_cast<pam_handle *> (29039); |
161 |
- conversation conversation (make_conversation (handle, "")); |
|
157 |
+ conversation conversation (make_conversation(handle, "")); |
|
162 | 158 |
pam_request request (handle, 0, 0, 0); |
163 | 159 |
|
164 | 160 |
// when |
... | ... |
@@ -168,6 +164,38 @@ int returns_empty_user_and_token_when_empty_answer() |
168 | 164 |
check (actual.user_name == "", "user name does not match"); |
169 | 165 |
check (actual.token == "", "token does not match"); |
170 | 166 |
succeed(); |
167 |
+ } |
|
168 |
+ |
|
169 |
+int returns_empty_token_when_colon_end() { |
|
170 |
+ // given |
|
171 |
+ pam_handle *handle = reinterpret_cast<pam_handle *> (29039); |
|
172 |
+ std::string user("user"); |
|
173 |
+ conversation conversation (make_conversation(handle, user + ":")); |
|
174 |
+ pam_request request (handle, 0, 0, 0); |
|
175 |
+ |
|
176 |
+ // when |
|
177 |
+ conversation_result actual = conversation.initiate (request); |
|
178 |
+ |
|
179 |
+ // then |
|
180 |
+ check (actual.user_name == user, "user name does not match"); |
|
181 |
+ check (actual.token == "", "token should be empty"); |
|
182 |
+ succeed(); |
|
183 |
+} |
|
184 |
+ |
|
185 |
+int returns_empty_user_when_colon_start() { |
|
186 |
+ // given |
|
187 |
+ pam_handle *handle = reinterpret_cast<pam_handle *> (29039); |
|
188 |
+ std::string token("token"); |
|
189 |
+ conversation conversation (make_conversation(handle, ":" + token)); |
|
190 |
+ pam_request request (handle, 0, 0, 0); |
|
191 |
+ |
|
192 |
+ // when |
|
193 |
+ conversation_result actual = conversation.initiate (request); |
|
194 |
+ |
|
195 |
+ // then |
|
196 |
+ check (actual.user_name == "", "user name does not match"); |
|
197 |
+ check (actual.token == token, "token should be empty"); |
|
198 |
+ succeed(); |
|
171 | 199 |
} |
172 | 200 |
|
173 | 201 |
RESET_VARS_START |
... | ... |
@@ -178,6 +206,8 @@ int run_tests() |
178 | 206 |
test (returns_user_and_token); |
179 | 207 |
test (returns_empty_user_and_token_when_no_colon); |
180 | 208 |
test (returns_empty_user_and_token_when_empty_answer); |
209 |
+ test (returns_empty_token_when_colon_end); |
|
210 |
+ test (returns_empty_user_when_colon_start); |
|
181 | 211 |
succeed(); |
182 | 212 |
} |
183 | 213 |
|
... | ... |
@@ -187,7 +217,6 @@ int main (int argc, char **argv) |
187 | 217 |
} |
188 | 218 |
|
189 | 219 |
/* |
190 |
-int returns_empty_user_and_token_when_empty_answer() |
|
191 | 220 |
int returns_empty_token_when_colon_end() |
192 | 221 |
int returns_empty_user_when_colon_begin() |
193 | 222 |
int returns_empty_user_and_token_when_pam_cant_create_conversation() |