Browse code
adds conversation delegate
Greg Wiley authored on 18/04/2017 23:09:59
Showing 3 changed files
Showing 3 changed files
... | ... |
@@ -21,6 +21,7 @@ class conversation_result { |
21 | 21 |
std::string user_name() { return user_name_; } |
22 | 22 |
}; |
23 | 23 |
|
24 |
+ |
|
24 | 25 |
class conversations_ifc { |
25 | 26 |
public: |
26 | 27 |
virtual ~conversations_ifc() {} |
... | ... |
@@ -28,7 +29,17 @@ class conversations_ifc { |
28 | 29 |
return conversation_result("",""); |
29 | 30 |
} |
30 | 31 |
}; |
31 |
-typedef std::shared_ptr<conversations_ifc> conversations; |
|
32 |
+ |
|
33 |
+class conversations : public conversations_ifc { |
|
34 |
+ private: |
|
35 |
+ std::shared_ptr<conversations_ifc> delegate_; |
|
36 |
+ public: |
|
37 |
+ conversations() : conversations(std::shared_ptr<conversations_ifc>(new conversations_ifc)) {} |
|
38 |
+ conversations(const std::shared_ptr<conversations_ifc> &delegate) : delegate_(delegate) {} |
|
39 |
+ conversation_result initiate_conversation() { |
|
40 |
+ return delegate_->initiate_conversation(); |
|
41 |
+ } |
|
42 |
+}; |
|
32 | 43 |
|
33 | 44 |
class token_conversation { |
34 | 45 |
public: |
... | ... |
@@ -25,7 +25,7 @@ int impl::setcred(pam_handle *handle, int flags, const std::vector<const std::st |
25 | 25 |
|
26 | 26 |
int impl::authenticate(pam_handle *handle, int flags, const std::vector<const std::string> &arguments) { |
27 | 27 |
|
28 |
- conversation_result conversation = conversations_->initiate_conversation(); |
|
28 |
+ conversation_result conversation = conversations_.initiate_conversation(); |
|
29 | 29 |
std::string user_name = conversation.user_name(); |
30 | 30 |
std::string token = conversation.token(); |
31 | 31 |
|
... | ... |
@@ -75,7 +75,7 @@ int authenticate_validates_with_received_token() { |
75 | 75 |
std::string user("user"); |
76 | 76 |
std::string token("token"); |
77 | 77 |
configuration.validator = validator(new fake_validator(user, token)); |
78 |
- configuration.conversations = conversations(new fake_conversations(user, token)); |
|
78 |
+ configuration.conversations = conversations(std::shared_ptr<conversations_ifc>(new fake_conversations(user, token))); |
|
79 | 79 |
dual_control dc(create_dual_control(configuration)); |
80 | 80 |
pam_handle_t *handle(0); |
81 | 81 |
std::vector<const std::string> arguments; |
... | ... |
@@ -93,7 +93,7 @@ int authenticate_fails_with_wrong_user() { |
93 | 93 |
dual_control_configuration configuration; |
94 | 94 |
std::string token("token"); |
95 | 95 |
configuration.validator = validator(new fake_validator("user", token)); |
96 |
- configuration.conversations = conversations(new fake_conversations("wrong user", token)); |
|
96 |
+ configuration.conversations = conversations(std::shared_ptr<conversations_ifc>(new fake_conversations("wrong user", token))); |
|
97 | 97 |
dual_control dc(create_dual_control(configuration)); |
98 | 98 |
pam_handle_t *handle(0); |
99 | 99 |
std::vector<const std::string> arguments; |
... | ... |
@@ -111,7 +111,7 @@ int authenticate_fails_with_wrong_token() { |
111 | 111 |
dual_control_configuration configuration; |
112 | 112 |
std::string user("user"); |
113 | 113 |
configuration.validator = validator(new fake_validator(user, "token")); |
114 |
- configuration.conversations = conversations(new fake_conversations(user, "wrong token")); |
|
114 |
+ configuration.conversations = conversations(std::shared_ptr<conversations_ifc>(new fake_conversations(user, "wrong token"))); |
|
115 | 115 |
dual_control dc(create_dual_control(configuration)); |
116 | 116 |
pam_handle_t *handle(0); |
117 | 117 |
std::vector<const std::string> arguments; |
... | ... |
@@ -130,7 +130,7 @@ int logs_authentication() { |
130 | 130 |
std::string user("user"); |
131 | 131 |
std::string token("token"); |
132 | 132 |
configuration.validator = validator(new fake_validator(user, token)); |
133 |
- configuration.conversations = conversations(new fake_conversations(user, token)); |
|
133 |
+ configuration.conversations = conversations(std::shared_ptr<conversations_ifc>(new fake_conversations(user, token))); |
|
134 | 134 |
mock_logger *test_logger = new mock_logger; |
135 | 135 |
configuration.logger = logger(std::shared_ptr<logger_ifc>(test_logger)); |
136 | 136 |
dual_control dc(create_dual_control(configuration)); |
... | ... |
@@ -153,7 +153,7 @@ int logs_authentication_failure() { |
153 | 153 |
std::string user("user"); |
154 | 154 |
std::string token("token"); |
155 | 155 |
configuration.validator = validator(new fake_validator(user, "not the received token")); |
156 |
- configuration.conversations = conversations(new fake_conversations(user, token)); |
|
156 |
+ configuration.conversations = conversations(std::shared_ptr<conversations_ifc>(new fake_conversations(user, token))); |
|
157 | 157 |
mock_logger *test_logger = new mock_logger; |
158 | 158 |
configuration.logger = logger(std::shared_ptr<logger_ifc>(test_logger)); |
159 | 159 |
dual_control dc(create_dual_control(configuration)); |