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

Side by Side Diff: remoting/host/policy_hack/policy_watcher_unittest.cc

Issue 820133002: Reusing names of policy keys from policy_constants.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Marked the 5 "new" policies as chrome_os:42- Created 5 years, 11 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/policy_hack/policy_watcher.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "policy/policy_constants.h"
10 #include "remoting/host/dns_blackhole_checker.h" 11 #include "remoting/host/dns_blackhole_checker.h"
11 #include "remoting/host/policy_hack/fake_policy_watcher.h" 12 #include "remoting/host/policy_hack/fake_policy_watcher.h"
12 #include "remoting/host/policy_hack/mock_policy_callback.h" 13 #include "remoting/host/policy_hack/mock_policy_callback.h"
13 #include "remoting/host/policy_hack/policy_watcher.h" 14 #include "remoting/host/policy_hack/policy_watcher.h"
14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 namespace remoting { 18 namespace remoting {
18 namespace policy_hack { 19 namespace policy_hack {
19 20
20 class PolicyWatcherTest : public testing::Test { 21 class PolicyWatcherTest : public testing::Test {
21 public: 22 public:
22 PolicyWatcherTest() { 23 PolicyWatcherTest() {
23 } 24 }
24 25
25 void SetUp() override { 26 void SetUp() override {
26 message_loop_proxy_ = base::MessageLoopProxy::current(); 27 message_loop_proxy_ = base::MessageLoopProxy::current();
27 policy_updated_callback_ = base::Bind( 28 policy_updated_callback_ = base::Bind(
28 &MockPolicyCallback::OnPolicyUpdate, 29 &MockPolicyCallback::OnPolicyUpdate,
29 base::Unretained(&mock_policy_callback_)); 30 base::Unretained(&mock_policy_callback_));
30 policy_error_callback_ = base::Bind( 31 policy_error_callback_ = base::Bind(
31 &MockPolicyCallback::OnPolicyError, 32 &MockPolicyCallback::OnPolicyError,
32 base::Unretained(&mock_policy_callback_)); 33 base::Unretained(&mock_policy_callback_));
33 policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_)); 34 policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_));
34 nat_true_.SetBoolean(PolicyWatcher::kNatPolicyName, true); 35 nat_true_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, true);
35 nat_false_.SetBoolean(PolicyWatcher::kNatPolicyName, false); 36 nat_false_.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal,
36 nat_one_.SetInteger(PolicyWatcher::kNatPolicyName, 1); 37 false);
37 domain_empty_.SetString(PolicyWatcher::kHostDomainPolicyName, 38 nat_one_.SetInteger(policy::key::kRemoteAccessHostFirewallTraversal, 1);
39 domain_empty_.SetString(policy::key::kRemoteAccessHostDomain,
38 std::string()); 40 std::string());
39 domain_full_.SetString(PolicyWatcher::kHostDomainPolicyName, kHostDomain); 41 domain_full_.SetString(policy::key::kRemoteAccessHostDomain, kHostDomain);
40 SetDefaults(nat_true_others_default_); 42 SetDefaults(nat_true_others_default_);
41 nat_true_others_default_.SetBoolean(PolicyWatcher::kNatPolicyName, true); 43 nat_true_others_default_.SetBoolean(
44 policy::key::kRemoteAccessHostFirewallTraversal, true);
42 SetDefaults(nat_false_others_default_); 45 SetDefaults(nat_false_others_default_);
43 nat_false_others_default_.SetBoolean(PolicyWatcher::kNatPolicyName, false); 46 nat_false_others_default_.SetBoolean(
47 policy::key::kRemoteAccessHostFirewallTraversal, false);
44 SetDefaults(domain_empty_others_default_); 48 SetDefaults(domain_empty_others_default_);
45 domain_empty_others_default_.SetString(PolicyWatcher::kHostDomainPolicyName, 49 domain_empty_others_default_.SetString(policy::key::kRemoteAccessHostDomain,
46 std::string()); 50 std::string());
47 SetDefaults(domain_full_others_default_); 51 SetDefaults(domain_full_others_default_);
48 domain_full_others_default_.SetString(PolicyWatcher::kHostDomainPolicyName, 52 domain_full_others_default_.SetString(policy::key::kRemoteAccessHostDomain,
49 kHostDomain); 53 kHostDomain);
50 nat_true_domain_empty_.SetBoolean(PolicyWatcher::kNatPolicyName, true); 54 nat_true_domain_empty_.SetBoolean(
51 nat_true_domain_empty_.SetString(PolicyWatcher::kHostDomainPolicyName, 55 policy::key::kRemoteAccessHostFirewallTraversal, true);
56 nat_true_domain_empty_.SetString(policy::key::kRemoteAccessHostDomain,
52 std::string()); 57 std::string());
53 nat_true_domain_full_.SetBoolean(PolicyWatcher::kNatPolicyName, true); 58 nat_true_domain_full_.SetBoolean(
54 nat_true_domain_full_.SetString(PolicyWatcher::kHostDomainPolicyName, 59 policy::key::kRemoteAccessHostFirewallTraversal, true);
55 kHostDomain); 60 nat_true_domain_full_.SetString(policy::key::kRemoteAccessHostDomain,
56 nat_false_domain_empty_.SetBoolean(PolicyWatcher::kNatPolicyName, false); 61 kHostDomain);
57 nat_false_domain_empty_.SetString(PolicyWatcher::kHostDomainPolicyName, 62 nat_false_domain_empty_.SetBoolean(
63 policy::key::kRemoteAccessHostFirewallTraversal, false);
64 nat_false_domain_empty_.SetString(policy::key::kRemoteAccessHostDomain,
58 std::string()); 65 std::string());
59 nat_false_domain_full_.SetBoolean(PolicyWatcher::kNatPolicyName, false); 66 nat_false_domain_full_.SetBoolean(
60 nat_false_domain_full_.SetString(PolicyWatcher::kHostDomainPolicyName, 67 policy::key::kRemoteAccessHostFirewallTraversal, false);
61 kHostDomain); 68 nat_false_domain_full_.SetString(policy::key::kRemoteAccessHostDomain,
69 kHostDomain);
62 SetDefaults(nat_true_domain_empty_others_default_); 70 SetDefaults(nat_true_domain_empty_others_default_);
63 nat_true_domain_empty_others_default_.SetBoolean( 71 nat_true_domain_empty_others_default_.SetBoolean(
64 PolicyWatcher::kNatPolicyName, true); 72 policy::key::kRemoteAccessHostFirewallTraversal, true);
65 nat_true_domain_empty_others_default_.SetString( 73 nat_true_domain_empty_others_default_.SetString(
66 PolicyWatcher::kHostDomainPolicyName, std::string()); 74 policy::key::kRemoteAccessHostDomain, std::string());
67 unknown_policies_.SetString("UnknownPolicyOne", std::string()); 75 unknown_policies_.SetString("UnknownPolicyOne", std::string());
68 unknown_policies_.SetString("UnknownPolicyTwo", std::string()); 76 unknown_policies_.SetString("UnknownPolicyTwo", std::string());
69 77
70 const char kOverrideNatTraversalToFalse[] = 78 const char kOverrideNatTraversalToFalse[] =
71 "{ \"RemoteAccessHostFirewallTraversal\": false }"; 79 "{ \"RemoteAccessHostFirewallTraversal\": false }";
72 nat_true_and_overridden_.SetBoolean(PolicyWatcher::kNatPolicyName, true); 80 nat_true_and_overridden_.SetBoolean(
81 policy::key::kRemoteAccessHostFirewallTraversal, true);
73 nat_true_and_overridden_.SetString( 82 nat_true_and_overridden_.SetString(
74 PolicyWatcher::kHostDebugOverridePoliciesName, 83 policy::key::kRemoteAccessHostDebugOverridePolicies,
75 kOverrideNatTraversalToFalse); 84 kOverrideNatTraversalToFalse);
76 pairing_true_.SetBoolean(PolicyWatcher::kHostAllowClientPairing, true); 85 pairing_true_.SetBoolean(policy::key::kRemoteAccessHostAllowClientPairing,
77 pairing_false_.SetBoolean(PolicyWatcher::kHostAllowClientPairing, false); 86 true);
78 gnubby_auth_true_.SetBoolean(PolicyWatcher::kHostAllowGnubbyAuthPolicyName, 87 pairing_false_.SetBoolean(policy::key::kRemoteAccessHostAllowClientPairing,
88 false);
89 gnubby_auth_true_.SetBoolean(policy::key::kRemoteAccessHostAllowGnubbyAuth,
79 true); 90 true);
80 gnubby_auth_false_.SetBoolean(PolicyWatcher::kHostAllowGnubbyAuthPolicyName, 91 gnubby_auth_false_.SetBoolean(policy::key::kRemoteAccessHostAllowGnubbyAuth,
81 false); 92 false);
82 relay_true_.SetBoolean(PolicyWatcher::kRelayPolicyName, true); 93 relay_true_.SetBoolean(policy::key::kRemoteAccessHostAllowRelayedConnection,
83 relay_false_.SetBoolean(PolicyWatcher::kRelayPolicyName, false); 94 true);
84 port_range_full_.SetString(PolicyWatcher::kUdpPortRangePolicyName, 95 relay_false_.SetBoolean(
96 policy::key::kRemoteAccessHostAllowRelayedConnection, false);
97 port_range_full_.SetString(policy::key::kRemoteAccessHostUdpPortRange,
85 kPortRange); 98 kPortRange);
86 port_range_empty_.SetString(PolicyWatcher::kUdpPortRangePolicyName, 99 port_range_empty_.SetString(policy::key::kRemoteAccessHostUdpPortRange,
87 std::string()); 100 std::string());
88 101
89 #if !defined(NDEBUG) 102 #if !defined(NDEBUG)
90 SetDefaults(nat_false_overridden_others_default_); 103 SetDefaults(nat_false_overridden_others_default_);
91 nat_false_overridden_others_default_.SetBoolean( 104 nat_false_overridden_others_default_.SetBoolean(
92 PolicyWatcher::kNatPolicyName, false); 105 policy::key::kRemoteAccessHostFirewallTraversal, false);
93 nat_false_overridden_others_default_.SetString( 106 nat_false_overridden_others_default_.SetString(
94 PolicyWatcher::kHostDebugOverridePoliciesName, 107 policy::key::kRemoteAccessHostDebugOverridePolicies,
95 kOverrideNatTraversalToFalse); 108 kOverrideNatTraversalToFalse);
96 #endif 109 #endif
97 } 110 }
98 111
99 protected: 112 protected:
100 void StartWatching() { 113 void StartWatching() {
101 policy_watcher_->StartWatching( 114 policy_watcher_->StartWatching(
102 policy_updated_callback_, 115 policy_updated_callback_,
103 policy_error_callback_); 116 policy_error_callback_);
104 base::RunLoop().RunUntilIdle(); 117 base::RunLoop().RunUntilIdle();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 base::DictionaryValue pairing_false_; 156 base::DictionaryValue pairing_false_;
144 base::DictionaryValue gnubby_auth_true_; 157 base::DictionaryValue gnubby_auth_true_;
145 base::DictionaryValue gnubby_auth_false_; 158 base::DictionaryValue gnubby_auth_false_;
146 base::DictionaryValue relay_true_; 159 base::DictionaryValue relay_true_;
147 base::DictionaryValue relay_false_; 160 base::DictionaryValue relay_false_;
148 base::DictionaryValue port_range_full_; 161 base::DictionaryValue port_range_full_;
149 base::DictionaryValue port_range_empty_; 162 base::DictionaryValue port_range_empty_;
150 163
151 private: 164 private:
152 void SetDefaults(base::DictionaryValue& dict) { 165 void SetDefaults(base::DictionaryValue& dict) {
153 dict.SetBoolean(PolicyWatcher::kNatPolicyName, true); 166 dict.SetBoolean(policy::key::kRemoteAccessHostFirewallTraversal, true);
154 dict.SetBoolean(PolicyWatcher::kRelayPolicyName, true); 167 dict.SetBoolean(policy::key::kRemoteAccessHostAllowRelayedConnection, true);
155 dict.SetString(PolicyWatcher::kUdpPortRangePolicyName, ""); 168 dict.SetString(policy::key::kRemoteAccessHostUdpPortRange, "");
156 dict.SetBoolean(PolicyWatcher::kHostRequireTwoFactorPolicyName, false); 169 dict.SetBoolean(policy::key::kRemoteAccessHostRequireTwoFactor, false);
157 dict.SetString(PolicyWatcher::kHostDomainPolicyName, std::string()); 170 dict.SetString(policy::key::kRemoteAccessHostDomain, std::string());
158 dict.SetBoolean(PolicyWatcher::kHostMatchUsernamePolicyName, false); 171 dict.SetBoolean(policy::key::kRemoteAccessHostMatchUsername, false);
159 dict.SetString(PolicyWatcher::kHostTalkGadgetPrefixPolicyName, 172 dict.SetString(policy::key::kRemoteAccessHostTalkGadgetPrefix,
160 kDefaultHostTalkGadgetPrefix); 173 kDefaultHostTalkGadgetPrefix);
161 dict.SetBoolean(PolicyWatcher::kHostRequireCurtainPolicyName, false); 174 dict.SetBoolean(policy::key::kRemoteAccessHostRequireCurtain, false);
162 dict.SetString(PolicyWatcher::kHostTokenUrlPolicyName, std::string()); 175 dict.SetString(policy::key::kRemoteAccessHostTokenUrl, std::string());
163 dict.SetString(PolicyWatcher::kHostTokenValidationUrlPolicyName, 176 dict.SetString(policy::key::kRemoteAccessHostTokenValidationUrl,
164 std::string()); 177 std::string());
165 dict.SetString(PolicyWatcher::kHostTokenValidationCertIssuerPolicyName, 178 dict.SetString(
166 std::string()); 179 policy::key::kRemoteAccessHostTokenValidationCertificateIssuer,
167 dict.SetBoolean(PolicyWatcher::kHostAllowClientPairing, true); 180 std::string());
168 dict.SetBoolean(PolicyWatcher::kHostAllowGnubbyAuthPolicyName, true); 181 dict.SetBoolean(policy::key::kRemoteAccessHostAllowClientPairing, true);
182 dict.SetBoolean(policy::key::kRemoteAccessHostAllowGnubbyAuth, true);
169 #if !defined(NDEBUG) 183 #if !defined(NDEBUG)
170 dict.SetString(PolicyWatcher::kHostDebugOverridePoliciesName, ""); 184 dict.SetString(policy::key::kRemoteAccessHostDebugOverridePolicies, "");
171 #endif 185 #endif
172 } 186 }
173 }; 187 };
174 188
175 const char* PolicyWatcherTest::kHostDomain = "google.com"; 189 const char* PolicyWatcherTest::kHostDomain = "google.com";
176 const char* PolicyWatcherTest::kPortRange = "12400-12409"; 190 const char* PolicyWatcherTest::kPortRange = "12400-12409";
177 191
178 MATCHER_P(IsPolicies, dict, "") { 192 MATCHER_P(IsPolicies, dict, "") {
179 return arg->Equals(dict); 193 return arg->Equals(dict);
180 } 194 }
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 457 }
444 policy_watcher_->SetPolicies(&nat_true_); 458 policy_watcher_->SetPolicies(&nat_true_);
445 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) { 459 for (int i = 0; i < (kMaxTransientErrorRetries - 1); i++) {
446 policy_watcher_->SignalTransientErrorForTest(); 460 policy_watcher_->SignalTransientErrorForTest();
447 } 461 }
448 StopWatching(); 462 StopWatching();
449 } 463 }
450 464
451 } // namespace policy_hack 465 } // namespace policy_hack
452 } // namespace remoting 466 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/policy_hack/policy_watcher.cc ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698