git.fiddlerwoaroof.com
Browse code

token installer handles directory fail

Greg Wiley authored on 03/05/2017 22:19:28
Showing 2 changed files
... ...
@@ -27,6 +27,10 @@ class impl : public installer_ifc {
27 27
             std::string user_name = c_user_name;
28 28
 
29 29
             auto found_user = directory_.find_user(user_name);
30
+            if (found_user.empty()) {
31
+                return "";
32
+            }
33
+
30 34
             user user(found_user[0]);
31 35
             std::string token(generator_());
32 36
             tokens_.save(user, token);
... ...
@@ -51,7 +51,6 @@ class fake_directory : public directory_ifc {
51 51
 
52 52
 int installs_token() {
53 53
     //given
54
-    user user;
55 54
     std::string user_name("user");
56 55
     std::string token("token");
57 56
     auto  test_tokens = std::make_shared<mock_tokens>();
... ...
@@ -91,9 +90,29 @@ int unistd_does_not_find_user_name() {
91 90
     succeed();
92 91
 }
93 92
 
93
+int directory_finds_no_user_info() {
94
+    std::string user_name("user");
95
+    std::string token("token");
96
+    auto  test_tokens = std::make_shared<mock_tokens>();
97
+    tokens tokens{test_tokens};
98
+    unistd unistd(std::make_shared<fake_unistd>(user_name));
99
+    directory directory(std::make_shared<fake_directory>("not the user"));
100
+    installer_ifc::generator generator = [&] { return token; };
101
+
102
+    installer installer = installer::create (tokens, unistd, directory, generator);
103
+
104
+    //when
105
+    installer.install_token();
106
+
107
+    //then
108
+    check(test_tokens->captured_token == "", "installed wrong token");
109
+    succeed();
110
+}
111
+
94 112
 int run_tests() {
95 113
     test(installs_token);
96 114
     test(unistd_does_not_find_user_name);
115
+    test(directory_finds_no_user_info);
97 116
     succeed();
98 117
 }
99 118