diff options
author | simonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-28 02:17:48 +0000 |
---|---|---|
committer | simonmorris@chromium.org <simonmorris@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-28 02:17:48 +0000 |
commit | b9612a5860f84d95563b2a50a39b799cbbd1cb36 (patch) | |
tree | a96a2b2c230d00a564cf91ce11c34a00da1da902 /remoting | |
parent | e5bb0cd64027ab6d9729749b1427ecdb1cad0a69 (diff) | |
download | chromium_src-b9612a5860f84d95563b2a50a39b799cbbd1cb36.zip chromium_src-b9612a5860f84d95563b2a50a39b799cbbd1cb36.tar.gz chromium_src-b9612a5860f84d95563b2a50a39b799cbbd1cb36.tar.bz2 |
[Chromoting] Add a host domain policy to the PolicyWatcher.
Follow-up CLs will make the host respect this policy, and will let Windows
and Mac builds read this string-valued policy.
BUG=132684
Review URL: https://chromiumcodereview.appspot.com/10816036
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148871 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/host/policy_hack/policy_watcher.cc | 40 | ||||
-rw-r--r-- | remoting/host/policy_hack/policy_watcher.h | 7 | ||||
-rw-r--r-- | remoting/host/policy_hack/policy_watcher_mac.mm | 1 | ||||
-rw-r--r-- | remoting/host/policy_hack/policy_watcher_unittest.cc | 170 | ||||
-rw-r--r-- | remoting/host/policy_hack/policy_watcher_win.cc | 1 |
5 files changed, 181 insertions, 38 deletions
diff --git a/remoting/host/policy_hack/policy_watcher.cc b/remoting/host/policy_hack/policy_watcher.cc index 56511984..33e5d7b 100644 --- a/remoting/host/policy_hack/policy_watcher.cc +++ b/remoting/host/policy_hack/policy_watcher.cc @@ -41,6 +41,24 @@ bool GetBooleanOrDefault(const base::DictionaryValue* dict, const char* key, return default_if_value_not_boolean; } +// Gets a string from a dictionary, or returns a default value if the string +// couldn't be read. +std::string GetStringOrDefault(const base::DictionaryValue* dict, + const char* key, + const std::string& default_if_value_missing, + const std::string& default_if_value_not_string) { + if (!dict->HasKey(key)) { + return default_if_value_missing; + } + const base::Value* value; + if (dict->Get(key, &value) && value->IsType(base::Value::TYPE_STRING)) { + std::string string_value; + CHECK(value->GetAsString(&string_value)); + return string_value; + } + return default_if_value_not_string; +} + // Copies a boolean from one dictionary to another, using a default value // if the boolean couldn't be read from the first dictionary. void CopyBooleanOrDefault(base::DictionaryValue* to, @@ -52,6 +70,17 @@ void CopyBooleanOrDefault(base::DictionaryValue* to, default_if_value_not_boolean))); } +// Copies a string from one dictionary to another, using a default value +// if the string couldn't be read from the first dictionary. +void CopyStringOrDefault(base::DictionaryValue* to, + const base::DictionaryValue* from, const char* key, + const std::string& default_if_value_missing, + const std::string& default_if_value_not_string) { + to->Set(key, base::Value::CreateStringValue( + GetStringOrDefault(from, key, default_if_value_missing, + default_if_value_not_string))); +} + // Copies all policy values from one dictionary to another, using default values // when necessary. scoped_ptr<base::DictionaryValue> AddDefaultValuesWhenNecessary( @@ -59,6 +88,8 @@ scoped_ptr<base::DictionaryValue> AddDefaultValuesWhenNecessary( scoped_ptr<base::DictionaryValue> to(new base::DictionaryValue()); CopyBooleanOrDefault(to.get(), from, PolicyWatcher::kNatPolicyName, true, false); + CopyStringOrDefault(to.get(), from, + PolicyWatcher::kHostDomainPolicyName, "", ""); return to.Pass(); } @@ -67,12 +98,21 @@ scoped_ptr<base::DictionaryValue> AddDefaultValuesWhenNecessary( const char PolicyWatcher::kNatPolicyName[] = "RemoteAccessHostFirewallTraversal"; +const char PolicyWatcher::kHostDomainPolicyName[] = + "RemoteAccessHostDomain"; + const char* const PolicyWatcher::kBooleanPolicyNames[] = { PolicyWatcher::kNatPolicyName }; const int PolicyWatcher::kBooleanPolicyNamesNum = arraysize(kBooleanPolicyNames); +const char* const PolicyWatcher::kStringPolicyNames[] = + { PolicyWatcher::kHostDomainPolicyName }; + +const int PolicyWatcher::kStringPolicyNamesNum = + arraysize(kStringPolicyNames); + PolicyWatcher::PolicyWatcher( scoped_refptr<base::SingleThreadTaskRunner> task_runner) : task_runner_(task_runner), diff --git a/remoting/host/policy_hack/policy_watcher.h b/remoting/host/policy_hack/policy_watcher.h index ac0a567..123073d 100644 --- a/remoting/host/policy_hack/policy_watcher.h +++ b/remoting/host/policy_hack/policy_watcher.h @@ -49,6 +49,9 @@ class PolicyWatcher { // The name of the NAT traversal policy. static const char kNatPolicyName[]; + // The name of the host domain policy. + static const char kHostDomainPolicyName[]; + protected: virtual void StartWatchingInternal() = 0; virtual void StopWatchingInternal() = 0; @@ -70,6 +73,10 @@ class PolicyWatcher { static const char* const kBooleanPolicyNames[]; static const int kBooleanPolicyNamesNum; + // The names of policies with string values. + static const char* const kStringPolicyNames[]; + static const int kStringPolicyNamesNum; + private: scoped_refptr<base::SingleThreadTaskRunner> task_runner_; diff --git a/remoting/host/policy_hack/policy_watcher_mac.mm b/remoting/host/policy_hack/policy_watcher_mac.mm index eee0412..26b3213 100644 --- a/remoting/host/policy_hack/policy_watcher_mac.mm +++ b/remoting/host/policy_hack/policy_watcher_mac.mm @@ -56,6 +56,7 @@ class PolicyWatcherMac : public PolicyWatcher { policy.SetBoolean(policy_name, allowed); } } + // TODO(simonmorris): Read policies whose names are in kStringPolicyNames. } // Set policy. Policy must be set (even if it is empty) so that the diff --git a/remoting/host/policy_hack/policy_watcher_unittest.cc b/remoting/host/policy_hack/policy_watcher_unittest.cc index 3829353..73f4c7d 100644 --- a/remoting/host/policy_hack/policy_watcher_unittest.cc +++ b/remoting/host/policy_hack/policy_watcher_unittest.cc @@ -25,9 +25,31 @@ class PolicyWatcherTest : public testing::Test { policy_callback_ = base::Bind(&MockPolicyCallback::OnPolicyUpdate, base::Unretained(&mock_policy_callback_)); policy_watcher_.reset(new FakePolicyWatcher(message_loop_proxy_)); - nat_true.SetBoolean(PolicyWatcher::kNatPolicyName, true); - nat_false.SetBoolean(PolicyWatcher::kNatPolicyName, false); - nat_one.SetInteger(PolicyWatcher::kNatPolicyName, 1); + nat_true_.SetBoolean(PolicyWatcher::kNatPolicyName, true); + nat_false_.SetBoolean(PolicyWatcher::kNatPolicyName, false); + nat_one_.SetInteger(PolicyWatcher::kNatPolicyName, 1); + domain_empty_.SetString(PolicyWatcher::kHostDomainPolicyName, ""); + domain_full_.SetString(PolicyWatcher::kHostDomainPolicyName, kHostDomain); + SetDefaults(nat_true_others_default_); + nat_true_others_default_.SetBoolean(PolicyWatcher::kNatPolicyName, true); + SetDefaults(nat_false_others_default_); + nat_false_others_default_.SetBoolean(PolicyWatcher::kNatPolicyName, false); + SetDefaults(domain_empty_others_default_); + domain_empty_others_default_.SetString(PolicyWatcher::kHostDomainPolicyName, + ""); + SetDefaults(domain_full_others_default_); + domain_full_others_default_.SetString(PolicyWatcher::kHostDomainPolicyName, + kHostDomain); + nat_true_domain_empty_.SetBoolean(PolicyWatcher::kNatPolicyName, true); + nat_true_domain_empty_.SetString(PolicyWatcher::kHostDomainPolicyName, ""); + nat_true_domain_full_.SetBoolean(PolicyWatcher::kNatPolicyName, true); + nat_true_domain_full_.SetString(PolicyWatcher::kHostDomainPolicyName, + kHostDomain); + nat_false_domain_empty_.SetBoolean(PolicyWatcher::kNatPolicyName, false); + nat_false_domain_empty_.SetString(PolicyWatcher::kHostDomainPolicyName, ""); + nat_false_domain_full_.SetBoolean(PolicyWatcher::kNatPolicyName, false); + nat_false_domain_full_.SetString(PolicyWatcher::kHostDomainPolicyName, + kHostDomain); } protected: @@ -43,106 +65,178 @@ class PolicyWatcherTest : public testing::Test { EXPECT_EQ(true, stop_event.IsSignaled()); } + static const char* kHostDomain; MessageLoop message_loop_; scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; MockPolicyCallback mock_policy_callback_; PolicyWatcher::PolicyCallback policy_callback_; scoped_ptr<FakePolicyWatcher> policy_watcher_; - base::DictionaryValue empty; - base::DictionaryValue nat_true; - base::DictionaryValue nat_false; - base::DictionaryValue nat_one; + base::DictionaryValue empty_; + base::DictionaryValue nat_true_; + base::DictionaryValue nat_false_; + base::DictionaryValue nat_one_; + base::DictionaryValue domain_empty_; + base::DictionaryValue domain_full_; + base::DictionaryValue nat_true_others_default_; + base::DictionaryValue nat_false_others_default_; + base::DictionaryValue domain_empty_others_default_; + base::DictionaryValue domain_full_others_default_; + base::DictionaryValue nat_true_domain_empty_; + base::DictionaryValue nat_true_domain_full_; + base::DictionaryValue nat_false_domain_empty_; + base::DictionaryValue nat_false_domain_full_; + + private: + void SetDefaults(base::DictionaryValue& dict) { + dict.SetBoolean(PolicyWatcher::kNatPolicyName, true); + dict.SetString(PolicyWatcher::kHostDomainPolicyName, ""); + } }; +const char* PolicyWatcherTest::kHostDomain = "google.com"; + MATCHER_P(IsPolicies, dict, "") { return arg->Equals(dict); } TEST_F(PolicyWatcherTest, None) { - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); StartWatching(); - policy_watcher_->SetPolicies(&empty); + policy_watcher_->SetPolicies(&empty_); StopWatching(); } TEST_F(PolicyWatcherTest, NatTrue) { - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); StartWatching(); - policy_watcher_->SetPolicies(&nat_true); + policy_watcher_->SetPolicies(&nat_true_); StopWatching(); } TEST_F(PolicyWatcherTest, NatFalse) { - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_))); StartWatching(); - policy_watcher_->SetPolicies(&nat_false); + policy_watcher_->SetPolicies(&nat_false_); StopWatching(); } TEST_F(PolicyWatcherTest, NatOne) { - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_false_others_default_))); + + StartWatching(); + policy_watcher_->SetPolicies(&nat_one_); + StopWatching(); +} + +TEST_F(PolicyWatcherTest, DomainEmpty) { + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&domain_empty_others_default_))); + + StartWatching(); + policy_watcher_->SetPolicies(&domain_empty_); + StopWatching(); +} + +TEST_F(PolicyWatcherTest, DomainFull) { + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&domain_full_others_default_))); StartWatching(); - policy_watcher_->SetPolicies(&nat_one); + policy_watcher_->SetPolicies(&domain_full_); StopWatching(); } TEST_F(PolicyWatcherTest, NatNoneThenTrue) { - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); StartWatching(); - policy_watcher_->SetPolicies(&empty); - policy_watcher_->SetPolicies(&nat_true); + policy_watcher_->SetPolicies(&empty_); + policy_watcher_->SetPolicies(&nat_true_); StopWatching(); } TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrue) { - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); StartWatching(); - policy_watcher_->SetPolicies(&empty); - policy_watcher_->SetPolicies(&nat_true); - policy_watcher_->SetPolicies(&nat_true); + policy_watcher_->SetPolicies(&empty_); + policy_watcher_->SetPolicies(&nat_true_); + policy_watcher_->SetPolicies(&nat_true_); StopWatching(); } TEST_F(PolicyWatcherTest, NatNoneThenTrueThenTrueThenFalse) { testing::InSequence sequence; - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_false_))); StartWatching(); - policy_watcher_->SetPolicies(&empty); - policy_watcher_->SetPolicies(&nat_true); - policy_watcher_->SetPolicies(&nat_true); - policy_watcher_->SetPolicies(&nat_false); + policy_watcher_->SetPolicies(&empty_); + policy_watcher_->SetPolicies(&nat_true_); + policy_watcher_->SetPolicies(&nat_true_); + policy_watcher_->SetPolicies(&nat_false_); StopWatching(); } TEST_F(PolicyWatcherTest, NatNoneThenFalse) { testing::InSequence sequence; - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_false_))); StartWatching(); - policy_watcher_->SetPolicies(&empty); - policy_watcher_->SetPolicies(&nat_false); + policy_watcher_->SetPolicies(&empty_); + policy_watcher_->SetPolicies(&nat_false_); StopWatching(); } TEST_F(PolicyWatcherTest, NatNoneThenFalseThenTrue) { testing::InSequence sequence; - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_false))); - EXPECT_CALL(mock_policy_callback_, OnPolicyUpdatePtr(IsPolicies(&nat_true))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_true_others_default_))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_false_))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_true_))); + + StartWatching(); + policy_watcher_->SetPolicies(&empty_); + policy_watcher_->SetPolicies(&nat_false_); + policy_watcher_->SetPolicies(&nat_true_); + StopWatching(); +} + +TEST_F(PolicyWatcherTest, ChangeOneRepeatedlyThenTwo) { + testing::InSequence sequence; + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_true_domain_empty_))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&domain_full_))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_false_))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&domain_empty_))); + EXPECT_CALL(mock_policy_callback_, + OnPolicyUpdatePtr(IsPolicies(&nat_true_domain_full_))); StartWatching(); - policy_watcher_->SetPolicies(&empty); - policy_watcher_->SetPolicies(&nat_false); - policy_watcher_->SetPolicies(&nat_true); + policy_watcher_->SetPolicies(&nat_true_domain_empty_); + policy_watcher_->SetPolicies(&nat_true_domain_full_); + policy_watcher_->SetPolicies(&nat_false_domain_full_); + policy_watcher_->SetPolicies(&nat_false_domain_empty_); + policy_watcher_->SetPolicies(&nat_true_domain_full_); StopWatching(); } diff --git a/remoting/host/policy_hack/policy_watcher_win.cc b/remoting/host/policy_hack/policy_watcher_win.cc index 5c247d6..9f3b5e4 100644 --- a/remoting/host/policy_hack/policy_watcher_win.cc +++ b/remoting/host/policy_hack/policy_watcher_win.cc @@ -151,6 +151,7 @@ class PolicyWatcherWin : policy->SetBoolean(policy_name, bool_value); } } + // TODO(simonmorris): Read policies whose names are in kStringPolicyNames. return policy; } |