Browse code
STASH
Greg Wiley authored on 20/04/2017 18:23:29
Showing 2 changed files
Showing 2 changed files
... | ... |
@@ -13,9 +13,18 @@ namespace |
13 | 13 |
{ |
14 | 14 |
class impl : public conversation_ifc |
15 | 15 |
{ |
16 |
+ private: |
|
17 |
+ pam pam_; |
|
16 | 18 |
public: |
19 |
+ impl(pam &pam) : pam_(pam) {} |
|
17 | 20 |
conversation_result initiate (const pam_request &request) { |
18 |
- return {"user","token"}; |
|
21 |
+ pam_conv *out; |
|
22 |
+ int result = pam_.get:_conv(request.handle(), |
|
23 |
+ /*int get_conv (pam_handle *handle, const pam_conv **out) |
|
24 |
+ { |
|
25 |
+ return delegate_->get_conv (handle, out); |
|
26 |
+ } |
|
27 |
+ */ |
|
19 | 28 |
} |
20 | 29 |
}; |
21 | 30 |
} |
... | ... |
@@ -94,7 +94,7 @@ std::shared_ptr<T> share (T *t) { |
94 | 94 |
return std::shared_ptr<T>(t); |
95 | 95 |
} |
96 | 96 |
|
97 |
-bool uses_pam_correctly() |
|
97 |
+bool returns_user_and_token() |
|
98 | 98 |
{ |
99 | 99 |
|
100 | 100 |
// given |
... | ... |
@@ -128,12 +128,47 @@ bool uses_pam_correctly() |
128 | 128 |
succeed(); |
129 | 129 |
} |
130 | 130 |
|
131 |
+bool returns_user_and_token_from_pam_conversation() |
|
132 |
+{ |
|
133 |
+ |
|
134 |
+ // given |
|
135 |
+ pam_handle *handle = reinterpret_cast<pam_handle *> (29039); |
|
136 |
+ std::string user ("user1"); |
|
137 |
+ std::string token ("token1"); |
|
138 |
+ pam_message prompt; |
|
139 |
+ prompt.msg_style = PAM_PROMPT_ECHO_OFF; |
|
140 |
+ prompt.msg = const_cast<char *>("Dual control token: "); |
|
141 |
+ pam_response response; |
|
142 |
+ response.resp_retcode = 0; |
|
143 |
+ std::string response_text(user + ":" + token); |
|
144 |
+ response.resp = const_cast<char *>(response_text.c_str()); |
|
145 |
+ conversation_data conversation_data = { |
|
146 |
+ std::vector<pam_message>(&prompt, &prompt + 1), |
|
147 |
+ std::vector<pam_response>(&response, &response + 1), |
|
148 |
+ PAM_SUCCESS |
|
149 |
+ }; |
|
150 |
+ pam pam (share (new fake_pam (handle, conversation_data))); |
|
151 |
+ pam_request request (handle, 0, 0, 0); |
|
152 |
+ |
|
153 |
+ conversation conversation (create_conversation (pam)); |
|
154 |
+ |
|
155 |
+ // when |
|
156 |
+ conversation_result actual = conversation.initiate (request); |
|
157 |
+ |
|
158 |
+ // then |
|
159 |
+ check(actual.user_name == user, "user name does not match"); |
|
160 |
+ check(actual.token == token, "token does not match"); |
|
161 |
+ |
|
162 |
+ succeed(); |
|
163 |
+} |
|
164 |
+ |
|
131 | 165 |
RESET_VARS_START |
132 | 166 |
RESET_VARS_END |
133 | 167 |
|
134 | 168 |
int run_tests() |
135 | 169 |
{ |
136 |
- test (uses_pam_correctly); |
|
170 |
+ test (returns_user_and_token); |
|
171 |
+ test (returns_user_and_token_from_pam_conversation); |
|
137 | 172 |
succeed(); |
138 | 173 |
} |
139 | 174 |
|