git.fiddlerwoaroof.com
Browse code

styled

Greg Wiley authored on 19/04/2017 17:13:00
Showing 22 changed files
... ...
@@ -3,7 +3,8 @@
3 3
 
4 4
 #include "argument.h"
5 5
 
6
-std::vector<const std::string> convert_arguments(int nargs, const char ** argv) {
6
+std::vector<const std::string> convert_arguments(int nargs, const char ** argv)
7
+{
7 8
     std::vector<std::string> temp;
8 9
 
9 10
     for (int i = 0; i < nargs; ++i) {
... ...
@@ -6,7 +6,8 @@
6 6
 #include "argument.h"
7 7
 #include "test_util.h"
8 8
 
9
-int convert_single_argument_to_cplusplus() {
9
+int convert_single_argument_to_cplusplus()
10
+{
10 11
     //given
11 12
     int nargs = 1;
12 13
     const char *arg = "blah";
... ...
@@ -24,7 +25,8 @@ int convert_single_argument_to_cplusplus() {
24 25
     succeed();
25 26
 }
26 27
 
27
-int convert_no_arguments_to_cplusplus() {
28
+int convert_no_arguments_to_cplusplus()
29
+{
28 30
     //given
29 31
     int nargs = 0;
30 32
     const char **argv = 0;
... ...
@@ -39,7 +41,8 @@ int convert_no_arguments_to_cplusplus() {
39 41
     succeed();
40 42
 }
41 43
 
42
-int convert_multiple_arguments_to_cplusplus() {
44
+int convert_multiple_arguments_to_cplusplus()
45
+{
43 46
     //given
44 47
     int nargs = 3;
45 48
     const char *arg1 = "one";
... ...
@@ -64,12 +67,14 @@ int convert_multiple_arguments_to_cplusplus() {
64 67
 RESET_VARS_START
65 68
 RESET_VARS_END
66 69
 
67
-int run_tests() {
70
+int run_tests()
71
+{
68 72
     test(convert_single_argument_to_cplusplus);
69 73
     test(convert_no_arguments_to_cplusplus);
70 74
     succeed();
71 75
 }
72 76
 
73
-int main() {
77
+int main()
78
+{
74 79
     return !run_tests();
75 80
 }
... ...
@@ -6,7 +6,8 @@
6 6
 #include "conversation.h"
7 7
 #include "pam.h"
8 8
 
9
-pam_token_conversation::pam_token_conversation(pam_handle_t *pamh, const pam_p pam) {
9
+pam_token_conversation::pam_token_conversation(pam_handle_t *pamh, const pam_p pam)
10
+{
10 11
     pam_conversation_p pam_conversation;
11 12
     int get_conversation_result = pam->get_conversation(pamh, pam_conversation);
12 13
     if (get_conversation_result != 0) {
... ...
@@ -39,10 +40,12 @@ pam_token_conversation::pam_token_conversation(pam_handle_t *pamh, const pam_p p
39 40
     token_ = token;
40 41
 }
41 42
 
42
-std::string pam_token_conversation::token() {
43
+std::string pam_token_conversation::token()
44
+{
43 45
     return token_;
44 46
 }
45 47
 
46
-std::string pam_token_conversation::user_name() {
48
+std::string pam_token_conversation::user_name()
49
+{
47 50
     return user_;
48 51
 }
... ...
@@ -9,53 +9,72 @@
9 9
 
10 10
 
11 11
 
12
-class conversation_result {
13
-    private:
14
-        std::string token_;
15
-        std::string user_name_;
16
-    public:
17
-        conversation_result(std::string user_name, std::string token)
18
-            : token_(token),
19
-              user_name_(user_name) {}
20
-        std::string token() { return token_; }
21
-        std::string user_name() { return user_name_; }
12
+class conversation_result
13
+{
14
+private:
15
+    std::string token_;
16
+    std::string user_name_;
17
+public:
18
+    conversation_result(std::string user_name, std::string token)
19
+        : token_(token),
20
+          user_name_(user_name) {}
21
+    std::string token()
22
+    {
23
+        return token_;
24
+    }
25
+    std::string user_name()
26
+    {
27
+        return user_name_;
28
+    }
22 29
 };
23 30
 
24 31
 
25
-class conversations_ifc {
26
-    public:
27
-        virtual ~conversations_ifc() {}
28
-        virtual conversation_result initiate_conversation() {
29
-            return conversation_result("","");
30
-        }
32
+class conversations_ifc
33
+{
34
+public:
35
+    virtual ~conversations_ifc() {}
36
+    virtual conversation_result initiate_conversation()
37
+    {
38
+        return conversation_result("","");
39
+    }
31 40
 };
32 41
 
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
+class conversations : public conversations_ifc
43
+{
44
+private:
45
+    std::shared_ptr<conversations_ifc> delegate_;
46
+public:
47
+    conversations() : conversations(std::shared_ptr<conversations_ifc>(new conversations_ifc)) {}
48
+    conversations(const std::shared_ptr<conversations_ifc> &delegate) : delegate_(delegate) {}
49
+    conversation_result initiate_conversation()
50
+    {
51
+        return delegate_->initiate_conversation();
52
+    }
42 53
 };
43 54
 
44
-class token_conversation {
45
-    public:
46
-        virtual ~token_conversation() {}
47
-        virtual std::string token() { return ""; }
48
-        virtual std::string user_name() { return ""; }
55
+class token_conversation
56
+{
57
+public:
58
+    virtual ~token_conversation() {}
59
+    virtual std::string token()
60
+    {
61
+        return "";
62
+    }
63
+    virtual std::string user_name()
64
+    {
65
+        return "";
66
+    }
49 67
 };
50 68
 
51
-class pam_token_conversation : public token_conversation {
52
-    public:
53
-        std::string user_;
54
-        std::string token_;
55
-        pam_token_conversation(pam_handle_t *pamh);
56
-        pam_token_conversation(pam_handle_t *pamh, const pam_p);
57
-        std::string token();
58
-        std::string user_name();
69
+class pam_token_conversation : public token_conversation
70
+{
71
+public:
72
+    std::string user_;
73
+    std::string token_;
74
+    pam_token_conversation(pam_handle_t *pamh);
75
+    pam_token_conversation(pam_handle_t *pamh, const pam_p);
76
+    std::string token();
77
+    std::string user_name();
59 78
 };
60 79
 
61 80
 #endif
... ...
@@ -8,107 +8,120 @@
8 8
 #include "pam.h"
9 9
 
10 10
 
11
-class fake_pam_conversation : public pam_conversation {
12
-    private:
13
-        pam_response response_;
14
-        std::string answer_;
15
-    public:
16
-        fake_pam_conversation(const std::string &answer) : answer_(answer) {}
17
-        int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers) {
18
-            if (prompts.size() != 1) {
19
-                throw std::string("test only supports one prompt");
20
-            }
21
-            response_.resp_retcode = 0;
22
-            response_.resp = const_cast<char *>(answer_.c_str());
23
-            answers.resize(1);
24
-            answers[0] = &response_;
25
-            return 0;
11
+class fake_pam_conversation : public pam_conversation
12
+{
13
+private:
14
+    pam_response response_;
15
+    std::string answer_;
16
+public:
17
+    fake_pam_conversation(const std::string &answer) : answer_(answer) {}
18
+    int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers)
19
+    {
20
+        if (prompts.size() != 1) {
21
+            throw std::string("test only supports one prompt");
26 22
         }
23
+        response_.resp_retcode = 0;
24
+        response_.resp = const_cast<char *>(answer_.c_str());
25
+        answers.resize(1);
26
+        answers[0] = &response_;
27
+        return 0;
28
+    }
27 29
 };
28 30
 
29
-class fake_failing_conversation: public pam_conversation {
31
+class fake_failing_conversation: public pam_conversation
32
+{
30 33
 
31
-    public:
32
-        int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers) {
33
-            return 1;
34
-        }
34
+public:
35
+    int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers)
36
+    {
37
+        return 1;
38
+    }
35 39
 };
36 40
 
37
-class fake_failing_answer_conversation: public pam_conversation {
38
-    private:
39
-        pam_response response_;
40
-        std::string answer_;
41
-    public:
42
-        fake_failing_answer_conversation() : answer_("ok:1") {}
43
-        int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers) {
44
-            if (prompts.size() != 1) {
45
-                throw std::string("test only supports one prompt");
46
-            }
47
-            response_.resp_retcode = 13;
48
-            response_.resp = const_cast<char *>(answer_.c_str());
49
-            answers.resize(1);
50
-            answers[0] = &response_;
51
-            return 0;
41
+class fake_failing_answer_conversation: public pam_conversation
42
+{
43
+private:
44
+    pam_response response_;
45
+    std::string answer_;
46
+public:
47
+    fake_failing_answer_conversation() : answer_("ok:1") {}
48
+    int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers)
49
+    {
50
+        if (prompts.size() != 1) {
51
+            throw std::string("test only supports one prompt");
52 52
         }
53
+        response_.resp_retcode = 13;
54
+        response_.resp = const_cast<char *>(answer_.c_str());
55
+        answers.resize(1);
56
+        answers[0] = &response_;
57
+        return 0;
58
+    }
53 59
 };
54 60
 
55
-class match_prompt_text_conversation : public pam_conversation {
56
-    private:
57
-        pam_response response_;
58
-        std::string answer_;
59
-        std::string prompt_;
60
-    public:
61
-        match_prompt_text_conversation(const std::string &prompt) : prompt_(prompt), answer_("ok:123") {}
62
-        int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers) {
63
-            if (prompt_ != prompts[0]->msg) {
64
-                throw std::string("prompt does not match");
65
-            }
66
-            response_.resp_retcode = 0;
67
-            response_.resp = const_cast<char *>(answer_.c_str());
68
-            answers.resize(1);
69
-            answers[0] = &response_;
70
-            return 0;
61
+class match_prompt_text_conversation : public pam_conversation
62
+{
63
+private:
64
+    pam_response response_;
65
+    std::string answer_;
66
+    std::string prompt_;
67
+public:
68
+    match_prompt_text_conversation(const std::string &prompt) : prompt_(prompt), answer_("ok:123") {}
69
+    int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers)
70
+    {
71
+        if (prompt_ != prompts[0]->msg) {
72
+            throw std::string("prompt does not match");
71 73
         }
74
+        response_.resp_retcode = 0;
75
+        response_.resp = const_cast<char *>(answer_.c_str());
76
+        answers.resize(1);
77
+        answers[0] = &response_;
78
+        return 0;
79
+    }
72 80
 
73 81
 };
74 82
 
75
-class match_prompt_style_conversation : public pam_conversation {
76
-    private:
77
-        pam_response response_;
78
-        std::string answer_;
79
-        int style_;
80
-    public:
81
-        match_prompt_style_conversation(int style) : style_(style), answer_("ok:123") {}
82
-        int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers) {
83
-            if (style_ != prompts[0]->msg_style) {
84
-                throw std::string("style does not match");
85
-            }
86
-            response_.resp_retcode = 0;
87
-            response_.resp = const_cast<char *>(answer_.c_str());
88
-            answers.resize(1);
89
-            answers[0] = &response_;
90
-            return 0;
83
+class match_prompt_style_conversation : public pam_conversation
84
+{
85
+private:
86
+    pam_response response_;
87
+    std::string answer_;
88
+    int style_;
89
+public:
90
+    match_prompt_style_conversation(int style) : style_(style), answer_("ok:123") {}
91
+    int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers)
92
+    {
93
+        if (style_ != prompts[0]->msg_style) {
94
+            throw std::string("style does not match");
91 95
         }
96
+        response_.resp_retcode = 0;
97
+        response_.resp = const_cast<char *>(answer_.c_str());
98
+        answers.resize(1);
99
+        answers[0] = &response_;
100
+        return 0;
101
+    }
92 102
 
93 103
 };
94 104
 
95
-class fake_pam : public pam {
96
-    private:
97
-        std::shared_ptr<pam_conversation> conversation_;
98
-    public:
99
-        fake_pam(std::shared_ptr<pam_conversation> conversation) : conversation_(conversation) {}
100
-        fake_pam() {}
101
-        int get_conversation(pam_handle_t *pamh, std::shared_ptr<pam_conversation> &conversation) {
102
-            if (conversation_) {
103
-               conversation = conversation_;
104
-               return 0;
105
-            }
106
-            return 12;
105
+class fake_pam : public pam
106
+{
107
+private:
108
+    std::shared_ptr<pam_conversation> conversation_;
109
+public:
110
+    fake_pam(std::shared_ptr<pam_conversation> conversation) : conversation_(conversation) {}
111
+    fake_pam() {}
112
+    int get_conversation(pam_handle_t *pamh, std::shared_ptr<pam_conversation> &conversation)
113
+    {
114
+        if (conversation_) {
115
+            conversation = conversation_;
116
+            return 0;
107 117
         }
118
+        return 12;
119
+    }
108 120
 };
109 121
 
110 122
 
111
-int returns_correct_token() {
123
+int returns_correct_token()
124
+{
112 125
     //given
113 126
     pam_handle_t *pamh;
114 127
     pam_conversation_p fake_conversation = (pam_conversation_p) new fake_pam_conversation("user:code");
... ...
@@ -122,7 +135,8 @@ int returns_correct_token() {
122 135
     succeed();
123 136
 }
124 137
 
125
-int returns_correct_user_name() {
138
+int returns_correct_user_name()
139
+{
126 140
     //given
127 141
     pam_handle_t *pamh;
128 142
     pam_conversation_p fake_conversation = (pam_conversation_p) new fake_pam_conversation("sally:token");
... ...
@@ -137,7 +151,8 @@ int returns_correct_user_name() {
137 151
     succeed();
138 152
 }
139 153
 
140
-int returns_empty_user_and_token_when_no_colon() {
154
+int returns_empty_user_and_token_when_no_colon()
155
+{
141 156
     //given
142 157
     pam_handle_t *pamh;
143 158
     pam_conversation_p fake_conversation = (pam_conversation_p) new fake_pam_conversation("sally");
... ...
@@ -152,7 +167,8 @@ int returns_empty_user_and_token_when_no_colon() {
152 167
     succeed();
153 168
 }
154 169
 
155
-int returns_empty_user_and_token_when_empty_answer() {
170
+int returns_empty_user_and_token_when_empty_answer()
171
+{
156 172
     //given
157 173
     pam_handle_t *pamh;
158 174
     pam_conversation_p fake_conversation = (pam_conversation_p) new fake_pam_conversation("");
... ...
@@ -167,7 +183,8 @@ int returns_empty_user_and_token_when_empty_answer() {
167 183
     succeed();
168 184
 }
169 185
 
170
-int returns_empty_token_when_colon_end() {
186
+int returns_empty_token_when_colon_end()
187
+{
171 188
     //given
172 189
     pam_handle_t *pamh;
173 190
     pam_conversation_p fake_conversation = (pam_conversation_p) new fake_pam_conversation("sally:");
... ...
@@ -182,7 +199,8 @@ int returns_empty_token_when_colon_end() {
182 199
     succeed();
183 200
 }
184 201
 
185
-int returns_empty_user_when_colon_begin() {
202
+int returns_empty_user_when_colon_begin()
203
+{
186 204
     //given
187 205
     pam_handle_t *pamh;
188 206
     pam_conversation_p fake_conversation = (pam_conversation_p) new fake_pam_conversation(":token");
... ...
@@ -197,7 +215,8 @@ int returns_empty_user_when_colon_begin() {
197 215
     succeed();
198 216
 }
199 217
 
200
-int returns_empty_user_and_token_when_pam_cant_create_conversation() {
218
+int returns_empty_user_and_token_when_pam_cant_create_conversation()
219
+{
201 220
     // given
202 221
     pam_handle_t *pamh;
203 222
     pam_p pam = (pam_p)new fake_pam;
... ...
@@ -212,7 +231,8 @@ int returns_empty_user_and_token_when_pam_cant_create_conversation() {
212 231
 
213 232
 }
214 233
 
215
-int prompts_user_with_correct_text() {
234
+int prompts_user_with_correct_text()
235
+{
216 236
     // given
217 237
     pam_handle_t *pamh;
218 238
     pam_conversation_p match_conversation = (pam_conversation_p) new match_prompt_text_conversation("Dual control token: ");
... ...
@@ -221,15 +241,16 @@ int prompts_user_with_correct_text() {
221 241
 
222 242
     // when / then
223 243
     try {
224
-      pam_token_conversation conversation(pamh, pam);
225
-      succeed();
244
+        pam_token_conversation conversation(pamh, pam);
245
+        succeed();
226 246
     } catch (const std::string &x) {
227 247
         fail();
228 248
     }
229 249
 
230 250
 }
231 251
 
232
-int prompts_user_with_correct_style() {
252
+int prompts_user_with_correct_style()
253
+{
233 254
     // given
234 255
     pam_handle_t *pamh;
235 256
     pam_conversation_p match_conversation = (pam_conversation_p) new match_prompt_style_conversation(PAM_PROMPT_ECHO_OFF);
... ...
@@ -238,14 +259,15 @@ int prompts_user_with_correct_style() {
238 259
 
239 260
     // when / then
240 261
     try {
241
-      pam_token_conversation conversation(pamh, pam);
242
-      succeed();
262
+        pam_token_conversation conversation(pamh, pam);
263
+        succeed();
243 264
     } catch (const std::string &x) {
244 265
         fail();
245 266
     }
246 267
 }
247 268
 
248
-int returns_empty_user_and_token_when_conversation_fails() {
269
+int returns_empty_user_and_token_when_conversation_fails()
270
+{
249 271
     //given
250 272
     pam_handle_t *pamh;
251 273
     pam_conversation_p fake_conversation = (pam_conversation_p) new fake_failing_conversation;
... ...
@@ -260,7 +282,8 @@ int returns_empty_user_and_token_when_conversation_fails() {
260 282
     succeed();
261 283
 }
262 284
 
263
-int returns_empty_user_and_token_when_conversation_answer_fails() {
285
+int returns_empty_user_and_token_when_conversation_answer_fails()
286
+{
264 287
     //given
265 288
     pam_handle_t *pamh;
266 289
     pam_conversation_p fake_conversation = (pam_conversation_p) new fake_failing_answer_conversation;
... ...
@@ -278,7 +301,8 @@ int returns_empty_user_and_token_when_conversation_answer_fails() {
278 301
 RESET_VARS_START
279 302
 RESET_VARS_END
280 303
 
281
-int run_tests() {
304
+int run_tests()
305
+{
282 306
     test(returns_correct_token);
283 307
     test(returns_correct_user_name);
284 308
     test(returns_empty_user_and_token_when_no_colon);
... ...
@@ -293,7 +317,8 @@ int run_tests() {
293 317
     succeed();
294 318
 }
295 319
 
296
-int main(int argc, char *args[]) {
320
+int main(int argc, char *args[])
321
+{
297 322
     return !run_tests();
298 323
 }
299 324
 
... ...
@@ -2,15 +2,16 @@
2 2
 #include "conversation.h"
3 3
 #include "validator.h"
4 4
 
5
-class impl : public dual_control_ifc {
6
-    private:
7
-       conversations conversations_;
8
-       validator validator_;
9
-       logger logger_;
10
-    public:
11
-        impl(const dual_control_configuration &configuration);
12
-        int authenticate(pam_handle *handle, int flags, const std::vector<const std::string> &arguments );
13
-        int setcred(pam_handle *handle, int flags, const std::vector<const std::string> &arguments);
5
+class impl : public dual_control_ifc
6
+{
7
+private:
8
+    conversations conversations_;
9
+    validator validator_;
10
+    logger logger_;
11
+public:
12
+    impl(const dual_control_configuration &configuration);
13
+    int authenticate(pam_handle *handle, int flags, const std::vector<const std::string> &arguments );
14
+    int setcred(pam_handle *handle, int flags, const std::vector<const std::string> &arguments);
14 15
 };
15 16
 
16 17
 impl::impl(const dual_control_configuration &configuration) :
... ...
@@ -18,11 +19,13 @@ impl::impl(const dual_control_configuration &configuration) :
18 19
     validator_(configuration.validator),
19 20
     logger_(configuration.logger) {}
20 21
 
21
-int impl::setcred(pam_handle *handle, int flags, const std::vector<const std::string> &arguments) {
22
+int impl::setcred(pam_handle *handle, int flags, const std::vector<const std::string> &arguments)
23
+{
22 24
     return PAM_SUCCESS;
23 25
 }
24 26
 
25
-int impl::authenticate(pam_handle *handle, int flags, const std::vector<const std::string> &arguments) {
27
+int impl::authenticate(pam_handle *handle, int flags, const std::vector<const std::string> &arguments)
28
+{
26 29
 
27 30
     conversation_result conversation = conversations_.initiate_conversation();
28 31
     std::string user_name = conversation.user_name();
... ...
@@ -34,7 +37,8 @@ int impl::authenticate(pam_handle *handle, int flags, const std::vector<const st
34 37
     return auth_result;
35 38
 }
36 39
 
37
-dual_control create_dual_control(const dual_control_configuration &configuration) {
40
+dual_control create_dual_control(const dual_control_configuration &configuration)
41
+{
38 42
     return dual_control(new impl(configuration));
39 43
 }
40 44
 
... ...
@@ -16,11 +16,12 @@
16 16
 #include "conversation.h"
17 17
 #include "logger.h"
18 18
 
19
-class dual_control_ifc {
20
-    public:
21
-        virtual ~dual_control_ifc() {}
22
-        virtual int authenticate(pam_handle_t *handle, int flags, const std::vector<const std::string> &arguments ) = 0;
23
-        virtual int setcred(pam_handle_t *handle, int flags, const std::vector<const std::string> &arguments) = 0;
19
+class dual_control_ifc
20
+{
21
+public:
22
+    virtual ~dual_control_ifc() {}
23
+    virtual int authenticate(pam_handle_t *handle, int flags, const std::vector<const std::string> &arguments ) = 0;
24
+    virtual int setcred(pam_handle_t *handle, int flags, const std::vector<const std::string> &arguments) = 0;
24 25
 };
25 26
 typedef std::shared_ptr<dual_control_ifc> dual_control;
26 27
 
... ...
@@ -11,12 +11,14 @@
11 11
 
12 12
 extern dual_control dc;
13 13
 
14
-PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv) {
14
+PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv)
15
+{
15 16
     std::vector<const std::string> arguments = convert_arguments(argc, argv);
16 17
     return dc->authenticate(pamh, flags, arguments);
17 18
 }
18 19
 
19
-PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv) {
20
+PAM_EXTERN int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv)
21
+{
20 22
     std::vector<const std::string> arguments = convert_arguments(argc, argv);
21 23
     return dc->setcred(pamh, flags, arguments);
22 24
 }
... ...
@@ -9,63 +9,83 @@
9 9
 
10 10
 
11 11
 template<class T>
12
-std::shared_ptr<T> share(T* t) {
13
-  return std::shared_ptr<T>(t);
12
+std::shared_ptr<T> share(T* t)
13
+{
14
+    return std::shared_ptr<T>(t);
14 15
 }
15 16
 
16 17
 
17
-void use_validator(dual_control_configuration &config, validator_ifc *value) {
18
+void use_validator(dual_control_configuration &config, validator_ifc *value)
19
+{
18 20
     config.validator = validator(share(value));
19 21
 }
20 22
 
21
-void use_conversations(dual_control_configuration &config, conversations_ifc *value) {
23
+void use_conversations(dual_control_configuration &config, conversations_ifc *value)
24
+{
22 25
     config.conversations = conversations(share(value));
23 26
 }
24 27
 
25
-void use_logger(dual_control_configuration &config, logger_ifc *value) {
28
+void use_logger(dual_control_configuration &config, logger_ifc *value)
29
+{
26 30
     config.logger = logger(share(value));
27 31
 }
28 32
 
29
-class mock_logger : public logger_ifc {
30
-    private:
31
-        int result_;
32
-        std::string user_name_;
33
-        std::string token_;
34
-    public:
35
-        void log(int result, const std::string &user_name, const std::string &token) {
36
-            result_ = result;
37
-            user_name_ = user_name;
38
-            token_ = token;
39
-        }
40
-        int logged_result() { return result_; }
41
-        std::string logged_user_name() { return user_name_; }
42
-        std::string logged_token() { return token_; }
33
+class mock_logger : public logger_ifc
34
+{
35
+private:
36
+    int result_;
37
+    std::string user_name_;
38
+    std::string token_;
39
+public:
40
+    void log(int result, const std::string &user_name, const std::string &token)
41
+    {
42
+        result_ = result;
43
+        user_name_ = user_name;
44
+        token_ = token;
45
+    }
46
+    int logged_result()
47
+    {
48
+        return result_;
49
+    }
50
+    std::string logged_user_name()
51
+    {
52
+        return user_name_;
53
+    }
54
+    std::string logged_token()
55
+    {
56
+        return token_;
57
+    }
43 58
 };
44 59
 
45
-class fake_conversations : public conversations_ifc {
46
-    private:
47
-        std::string user_name_;
48
-        std::string token_;
49
-    public:
50
-        fake_conversations(const std::string &user_name, const std::string &token) : user_name_(user_name), token_(token) {}
51
-        conversation_result initiate_conversation() {
52
-            return conversation_result(user_name_, token_);
53
-        }
60
+class fake_conversations : public conversations_ifc
61
+{
62
+private:
63
+    std::string user_name_;
64
+    std::string token_;
65
+public:
66
+    fake_conversations(const std::string &user_name, const std::string &token) : user_name_(user_name), token_(token) {}
67
+    conversation_result initiate_conversation()
68
+    {
69
+        return conversation_result(user_name_, token_);
70
+    }
54 71
 };
55 72
 
56
-class fake_validator : public validator_ifc {
57
-    private:
58
-        std::string user_;
59
-        std::string token_;
60
-    public:
61
-        fake_validator(const std::string &user, const std::string &token): user_(user), token_(token) {}
62
-        bool validate(const std::string &user, const std::string &token) {
63
-            return user_ == user && token_ == token;
64
-        }
73
+class fake_validator : public validator_ifc
74
+{
75
+private:
76
+    std::string user_;
77
+    std::string token_;
78
+public:
79
+    fake_validator(const std::string &user, const std::string &token): user_(user), token_(token) {}
80
+    bool validate(const std::string &user, const std::string &token)
81
+    {
82
+        return user_ == user && token_ == token;
83
+    }
65 84
 };
66 85
 
67 86
 
68
-int setcred_returns_success() {
87
+int setcred_returns_success()
88
+{
69 89
     //given
70 90
     dual_control_configuration configuration;
71 91
     pam_handle *pamh(0);
... ...
@@ -81,7 +101,8 @@ int setcred_returns_success() {
81 101
 
82 102
 }
83 103
 
84
-int authenticate_validates_with_received_token() {
104
+int authenticate_validates_with_received_token()
105
+{
85 106
     // given
86 107
     dual_control_configuration configuration;
87 108
     std::string user("user");
... ...
@@ -100,7 +121,8 @@ int authenticate_validates_with_received_token() {
100 121
     succeed();
101 122
 }
102 123
 
103
-int authenticate_fails_with_wrong_user() {
124
+int authenticate_fails_with_wrong_user()
125
+{
104 126
     // given
105 127
     dual_control_configuration configuration;
106 128
     std::string token("token");
... ...
@@ -118,7 +140,8 @@ int authenticate_fails_with_wrong_user() {
118 140
     succeed();
119 141
 }
120 142
 
121
-int authenticate_fails_with_wrong_token() {
143
+int authenticate_fails_with_wrong_token()
144
+{
122 145
     // given
123 146
     dual_control_configuration configuration;
124 147
     std::string user("user");
... ...
@@ -136,7 +159,8 @@ int authenticate_fails_with_wrong_token() {
136 159
     succeed();
137 160
 }
138 161
 
139
-int logs_authentication() {
162
+int logs_authentication()
163
+{
140 164
     //given
141 165
     dual_control_configuration configuration;
142 166
     std::string user("user");
... ...
@@ -159,7 +183,8 @@ int logs_authentication() {
159 183
     succeed();
160 184
 }
161 185
 
162
-int logs_authentication_failure() {
186
+int logs_authentication_failure()
187
+{
163 188
     //given
164 189
     dual_control_configuration configuration;
165 190
     std::string user("user");
... ...
@@ -186,7 +211,8 @@ int logs_authentication_failure() {
186 211
 RESET_VARS_START
187 212
 RESET_VARS_END
188 213
 
189
-int runtests() {
214
+int runtests()
215
+{
190 216
     test(setcred_returns_success);
191 217
     test(authenticate_validates_with_received_token);
192 218
     test(authenticate_fails_with_wrong_user);
... ...
@@ -196,8 +222,9 @@ int runtests() {
196 222
     succeed();
197 223
 }
198 224
 
199
-int main(int argc, char* argv[]) {
200
-   return !runtests();
225
+int main(int argc, char* argv[])
226
+{
227
+    return !runtests();
201 228
 }
202 229
 
203 230
 
... ...
@@ -4,21 +4,24 @@
4 4
 #include <memory>
5 5
 #include <string>
6 6
 
7
-class logger_ifc {
8
-    public:
9
-        virtual ~logger_ifc() {}
10
-        virtual void log(int result, const std::string &user_name, const std::string &token) {};
7
+class logger_ifc
8
+{
9
+public:
10
+    virtual ~logger_ifc() {}
11
+    virtual void log(int result, const std::string &user_name, const std::string &token) {};
11 12
 };
12 13
 
13
-class logger : public logger_ifc {
14
-    private:
15
-        std::shared_ptr<logger_ifc> delegate_;
16
-    public:
17
-        logger(const std::shared_ptr<logger_ifc> &delegate) : delegate_(delegate) {}
18
-        logger() : logger(std::shared_ptr<logger_ifc>(new logger_ifc)) {}
19
-        void log(int result, const std::string &user_name, const std::string &token) {
20
-            delegate_->log(result, user_name, token);
21
-        }
14
+class logger : public logger_ifc
15
+{
16
+private:
17
+    std::shared_ptr<logger_ifc> delegate_;
18
+public:
19
+    logger(const std::shared_ptr<logger_ifc> &delegate) : delegate_(delegate) {}
20
+    logger() : logger(std::shared_ptr<logger_ifc>(new logger_ifc)) {}
21
+    void log(int result, const std::string &user_name, const std::string &token)
22
+    {
23
+        delegate_->log(result, user_name, token);
24
+    }
22 25
 };
23 26
 
24 27
 #endif
... ...
@@ -6,13 +6,15 @@
6 6
 
7 7
 static const char program_name[] = "pam_dual_control";
8 8
 
9
-void log_success() {
9
+void log_success()
10
+{
10 11
     openlog(program_name, 0, LOG_AUTHPRIV);
11 12
     syslog(LOG_NOTICE, "dual control succeeded");
12 13
     closelog();
13 14
 }
14 15
 
15
-void log_failure() {
16
+void log_failure()
17
+{
16 18
     openlog(program_name, 0, LOG_AUTHPRIV);
17 19
     syslog(LOG_NOTICE, "dual control failed");
18 20
     closelog();
... ...
@@ -7,20 +7,23 @@
7 7
 
8 8
 int logged_priority = -1000;
9 9
 const char *logged_message = "";
10
-void fake_syslog(int priority, const char *message, ...) {
10
+void fake_syslog(int priority, const char *message, ...)
11
+{
11 12
     logged_priority = priority;
12 13
     logged_message = message;
13 14
 }
14 15
 
15 16
 int close_log_invoked = 0;
16
-void fake_closelog(void) {
17
+void fake_closelog(void)
18
+{
17 19
     close_log_invoked = 1;
18 20
 }
19 21
 
20 22
 int opened_facility = -1000;
21 23
 const char *opened_program_name = "";
22 24
 int opened_logopt = -1000;
23
-void fake_openlog(const char *ident, int logopt, int facility) {
25
+void fake_openlog(const char *ident, int logopt, int facility)
26
+{
24 27
     opened_facility = facility;
25 28
     opened_program_name = ident;
26 29
     opened_logopt = logopt;
... ...
@@ -34,7 +37,8 @@ const char *opened_program_name = "";
34 37
 int opened_logopt = -1000;
35 38
 RESET_VARS_END
36 39
 
37
-int test_log_success() {
40
+int test_log_success()
41
+{
38 42
     // given
39 43
 
40 44
     // when
... ...
@@ -50,7 +54,8 @@ int test_log_success() {
50 54
     succeed();
51 55
 }
52 56
 
53
-int test_log_failure() {
57
+int test_log_failure()
58
+{
54 59
     //given
55 60
 
56 61
     //when
... ...
@@ -66,13 +71,15 @@ int test_log_failure() {
66 71
     succeed();
67 72
 }
68 73
 
69
-int test_runner() {
74
+int test_runner()
75
+{
70 76
     test(test_log_success);
71 77
     test(test_log_failure);
72 78
     succeed();
73 79
 }
74 80
 
75
-int main(int numargs, char **args) {
81
+int main(int numargs, char **args)
82
+{
76 83
     return !test_runner();
77 84
 }
78 85
 
... ...
@@ -6,31 +6,36 @@
6 6
 
7 7
 #include "pam.h"
8 8
 
9
-class pam_conversation_impl : public pam_conversation {
10
-    private:
11
-        struct pam_conv *pam_conv_;
12
-    public:
13
-        pam_conversation_impl(pam_conv *conv) : pam_conv_(conv) {}
14
-        int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers);
9
+class pam_conversation_impl : public pam_conversation
10
+{
11
+private:
12
+    struct pam_conv *pam_conv_;
13
+public:
14
+    pam_conversation_impl(pam_conv *conv) : pam_conv_(conv) {}
15
+    int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers);
15 16
 };
16 17
 
17
-class pam_impl : public pam {
18
-    public:
19
-        int get_conversation(pam_handle_t *pamh, std::shared_ptr<pam_conversation> &conversation);
18
+class pam_impl : public pam
19
+{
20
+public:
21
+    int get_conversation(pam_handle_t *pamh, std::shared_ptr<pam_conversation> &conversation);
20 22
 };
21 23
 
22
-int pam_impl::get_conversation(pam_handle_t *pamh, std::shared_ptr<pam_conversation> &conversation) {
24
+int pam_impl::get_conversation(pam_handle_t *pamh, std::shared_ptr<pam_conversation> &conversation)
25
+{
23 26
     struct pam_conv *pam_conv;
24 27
     int result = pam_get_item(pamh, PAM_CONV, (const void **)&pam_conv);
25 28
     conversation.reset(new pam_conversation_impl(pam_conv));
26 29
     return result;
27 30
 }
28 31
 
29
-int pam_conversation_impl::conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers) {
32
+int pam_conversation_impl::conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers)
33
+{
30 34
     return pam_conv_->conv(prompts.size(), const_cast<const struct pam_message **>(prompts.data()),
31
-            answers.data(), pam_conv_->appdata_ptr);
35
+                           answers.data(), pam_conv_->appdata_ptr);
32 36
 }
33 37
 
34
-pam_p get_system_pam() {
38
+pam_p get_system_pam()
39
+{
35 40
     return (pam_p)new pam_impl;
36 41
 }
... ...
@@ -5,15 +5,17 @@
5 5
 #include <memory>
6 6
 #include <security/pam_modules.h>
7 7
 
8
-class pam_conversation {
9
-    public:
10
-        virtual int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers) = 0;
8
+class pam_conversation
9
+{
10
+public:
11
+    virtual int conv(const std::vector<const struct pam_message *> &prompts, std::vector<struct pam_response *> &answers) = 0;
11 12
 };
12 13
 typedef std::shared_ptr<pam_conversation> pam_conversation_p;
13 14
 
14
-class pam {
15
-    public:
16
-        virtual int get_conversation(pam_handle_t *pamh, std::shared_ptr<pam_conversation> &conversation) = 0;
15
+class pam
16
+{
17
+public:
18
+    virtual int get_conversation(pam_handle_t *pamh, std::shared_ptr<pam_conversation> &conversation) = 0;
17 19
 };
18 20
 typedef std::shared_ptr<pam> pam_p;
19 21
 
... ...
@@ -6,9 +6,10 @@
6 6
 #include "user.h"
7 7
 
8 8
 
9
-class user_token_supplier {
10
-    public:
11
-       virtual std::string token(const user_p user) = 0;
9
+class user_token_supplier
10
+{
11
+public:
12
+    virtual std::string token(const user_p user) = 0;
12 13
 };
13 14
 typedef std::shared_ptr<user_token_supplier> user_token_supplier_p;
14 15
 
... ...
@@ -11,24 +11,27 @@ const char *fake_user_token = "";
11 11
 
12 12
 // all the fake system calls
13 13
 const char *fake_home_dir = "";
14
-int fake_getpwnam_r(const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result) {
15
-  strcpy(buffer, fake_home_dir);
16
-  pwd->pw_dir = buffer;
17
-  int ok = !strcmp(nam, fake_user);
18
-  *result = ok ? pwd : 0;
19
-  return !ok;
14
+int fake_getpwnam_r(const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
15
+{
16
+    strcpy(buffer, fake_home_dir);
17
+    pwd->pw_dir = buffer;
18
+    int ok = !strcmp(nam, fake_user);
19
+    *result = ok ? pwd : 0;
20
+    return !ok;
20 21
 }
21 22
 
22 23
 
23 24
 const char *fake_stat_path = "";
24
-int fake_stat(const char *path, struct stat *stat) {
25
+int fake_stat(const char *path, struct stat *stat)
26
+{
25 27
     return (strcmp(fake_stat_path, path));
26 28
 }
27 29
 
28 30
 const char *fake_fopen_path = "";
29 31
 const char *fake_fopen_mode = "";
30 32
 FILE *_fhandle = 0;
31
-FILE *fake_fopen(const char *path, const char *mode) {
33
+FILE *fake_fopen(const char *path, const char *mode)
34
+{
32 35
     static FILE handle;
33 36
     int path_matches = !strcmp(fake_fopen_path, path);
34 37
     int mode_matches = !strcmp(fake_fopen_mode, mode);
... ...
@@ -41,16 +44,18 @@ FILE *fake_fopen(const char *path, const char *mode) {
41 44
     }
42 45
 }
43 46
 
44
-char *fake_fgets(char *buf, int n, FILE *fp) {
47
+char *fake_fgets(char *buf, int n, FILE *fp)
48
+{
45 49
     if (_fhandle == fp && fp != 0) {
46
-       strncpy(buf, fake_user_token, n - 1);
50
+        strncpy(buf, fake_user_token, n - 1);
47 51
         return buf;
48 52
     } else {
49 53
         return 0;
50 54
     }
51 55
 }
52 56
 
53
-int fake_fclose(FILE *fp) {
57
+int fake_fclose(FILE *fp)
58
+{
54 59
     return 0;
55 60
 }
56 61
 
... ...
@@ -69,7 +74,8 @@ fake_fopen_mode = "r";
69 74
 RESET_VARS_END
70 75
 
71 76
 
72
-int validate_compares_to_user_token() {
77
+int validate_compares_to_user_token()
78
+{
73 79
 
74 80
     // given
75 81
 
... ...
@@ -83,7 +89,8 @@ int validate_compares_to_user_token() {
83 89
 
84 90
 }
85 91
 
86
-int validates_from_the_right_user() {
92
+int validates_from_the_right_user()
93
+{
87 94
     //given
88 95
 
89 96
     //when
... ...
@@ -94,7 +101,8 @@ int validates_from_the_right_user() {
94 101
     succeed();
95 102
 }
96 103
 
97
-int validates_user_specific_token() {
104
+int validates_user_specific_token()
105
+{
98 106
     //given
99 107
 
100 108
     //when
... ...
@@ -105,14 +113,16 @@ int validates_user_specific_token() {
105 113
     succeed();
106 114
 }
107 115
 
108
-int runtests() {
116
+int runtests()
117
+{
109 118
     test(validate_compares_to_user_token);
110 119
     test(validates_from_the_right_user);
111 120
     test(validates_user_specific_token);
112 121
     succeed();
113 122
 }
114 123
 
115
-int main(int argc, char **argv) {
124
+int main(int argc, char **argv)
125
+{
116 126
     int rval = !runtests();
117 127
     return rval;
118 128
 }
... ...
@@ -8,30 +8,35 @@
8 8
 #include "user.h"
9 9
 #include "test_support.h"
10 10
 
11
-user::user(struct passwd *sys_info) : info(sys_info) {
11
+user::user(struct passwd *sys_info) : info(sys_info)
12
+{
12 13
 }
13 14
 
14
-std::string user::home_directory() {
15
+std::string user::home_directory()
16
+{
15 17
     return info->pw_dir;
16 18
 }
17 19
 
18 20
 // concrete user implementation
19 21
 
20
-class concrete_user : public user {
21
-     private:
22
-        std::vector<char> buffer_;
23
-        std::shared_ptr<struct passwd> store_;
24
-     public:
25
-         concrete_user(const std::vector<char> &buffer, const std::shared_ptr<struct passwd> &store);
22
+class concrete_user : public user
23
+{
24
+private:
25
+    std::vector<char> buffer_;
26
+    std::shared_ptr<struct passwd> store_;
27
+public:
28
+    concrete_user(const std::vector<char> &buffer, const std::shared_ptr<struct passwd> &store);
26 29
 };
27 30
 
28 31
 concrete_user::concrete_user(const std::vector<char> &buffer, const std::shared_ptr<struct passwd> &store) :
29 32
     buffer_(buffer),
30 33
     store_(store),
31
-    user(store.get()) {
34
+    user(store.get())
35
+{
32 36
 }
33 37
 
34
-const std::shared_ptr<user> create_user(const std::string &user_name) {
38
+const std::shared_ptr<user> create_user(const std::string &user_name)
39
+{
35 40
     std::vector<char> buffer(sysconf(_SC_GETPW_R_SIZE_MAX));
36 41
     std::shared_ptr<struct passwd> sys_passwd(new struct passwd);
37 42
     struct passwd *found_passwd(0);
... ...
@@ -5,18 +5,20 @@
5 5
 #include <memory>
6 6
 #include <pwd.h>
7 7
 
8
-class user {
9
-    public:
10
-        virtual ~user() {}
8
+class user
9
+{
10
+public:
11
+    virtual ~user() {}
11 12
 //        virtual std::string home_directory() = 0;
12 13
 };
13 14
 
14 15
 
15 16
 typedef std::shared_ptr<user> user_p;
16
-class directory {
17
-    public:
18
-       virtual ~directory() {}
19
-        virtual const user_p find_user(const std::string &user_name) = 0;
17
+class directory
18
+{
19
+public:
20
+    virtual ~directory() {}
21
+    virtual const user_p find_user(const std::string &user_name) = 0;
20 22
 };
21 23
 
22 24
 typedef std::shared_ptr<directory> directory_p;
... ...
@@ -4,7 +4,8 @@
4 4
 #include "test_util.h"
5 5
 
6 6
 
7
-bool gets_home_directory() {
7
+bool gets_home_directory()
8
+{
8 9
     //given
9 10
     const char *expected_home_directory = "home/msmith";
10 11
     struct passwd test_passwd;
... ...
@@ -21,16 +22,18 @@ bool gets_home_directory() {
21 22
 
22 23
 
23 24
 std::shared_ptr<struct passwd> fake_passwd;
24
-int fake_getpwnam_r(const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result) {
25
-  if (fake_passwd) {
26
-      *pwd = *fake_passwd;
27
-      *result = pwd;
28
-      return 0;
29
-  }
30
-  return -1;
25
+int fake_getpwnam_r(const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
26
+{
27
+    if (fake_passwd) {
28
+        *pwd = *fake_passwd;
29
+        *result = pwd;
30
+        return 0;
31
+    }
32
+    return -1;
31 33
 }
32 34
 
33
-bool create_user_succeeds() {
35
+bool create_user_succeeds()
36
+{
34 37
     // given
35 38
     std::string username("msmith");
36 39
     std::string home_directory("this is my home");
... ...
@@ -48,7 +51,8 @@ bool create_user_succeeds() {
48 51
 
49 52
 }
50 53
 
51
-bool create_user_nonexistent() {
54
+bool create_user_nonexistent()
55
+{
52 56
     // given
53 57
     std::string username("msmith");
54 58
 
... ...
@@ -65,13 +69,15 @@ RESET_VARS_START
65 69
 fake_passwd.reset((struct passwd *)0);
66 70
 RESET_VARS_END
67 71
 
68
-int run_tests() {
72
+int run_tests()
73
+{
69 74
     test(gets_home_directory);
70 75
     test(create_user_succeeds);
71 76
     test(create_user_nonexistent);
72 77
     succeed();
73 78
 }
74
-int main(int argc, char *argv[]) {
79
+int main(int argc, char *argv[])
80
+{
75 81
     return !run_tests();
76 82
 }
77 83
 
... ...
@@ -3,7 +3,8 @@
3 3
 
4 4
 #include "validator.h"
5 5
 
6
-bool old_validator::validate(const std::string &user_name, const std::string &token) {
6
+bool old_validator::validate(const std::string &user_name, const std::string &token)
7
+{
7 8
     user_p found_user = directory_->find_user(user_name);
8 9
 
9 10
     if (!found_user) {
... ...
@@ -7,34 +7,39 @@
7 7
 #include "user.h"
8 8
 #include "token.h"
9 9
 
10
-class validator_ifc {
11
-    public:
12
-        virtual ~validator_ifc() {}
13
-        virtual bool validate(const std::string &user_name, const std::string &token) {
14
-           return false;
15
-        }
10
+class validator_ifc
11
+{
12
+public:
13
+    virtual ~validator_ifc() {}
14
+    virtual bool validate(const std::string &user_name, const std::string &token)
15
+    {
16
+        return false;
17
+    }
16 18
 };
17 19
 
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
-        }
20
+class validator : public validator_ifc
21
+{
22
+private:
23
+    std::shared_ptr<validator_ifc> delegate_;
24
+public:
25
+    validator(const std::shared_ptr<validator_ifc> &delegate) : delegate_(delegate) {}
26
+    validator() : validator(std::shared_ptr<validator_ifc>(new validator_ifc)) {}
27
+    bool validate(const std::string &user_name, const std::string &token)
28
+    {
29
+        return delegate_->validate(user_name, token);
30
+    }
27 31
 };
28 32
 
29
-class old_validator {
30
-    private:
31
-        directory_p directory_;
32
-        user_token_supplier_p user_token_supplier_;
33
-    public:
34
-        old_validator(const directory_p &directory, const user_token_supplier_p &user_token_supplier):
35
-            directory_(directory),
36
-            user_token_supplier_(user_token_supplier) {}
37
-        bool validate(const std::string &user, const std::string &token);
33
+class old_validator
34
+{
35
+private:
36
+    directory_p directory_;
37
+    user_token_supplier_p user_token_supplier_;
38
+public:
39
+    old_validator(const directory_p &directory, const user_token_supplier_p &user_token_supplier):
40
+        directory_(directory),
41
+        user_token_supplier_(user_token_supplier) {}
42
+    bool validate(const std::string &user, const std::string &token);
38 43
 };
39 44
 
40 45
 #endif
... ...
@@ -3,36 +3,41 @@
3 3
 #include "test_util.h"
4 4
 #include "token.h"
5 5
 
6
-class fake_directory : public directory {
7
-    private:
8
-        std::string user_name_;
9
-    public:
10
-        fake_directory(const std::string &user_name) : user_name_(user_name) {}
11
-        fake_directory() : user_name_("_NOT_A_USER") {}
12
-
13
-        virtual const user_p find_user(const std::string &user_name) {
14
-            user_p result;
15
-            if (user_name == user_name_) {
16
-                result.reset(new user);
17
-            }
18
-
19
-            return result;
6
+class fake_directory : public directory
7
+{
8
+private:
9
+    std::string user_name_;
10
+public:
11
+    fake_directory(const std::string &user_name) : user_name_(user_name) {}
12
+    fake_directory() : user_name_("_NOT_A_USER") {}
13
+
14
+    virtual const user_p find_user(const std::string &user_name)
15
+    {
16
+        user_p result;
17
+        if (user_name == user_name_) {
18
+            result.reset(new user);
20 19
         }
20
+
21
+        return result;
22
+    }
21 23
 };
22 24
 
23
-class fake_user_token_supplier : public user_token_supplier {
24
-    private:
25
-        std::string token_;
26
-    public:
27
-        fake_user_token_supplier(const std::string &token) : token_(token) {}
28
-        fake_user_token_supplier() : token_("_NOT_A_TOKEN") {}
29
-        virtual std::string token(const user_p user)  {
30
-            return token_;
31
-        }
25
+class fake_user_token_supplier : public user_token_supplier
26
+{
27
+private:
28
+    std::string token_;
29
+public:
30
+    fake_user_token_supplier(const std::string &token) : token_(token) {}
31
+    fake_user_token_supplier() : token_("_NOT_A_TOKEN") {}
32
+    virtual std::string token(const user_p user)
33
+    {
34
+        return token_;
35
+    }
32 36
 };
33 37
 
34 38
 
35
-bool validator_validates() {
39
+bool validator_validates()
40
+{
36 41
 
37 42
     // given
38 43
     std::string token = "token";
... ...
@@ -51,53 +56,57 @@ bool validator_validates() {
51 56
     succeed();
52 57
 }
53 58
 
54
-bool validator_fails_unknown_user() {
59
+bool validator_fails_unknown_user()
60
+{
55 61
 
56
-   // given
57
-   std::string token = "token";
58
-   user_token_supplier_p user_token_supplier(new fake_user_token_supplier(token));
59
-   directory_p directory(new fake_directory);
60
-   old_validator validator(directory, user_token_supplier);
62
+    // given
63
+    std::string token = "token";
64
+    user_token_supplier_p user_token_supplier(new fake_user_token_supplier(token));
65
+    directory_p directory(new fake_directory);
66
+    old_validator validator(directory, user_token_supplier);
61 67
 
62 68
 
63
-   // when
64
-   bool actual = validator.validate("notuser", token);
69
+    // when
70
+    bool actual = validator.validate("notuser", token);
65 71
 
66 72
 
67
-   // then
68
-   check(!actual, "should not be valid");
69
-   succeed();
73
+    // then
74
+    check(!actual, "should not be valid");
75
+    succeed();
70 76
 }
71 77
 
72
-bool validator_fails_incorrect_token() {
78
+bool validator_fails_incorrect_token()
79
+{
73 80
 
74
-   // given
81
+    // given
75 82
     user_token_supplier_p user_token_supplier(new fake_user_token_supplier);
76 83
     std::string user_name = "msmith";
77 84
     directory_p directory(new fake_directory(user_name));
78 85
     old_validator validator(directory, user_token_supplier);
79 86
 
80 87
 
81
-   // when
82
-   bool actual = validator.validate(user_name, "token");
88
+    // when
89
+    bool actual = validator.validate(user_name, "token");
83 90
 
84 91
 
85
-   // then
86
-   check(!actual, "should not be valid");
87
-   succeed();
92
+    // then
93
+    check(!actual, "should not be valid");
94
+    succeed();
88 95
 }
89 96
 
90 97
 RESET_VARS_START
91 98
 RESET_VARS_END
92 99
 
93
-bool run_tests() {
100
+bool run_tests()
101
+{
94 102
     test(validator_validates);
95 103
     test(validator_fails_unknown_user);
96 104
     test(validator_fails_incorrect_token);
97 105
     succeed();
98 106
 }
99 107
 
100
-int main(int argc, char *argv[]) {
108
+int main(int argc, char *argv[])
109
+{
101 110
     return !run_tests();
102 111
 }
103 112