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

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

Issue 268483003: Revert 267234 "New policies: enable/disable relay; port range" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
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 "remoting/host/dns_blackhole_checker.h" 10 #include "remoting/host/dns_blackhole_checker.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 nat_true_and_overridden_.SetBoolean(PolicyWatcher::kNatPolicyName, true); 68 nat_true_and_overridden_.SetBoolean(PolicyWatcher::kNatPolicyName, true);
69 nat_true_and_overridden_.SetString( 69 nat_true_and_overridden_.SetString(
70 PolicyWatcher::kHostDebugOverridePoliciesName, 70 PolicyWatcher::kHostDebugOverridePoliciesName,
71 kOverrideNatTraversalToFalse); 71 kOverrideNatTraversalToFalse);
72 pairing_true_.SetBoolean(PolicyWatcher::kHostAllowClientPairing, true); 72 pairing_true_.SetBoolean(PolicyWatcher::kHostAllowClientPairing, true);
73 pairing_false_.SetBoolean(PolicyWatcher::kHostAllowClientPairing, false); 73 pairing_false_.SetBoolean(PolicyWatcher::kHostAllowClientPairing, false);
74 gnubby_auth_true_.SetBoolean(PolicyWatcher::kHostAllowGnubbyAuthPolicyName, 74 gnubby_auth_true_.SetBoolean(PolicyWatcher::kHostAllowGnubbyAuthPolicyName,
75 true); 75 true);
76 gnubby_auth_false_.SetBoolean(PolicyWatcher::kHostAllowGnubbyAuthPolicyName, 76 gnubby_auth_false_.SetBoolean(PolicyWatcher::kHostAllowGnubbyAuthPolicyName,
77 false); 77 false);
78 relay_true_.SetBoolean(PolicyWatcher::kRelayPolicyName, true);
79 relay_false_.SetBoolean(PolicyWatcher::kRelayPolicyName, false);
80 port_range_full_.SetString(PolicyWatcher::kUdpPortRangePolicyName,
81 kPortRange);
82 port_range_empty_.SetString(PolicyWatcher::kUdpPortRangePolicyName,
83 std::string());
84
85 #if !defined(NDEBUG) 78 #if !defined(NDEBUG)
86 SetDefaults(nat_false_overridden_others_default_); 79 SetDefaults(nat_false_overridden_others_default_);
87 nat_false_overridden_others_default_.SetBoolean( 80 nat_false_overridden_others_default_.SetBoolean(
88 PolicyWatcher::kNatPolicyName, false); 81 PolicyWatcher::kNatPolicyName, false);
89 nat_false_overridden_others_default_.SetString( 82 nat_false_overridden_others_default_.SetString(
90 PolicyWatcher::kHostDebugOverridePoliciesName, 83 PolicyWatcher::kHostDebugOverridePoliciesName,
91 kOverrideNatTraversalToFalse); 84 kOverrideNatTraversalToFalse);
92 #endif 85 #endif
93 } 86 }
94 87
95 protected: 88 protected:
96 void StartWatching() { 89 void StartWatching() {
97 policy_watcher_->StartWatching(policy_callback_); 90 policy_watcher_->StartWatching(policy_callback_);
98 base::RunLoop().RunUntilIdle(); 91 base::RunLoop().RunUntilIdle();
99 } 92 }
100 93
101 void StopWatching() { 94 void StopWatching() {
102 base::WaitableEvent stop_event(false, false); 95 base::WaitableEvent stop_event(false, false);
103 policy_watcher_->StopWatching(&stop_event); 96 policy_watcher_->StopWatching(&stop_event);
104 base::RunLoop().RunUntilIdle(); 97 base::RunLoop().RunUntilIdle();
105 EXPECT_EQ(true, stop_event.IsSignaled()); 98 EXPECT_EQ(true, stop_event.IsSignaled());
106 } 99 }
107 100
108 static const char* kHostDomain; 101 static const char* kHostDomain;
109 static const char* kPortRange;
110 base::MessageLoop message_loop_; 102 base::MessageLoop message_loop_;
111 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 103 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
112 MockPolicyCallback mock_policy_callback_; 104 MockPolicyCallback mock_policy_callback_;
113 PolicyWatcher::PolicyCallback policy_callback_; 105 PolicyWatcher::PolicyCallback policy_callback_;
114 scoped_ptr<FakePolicyWatcher> policy_watcher_; 106 scoped_ptr<FakePolicyWatcher> policy_watcher_;
115 base::DictionaryValue empty_; 107 base::DictionaryValue empty_;
116 base::DictionaryValue nat_true_; 108 base::DictionaryValue nat_true_;
117 base::DictionaryValue nat_false_; 109 base::DictionaryValue nat_false_;
118 base::DictionaryValue nat_one_; 110 base::DictionaryValue nat_one_;
119 base::DictionaryValue domain_empty_; 111 base::DictionaryValue domain_empty_;
120 base::DictionaryValue domain_full_; 112 base::DictionaryValue domain_full_;
121 base::DictionaryValue nat_true_others_default_; 113 base::DictionaryValue nat_true_others_default_;
122 base::DictionaryValue nat_false_others_default_; 114 base::DictionaryValue nat_false_others_default_;
123 base::DictionaryValue domain_empty_others_default_; 115 base::DictionaryValue domain_empty_others_default_;
124 base::DictionaryValue domain_full_others_default_; 116 base::DictionaryValue domain_full_others_default_;
125 base::DictionaryValue nat_true_domain_empty_; 117 base::DictionaryValue nat_true_domain_empty_;
126 base::DictionaryValue nat_true_domain_full_; 118 base::DictionaryValue nat_true_domain_full_;
127 base::DictionaryValue nat_false_domain_empty_; 119 base::DictionaryValue nat_false_domain_empty_;
128 base::DictionaryValue nat_false_domain_full_; 120 base::DictionaryValue nat_false_domain_full_;
129 base::DictionaryValue nat_true_domain_empty_others_default_; 121 base::DictionaryValue nat_true_domain_empty_others_default_;
130 base::DictionaryValue unknown_policies_; 122 base::DictionaryValue unknown_policies_;
131 base::DictionaryValue nat_true_and_overridden_; 123 base::DictionaryValue nat_true_and_overridden_;
132 base::DictionaryValue nat_false_overridden_others_default_; 124 base::DictionaryValue nat_false_overridden_others_default_;
133 base::DictionaryValue pairing_true_; 125 base::DictionaryValue pairing_true_;
134 base::DictionaryValue pairing_false_; 126 base::DictionaryValue pairing_false_;
135 base::DictionaryValue gnubby_auth_true_; 127 base::DictionaryValue gnubby_auth_true_;
136 base::DictionaryValue gnubby_auth_false_; 128 base::DictionaryValue gnubby_auth_false_;
137 base::DictionaryValue relay_true_;
138 base::DictionaryValue relay_false_;
139 base::DictionaryValue port_range_full_;
140 base::DictionaryValue port_range_empty_;
141 129
142 private: 130 private:
143 void SetDefaults(base::DictionaryValue& dict) { 131 void SetDefaults(base::DictionaryValue& dict) {
144 dict.SetBoolean(PolicyWatcher::kNatPolicyName, true); 132 dict.SetBoolean(PolicyWatcher::kNatPolicyName, true);
145 dict.SetBoolean(PolicyWatcher::kRelayPolicyName, true);
146 dict.SetString(PolicyWatcher::kUdpPortRangePolicyName, "");
147 dict.SetBoolean(PolicyWatcher::kHostRequireTwoFactorPolicyName, false); 133 dict.SetBoolean(PolicyWatcher::kHostRequireTwoFactorPolicyName, false);
148 dict.SetString(PolicyWatcher::kHostDomainPolicyName, std::string()); 134 dict.SetString(PolicyWatcher::kHostDomainPolicyName, std::string());
149 dict.SetBoolean(PolicyWatcher::kHostMatchUsernamePolicyName, false); 135 dict.SetBoolean(PolicyWatcher::kHostMatchUsernamePolicyName, false);
150 dict.SetString(PolicyWatcher::kHostTalkGadgetPrefixPolicyName, 136 dict.SetString(PolicyWatcher::kHostTalkGadgetPrefixPolicyName,
151 kDefaultHostTalkGadgetPrefix); 137 kDefaultHostTalkGadgetPrefix);
152 dict.SetBoolean(PolicyWatcher::kHostRequireCurtainPolicyName, false); 138 dict.SetBoolean(PolicyWatcher::kHostRequireCurtainPolicyName, false);
153 dict.SetString(PolicyWatcher::kHostTokenUrlPolicyName, std::string()); 139 dict.SetString(PolicyWatcher::kHostTokenUrlPolicyName, std::string());
154 dict.SetString(PolicyWatcher::kHostTokenValidationUrlPolicyName, 140 dict.SetString(PolicyWatcher::kHostTokenValidationUrlPolicyName,
155 std::string()); 141 std::string());
156 dict.SetString(PolicyWatcher::kHostTokenValidationCertIssuerPolicyName, 142 dict.SetString(PolicyWatcher::kHostTokenValidationCertIssuerPolicyName,
157 std::string()); 143 std::string());
158 dict.SetBoolean(PolicyWatcher::kHostAllowClientPairing, true); 144 dict.SetBoolean(PolicyWatcher::kHostAllowClientPairing, true);
159 dict.SetBoolean(PolicyWatcher::kHostAllowGnubbyAuthPolicyName, true); 145 dict.SetBoolean(PolicyWatcher::kHostAllowGnubbyAuthPolicyName, true);
160 #if !defined(NDEBUG) 146 #if !defined(NDEBUG)
161 dict.SetString(PolicyWatcher::kHostDebugOverridePoliciesName, ""); 147 dict.SetString(PolicyWatcher::kHostDebugOverridePoliciesName, "");
162 #endif 148 #endif
163 } 149 }
164 }; 150 };
165 151
166 const char* PolicyWatcherTest::kHostDomain = "google.com"; 152 const char* PolicyWatcherTest::kHostDomain = "google.com";
167 const char* PolicyWatcherTest::kPortRange = "12400-12409";
168 153
169 MATCHER_P(IsPolicies, dict, "") { 154 MATCHER_P(IsPolicies, dict, "") {
170 return arg->Equals(dict); 155 return arg->Equals(dict);
171 } 156 }
172 157
173 TEST_F(PolicyWatcherTest, None) { 158 TEST_F(PolicyWatcherTest, None) {
174 EXPECT_CALL(mock_policy_callback_, 159 EXPECT_CALL(mock_policy_callback_,
175 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); 160 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
176 161
177 StartWatching(); 162 StartWatching();
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 EXPECT_CALL(mock_policy_callback_, 348 EXPECT_CALL(mock_policy_callback_,
364 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_true_))); 349 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_true_)));
365 350
366 StartWatching(); 351 StartWatching();
367 policy_watcher_->SetPolicies(&empty_); 352 policy_watcher_->SetPolicies(&empty_);
368 policy_watcher_->SetPolicies(&gnubby_auth_false_); 353 policy_watcher_->SetPolicies(&gnubby_auth_false_);
369 policy_watcher_->SetPolicies(&gnubby_auth_true_); 354 policy_watcher_->SetPolicies(&gnubby_auth_true_);
370 StopWatching(); 355 StopWatching();
371 } 356 }
372 357
373 TEST_F(PolicyWatcherTest, Relay) {
374 testing::InSequence sequence;
375 EXPECT_CALL(mock_policy_callback_,
376 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
377 EXPECT_CALL(mock_policy_callback_,
378 OnPolicyUpdatePtr(IsPolicies(&relay_false_)));
379 EXPECT_CALL(mock_policy_callback_,
380 OnPolicyUpdatePtr(IsPolicies(&relay_true_)));
381
382 StartWatching();
383 policy_watcher_->SetPolicies(&empty_);
384 policy_watcher_->SetPolicies(&relay_false_);
385 policy_watcher_->SetPolicies(&relay_true_);
386 StopWatching();
387 }
388
389 TEST_F(PolicyWatcherTest, UdpPortRange) {
390 testing::InSequence sequence;
391 EXPECT_CALL(mock_policy_callback_,
392 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_)));
393 EXPECT_CALL(mock_policy_callback_,
394 OnPolicyUpdatePtr(IsPolicies(&port_range_full_)));
395 EXPECT_CALL(mock_policy_callback_,
396 OnPolicyUpdatePtr(IsPolicies(&port_range_empty_)));
397
398 StartWatching();
399 policy_watcher_->SetPolicies(&empty_);
400 policy_watcher_->SetPolicies(&port_range_full_);
401 policy_watcher_->SetPolicies(&port_range_empty_);
402 StopWatching();
403 }
404
405 } // namespace policy_hack 358 } // namespace policy_hack
406 } // namespace remoting 359 } // namespace remoting
OLDNEW
« no previous file with comments | « trunk/src/remoting/host/policy_hack/policy_watcher.cc ('k') | trunk/src/remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698