git.fiddlerwoaroof.com
Browse code

do not pass if unkknown requester

Greg Wiley authored on 02/05/2017 17:45:34
Showing 2 changed files
... ...
@@ -32,6 +32,10 @@ public:
32 32
     {
33 33
         std::vector<user> found_user = directory_.find_user (authorizer_user_name);
34 34
 
35
+        if (requester_user_name.empty()) {
36
+            return false;
37
+        }
38
+
35 39
         if (requester_user_name == authorizer_user_name) {
36 40
             return false;
37 41
         }
... ...
@@ -132,6 +132,25 @@ bool validator_fails_with_own_token() {
132 132
 
133 133
 }
134 134
 
135
+bool validator_fails_with_unknown_requester() {
136
+    // given
137
+    std::string requester_user_name("");
138
+    std::string authorizer_user_name("authorizer");
139
+    std::string authorizer_token("token");
140
+    directory directory (share (new fake_directory (authorizer_user_name)));
141
+    user_token_supplier user_token_supplier (share (new
142
+            fake_user_token_supplier(authorizer_token)));
143
+    validator validator = validator::create (directory, user_token_supplier);
144
+
145
+    // when
146
+    bool actual = validator.validate (requester_user_name, authorizer_user_name, authorizer_token);
147
+
148
+    // then
149
+    check(!actual, "should not be valid");
150
+    succeed();
151
+
152
+}
153
+
135 154
 RESET_VARS_START
136 155
 RESET_VARS_END
137 156
 
... ...
@@ -141,6 +160,7 @@ bool run_tests()
141 160
     test (validator_fails_unknown_user);
142 161
     test (validator_fails_incorrect_token);
143 162
     test (validator_fails_with_own_token);
163
+    test (validator_fails_with_unknown_requester);
144 164
     succeed();
145 165
 }
146 166