Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: remoting/host/it2me/it2me_host_unittest.cc

Issue 2682473003: Add support for multiple allowed domains (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "remoting/host/it2me/it2me_host.h" 5 #include "remoting/host/it2me/it2me_host.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 // testing::Test interface. 87 // testing::Test interface.
88 void SetUp() override; 88 void SetUp() override;
89 void TearDown() override; 89 void TearDown() override;
90 90
91 void OnValidationComplete(const base::Closure& resume_callback, 91 void OnValidationComplete(const base::Closure& resume_callback,
92 ValidationResult validation_result); 92 ValidationResult validation_result);
93 93
94 protected: 94 protected:
95 void SetClientDomainPolicy(const std::string& policy_value); 95 void SetClientDomainPolicy(const std::string& policy_value);
96 void SetClientDomainListPolicy(const std::vector<std::string>& policy_value);
96 97
97 void RunValidationCallback(const std::string& remote_jid); 98 void RunValidationCallback(const std::string& remote_jid);
98 99
99 ValidationResult validation_result_ = ValidationResult::SUCCESS; 100 ValidationResult validation_result_ = ValidationResult::SUCCESS;
100 std::string remote_user_email_; 101 std::string remote_user_email_;
101 102
102 // Used to set ConfirmationDialog behavior. 103 // Used to set ConfirmationDialog behavior.
103 FakeIt2MeConfirmationDialog* dialog_ = nullptr; 104 FakeIt2MeConfirmationDialog* dialog_ = nullptr;
104 105
105 private: 106 private:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 151
151 void It2MeHostTest::SetClientDomainPolicy(const std::string& policy_value) { 152 void It2MeHostTest::SetClientDomainPolicy(const std::string& policy_value) {
152 std::unique_ptr<base::DictionaryValue> policies(new base::DictionaryValue()); 153 std::unique_ptr<base::DictionaryValue> policies(new base::DictionaryValue());
153 policies->SetString(policy::key::kRemoteAccessHostClientDomain, policy_value); 154 policies->SetString(policy::key::kRemoteAccessHostClientDomain, policy_value);
154 155
155 base::RunLoop run_loop; 156 base::RunLoop run_loop;
156 it2me_host_->SetPolicyForTesting(std::move(policies), run_loop.QuitClosure()); 157 it2me_host_->SetPolicyForTesting(std::move(policies), run_loop.QuitClosure());
157 run_loop.Run(); 158 run_loop.Run();
158 } 159 }
159 160
161 void It2MeHostTest::SetClientDomainListPolicy(
162 const std::vector<std::string> &policy_value) {
163 auto policies = base::MakeUnique<base::DictionaryValue>();
164 auto domains = base::MakeUnique<base::ListValue>();
165 domains->AppendStrings(policy_value);
166 policies->Set(policy::key::kRemoteAccessHostClientDomainList,
167 std::move(domains));
168
169 base::RunLoop run_loop;
170 it2me_host_->SetPolicyForTesting(std::move(policies), run_loop.QuitClosure());
171 run_loop.Run();
172 }
173
160 void It2MeHostTest::RunValidationCallback(const std::string& remote_jid) { 174 void It2MeHostTest::RunValidationCallback(const std::string& remote_jid) {
161 base::RunLoop run_loop; 175 base::RunLoop run_loop;
162 176
163 network_task_runner_->PostTask( 177 network_task_runner_->PostTask(
164 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, it2me_host_.get(), 178 FROM_HERE, base::Bind(&It2MeHost::SetStateForTesting, it2me_host_.get(),
165 It2MeHostState::kStarting, std::string())); 179 It2MeHostState::kStarting, std::string()));
166 180
167 network_task_runner_->PostTask( 181 network_task_runner_->PostTask(
168 FROM_HERE, 182 FROM_HERE,
169 base::Bind(&It2MeHost::SetStateForTesting, it2me_host_.get(), 183 base::Bind(&It2MeHost::SetStateForTesting, it2me_host_.get(),
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 RunValidationCallback(kTestClientJid); 249 RunValidationCallback(kTestClientJid);
236 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); 250 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_);
237 } 251 }
238 252
239 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_MatchEnd) { 253 TEST_F(It2MeHostTest, ConnectionValidation_WrongClientDomain_MatchEnd) {
240 SetClientDomainPolicy(kMismatchedDomain1); 254 SetClientDomainPolicy(kMismatchedDomain1);
241 RunValidationCallback(kTestClientJid); 255 RunValidationCallback(kTestClientJid);
242 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); 256 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_);
243 } 257 }
244 258
259 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainListPolicy_Match) {
260 SetClientDomainListPolicy({kMismatchedDomain1, kMismatchedDomain2,
261 kMatchingDomain, kMismatchedDomain3});
262 RunValidationCallback(kTestClientJid);
263 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
264 }
265
266 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainListPolicy_NoMatch) {
267 SetClientDomainListPolicy({kMismatchedDomain1, kMismatchedDomain2,
268 kMismatchedDomain3});
269 RunValidationCallback(kTestClientJid);
270 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_);
271 }
272
273 TEST_F(It2MeHostTest,
274 ConnectionValidation_ClientDomainListPolicy_InvalidUsername) {
275 SetClientDomainListPolicy({kMismatchedDomain1, kMismatchedDomain2,
276 kMatchingDomain, kMismatchedDomain3});
277 RunValidationCallback(kTestClientJidWithSlash);
278 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_);
279 }
280
281 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainListPolicy_NoJid) {
282 SetClientDomainListPolicy({kMismatchedDomain1, kMismatchedDomain2,
283 kMatchingDomain, kMismatchedDomain3});
284 RunValidationCallback(kTestClientUsernameNoJid);
285 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_);
286 }
287
288 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainPolicy_List_Match) {
289 SetClientDomainPolicy(kMatchingDomain);
290 SetClientDomainListPolicy({kMismatchedDomain1, kMismatchedDomain2,
291 kMatchingDomain, kMismatchedDomain3});
292 RunValidationCallback(kTestClientJid);
293 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
294 }
295
296 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainPolicy_List_NoMatch1) {
297 SetClientDomainPolicy(kMatchingDomain);
298 SetClientDomainListPolicy({kMismatchedDomain1, kMismatchedDomain2,
299 kMismatchedDomain3});
300 RunValidationCallback(kTestClientJid);
301 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_);
302 }
303
304 TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainPolicy_List_NoMatch2) {
305 SetClientDomainPolicy(kMismatchedDomain1);
306 SetClientDomainListPolicy({kMismatchedDomain1, kMismatchedDomain2,
307 kMatchingDomain, kMismatchedDomain3});
308 RunValidationCallback(kTestClientJid);
309 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_);
310 }
311
245 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { 312 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) {
246 RunValidationCallback(kTestClientJid); 313 RunValidationCallback(kTestClientJid);
247 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 314 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
248 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str()); 315 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str());
249 } 316 }
250 317
251 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { 318 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) {
252 dialog_->set_dialog_result(DialogResult::CANCEL); 319 dialog_->set_dialog_result(DialogResult::CANCEL);
253 RunValidationCallback(kTestClientJid); 320 RunValidationCallback(kTestClientJid);
254 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_); 321 ASSERT_EQ(ValidationResult::ERROR_REJECTED_BY_USER, validation_result_);
255 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str()); 322 ASSERT_STREQ(kTestClientUserName, remote_user_email_.c_str());
256 } 323 }
257 324
258 } // namespace remoting 325 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698