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

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

Issue 2912143002: Host port range policy is no longer ignored in it2me host. (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « remoting/host/it2me/it2me_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/message_loop/message_loop.h" 19 #include "base/message_loop/message_loop.h"
20 #include "base/run_loop.h" 20 #include "base/run_loop.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "components/policy/policy_constants.h" 22 #include "components/policy/policy_constants.h"
23 #include "remoting/base/auto_thread_task_runner.h" 23 #include "remoting/base/auto_thread_task_runner.h"
24 #include "remoting/host/chromoting_host.h"
24 #include "remoting/host/chromoting_host_context.h" 25 #include "remoting/host/chromoting_host_context.h"
25 #include "remoting/host/it2me/it2me_confirmation_dialog.h" 26 #include "remoting/host/it2me/it2me_confirmation_dialog.h"
26 #include "remoting/host/policy_watcher.h" 27 #include "remoting/host/policy_watcher.h"
28 #include "remoting/protocol/transport_context.h"
27 #include "remoting/signaling/fake_signal_strategy.h" 29 #include "remoting/signaling/fake_signal_strategy.h"
28 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
29 31
30 #if defined(OS_LINUX) 32 #if defined(OS_LINUX)
31 #include "base/linux_util.h" 33 #include "base/linux_util.h"
32 #endif // defined(OS_LINUX) 34 #endif // defined(OS_LINUX)
33 35
34 namespace remoting { 36 namespace remoting {
35 37
36 namespace { 38 namespace {
37 39
38 // Shortening some type names for readability. 40 // Shortening some type names for readability.
39 typedef protocol::ValidatingAuthenticator::Result ValidationResult; 41 typedef protocol::ValidatingAuthenticator::Result ValidationResult;
40 typedef It2MeConfirmationDialog::Result DialogResult; 42 typedef It2MeConfirmationDialog::Result DialogResult;
41 43
42 const char kTestUserName[] = "ficticious_user@gmail.com"; 44 const char kTestUserName[] = "ficticious_user@gmail.com";
43 const char kTestClientJid[] = "ficticious_user@gmail.com/jid_resource"; 45 const char kTestClientJid[] = "ficticious_user@gmail.com/jid_resource";
44 const char kTestClientJid2[] = "ficticious_user_2@gmail.com/jid_resource"; 46 const char kTestClientJid2[] = "ficticious_user_2@gmail.com/jid_resource";
45 const char kTestClientUsernameNoJid[] = "completely_ficticious_user@gmail.com"; 47 const char kTestClientUsernameNoJid[] = "completely_ficticious_user@gmail.com";
46 const char kTestClientJidWithSlash[] = "fake/user@gmail.com/jid_resource"; 48 const char kTestClientJidWithSlash[] = "fake/user@gmail.com/jid_resource";
47 const char kResourceOnly[] = "/jid_resource"; 49 const char kResourceOnly[] = "/jid_resource";
48 const char kMatchingDomain[] = "gmail.com"; 50 const char kMatchingDomain[] = "gmail.com";
49 const char kMismatchedDomain1[] = "similar_to_gmail.com"; 51 const char kMismatchedDomain1[] = "similar_to_gmail.com";
50 const char kMismatchedDomain2[] = "gmail_at_the_beginning.com"; 52 const char kMismatchedDomain2[] = "gmail_at_the_beginning.com";
51 const char kMismatchedDomain3[] = "not_even_close.com"; 53 const char kMismatchedDomain3[] = "not_even_close.com";
54 // Note that this is intentionally different from the default port range.
55 const char kPortRange[] = "12401-12408";
52 56
53 } // namespace 57 } // namespace
54 58
55 class FakeIt2MeConfirmationDialog : public It2MeConfirmationDialog { 59 class FakeIt2MeConfirmationDialog : public It2MeConfirmationDialog {
56 public: 60 public:
57 FakeIt2MeConfirmationDialog(const std::string& remote_user_email, 61 FakeIt2MeConfirmationDialog(const std::string& remote_user_email,
58 DialogResult dialog_result); 62 DialogResult dialog_result);
59 ~FakeIt2MeConfirmationDialog() override; 63 ~FakeIt2MeConfirmationDialog() override;
60 64
61 // It2MeConfirmationDialog implementation. 65 // It2MeConfirmationDialog implementation.
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 162
159 ValidationResult validation_result_ = ValidationResult::SUCCESS; 163 ValidationResult validation_result_ = ValidationResult::SUCCESS;
160 164
161 base::Closure state_change_callback_; 165 base::Closure state_change_callback_;
162 166
163 It2MeHostState last_host_state_ = It2MeHostState::kDisconnected; 167 It2MeHostState last_host_state_ = It2MeHostState::kDisconnected;
164 168
165 // Used to set ConfirmationDialog behavior. 169 // Used to set ConfirmationDialog behavior.
166 FakeIt2MeDialogFactory* dialog_factory_ = nullptr; 170 FakeIt2MeDialogFactory* dialog_factory_ = nullptr;
167 171
172 scoped_refptr<It2MeHost> it2me_host_;
173
168 private: 174 private:
169 void StartupHostStateHelper(const base::Closure& quit_closure); 175 void StartupHostStateHelper(const base::Closure& quit_closure);
170 176
171 std::unique_ptr<base::MessageLoop> message_loop_; 177 std::unique_ptr<base::MessageLoop> message_loop_;
172 std::unique_ptr<base::RunLoop> run_loop_; 178 std::unique_ptr<base::RunLoop> run_loop_;
173 179
174 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; 180 scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
175 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; 181 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
176 182
177 scoped_refptr<It2MeHost> it2me_host_;
178
179 base::WeakPtrFactory<It2MeHostTest> weak_factory_; 183 base::WeakPtrFactory<It2MeHostTest> weak_factory_;
180 184
181 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest); 185 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest);
182 }; 186 };
183 187
184 It2MeHostTest::It2MeHostTest() : weak_factory_(this) {} 188 It2MeHostTest::It2MeHostTest() : weak_factory_(this) {}
185 189
186 It2MeHostTest::~It2MeHostTest() {} 190 It2MeHostTest::~It2MeHostTest() {}
187 191
188 void It2MeHostTest::SetUp() { 192 void It2MeHostTest::SetUp() {
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 SetPolicies({{policy::key::kRemoteAccessHostClientDomainList, 503 SetPolicies({{policy::key::kRemoteAccessHostClientDomainList,
500 MakeList({kMismatchedDomain1, kMismatchedDomain2, 504 MakeList({kMismatchedDomain1, kMismatchedDomain2,
501 kMismatchedDomain3})}}); 505 kMismatchedDomain3})}});
502 StartHost(); 506 StartHost();
503 RunValidationCallback(kTestClientJid); 507 RunValidationCallback(kTestClientJid);
504 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); 508 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_);
505 RunUntilStateChanged(It2MeHostState::kDisconnected); 509 RunUntilStateChanged(It2MeHostState::kDisconnected);
506 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); 510 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
507 } 511 }
508 512
513 TEST_F(It2MeHostTest, HostUdpPortRangePolicy_ValidRange) {
514 PortRange port_range_actual;
515 ASSERT_TRUE(PortRange::Parse(kPortRange, &port_range_actual));
516 SetPolicies(
517 {{policy::key::kRemoteAccessHostUdpPortRange, base::Value(kPortRange)}});
518 StartHost();
519 PortRange port_range = it2me_host_->host_->transport_context_for_tests()
520 ->network_settings()
521 .port_range;
522 ASSERT_EQ(port_range_actual.min_port, port_range.min_port);
523 ASSERT_EQ(port_range_actual.max_port, port_range.max_port);
524 }
525
526 TEST_F(It2MeHostTest, HostUdpPortRangePolicy_NoRange) {
527 StartHost();
528 PortRange port_range = it2me_host_->host_->transport_context_for_tests()
529 ->network_settings()
530 .port_range;
531 ASSERT_TRUE(port_range.is_null());
532 }
533
509 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { 534 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) {
510 StartHost(); 535 StartHost();
511 RunValidationCallback(kTestClientJid); 536 RunValidationCallback(kTestClientJid);
512 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 537 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
513 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); 538 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_);
514 ShutdownHost(); 539 ShutdownHost();
515 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); 540 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
516 } 541 }
517 542
518 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { 543 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) {
(...skipping 11 matching lines...) Expand all
530 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); 555 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_);
531 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); 556 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_);
532 557
533 RunValidationCallback(kTestClientJid2); 558 RunValidationCallback(kTestClientJid2);
534 ASSERT_EQ(ValidationResult::ERROR_TOO_MANY_CONNECTIONS, validation_result_); 559 ASSERT_EQ(ValidationResult::ERROR_TOO_MANY_CONNECTIONS, validation_result_);
535 RunUntilStateChanged(It2MeHostState::kDisconnected); 560 RunUntilStateChanged(It2MeHostState::kDisconnected);
536 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); 561 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
537 } 562 }
538 563
539 } // namespace remoting 564 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/it2me/it2me_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698