Browse code
Read key from filesystem, fix mocks of token
Ed Langley authored on 12/06/2017 23:45:19
Showing 2 changed files
Showing 2 changed files
... | ... |
@@ -24,6 +24,16 @@ class mock_tokens : public tokens_ifc |
24 | 24 |
{ |
25 | 25 |
public: |
26 | 26 |
mutable std::string captured_token; |
27 |
+ const std::string key_; |
|
28 |
+ |
|
29 |
+ mock_tokens (std::string key) |
|
30 |
+ : key_ (key) |
|
31 |
+ {} |
|
32 |
+ |
|
33 |
+ std::string token (const user &user) const override { |
|
34 |
+ return key_; |
|
35 |
+ } |
|
36 |
+ |
|
27 | 37 |
void save (const user &user, const std::string &token) const override |
28 | 38 |
{ |
29 | 39 |
captured_token = token; |
... | ... |
@@ -92,13 +102,13 @@ int installs_token() |
92 | 102 |
{ |
93 | 103 |
//given |
94 | 104 |
std::string user_name ("user"); |
95 |
- std::string token ("token"); |
|
96 |
- auto test_tokens = std::make_shared<mock_tokens>(); |
|
105 |
+ std::string key ("thekey"); |
|
106 |
+ auto test_tokens = std::make_shared<mock_tokens>(key); |
|
97 | 107 |
tokens tokens{test_tokens}; |
98 | 108 |
unistd unistd (std::make_shared<fake_unistd> (user_name)); |
99 | 109 |
directory directory (std::make_shared<fake_directory> (user_name)); |
100 | 110 |
std::shared_ptr<fake_totp_generator> fake_generator = |
101 |
- std::make_shared<fake_totp_generator> (token); |
|
111 |
+ std::make_shared<fake_totp_generator> (); |
|
102 | 112 |
totp_generator generator (fake_generator); |
103 | 113 |
|
104 | 114 |
installer installer = installer::create (tokens, unistd, directory, |
... | ... |
@@ -108,8 +118,8 @@ int installs_token() |
108 | 118 |
std::string result = installer.install_token(); |
109 | 119 |
|
110 | 120 |
//then |
111 |
- check (test_tokens->captured_token == token, "installed wrong token"); |
|
112 |
- check (result == token, "installer returned wrong token"); |
|
121 |
+ check (test_tokens->captured_token == key, "installed wrong token"); |
|
122 |
+ check (result == key, "installer returned wrong token"); |
|
113 | 123 |
succeed(); |
114 | 124 |
} |
115 | 125 |
|
... | ... |
@@ -117,8 +127,8 @@ int unistd_does_not_find_user_name_nullptr_case() |
117 | 127 |
{ |
118 | 128 |
//given |
119 | 129 |
std::string user_name ("user"); |
120 |
- std::string token ("token"); |
|
121 |
- auto test_tokens = std::make_shared<mock_tokens>(); |
|
130 |
+ std::string key ("token"); |
|
131 |
+ auto test_tokens = std::make_shared<mock_tokens>(key); |
|
122 | 132 |
tokens tokens{test_tokens}; |
123 | 133 |
unistd unistd (std::make_shared<fail_unistd>()); |
124 | 134 |
directory directory (std::make_shared<fake_directory> (user_name)); |
... | ... |
@@ -141,8 +151,8 @@ int unistd_does_not_find_user_name_empty_string_case() |
141 | 151 |
{ |
142 | 152 |
//given |
143 | 153 |
std::string user_name ("user"); |
144 |
- std::string token ("token"); |
|
145 |
- auto test_tokens = std::make_shared<mock_tokens>(); |
|
154 |
+ std::string key ("token"); |
|
155 |
+ auto test_tokens = std::make_shared<mock_tokens>(key); |
|
146 | 156 |
tokens tokens{test_tokens}; |
147 | 157 |
unistd unistd (std::make_shared<fake_unistd> ("")); |
148 | 158 |
directory directory (std::make_shared<fake_directory> (user_name)); |
... | ... |
@@ -164,8 +174,8 @@ int unistd_does_not_find_user_name_empty_string_case() |
164 | 174 |
int directory_finds_no_user_info() |
165 | 175 |
{ |
166 | 176 |
std::string user_name ("user"); |
167 |
- std::string token ("token"); |
|
168 |
- auto test_tokens = std::make_shared<mock_tokens>(); |
|
177 |
+ std::string key ("token"); |
|
178 |
+ auto test_tokens = std::make_shared<mock_tokens>(key); |
|
169 | 179 |
tokens tokens{test_tokens}; |
170 | 180 |
unistd unistd (std::make_shared<fake_unistd> (user_name)); |
171 | 181 |
directory directory (std::make_shared<fake_directory> ("not the user")); |