Chromium Code Reviews| OLD | NEW |
|---|---|
| 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"; | |
| 56 const char kInvalidPortRange[] = "not a port range"; | |
| 52 | 57 |
| 53 } // namespace | 58 } // namespace |
| 54 | 59 |
| 55 class FakeIt2MeConfirmationDialog : public It2MeConfirmationDialog { | 60 class FakeIt2MeConfirmationDialog : public It2MeConfirmationDialog { |
| 56 public: | 61 public: |
| 57 FakeIt2MeConfirmationDialog(const std::string& remote_user_email, | 62 FakeIt2MeConfirmationDialog(const std::string& remote_user_email, |
| 58 DialogResult dialog_result); | 63 DialogResult dialog_result); |
| 59 ~FakeIt2MeConfirmationDialog() override; | 64 ~FakeIt2MeConfirmationDialog() override; |
| 60 | 65 |
| 61 // It2MeConfirmationDialog implementation. | 66 // It2MeConfirmationDialog implementation. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 | 163 |
| 159 ValidationResult validation_result_ = ValidationResult::SUCCESS; | 164 ValidationResult validation_result_ = ValidationResult::SUCCESS; |
| 160 | 165 |
| 161 base::Closure state_change_callback_; | 166 base::Closure state_change_callback_; |
| 162 | 167 |
| 163 It2MeHostState last_host_state_ = It2MeHostState::kDisconnected; | 168 It2MeHostState last_host_state_ = It2MeHostState::kDisconnected; |
| 164 | 169 |
| 165 // Used to set ConfirmationDialog behavior. | 170 // Used to set ConfirmationDialog behavior. |
| 166 FakeIt2MeDialogFactory* dialog_factory_ = nullptr; | 171 FakeIt2MeDialogFactory* dialog_factory_ = nullptr; |
| 167 | 172 |
| 173 scoped_refptr<It2MeHost> it2me_host_; | |
| 174 | |
| 168 private: | 175 private: |
| 169 void StartupHostStateHelper(const base::Closure& quit_closure); | 176 void StartupHostStateHelper(const base::Closure& quit_closure); |
| 170 | 177 |
| 171 std::unique_ptr<base::MessageLoop> message_loop_; | 178 std::unique_ptr<base::MessageLoop> message_loop_; |
| 172 std::unique_ptr<base::RunLoop> run_loop_; | 179 std::unique_ptr<base::RunLoop> run_loop_; |
| 173 | 180 |
| 174 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; | 181 scoped_refptr<AutoThreadTaskRunner> network_task_runner_; |
| 175 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; | 182 scoped_refptr<AutoThreadTaskRunner> ui_task_runner_; |
| 176 | 183 |
| 177 scoped_refptr<It2MeHost> it2me_host_; | |
| 178 | |
| 179 base::WeakPtrFactory<It2MeHostTest> weak_factory_; | 184 base::WeakPtrFactory<It2MeHostTest> weak_factory_; |
| 180 | 185 |
| 181 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest); | 186 DISALLOW_COPY_AND_ASSIGN(It2MeHostTest); |
| 182 }; | 187 }; |
| 183 | 188 |
| 184 It2MeHostTest::It2MeHostTest() : weak_factory_(this) {} | 189 It2MeHostTest::It2MeHostTest() : weak_factory_(this) {} |
| 185 | 190 |
| 186 It2MeHostTest::~It2MeHostTest() {} | 191 It2MeHostTest::~It2MeHostTest() {} |
| 187 | 192 |
| 188 void It2MeHostTest::SetUp() { | 193 void It2MeHostTest::SetUp() { |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 499 SetPolicies({{policy::key::kRemoteAccessHostClientDomainList, | 504 SetPolicies({{policy::key::kRemoteAccessHostClientDomainList, |
| 500 MakeList({kMismatchedDomain1, kMismatchedDomain2, | 505 MakeList({kMismatchedDomain1, kMismatchedDomain2, |
| 501 kMismatchedDomain3})}}); | 506 kMismatchedDomain3})}}); |
| 502 StartHost(); | 507 StartHost(); |
| 503 RunValidationCallback(kTestClientJid); | 508 RunValidationCallback(kTestClientJid); |
| 504 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); | 509 ASSERT_EQ(ValidationResult::ERROR_INVALID_ACCOUNT, validation_result_); |
| 505 RunUntilStateChanged(It2MeHostState::kDisconnected); | 510 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 506 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); | 511 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 507 } | 512 } |
| 508 | 513 |
| 514 TEST_F(It2MeHostTest, ConnectionValidation_HostUdpPortRangePolicy_ValidRange) { | |
|
Sergey Ulanov
2017/05/25 19:34:53
This test name is too long. I don't think you need
Gus Smith
2017/05/25 21:39:09
Done.
| |
| 515 PortRange port_range_actual; | |
| 516 ASSERT_TRUE(PortRange::Parse(kPortRange, &port_range_actual)); | |
| 517 SetPolicies( | |
| 518 {{policy::key::kRemoteAccessHostUdpPortRange, base::Value(kPortRange)}}); | |
| 519 StartHost(); | |
| 520 PortRange port_range = it2me_host_->host_->transport_context_for_tests() | |
| 521 ->network_settings() | |
| 522 .port_range; | |
| 523 ASSERT_EQ(port_range_actual.min_port, port_range.min_port); | |
| 524 ASSERT_EQ(port_range_actual.max_port, port_range.max_port); | |
| 525 } | |
| 526 | |
| 527 TEST_F(It2MeHostTest, | |
| 528 ConnectionValidation_HostUdpPortRangePolicy_InvalidRange) { | |
| 529 SetPolicies({{policy::key::kRemoteAccessHostUdpPortRange, | |
| 530 base::Value(kInvalidPortRange)}}); | |
| 531 StartHost(); | |
| 532 ASSERT_EQ(It2MeHostState::kError, last_host_state_); | |
| 533 } | |
| 534 | |
| 535 TEST_F(It2MeHostTest, ConnectionValidation_HostUdpPortRangePolicy_NoRange) { | |
| 536 StartHost(); | |
| 537 PortRange port_range = it2me_host_->host_->transport_context_for_tests() | |
| 538 ->network_settings() | |
| 539 .port_range; | |
| 540 ASSERT_EQ(0, port_range.min_port); | |
| 541 ASSERT_EQ(0, port_range.max_port); | |
|
Sergey Ulanov
2017/05/25 19:34:53
nit: ASSERT_TRUE(port_range.is_null());
Gus Smith
2017/05/25 21:39:09
Done.
| |
| 542 } | |
| 543 | |
| 509 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { | 544 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) { |
| 510 StartHost(); | 545 StartHost(); |
| 511 RunValidationCallback(kTestClientJid); | 546 RunValidationCallback(kTestClientJid); |
| 512 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); | 547 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
| 513 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); | 548 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
| 514 ShutdownHost(); | 549 ShutdownHost(); |
| 515 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); | 550 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 516 } | 551 } |
| 517 | 552 |
| 518 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { | 553 TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Reject) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 530 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); | 565 ASSERT_EQ(ValidationResult::SUCCESS, validation_result_); |
| 531 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); | 566 ASSERT_EQ(It2MeHostState::kConnecting, last_host_state_); |
| 532 | 567 |
| 533 RunValidationCallback(kTestClientJid2); | 568 RunValidationCallback(kTestClientJid2); |
| 534 ASSERT_EQ(ValidationResult::ERROR_TOO_MANY_CONNECTIONS, validation_result_); | 569 ASSERT_EQ(ValidationResult::ERROR_TOO_MANY_CONNECTIONS, validation_result_); |
| 535 RunUntilStateChanged(It2MeHostState::kDisconnected); | 570 RunUntilStateChanged(It2MeHostState::kDisconnected); |
| 536 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); | 571 ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_); |
| 537 } | 572 } |
| 538 | 573 |
| 539 } // namespace remoting | 574 } // namespace remoting |
| OLD | NEW |