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

Unified Diff: remoting/host/it2me/it2me_host_unittest.cc

Issue 2901033002: Host port range policy is no longer ignored in it2me host (Closed)
Patch Set: Host port range policy is no longer ignored in it2me host Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« remoting/host/it2me/it2me_host.cc ('K') | « remoting/host/it2me/it2me_host.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/it2me/it2me_host_unittest.cc
diff --git a/remoting/host/it2me/it2me_host_unittest.cc b/remoting/host/it2me/it2me_host_unittest.cc
index 77945ebc5ac71849e33d5a5b1e696c8e9f9db1fa..8583465a103e994ef285a101611460a97f430f5e 100644
--- a/remoting/host/it2me/it2me_host_unittest.cc
+++ b/remoting/host/it2me/it2me_host_unittest.cc
@@ -21,9 +21,11 @@
#include "base/threading/thread_task_runner_handle.h"
#include "components/policy/policy_constants.h"
#include "remoting/base/auto_thread_task_runner.h"
+#include "remoting/host/chromoting_host.h"
#include "remoting/host/chromoting_host_context.h"
#include "remoting/host/it2me/it2me_confirmation_dialog.h"
#include "remoting/host/policy_watcher.h"
+#include "remoting/protocol/transport_context.h"
#include "remoting/signaling/fake_signal_strategy.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -49,6 +51,9 @@ const char kMatchingDomain[] = "gmail.com";
const char kMismatchedDomain1[] = "similar_to_gmail.com";
const char kMismatchedDomain2[] = "gmail_at_the_beginning.com";
const char kMismatchedDomain3[] = "not_even_close.com";
+// Note that this is intentionally different from the default port range.
+const char kPortRange[] = "12401-12408";
+const char kInvalidPortRange[] = "not a port range";
} // namespace
@@ -165,6 +170,8 @@ class It2MeHostTest : public testing::Test, public It2MeHost::Observer {
// Used to set ConfirmationDialog behavior.
FakeIt2MeDialogFactory* dialog_factory_ = nullptr;
+ scoped_refptr<It2MeHost> it2me_host_;
+
private:
void StartupHostStateHelper(const base::Closure& quit_closure);
@@ -174,8 +181,6 @@ class It2MeHostTest : public testing::Test, public It2MeHost::Observer {
scoped_refptr<AutoThreadTaskRunner> network_task_runner_;
scoped_refptr<AutoThreadTaskRunner> ui_task_runner_;
- scoped_refptr<It2MeHost> it2me_host_;
-
base::WeakPtrFactory<It2MeHostTest> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(It2MeHostTest);
@@ -506,6 +511,36 @@ TEST_F(It2MeHostTest, ConnectionValidation_ClientDomainListPolicy_NoMatch) {
ASSERT_EQ(It2MeHostState::kDisconnected, last_host_state_);
}
+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.
+ PortRange port_range_actual;
+ ASSERT_TRUE(PortRange::Parse(kPortRange, &port_range_actual));
+ SetPolicies(
+ {{policy::key::kRemoteAccessHostUdpPortRange, base::Value(kPortRange)}});
+ StartHost();
+ PortRange port_range = it2me_host_->host_->transport_context_for_tests()
+ ->network_settings()
+ .port_range;
+ ASSERT_EQ(port_range_actual.min_port, port_range.min_port);
+ ASSERT_EQ(port_range_actual.max_port, port_range.max_port);
+}
+
+TEST_F(It2MeHostTest,
+ ConnectionValidation_HostUdpPortRangePolicy_InvalidRange) {
+ SetPolicies({{policy::key::kRemoteAccessHostUdpPortRange,
+ base::Value(kInvalidPortRange)}});
+ StartHost();
+ ASSERT_EQ(It2MeHostState::kError, last_host_state_);
+}
+
+TEST_F(It2MeHostTest, ConnectionValidation_HostUdpPortRangePolicy_NoRange) {
+ StartHost();
+ PortRange port_range = it2me_host_->host_->transport_context_for_tests()
+ ->network_settings()
+ .port_range;
+ ASSERT_EQ(0, port_range.min_port);
+ 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.
+}
+
TEST_F(It2MeHostTest, ConnectionValidation_ConfirmationDialog_Accept) {
StartHost();
RunValidationCallback(kTestClientJid);
« remoting/host/it2me/it2me_host.cc ('K') | « remoting/host/it2me/it2me_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698