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 |
77 nat_true_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, true); | 80 nat_true_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, true); |
78 nat_false_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, false); | 81 nat_false_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, false); |
79 nat_one_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); | 82 nat_one_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); |
80 nat_one_domain_full_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); | 83 nat_one_domain_full_.SetInteger(key::kRemoteAccessHostFirewallTraversal, 1); |
81 nat_one_domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); | 84 nat_one_domain_full_.Set(key::kRemoteAccessHostDomainList, |
82 domain_empty_.SetString(key::kRemoteAccessHostDomain, std::string()); | 85 host_domain.CreateDeepCopy()); |
83 domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); | 86 domain_empty_.Set(key::kRemoteAccessHostDomainList, |
| 87 base::MakeUnique<base::ListValue>()); |
| 88 domain_full_.Set(key::kRemoteAccessHostDomainList, |
| 89 host_domain.CreateDeepCopy()); |
84 SetDefaults(nat_true_others_default_); | 90 SetDefaults(nat_true_others_default_); |
85 nat_true_others_default_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, | 91 nat_true_others_default_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, |
86 true); | 92 true); |
87 SetDefaults(nat_false_others_default_); | 93 SetDefaults(nat_false_others_default_); |
88 nat_false_others_default_.SetBoolean( | 94 nat_false_others_default_.SetBoolean( |
89 key::kRemoteAccessHostFirewallTraversal, false); | 95 key::kRemoteAccessHostFirewallTraversal, false); |
90 SetDefaults(domain_empty_others_default_); | 96 SetDefaults(domain_empty_others_default_); |
91 domain_empty_others_default_.SetString(key::kRemoteAccessHostDomain, | 97 domain_empty_others_default_.Set(key::kRemoteAccessHostDomainList, |
92 std::string()); | 98 base::MakeUnique<base::ListValue>()); |
93 SetDefaults(domain_full_others_default_); | 99 SetDefaults(domain_full_others_default_); |
94 domain_full_others_default_.SetString(key::kRemoteAccessHostDomain, | 100 domain_full_others_default_.Set(key::kRemoteAccessHostDomainList, |
95 kHostDomain); | 101 host_domain.CreateDeepCopy()); |
96 nat_true_domain_empty_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, | 102 nat_true_domain_empty_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, |
97 true); | 103 true); |
98 nat_true_domain_empty_.SetString(key::kRemoteAccessHostDomain, | 104 nat_true_domain_empty_.Set(key::kRemoteAccessHostDomainList, |
99 std::string()); | 105 base::MakeUnique<base::ListValue>()); |
100 nat_true_domain_full_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, | 106 nat_true_domain_full_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, |
101 true); | 107 true); |
102 nat_true_domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); | 108 nat_true_domain_full_.Set(key::kRemoteAccessHostDomainList, |
| 109 host_domain.CreateDeepCopy()); |
103 nat_false_domain_empty_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, | 110 nat_false_domain_empty_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, |
104 false); | 111 false); |
105 nat_false_domain_empty_.SetString(key::kRemoteAccessHostDomain, | 112 nat_false_domain_empty_.Set(key::kRemoteAccessHostDomainList, |
106 std::string()); | 113 base::MakeUnique<base::ListValue>()); |
107 nat_false_domain_full_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, | 114 nat_false_domain_full_.SetBoolean(key::kRemoteAccessHostFirewallTraversal, |
108 false); | 115 false); |
109 nat_false_domain_full_.SetString(key::kRemoteAccessHostDomain, kHostDomain); | 116 nat_false_domain_full_.Set(key::kRemoteAccessHostDomainList, |
| 117 host_domain.CreateDeepCopy()); |
110 SetDefaults(nat_true_domain_empty_others_default_); | 118 SetDefaults(nat_true_domain_empty_others_default_); |
111 nat_true_domain_empty_others_default_.SetBoolean( | 119 nat_true_domain_empty_others_default_.SetBoolean( |
112 key::kRemoteAccessHostFirewallTraversal, true); | 120 key::kRemoteAccessHostFirewallTraversal, true); |
113 nat_true_domain_empty_others_default_.SetString( | 121 nat_true_domain_empty_others_default_.Set( |
114 key::kRemoteAccessHostDomain, std::string()); | 122 key::kRemoteAccessHostDomainList, base::MakeUnique<base::ListValue>()); |
115 unknown_policies_.SetString("UnknownPolicyOne", std::string()); | 123 unknown_policies_.SetString("UnknownPolicyOne", std::string()); |
116 unknown_policies_.SetString("UnknownPolicyTwo", std::string()); | 124 unknown_policies_.SetString("UnknownPolicyTwo", std::string()); |
117 unknown_policies_.SetBoolean("RemoteAccessHostUnknownPolicyThree", true); | 125 unknown_policies_.SetBoolean("RemoteAccessHostUnknownPolicyThree", true); |
118 | 126 |
119 pairing_true_.SetBoolean(key::kRemoteAccessHostAllowClientPairing, true); | 127 pairing_true_.SetBoolean(key::kRemoteAccessHostAllowClientPairing, true); |
120 pairing_false_.SetBoolean(key::kRemoteAccessHostAllowClientPairing, false); | 128 pairing_false_.SetBoolean(key::kRemoteAccessHostAllowClientPairing, false); |
121 gnubby_auth_true_.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, true); | 129 gnubby_auth_true_.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, true); |
122 gnubby_auth_false_.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, false); | 130 gnubby_auth_false_.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, false); |
123 relay_true_.SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, true); | 131 relay_true_.SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, true); |
124 relay_false_.SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, | 132 relay_false_.SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, |
125 false); | 133 false); |
126 port_range_full_.SetString(key::kRemoteAccessHostUdpPortRange, kPortRange); | 134 port_range_full_.SetString(key::kRemoteAccessHostUdpPortRange, kPortRange); |
127 port_range_empty_.SetString(key::kRemoteAccessHostUdpPortRange, | 135 port_range_empty_.SetString(key::kRemoteAccessHostUdpPortRange, |
128 std::string()); | 136 std::string()); |
129 port_range_malformed_.SetString(key::kRemoteAccessHostUdpPortRange, | 137 port_range_malformed_.SetString(key::kRemoteAccessHostUdpPortRange, |
130 "malformed"); | 138 "malformed"); |
131 port_range_malformed_domain_full_.MergeDictionary(&port_range_malformed_); | 139 port_range_malformed_domain_full_.MergeDictionary(&port_range_malformed_); |
132 port_range_malformed_domain_full_.SetString(key::kRemoteAccessHostDomain, | 140 port_range_malformed_domain_full_.Set(key::kRemoteAccessHostDomainList, |
133 kHostDomain); | 141 host_domain.CreateDeepCopy()); |
134 | 142 |
135 curtain_true_.SetBoolean(key::kRemoteAccessHostRequireCurtain, true); | 143 curtain_true_.SetBoolean(key::kRemoteAccessHostRequireCurtain, true); |
136 curtain_false_.SetBoolean(key::kRemoteAccessHostRequireCurtain, false); | 144 curtain_false_.SetBoolean(key::kRemoteAccessHostRequireCurtain, false); |
137 username_true_.SetBoolean(key::kRemoteAccessHostMatchUsername, true); | 145 username_true_.SetBoolean(key::kRemoteAccessHostMatchUsername, true); |
138 username_false_.SetBoolean(key::kRemoteAccessHostMatchUsername, false); | 146 username_false_.SetBoolean(key::kRemoteAccessHostMatchUsername, false); |
139 talk_gadget_blah_.SetString(key::kRemoteAccessHostTalkGadgetPrefix, "blah"); | 147 talk_gadget_blah_.SetString(key::kRemoteAccessHostTalkGadgetPrefix, "blah"); |
140 third_party_auth_partial_.SetString(key::kRemoteAccessHostTokenUrl, | 148 third_party_auth_partial_.SetString(key::kRemoteAccessHostTokenUrl, |
141 "https://token.com"); | 149 "https://token.com"); |
142 third_party_auth_partial_.SetString( | 150 third_party_auth_partial_.SetString( |
143 key::kRemoteAccessHostTokenValidationUrl, "https://validation.com"); | 151 key::kRemoteAccessHostTokenValidationUrl, "https://validation.com"); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 base::DictionaryValue third_party_auth_partial_; | 251 base::DictionaryValue third_party_auth_partial_; |
244 base::DictionaryValue third_party_auth_cert_empty_; | 252 base::DictionaryValue third_party_auth_cert_empty_; |
245 base::DictionaryValue remote_assistance_uiaccess_true_; | 253 base::DictionaryValue remote_assistance_uiaccess_true_; |
246 base::DictionaryValue remote_assistance_uiaccess_false_; | 254 base::DictionaryValue remote_assistance_uiaccess_false_; |
247 | 255 |
248 private: | 256 private: |
249 void SetDefaults(base::DictionaryValue& dict) { | 257 void SetDefaults(base::DictionaryValue& dict) { |
250 dict.SetBoolean(key::kRemoteAccessHostFirewallTraversal, true); | 258 dict.SetBoolean(key::kRemoteAccessHostFirewallTraversal, true); |
251 dict.SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, true); | 259 dict.SetBoolean(key::kRemoteAccessHostAllowRelayedConnection, true); |
252 dict.SetString(key::kRemoteAccessHostUdpPortRange, ""); | 260 dict.SetString(key::kRemoteAccessHostUdpPortRange, ""); |
253 dict.SetString(key::kRemoteAccessHostClientDomain, std::string()); | 261 dict.Set(key::kRemoteAccessHostClientDomainList, |
254 dict.SetString(key::kRemoteAccessHostDomain, std::string()); | 262 base::MakeUnique<base::ListValue>()); |
| 263 dict.Set(key::kRemoteAccessHostDomainList, |
| 264 base::MakeUnique<base::ListValue>()); |
255 dict.SetBoolean(key::kRemoteAccessHostMatchUsername, false); | 265 dict.SetBoolean(key::kRemoteAccessHostMatchUsername, false); |
256 dict.SetString(key::kRemoteAccessHostTalkGadgetPrefix, | 266 dict.SetString(key::kRemoteAccessHostTalkGadgetPrefix, |
257 kDefaultHostTalkGadgetPrefix); | 267 kDefaultHostTalkGadgetPrefix); |
258 dict.SetBoolean(key::kRemoteAccessHostRequireCurtain, false); | 268 dict.SetBoolean(key::kRemoteAccessHostRequireCurtain, false); |
259 dict.SetString(key::kRemoteAccessHostTokenUrl, ""); | 269 dict.SetString(key::kRemoteAccessHostTokenUrl, ""); |
260 dict.SetString(key::kRemoteAccessHostTokenValidationUrl, ""); | 270 dict.SetString(key::kRemoteAccessHostTokenValidationUrl, ""); |
261 dict.SetString(key::kRemoteAccessHostTokenValidationCertificateIssuer, ""); | 271 dict.SetString(key::kRemoteAccessHostTokenValidationCertificateIssuer, ""); |
262 dict.SetBoolean(key::kRemoteAccessHostAllowClientPairing, true); | 272 dict.SetBoolean(key::kRemoteAccessHostAllowClientPairing, true); |
263 dict.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, true); | 273 dict.SetBoolean(key::kRemoteAccessHostAllowGnubbyAuth, true); |
264 dict.SetBoolean(key::kRemoteAccessHostAllowUiAccessForRemoteAssistance, | 274 dict.SetBoolean(key::kRemoteAccessHostAllowUiAccessForRemoteAssistance, |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 std::map<std::string, base::Value::Type> actual_schema; | 662 std::map<std::string, base::Value::Type> actual_schema; |
653 const policy::Schema* schema = GetPolicySchema(); | 663 const policy::Schema* schema = GetPolicySchema(); |
654 ASSERT_TRUE(schema->valid()); | 664 ASSERT_TRUE(schema->valid()); |
655 for (auto it = schema->GetPropertiesIterator(); !it.IsAtEnd(); it.Advance()) { | 665 for (auto it = schema->GetPropertiesIterator(); !it.IsAtEnd(); it.Advance()) { |
656 std::string key = it.key(); | 666 std::string key = it.key(); |
657 if (key.find("RemoteAccessHost") == std::string::npos) { | 667 if (key.find("RemoteAccessHost") == std::string::npos) { |
658 // For now PolicyWatcher::GetPolicySchema() mixes Chrome and Chromoting | 668 // For now PolicyWatcher::GetPolicySchema() mixes Chrome and Chromoting |
659 // policies, so we have to skip them here. | 669 // policies, so we have to skip them here. |
660 continue; | 670 continue; |
661 } | 671 } |
| 672 if (key == policy::key::kRemoteAccessHostDomain || |
| 673 key == policy::key::kRemoteAccessHostClientDomain) { |
| 674 // These policies are deprecated and get removed during normalization |
| 675 continue; |
| 676 } |
662 actual_schema[key] = it.schema().type(); | 677 actual_schema[key] = it.schema().type(); |
663 } | 678 } |
664 | 679 |
665 EXPECT_THAT(actual_schema, testing::ContainerEq(expected_schema)); | 680 EXPECT_THAT(actual_schema, testing::ContainerEq(expected_schema)); |
666 } | 681 } |
667 | 682 |
668 TEST_F(PolicyWatcherTest, SchemaTypeCheck) { | 683 TEST_F(PolicyWatcherTest, SchemaTypeCheck) { |
669 const policy::Schema* schema = GetPolicySchema(); | 684 const policy::Schema* schema = GetPolicySchema(); |
670 ASSERT_TRUE(schema->valid()); | 685 ASSERT_TRUE(schema->valid()); |
671 | 686 |
672 // Check one, random "string" policy to see if the type propagated correctly | 687 // Check one, random "string" policy to see if the type propagated correctly |
673 // from policy_templates.json file. | 688 // from policy_templates.json file. |
674 const policy::Schema string_schema = | 689 const policy::Schema string_schema = |
675 schema->GetKnownProperty("RemoteAccessHostDomain"); | 690 schema->GetKnownProperty("RemoteAccessHostDomain"); |
676 EXPECT_TRUE(string_schema.valid()); | 691 EXPECT_TRUE(string_schema.valid()); |
677 EXPECT_EQ(string_schema.type(), base::Value::Type::STRING); | 692 EXPECT_EQ(string_schema.type(), base::Value::Type::STRING); |
678 | 693 |
679 // And check one, random "boolean" policy to see if the type propagated | 694 // And check one, random "boolean" policy to see if the type propagated |
680 // correctly from policy_templates.json file. | 695 // correctly from policy_templates.json file. |
681 const policy::Schema boolean_schema = | 696 const policy::Schema boolean_schema = |
682 schema->GetKnownProperty("RemoteAccessHostRequireCurtain"); | 697 schema->GetKnownProperty("RemoteAccessHostRequireCurtain"); |
683 EXPECT_TRUE(boolean_schema.valid()); | 698 EXPECT_TRUE(boolean_schema.valid()); |
684 EXPECT_EQ(boolean_schema.type(), base::Value::Type::BOOLEAN); | 699 EXPECT_EQ(boolean_schema.type(), base::Value::Type::BOOLEAN); |
685 } | 700 } |
686 | 701 |
687 } // namespace remoting | 702 } // namespace remoting |
OLD | NEW |