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