| OLD | NEW |
| 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 Loading... |
| 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 |
| 78 #if !defined(NDEBUG) | 85 #if !defined(NDEBUG) |
| 79 SetDefaults(nat_false_overridden_others_default_); | 86 SetDefaults(nat_false_overridden_others_default_); |
| 80 nat_false_overridden_others_default_.SetBoolean( | 87 nat_false_overridden_others_default_.SetBoolean( |
| 81 PolicyWatcher::kNatPolicyName, false); | 88 PolicyWatcher::kNatPolicyName, false); |
| 82 nat_false_overridden_others_default_.SetString( | 89 nat_false_overridden_others_default_.SetString( |
| 83 PolicyWatcher::kHostDebugOverridePoliciesName, | 90 PolicyWatcher::kHostDebugOverridePoliciesName, |
| 84 kOverrideNatTraversalToFalse); | 91 kOverrideNatTraversalToFalse); |
| 85 #endif | 92 #endif |
| 86 } | 93 } |
| 87 | 94 |
| 88 protected: | 95 protected: |
| 89 void StartWatching() { | 96 void StartWatching() { |
| 90 policy_watcher_->StartWatching(policy_callback_); | 97 policy_watcher_->StartWatching(policy_callback_); |
| 91 base::RunLoop().RunUntilIdle(); | 98 base::RunLoop().RunUntilIdle(); |
| 92 } | 99 } |
| 93 | 100 |
| 94 void StopWatching() { | 101 void StopWatching() { |
| 95 base::WaitableEvent stop_event(false, false); | 102 base::WaitableEvent stop_event(false, false); |
| 96 policy_watcher_->StopWatching(&stop_event); | 103 policy_watcher_->StopWatching(&stop_event); |
| 97 base::RunLoop().RunUntilIdle(); | 104 base::RunLoop().RunUntilIdle(); |
| 98 EXPECT_EQ(true, stop_event.IsSignaled()); | 105 EXPECT_EQ(true, stop_event.IsSignaled()); |
| 99 } | 106 } |
| 100 | 107 |
| 101 static const char* kHostDomain; | 108 static const char* kHostDomain; |
| 109 static const char* kPortRange; |
| 102 base::MessageLoop message_loop_; | 110 base::MessageLoop message_loop_; |
| 103 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; | 111 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 104 MockPolicyCallback mock_policy_callback_; | 112 MockPolicyCallback mock_policy_callback_; |
| 105 PolicyWatcher::PolicyCallback policy_callback_; | 113 PolicyWatcher::PolicyCallback policy_callback_; |
| 106 scoped_ptr<FakePolicyWatcher> policy_watcher_; | 114 scoped_ptr<FakePolicyWatcher> policy_watcher_; |
| 107 base::DictionaryValue empty_; | 115 base::DictionaryValue empty_; |
| 108 base::DictionaryValue nat_true_; | 116 base::DictionaryValue nat_true_; |
| 109 base::DictionaryValue nat_false_; | 117 base::DictionaryValue nat_false_; |
| 110 base::DictionaryValue nat_one_; | 118 base::DictionaryValue nat_one_; |
| 111 base::DictionaryValue domain_empty_; | 119 base::DictionaryValue domain_empty_; |
| 112 base::DictionaryValue domain_full_; | 120 base::DictionaryValue domain_full_; |
| 113 base::DictionaryValue nat_true_others_default_; | 121 base::DictionaryValue nat_true_others_default_; |
| 114 base::DictionaryValue nat_false_others_default_; | 122 base::DictionaryValue nat_false_others_default_; |
| 115 base::DictionaryValue domain_empty_others_default_; | 123 base::DictionaryValue domain_empty_others_default_; |
| 116 base::DictionaryValue domain_full_others_default_; | 124 base::DictionaryValue domain_full_others_default_; |
| 117 base::DictionaryValue nat_true_domain_empty_; | 125 base::DictionaryValue nat_true_domain_empty_; |
| 118 base::DictionaryValue nat_true_domain_full_; | 126 base::DictionaryValue nat_true_domain_full_; |
| 119 base::DictionaryValue nat_false_domain_empty_; | 127 base::DictionaryValue nat_false_domain_empty_; |
| 120 base::DictionaryValue nat_false_domain_full_; | 128 base::DictionaryValue nat_false_domain_full_; |
| 121 base::DictionaryValue nat_true_domain_empty_others_default_; | 129 base::DictionaryValue nat_true_domain_empty_others_default_; |
| 122 base::DictionaryValue unknown_policies_; | 130 base::DictionaryValue unknown_policies_; |
| 123 base::DictionaryValue nat_true_and_overridden_; | 131 base::DictionaryValue nat_true_and_overridden_; |
| 124 base::DictionaryValue nat_false_overridden_others_default_; | 132 base::DictionaryValue nat_false_overridden_others_default_; |
| 125 base::DictionaryValue pairing_true_; | 133 base::DictionaryValue pairing_true_; |
| 126 base::DictionaryValue pairing_false_; | 134 base::DictionaryValue pairing_false_; |
| 127 base::DictionaryValue gnubby_auth_true_; | 135 base::DictionaryValue gnubby_auth_true_; |
| 128 base::DictionaryValue gnubby_auth_false_; | 136 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_; |
| 129 | 141 |
| 130 private: | 142 private: |
| 131 void SetDefaults(base::DictionaryValue& dict) { | 143 void SetDefaults(base::DictionaryValue& dict) { |
| 132 dict.SetBoolean(PolicyWatcher::kNatPolicyName, true); | 144 dict.SetBoolean(PolicyWatcher::kNatPolicyName, true); |
| 145 dict.SetBoolean(PolicyWatcher::kRelayPolicyName, true); |
| 146 dict.SetString(PolicyWatcher::kUdpPortRangePolicyName, ""); |
| 133 dict.SetBoolean(PolicyWatcher::kHostRequireTwoFactorPolicyName, false); | 147 dict.SetBoolean(PolicyWatcher::kHostRequireTwoFactorPolicyName, false); |
| 134 dict.SetString(PolicyWatcher::kHostDomainPolicyName, std::string()); | 148 dict.SetString(PolicyWatcher::kHostDomainPolicyName, std::string()); |
| 135 dict.SetBoolean(PolicyWatcher::kHostMatchUsernamePolicyName, false); | 149 dict.SetBoolean(PolicyWatcher::kHostMatchUsernamePolicyName, false); |
| 136 dict.SetString(PolicyWatcher::kHostTalkGadgetPrefixPolicyName, | 150 dict.SetString(PolicyWatcher::kHostTalkGadgetPrefixPolicyName, |
| 137 kDefaultHostTalkGadgetPrefix); | 151 kDefaultHostTalkGadgetPrefix); |
| 138 dict.SetBoolean(PolicyWatcher::kHostRequireCurtainPolicyName, false); | 152 dict.SetBoolean(PolicyWatcher::kHostRequireCurtainPolicyName, false); |
| 139 dict.SetString(PolicyWatcher::kHostTokenUrlPolicyName, std::string()); | 153 dict.SetString(PolicyWatcher::kHostTokenUrlPolicyName, std::string()); |
| 140 dict.SetString(PolicyWatcher::kHostTokenValidationUrlPolicyName, | 154 dict.SetString(PolicyWatcher::kHostTokenValidationUrlPolicyName, |
| 141 std::string()); | 155 std::string()); |
| 142 dict.SetString(PolicyWatcher::kHostTokenValidationCertIssuerPolicyName, | 156 dict.SetString(PolicyWatcher::kHostTokenValidationCertIssuerPolicyName, |
| 143 std::string()); | 157 std::string()); |
| 144 dict.SetBoolean(PolicyWatcher::kHostAllowClientPairing, true); | 158 dict.SetBoolean(PolicyWatcher::kHostAllowClientPairing, true); |
| 145 dict.SetBoolean(PolicyWatcher::kHostAllowGnubbyAuthPolicyName, true); | 159 dict.SetBoolean(PolicyWatcher::kHostAllowGnubbyAuthPolicyName, true); |
| 146 #if !defined(NDEBUG) | 160 #if !defined(NDEBUG) |
| 147 dict.SetString(PolicyWatcher::kHostDebugOverridePoliciesName, ""); | 161 dict.SetString(PolicyWatcher::kHostDebugOverridePoliciesName, ""); |
| 148 #endif | 162 #endif |
| 149 } | 163 } |
| 150 }; | 164 }; |
| 151 | 165 |
| 152 const char* PolicyWatcherTest::kHostDomain = "google.com"; | 166 const char* PolicyWatcherTest::kHostDomain = "google.com"; |
| 167 const char* PolicyWatcherTest::kPortRange = "12400-12409"; |
| 153 | 168 |
| 154 MATCHER_P(IsPolicies, dict, "") { | 169 MATCHER_P(IsPolicies, dict, "") { |
| 155 return arg->Equals(dict); | 170 return arg->Equals(dict); |
| 156 } | 171 } |
| 157 | 172 |
| 158 TEST_F(PolicyWatcherTest, None) { | 173 TEST_F(PolicyWatcherTest, None) { |
| 159 EXPECT_CALL(mock_policy_callback_, | 174 EXPECT_CALL(mock_policy_callback_, |
| 160 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); | 175 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); |
| 161 | 176 |
| 162 StartWatching(); | 177 StartWatching(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 EXPECT_CALL(mock_policy_callback_, | 363 EXPECT_CALL(mock_policy_callback_, |
| 349 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_true_))); | 364 OnPolicyUpdatePtr(IsPolicies(&gnubby_auth_true_))); |
| 350 | 365 |
| 351 StartWatching(); | 366 StartWatching(); |
| 352 policy_watcher_->SetPolicies(&empty_); | 367 policy_watcher_->SetPolicies(&empty_); |
| 353 policy_watcher_->SetPolicies(&gnubby_auth_false_); | 368 policy_watcher_->SetPolicies(&gnubby_auth_false_); |
| 354 policy_watcher_->SetPolicies(&gnubby_auth_true_); | 369 policy_watcher_->SetPolicies(&gnubby_auth_true_); |
| 355 StopWatching(); | 370 StopWatching(); |
| 356 } | 371 } |
| 357 | 372 |
| 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 |
| 358 } // namespace policy_hack | 405 } // namespace policy_hack |
| 359 } // namespace remoting | 406 } // namespace remoting |
| OLD | NEW |