Browse code
validator delegate
Greg Wiley authored on 18/04/2017 23:19:42
Showing 3 changed files
Showing 3 changed files
... | ... |
@@ -29,7 +29,7 @@ int impl::authenticate(pam_handle *handle, int flags, const std::vector<const st |
29 | 29 |
std::string user_name = conversation.user_name(); |
30 | 30 |
std::string token = conversation.token(); |
31 | 31 |
|
32 |
- int auth_result = validator_->validate(user_name, token) ? PAM_SUCCESS : PAM_AUTH_ERR; |
|
32 |
+ int auth_result = validator_.validate(user_name, token) ? PAM_SUCCESS : PAM_AUTH_ERR; |
|
33 | 33 |
|
34 | 34 |
logger_.log(auth_result, user_name, token); |
35 | 35 |
return auth_result; |
... | ... |
@@ -74,7 +74,7 @@ int authenticate_validates_with_received_token() { |
74 | 74 |
dual_control_configuration configuration; |
75 | 75 |
std::string user("user"); |
76 | 76 |
std::string token("token"); |
77 |
- configuration.validator = validator(new fake_validator(user, token)); |
|
77 |
+ configuration.validator = validator(std::shared_ptr<validator_ifc>(new fake_validator(user, token))); |
|
78 | 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); |
... | ... |
@@ -92,7 +92,7 @@ int authenticate_fails_with_wrong_user() { |
92 | 92 |
// given |
93 | 93 |
dual_control_configuration configuration; |
94 | 94 |
std::string token("token"); |
95 |
- configuration.validator = validator(new fake_validator("user", token)); |
|
95 |
+ configuration.validator = validator(std::shared_ptr<validator_ifc>(new fake_validator("user", token))); |
|
96 | 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); |
... | ... |
@@ -110,7 +110,7 @@ int authenticate_fails_with_wrong_token() { |
110 | 110 |
// given |
111 | 111 |
dual_control_configuration configuration; |
112 | 112 |
std::string user("user"); |
113 |
- configuration.validator = validator(new fake_validator(user, "token")); |
|
113 |
+ configuration.validator = validator(std::shared_ptr<validator_ifc>(new fake_validator(user, "token"))); |
|
114 | 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); |
... | ... |
@@ -129,7 +129,7 @@ int logs_authentication() { |
129 | 129 |
dual_control_configuration configuration; |
130 | 130 |
std::string user("user"); |
131 | 131 |
std::string token("token"); |
132 |
- configuration.validator = validator(new fake_validator(user, token)); |
|
132 |
+ configuration.validator = validator(std::shared_ptr<validator_ifc>(new fake_validator(user, token))); |
|
133 | 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)); |
... | ... |
@@ -152,7 +152,7 @@ int logs_authentication_failure() { |
152 | 152 |
dual_control_configuration configuration; |
153 | 153 |
std::string user("user"); |
154 | 154 |
std::string token("token"); |
155 |
- configuration.validator = validator(new fake_validator(user, "not the received token")); |
|
155 |
+ configuration.validator = validator(std::shared_ptr<validator_ifc>(new fake_validator(user, "not the received token"))); |
|
156 | 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)); |
... | ... |
@@ -10,12 +10,21 @@ |
10 | 10 |
class validator_ifc { |
11 | 11 |
public: |
12 | 12 |
virtual ~validator_ifc() {} |
13 |
- virtual bool validate(const std::string &user, const std::string &token) { |
|
13 |
+ virtual bool validate(const std::string &user_name, const std::string &token) { |
|
14 | 14 |
return false; |
15 | 15 |
} |
16 | 16 |
}; |
17 | 17 |
|
18 |
-typedef std::shared_ptr<validator_ifc> validator; |
|
18 |
+class validator : public validator_ifc { |
|
19 |
+ private: |
|
20 |
+ std::shared_ptr<validator_ifc> delegate_; |
|
21 |
+ public: |
|
22 |
+ validator(const std::shared_ptr<validator_ifc> &delegate) : delegate_(delegate) {} |
|
23 |
+ validator() : validator(std::shared_ptr<validator_ifc>(new validator_ifc)) {} |
|
24 |
+ bool validate(const std::string &user_name, const std::string &token) { |
|
25 |
+ return delegate_->validate(user_name, token); |
|
26 |
+ } |
|
27 |
+}; |
|
19 | 28 |
|
20 | 29 |
class old_validator { |
21 | 30 |
private: |