Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/policy_watcher.h" | 5 #include "remoting/host/policy_watcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 // We expect no callbacks unless explicitly specified by individual tests. | 67 // We expect no callbacks unless explicitly specified by individual tests. |
| 68 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_)).Times(0); | 68 EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(testing::_)).Times(0); |
| 69 EXPECT_CALL(mock_policy_callback_, OnPolicyError()).Times(0); | 69 EXPECT_CALL(mock_policy_callback_, OnPolicyError()).Times(0); |
| 70 | 70 |
| 71 // Retaining a raw pointer to keep control over policy contents. | 71 // Retaining a raw pointer to keep control over policy contents. |
| 72 policy_loader_ = | 72 policy_loader_ = |
| 73 new policy::FakeAsyncPolicyLoader(base::ThreadTaskRunnerHandle::Get()); | 73 new policy::FakeAsyncPolicyLoader(base::ThreadTaskRunnerHandle::Get()); |
| 74 policy_watcher_ = PolicyWatcher::CreateFromPolicyLoaderForTesting( | 74 policy_watcher_ = PolicyWatcher::CreateFromPolicyLoaderForTesting( |
| 75 base::WrapUnique(policy_loader_)); | 75 base::WrapUnique(policy_loader_)); |
| 76 | 76 |
| 77 base::ListValue host_domain; | |
| 78 host_domain.AppendString(kHostDomain); | |
| 79 base::ListValue client_domain; | |
| 80 client_domain.AppendString(kClientDomain); | |
| 81 base::ListValue multiple_host_domains; | |
| 82 multiple_host_domains.AppendString("a.com"); | |
|
rkjnsn
2017/04/19 23:13:24
I could make "a.com", et cetera constants. I didn'
| |
| 83 multiple_host_domains.AppendString("b.com"); | |
| 84 multiple_host_domains.AppendString("c.com"); | |
| 85 base::ListValue multiple_client_domains; | |
| 86 multiple_client_domains.AppendString("d.com"); | |
| 87 multiple_client_domains.AppendString("e.com"); | |
| 88 multiple_client_domains.AppendString("f.com"); | |
| 89 | |
| 77 nat_true_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, true); | 90 nat_true_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, true); |
| 78 nat_false_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, false); | 91 nat_false_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, false); |
| 79 nat_one_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); | 92 nat_one_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); |
| 80 nat_one_domain_full_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); | 93 nat_one_domain_full_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); |
| 81 nat_one_domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); | 94 nat_one_domain_full_.Set(key::kRemoteAccessHostDomainList, |
| 82 domain_empty_.SetString(key::kRemoteAccessHostDomain, std::string()); | 95 host_domain.CreateDeepCopy()); |
| 83 domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); | 96 domain_empty_.Set(key::kRemoteAccessHostDomainList, |
| 97 base::MakeUnique<base::ListValue>()); | |
| 98 domain_full_.Set(key::kRemoteAccessHostDomainList, | |
| 99 host_domain.CreateDeepCopy()); | |
| 84 SetDefaults(nat_true_others_default_); | 100 SetDefaults(nat_true_others_default_); |
| 85 nat_true_others_default_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, | 101 nat_true_others_default_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, |
| 86 true); | 102 true); |
| 87 SetDefaults(nat_false_others_default_); | 103 SetDefaults(nat_false_others_default_); |
| 88 nat_false_others_default_.SetBoolean( | 104 nat_false_others_default_.SetBoolean( |
| 89 key::kRemoteAccessHostFirewallTraversal, false); | 105 key::kRemoteAccessHostFirewallTraversal, false); |
| 90 SetDefaults(domain_empty_others_default_); | 106 SetDefaults(domain_empty_others_default_); |
| 91 domain_empty_others_default_.SetString(key::kRemoteAccessHostDomain, | 107 domain_empty_others_default_.Set(key::kRemoteAccessHostDomainList, |
| 92 std::string()); | 108 base::MakeUnique<base::ListValue>()); |
| 93 SetDefaults(domain_full_others_default_); | 109 SetDefaults(domain_full_others_default_); |
| 94 domain_full_others_default_.SetString(key::kRemoteAccessHostDomain, | 110 domain_full_others_default_.Set(key::kRemoteAccessHostDomainList, |
| 95 kHostDomain); | 111 host_domain.CreateDeepCopy()); |
| 96 nat_true_domain_empty_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, | 112 nat_true_domain_empty_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, |
| 97 true); | 113 true); |
| 98 nat_true_domain_empty_.SetString(key::kRemoteAccessHostDomain, | 114 nat_true_domain_empty_.Set(key::kRemoteAccessHostDomainList, |
| 99 std::string()); | 115 base::MakeUnique<base::ListValue>()); |
| 100 nat_true_domain_full_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, | 116 nat_true_domain_full_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, |
| 101 true); | 117 true); |
| 102 nat_true_domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); | 118 nat_true_domain_full_.Set(key::kRemoteAccessHostDomainList, |
| 119 host_domain.CreateDeepCopy()); | |
| 103 nat_false_domain_empty_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, | 120 nat_false_domain_empty_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, |
| 104 false); | 121 false); |
| 105 nat_false_domain_empty_.SetString(key::kRemoteAccessHostDomain, | 122 nat_false_domain_empty_.Set(key::kRemoteAccessHostDomainList, |
| 106 std::string()); | 123 base::MakeUnique<base::ListValue>()); |
| 107 nat_false_domain_full_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, | 124 nat_false_domain_full_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, |
| 108 false); | 125 false); |
| 109 nat_false_domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); | 126 nat_false_domain_full_.Set(key::kRemoteAccessHostDomainList, |
| 127 host_domain.CreateDeepCopy()); | |
| 110 SetDefaults(nat_true_domain_empty_others_default_); | 128 SetDefaults(nat_true_domain_empty_others_default_); |
| 111 nat_true_domain_empty_others_default_.SetBoolean( | 129 nat_true_domain_empty_others_default_.SetBoolean( |
| 112 key::kRemoteAccessHostFirewallTraversal, true); | 130 key::kRemoteAccessHostFirewallTraversal, true); |
| 113 nat_true_domain_empty_others_default_.SetString( | 131 nat_true_domain_empty_others_default_.Set( |
| 114 key::kRemoteAccessHostDomain, std::string()); | 132 key::kRemoteAccessHostDomainList, base::MakeUnique<base::ListValue>()); |
| 115 unknown_policies_.SetString("UnknownPolicyOne", std::string()); | 133 unknown_policies_.SetString("UnknownPolicyOne", std::string()); |
| 116 unknown_policies_.SetString("UnknownPolicyTwo", std::string()); | 134 unknown_policies_.SetString("UnknownPolicyTwo", std::string()); |
| 117 unknown_policies_.SetBoolean("RemoteAccessHostUnknownPolicyThree", true); | 135 unknown_policies_.SetBoolean("RemoteAccessHostUnknownPolicyThree", true); |
| 118 | 136 |
| 119 pairing_true_.SetBoolean(key::kRemoteAccessHostAllowClientPairing, true); | 137 pairing_true_.SetBoolean(key::kRemoteAccessHostAllowClientPairing, true); |
| 120 pairing_false_.SetBoolean(key::kRemoteAccessHostAllowClientPairing, false); | 138 pairing_false_.SetBoolean(key::kRemoteAccessHostAllowClientPairing, false); |
| 121 gnubby_auth_true_.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, true); | 139 gnubby_auth_true_.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, true); |
| 122 gnubby_auth_false_.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, false); | 140 gnubby_auth_false_.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, false); |
| 123 relay_true_.SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, true); | 141 relay_true_.SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, true); |
| 124 relay_false_.SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, | 142 relay_false_.SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, |
| 125 false); | 143 false); |
| 126 port_range_full_.SetString(key::kRemoteAccessHostUdpPortRange, kPortRange); | 144 port_range_full_.SetString(key::kRemoteAccessHostUdpPortRange, kPortRange); |
| 127 port_range_empty_.SetString(key::kRemoteAccessHostUdpPortRange, | 145 port_range_empty_.SetString(key::kRemoteAccessHostUdpPortRange, |
| 128 std::string()); | 146 std::string()); |
| 129 port_range_malformed_.SetString(key::kRemoteAccessHostUdpPortRange, | 147 port_range_malformed_.SetString(key::kRemoteAccessHostUdpPortRange, |
| 130 "malformed"); | 148 "malformed"); |
| 131 port_range_malformed_domain_full_.MergeDictionary(&port_range_malformed_); | 149 port_range_malformed_domain_full_.MergeDictionary(&port_range_malformed_); |
| 132 port_range_malformed_domain_full_.SetString(key::kRemoteAccessHostDomain, | 150 port_range_malformed_domain_full_.Set(key::kRemoteAccessHostDomainList, |
| 133 kHostDomain); | 151 host_domain.CreateDeepCopy()); |
| 134 | 152 |
| 135 curtain_true_.SetBoolean(key::kRemoteAccessHostRequireCurtain, true); | 153 curtain_true_.SetBoolean(key::kRemoteAccessHostRequireCurtain, true); |
| 136 curtain_false_.SetBoolean(key::kRemoteAccessHostRequireCurtain, false); | 154 curtain_false_.SetBoolean(key::kRemoteAccessHostRequireCurtain, false); |
| 137 username_true_.SetBoolean(key::kRemoteAccessHostMatchUsername, true); | 155 username_true_.SetBoolean(key::kRemoteAccessHostMatchUsername, true); |
| 138 username_false_.SetBoolean(key::kRemoteAccessHostMatchUsername, false); | 156 username_false_.SetBoolean(key::kRemoteAccessHostMatchUsername, false); |
| 139 talk_gadget_blah_.SetString(key::kRemoteAccessHostTalkGadgetPrefix, "blah"); | 157 talk_gadget_blah_.SetString(key::kRemoteAccessHostTalkGadgetPrefix, "blah"); |
| 140 third_party_auth_partial_.SetString(key::kRemoteAccessHostTokenUrl, | 158 third_party_auth_partial_.SetString(key::kRemoteAccessHostTokenUrl, |
| 141 "https://token.com"); | 159 "https://token.com"); |
| 142 third_party_auth_partial_.SetString( | 160 third_party_auth_partial_.SetString( |
| 143 key::kRemoteAccessHostTokenValidationUrl, "https://validation.com"); | 161 key::kRemoteAccessHostTokenValidationUrl, "https://validation.com"); |
| 144 third_party_auth_full_.MergeDictionary(&third_party_auth_partial_); | 162 third_party_auth_full_.MergeDictionary(&third_party_auth_partial_); |
| 145 third_party_auth_full_.SetString( | 163 third_party_auth_full_.SetString( |
| 146 key::kRemoteAccessHostTokenValidationCertificateIssuer, | 164 key::kRemoteAccessHostTokenValidationCertificateIssuer, |
| 147 "certificate subject"); | 165 "certificate subject"); |
| 148 third_party_auth_cert_empty_.MergeDictionary(&third_party_auth_partial_); | 166 third_party_auth_cert_empty_.MergeDictionary(&third_party_auth_partial_); |
| 149 third_party_auth_cert_empty_.SetString( | 167 third_party_auth_cert_empty_.SetString( |
| 150 key::kRemoteAccessHostTokenValidationCertificateIssuer, ""); | 168 key::kRemoteAccessHostTokenValidationCertificateIssuer, ""); |
| 151 remote_assistance_uiaccess_true_.SetBoolean( | 169 remote_assistance_uiaccess_true_.SetBoolean( |
| 152 key::kRemoteAccessHostAllowUiAccessForRemoteAssistance, true); | 170 key::kRemoteAccessHostAllowUiAccessForRemoteAssistance, true); |
| 153 remote_assistance_uiaccess_false_.SetBoolean( | 171 remote_assistance_uiaccess_false_.SetBoolean( |
| 154 key::kRemoteAccessHostAllowUiAccessForRemoteAssistance, false); | 172 key::kRemoteAccessHostAllowUiAccessForRemoteAssistance, false); |
| 173 | |
| 174 deprecated_policies_.SetString(key::kRemoteAccessHostDomain, kHostDomain); | |
|
rkjnsn
2017/04/19 23:13:24
I mainly just added stuff to the end of the releva
| |
| 175 deprecated_policies_.SetString(key::kRemoteAccessHostClientDomain, | |
| 176 kClientDomain); | |
| 177 // Deprecated policies should get converted if new ones aren't present. | |
| 178 SetDefaults(deprecated_policies_expected_); | |
| 179 deprecated_policies_expected_.Set(key::kRemoteAccessHostDomainList, | |
| 180 host_domain.CreateDeepCopy()); | |
| 181 deprecated_policies_expected_.Set(key::kRemoteAccessHostClientDomainList, | |
| 182 client_domain.CreateDeepCopy()); | |
| 183 | |
| 184 deprecated_and_new_policies_.SetString(key::kRemoteAccessHostDomain, | |
| 185 kHostDomain); | |
| 186 deprecated_and_new_policies_.SetString(key::kRemoteAccessHostClientDomain, | |
| 187 kClientDomain); | |
| 188 deprecated_and_new_policies_.Set(key::kRemoteAccessHostDomainList, | |
| 189 multiple_host_domains.CreateDeepCopy()); | |
| 190 deprecated_and_new_policies_.Set(key::kRemoteAccessHostClientDomainList, | |
| 191 multiple_client_domains.CreateDeepCopy()); | |
| 192 // Deprecated policies should just be dropped in new ones are present. | |
| 193 SetDefaults(deprecated_and_new_policies_expected_); | |
| 194 deprecated_and_new_policies_expected_.Set( | |
| 195 key::kRemoteAccessHostDomainList, | |
| 196 multiple_host_domains.CreateDeepCopy()); | |
| 197 deprecated_and_new_policies_expected_.Set( | |
| 198 key::kRemoteAccessHostClientDomainList, | |
| 199 multiple_client_domains.CreateDeepCopy()); | |
| 200 | |
| 201 // Empty strings should be treated as not set. | |
| 202 deprecated_empty_strings_.SetString(key::kRemoteAccessHostDomain, ""); | |
| 203 deprecated_empty_strings_.SetString(key::kRemoteAccessHostClientDomain, ""); | |
| 155 } | 204 } |
| 156 | 205 |
| 157 void TearDown() override { | 206 void TearDown() override { |
| 158 policy_watcher_.reset(); | 207 policy_watcher_.reset(); |
| 159 policy_loader_ = nullptr; | 208 policy_loader_ = nullptr; |
| 160 base::RunLoop().RunUntilIdle(); | 209 base::RunLoop().RunUntilIdle(); |
| 161 } | 210 } |
| 162 | 211 |
| 163 protected: | 212 protected: |
| 164 void StartWatching() { | 213 void StartWatching() { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 190 return policy_watcher_->GetPolicySchema(); | 239 return policy_watcher_->GetPolicySchema(); |
| 191 } | 240 } |
| 192 | 241 |
| 193 const base::DictionaryValue& GetDefaultValues() { | 242 const base::DictionaryValue& GetDefaultValues() { |
| 194 return *(policy_watcher_->default_values_); | 243 return *(policy_watcher_->default_values_); |
| 195 } | 244 } |
| 196 | 245 |
| 197 MOCK_METHOD0(PostPolicyWatcherShutdown, void()); | 246 MOCK_METHOD0(PostPolicyWatcherShutdown, void()); |
| 198 | 247 |
| 199 static const char* kHostDomain; | 248 static const char* kHostDomain; |
| 249 static const char* kClientDomain; | |
| 200 static const char* kPortRange; | 250 static const char* kPortRange; |
| 201 base::MessageLoop message_loop_; | 251 base::MessageLoop message_loop_; |
| 202 MockPolicyCallback mock_policy_callback_; | 252 MockPolicyCallback mock_policy_callback_; |
| 203 | 253 |
| 204 // |policy_loader_| is owned by |policy_watcher_|. PolicyWatcherTest retains | 254 // |policy_loader_| is owned by |policy_watcher_|. PolicyWatcherTest retains |
| 205 // a raw pointer to |policy_loader_| in order to control the simulated / faked | 255 // a raw pointer to |policy_loader_| in order to control the simulated / faked |
| 206 // policy contents. | 256 // policy contents. |
| 207 policy::FakeAsyncPolicyLoader* policy_loader_; | 257 policy::FakeAsyncPolicyLoader* policy_loader_; |
| 208 std::unique_ptr<PolicyWatcher> policy_watcher_; | 258 std::unique_ptr<PolicyWatcher> policy_watcher_; |
| 209 | 259 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 237 base::DictionaryValue curtain_true_; | 287 base::DictionaryValue curtain_true_; |
| 238 base::DictionaryValue curtain_false_; | 288 base::DictionaryValue curtain_false_; |
| 239 base::DictionaryValue username_true_; | 289 base::DictionaryValue username_true_; |
| 240 base::DictionaryValue username_false_; | 290 base::DictionaryValue username_false_; |
| 241 base::DictionaryValue talk_gadget_blah_; | 291 base::DictionaryValue talk_gadget_blah_; |
| 242 base::DictionaryValue third_party_auth_full_; | 292 base::DictionaryValue third_party_auth_full_; |
| 243 base::DictionaryValue third_party_auth_partial_; | 293 base::DictionaryValue third_party_auth_partial_; |
| 244 base::DictionaryValue third_party_auth_cert_empty_; | 294 base::DictionaryValue third_party_auth_cert_empty_; |
| 245 base::DictionaryValue remote_assistance_uiaccess_true_; | 295 base::DictionaryValue remote_assistance_uiaccess_true_; |
| 246 base::DictionaryValue remote_assistance_uiaccess_false_; | 296 base::DictionaryValue remote_assistance_uiaccess_false_; |
| 297 base::DictionaryValue deprecated_policies_; | |
| 298 base::DictionaryValue deprecated_policies_expected_; | |
| 299 base::DictionaryValue deprecated_and_new_policies_; | |
| 300 base::DictionaryValue deprecated_and_new_policies_expected_; | |
| 301 base::DictionaryValue deprecated_empty_strings_; | |
| 247 | 302 |
| 248 private: | 303 private: |
| 249 void SetDefaults(base::DictionaryValue& dict) { | 304 void SetDefaults(base::DictionaryValue& dict) { |
| 250 dict.SetBoolean(key::kRemoteAccessHostFirewallTraversal, true); | 305 dict.SetBoolean(key::kRemoteAccessHostFirewallTraversal, true); |
| 251 dict.SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, true); | 306 dict.SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, true); |
| 252 dict.SetString(key::kRemoteAccessHostUdpPortRange, ""); | 307 dict.SetString(key::kRemoteAccessHostUdpPortRange, ""); |
| 253 dict.SetString(key::kRemoteAccessHostClientDomain, std::string()); | 308 dict.Set(key::kRemoteAccessHostClientDomainList, |
| 254 dict.SetString(key::kRemoteAccessHostDomain, std::string()); | 309 base::MakeUnique<base::ListValue>()); |
| 310 dict.Set(key::kRemoteAccessHostDomainList, | |
| 311 base::MakeUnique<base::ListValue>()); | |
| 255 dict.SetBoolean(key::kRemoteAccessHostMatchUsername, false); | 312 dict.SetBoolean(key::kRemoteAccessHostMatchUsername, false); |
| 256 dict.SetString(key::kRemoteAccessHostTalkGadgetPrefix, | 313 dict.SetString(key::kRemoteAccessHostTalkGadgetPrefix, |
| 257 kDefaultHostTalkGadgetPrefix); | 314 kDefaultHostTalkGadgetPrefix); |
| 258 dict.SetBoolean(key::kRemoteAccessHostRequireCurtain, false); | 315 dict.SetBoolean(key::kRemoteAccessHostRequireCurtain, false); |
| 259 dict.SetString(key::kRemoteAccessHostTokenUrl, ""); | 316 dict.SetString(key::kRemoteAccessHostTokenUrl, ""); |
| 260 dict.SetString(key::kRemoteAccessHostTokenValidationUrl, ""); | 317 dict.SetString(key::kRemoteAccessHostTokenValidationUrl, ""); |
| 261 dict.SetString(key::kRemoteAccessHostTokenValidationCertificateIssuer, ""); | 318 dict.SetString(key::kRemoteAccessHostTokenValidationCertificateIssuer, ""); |
| 262 dict.SetBoolean(key::kRemoteAccessHostAllowClientPairing, true); | 319 dict.SetBoolean(key::kRemoteAccessHostAllowClientPairing, true); |
| 263 dict.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, true); | 320 dict.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, true); |
| 264 dict.SetBoolean(key::kRemoteAccessHostAllowUiAccessForRemoteAssistance, | 321 dict.SetBoolean(key::kRemoteAccessHostAllowUiAccessForRemoteAssistance, |
| 265 false); | 322 false); |
| 266 | 323 |
| 267 ASSERT_THAT(&dict, IsPolicies(&GetDefaultValues())) | 324 ASSERT_THAT(&dict, IsPolicies(&GetDefaultValues())) |
| 268 << "Sanity check that defaults expected by the test code " | 325 << "Sanity check that defaults expected by the test code " |
| 269 << "match what is stored in PolicyWatcher::default_values_"; | 326 << "match what is stored in PolicyWatcher::default_values_"; |
| 270 } | 327 } |
| 271 }; | 328 }; |
| 272 | 329 |
| 273 const char* PolicyWatcherTest::kHostDomain = "google.com"; | 330 const char* PolicyWatcherTest::kHostDomain = "google.com"; |
| 331 const char* PolicyWatcherTest::kClientDomain = "client.com"; | |
| 274 const char* PolicyWatcherTest::kPortRange = "12400-12409"; | 332 const char* PolicyWatcherTest::kPortRange = "12400-12409"; |
| 275 | 333 |
| 276 TEST_F(PolicyWatcherTest, None) { | 334 TEST_F(PolicyWatcherTest, None) { |
| 277 EXPECT_CALL(mock_policy_callback_, | 335 EXPECT_CALL(mock_policy_callback_, |
| 278 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); | 336 OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); |
| 279 | 337 |
| 280 SetPolicies(empty_); | 338 SetPolicies(empty_); |
| 281 StartWatching(); | 339 StartWatching(); |
| 282 } | 340 } |
| 283 | 341 |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 std::map<std::string, base::Value::Type> actual_schema; | 710 std::map<std::string, base::Value::Type> actual_schema; |
| 653 const policy::Schema* schema = GetPolicySchema(); | 711 const policy::Schema* schema = GetPolicySchema(); |
| 654 ASSERT_TRUE(schema->valid()); | 712 ASSERT_TRUE(schema->valid()); |
| 655 for (auto it = schema->GetPropertiesIterator(); !it.IsAtEnd(); it.Advance()) { | 713 for (auto it = schema->GetPropertiesIterator(); !it.IsAtEnd(); it.Advance()) { |
| 656 std::string key = it.key(); | 714 std::string key = it.key(); |
| 657 if (key.find("RemoteAccessHost") == std::string::npos) { | 715 if (key.find("RemoteAccessHost") == std::string::npos) { |
| 658 // For now PolicyWatcher::GetPolicySchema() mixes Chrome and Chromoting | 716 // For now PolicyWatcher::GetPolicySchema() mixes Chrome and Chromoting |
| 659 // policies, so we have to skip them here. | 717 // policies, so we have to skip them here. |
| 660 continue; | 718 continue; |
| 661 } | 719 } |
| 720 if (key == policy::key::kRemoteAccessHostDomain || | |
| 721 key == policy::key::kRemoteAccessHostClientDomain) { | |
| 722 // These policies are deprecated and get removed during normalization | |
| 723 continue; | |
| 724 } | |
| 662 actual_schema[key] = it.schema().type(); | 725 actual_schema[key] = it.schema().type(); |
| 663 } | 726 } |
| 664 | 727 |
| 665 EXPECT_THAT(actual_schema, testing::ContainerEq(expected_schema)); | 728 EXPECT_THAT(actual_schema, testing::ContainerEq(expected_schema)); |
| 666 } | 729 } |
| 667 | 730 |
| 668 TEST_F(PolicyWatcherTest, SchemaTypeCheck) { | 731 TEST_F(PolicyWatcherTest, SchemaTypeCheck) { |
| 669 const policy::Schema* schema = GetPolicySchema(); | 732 const policy::Schema* schema = GetPolicySchema(); |
| 670 ASSERT_TRUE(schema->valid()); | 733 ASSERT_TRUE(schema->valid()); |
| 671 | 734 |
| 672 // Check one, random "string" policy to see if the type propagated correctly | 735 // Check one, random "string" policy to see if the type propagated correctly |
| 673 // from policy_templates.json file. | 736 // from policy_templates.json file. |
| 674 const policy::Schema string_schema = | 737 const policy::Schema string_schema = |
| 675 schema->GetKnownProperty("RemoteAccessHostDomain"); | 738 schema->GetKnownProperty("RemoteAccessHostDomain"); |
| 676 EXPECT_TRUE(string_schema.valid()); | 739 EXPECT_TRUE(string_schema.valid()); |
| 677 EXPECT_EQ(string_schema.type(), base::Value::Type::STRING); | 740 EXPECT_EQ(string_schema.type(), base::Value::Type::STRING); |
| 678 | 741 |
| 679 // And check one, random "boolean" policy to see if the type propagated | 742 // And check one, random "boolean" policy to see if the type propagated |
| 680 // correctly from policy_templates.json file. | 743 // correctly from policy_templates.json file. |
| 681 const policy::Schema boolean_schema = | 744 const policy::Schema boolean_schema = |
| 682 schema->GetKnownProperty("RemoteAccessHostRequireCurtain"); | 745 schema->GetKnownProperty("RemoteAccessHostRequireCurtain"); |
| 683 EXPECT_TRUE(boolean_schema.valid()); | 746 EXPECT_TRUE(boolean_schema.valid()); |
| 684 EXPECT_EQ(boolean_schema.type(), base::Value::Type::BOOLEAN); | 747 EXPECT_EQ(boolean_schema.type(), base::Value::Type::BOOLEAN); |
| 685 } | 748 } |
| 686 | 749 |
| 750 TEST_F(PolicyWatcherTest, DeprecatedOnly) { | |
| 751 EXPECT_CALL(mock_policy_callback_, | |
| 752 OnPolicyUpdatePtr(IsPolicies(&deprecated_policies_expected_))); | |
| 753 SetPolicies(deprecated_policies_); | |
| 754 StartWatching(); | |
| 755 } | |
| 756 | |
| 757 TEST_F(PolicyWatcherTest, DeprecatedAndNew) { | |
| 758 EXPECT_CALL( | |
| 759 mock_policy_callback_, | |
| 760 OnPolicyUpdatePtr(IsPolicies(&deprecated_and_new_policies_expected_))); | |
| 761 SetPolicies(deprecated_and_new_policies_); | |
| 762 StartWatching(); | |
| 763 } | |
| 764 | |
| 765 TEST_F(PolicyWatcherTest, DeprecatedEmpty) { | |
| 766 EXPECT_CALL(mock_policy_callback_, | |
| 767 OnPolicyUpdatePtr(IsPolicies(&GetDefaultValues()))); | |
| 768 SetPolicies(deprecated_empty_strings_); | |
| 769 StartWatching(); | |
| 770 } | |
| 771 | |
| 687 } // namespace remoting | 772 } // namespace remoting |
| OLD | NEW |