Browse code
better config in tests
Greg Wiley authored on 18/04/2017 23:36:22
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -14,6 +14,18 @@ std::shared_ptr<T> share(T* t) { |
14 | 14 |
} |
15 | 15 |
|
16 | 16 |
|
17 |
+void use_validator(dual_control_configuration &config, validator_ifc *value) { |
|
18 |
+ config.validator = validator(share(value)); |
|
19 |
+} |
|
20 |
+ |
|
21 |
+void use_conversations(dual_control_configuration &config, conversations_ifc *value) { |
|
22 |
+ config.conversations = conversations(share(value)); |
|
23 |
+} |
|
24 |
+ |
|
25 |
+void use_logger(dual_control_configuration &config, logger_ifc *value) { |
|
26 |
+ config.logger = logger(share(value)); |
|
27 |
+} |
|
28 |
+ |
|
17 | 29 |
class mock_logger : public logger_ifc { |
18 | 30 |
private: |
19 | 31 |
int result_; |
... | ... |
@@ -25,15 +37,9 @@ class mock_logger : public logger_ifc { |
25 | 37 |
user_name_ = user_name; |
26 | 38 |
token_ = token; |
27 | 39 |
} |
28 |
- int logged_result() { |
|
29 |
- return result_; |
|
30 |
- } |
|
31 |
- std::string logged_user_name() { |
|
32 |
- return user_name_; |
|
33 |
- } |
|
34 |
- std::string logged_token() { |
|
35 |
- return token_; |
|
36 |
- } |
|
40 |
+ int logged_result() { return result_; } |
|
41 |
+ std::string logged_user_name() { return user_name_; } |
|
42 |
+ std::string logged_token() { return token_; } |
|
37 | 43 |
}; |
38 | 44 |
|
39 | 45 |
class fake_conversations : public conversations_ifc { |
... | ... |
@@ -80,8 +86,8 @@ int authenticate_validates_with_received_token() { |
80 | 86 |
dual_control_configuration configuration; |
81 | 87 |
std::string user("user"); |
82 | 88 |
std::string token("token"); |
83 |
- configuration.validator = validator(share(new fake_validator(user, token))); |
|
84 |
- configuration.conversations = conversations(share(new fake_conversations(user, token))); |
|
89 |
+ use_validator(configuration, new fake_validator(user, token)); |
|
90 |
+ use_conversations(configuration, new fake_conversations(user, token)); |
|
85 | 91 |
dual_control dc(create_dual_control(configuration)); |
86 | 92 |
pam_handle_t *handle(0); |
87 | 93 |
std::vector<const std::string> arguments; |
... | ... |
@@ -98,8 +104,8 @@ int authenticate_fails_with_wrong_user() { |
98 | 104 |
// given |
99 | 105 |
dual_control_configuration configuration; |
100 | 106 |
std::string token("token"); |
101 |
- configuration.validator = validator(share(new fake_validator("user", token))); |
|
102 |
- configuration.conversations = conversations(share(new fake_conversations("wrong user", token))); |
|
107 |
+ use_validator(configuration, new fake_validator("user", token)); |
|
108 |
+ use_conversations(configuration, new fake_conversations("wrong user", token)); |
|
103 | 109 |
dual_control dc(create_dual_control(configuration)); |
104 | 110 |
pam_handle_t *handle(0); |
105 | 111 |
std::vector<const std::string> arguments; |
... | ... |
@@ -116,8 +122,8 @@ int authenticate_fails_with_wrong_token() { |
116 | 122 |
// given |
117 | 123 |
dual_control_configuration configuration; |
118 | 124 |
std::string user("user"); |
119 |
- configuration.validator = validator(share(new fake_validator(user, "token"))); |
|
120 |
- configuration.conversations = conversations(share(new fake_conversations(user, "wrong token"))); |
|
125 |
+ use_validator(configuration, new fake_validator(user, "token")); |
|
126 |
+ use_conversations(configuration, new fake_conversations(user, "wrong token")); |
|
121 | 127 |
dual_control dc(create_dual_control(configuration)); |
122 | 128 |
pam_handle_t *handle(0); |
123 | 129 |
std::vector<const std::string> arguments; |
... | ... |
@@ -135,10 +141,10 @@ int logs_authentication() { |
135 | 141 |
dual_control_configuration configuration; |
136 | 142 |
std::string user("user"); |
137 | 143 |
std::string token("token"); |
138 |
- configuration.validator = validator(share(new fake_validator(user, token))); |
|
139 |
- configuration.conversations = conversations(share(new fake_conversations(user, token))); |
|
140 |
- mock_logger *test_logger = new mock_logger; |
|
141 |
- configuration.logger = logger(share(test_logger)); |
|
144 |
+ use_validator(configuration, new fake_validator(user, token)); |
|
145 |
+ use_conversations(configuration, new fake_conversations(user, token)); |
|
146 |
+ mock_logger *test_logger; |
|
147 |
+ use_logger(configuration, test_logger = new mock_logger); |
|
142 | 148 |
dual_control dc(create_dual_control(configuration)); |
143 | 149 |
pam_handle_t *handle(0); |
144 | 150 |
std::vector<const std::string> arguments; |
... | ... |
@@ -158,10 +164,10 @@ int logs_authentication_failure() { |
158 | 164 |
dual_control_configuration configuration; |
159 | 165 |
std::string user("user"); |
160 | 166 |
std::string token("token"); |
161 |
- configuration.validator = validator(share(new fake_validator(user, "not the received token"))); |
|
162 |
- configuration.conversations = conversations(share(new fake_conversations(user, token))); |
|
163 |
- mock_logger *test_logger = new mock_logger; |
|
164 |
- configuration.logger = logger(share(test_logger)); |
|
167 |
+ use_validator(configuration, new fake_validator(user, "not the received token")); |
|
168 |
+ use_conversations(configuration, new fake_conversations(user, token)); |
|
169 |
+ mock_logger *test_logger; |
|
170 |
+ use_logger(configuration, test_logger = new mock_logger); |
|
165 | 171 |
dual_control dc(create_dual_control(configuration)); |
166 | 172 |
pam_handle_t *handle(0); |
167 | 173 |
std::vector<const std::string> arguments; |