| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/login/signed_settings.h" | 5 #include "chrome/browser/chromeos/login/signed_settings.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | |
| 8 #include "base/logging.h" | 7 #include "base/logging.h" |
| 9 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 10 #include "base/scoped_temp_dir.h" | |
| 11 #include "base/stringprintf.h" | |
| 12 #include "chrome/browser/chromeos/cros/cros_library.h" | 9 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 13 #include "chrome/browser/chromeos/cros/mock_library_loader.h" | 10 #include "chrome/browser/chromeos/cros/mock_library_loader.h" |
| 14 #include "chrome/browser/chromeos/cros_settings_names.h" | 11 #include "chrome/browser/chromeos/cros_settings_names.h" |
| 15 #include "chrome/browser/chromeos/dbus/mock_dbus_thread_manager.h" | 12 #include "chrome/browser/chromeos/dbus/mock_dbus_thread_manager.h" |
| 16 #include "chrome/browser/chromeos/dbus/mock_session_manager_client.h" | 13 #include "chrome/browser/chromeos/dbus/mock_session_manager_client.h" |
| 17 #include "chrome/browser/chromeos/login/mock_owner_key_utils.h" | 14 #include "chrome/browser/chromeos/login/mock_owner_key_utils.h" |
| 18 #include "chrome/browser/chromeos/login/mock_ownership_service.h" | 15 #include "chrome/browser/chromeos/login/mock_ownership_service.h" |
| 19 #include "chrome/browser/chromeos/login/owner_manager_unittest.h" | 16 #include "chrome/browser/chromeos/login/owner_manager_unittest.h" |
| 20 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" | 17 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" |
| 21 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 18 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 22 #include "content/test/test_browser_thread.h" | 19 #include "content/test/test_browser_thread.h" |
| 23 #include "crypto/rsa_private_key.h" | |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 22 |
| 27 using ::testing::A; | 23 using ::testing::A; |
| 28 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
| 29 using ::testing::Return; | 25 using ::testing::Return; |
| 30 using ::testing::ReturnRef; | 26 using ::testing::ReturnRef; |
| 31 using ::testing::SaveArg; | 27 using ::testing::SaveArg; |
| 32 using ::testing::StrEq; | 28 using ::testing::StrEq; |
| 33 using ::testing::WithArg; | 29 using ::testing::WithArg; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 public: | 73 public: |
| 78 explicit NormalDelegate(T to_expect) : DummyDelegate<T>(to_expect) {} | 74 explicit NormalDelegate(T to_expect) : DummyDelegate<T>(to_expect) {} |
| 79 virtual ~NormalDelegate() {} | 75 virtual ~NormalDelegate() {} |
| 80 protected: | 76 protected: |
| 81 virtual void compare_expected(T to_compare) { | 77 virtual void compare_expected(T to_compare) { |
| 82 // without this-> this won't build. | 78 // without this-> this won't build. |
| 83 EXPECT_EQ(this->expected_, to_compare); | 79 EXPECT_EQ(this->expected_, to_compare); |
| 84 } | 80 } |
| 85 }; | 81 }; |
| 86 | 82 |
| 87 // Specialized version for Value objects because these compare differently. | |
| 88 class PolicyDelegate : public DummyDelegate<const base::Value*> { | |
| 89 public: | |
| 90 explicit PolicyDelegate(const base::Value* to_expect) | |
| 91 : DummyDelegate<const base::Value*>(to_expect) {} | |
| 92 virtual ~PolicyDelegate() {} | |
| 93 protected: | |
| 94 virtual void compare_expected(const base::Value* to_compare) { | |
| 95 // without this-> this won't build. | |
| 96 EXPECT_TRUE(this->expected_->Equals(to_compare)); | |
| 97 } | |
| 98 }; | |
| 99 | |
| 100 class ProtoDelegate : public DummyDelegate<const em::PolicyFetchResponse&> { | 83 class ProtoDelegate : public DummyDelegate<const em::PolicyFetchResponse&> { |
| 101 public: | 84 public: |
| 102 explicit ProtoDelegate(const em::PolicyFetchResponse& e) | 85 explicit ProtoDelegate(const em::PolicyFetchResponse& e) |
| 103 : DummyDelegate<const em::PolicyFetchResponse&>(e) { | 86 : DummyDelegate<const em::PolicyFetchResponse&>(e) { |
| 104 } | 87 } |
| 105 virtual ~ProtoDelegate() {} | 88 virtual ~ProtoDelegate() {} |
| 106 protected: | 89 protected: |
| 107 virtual void compare_expected(const em::PolicyFetchResponse& to_compare) { | 90 virtual void compare_expected(const em::PolicyFetchResponse& to_compare) { |
| 108 std::string ex_string, comp_string; | 91 std::string ex_string, comp_string; |
| 109 EXPECT_TRUE(expected_.SerializeToString(&ex_string)); | 92 EXPECT_TRUE(expected_.SerializeToString(&ex_string)); |
| 110 EXPECT_TRUE(to_compare.SerializeToString(&comp_string)); | 93 EXPECT_TRUE(to_compare.SerializeToString(&comp_string)); |
| 111 EXPECT_EQ(ex_string, comp_string); | 94 EXPECT_EQ(ex_string, comp_string); |
| 112 } | 95 } |
| 113 }; | 96 }; |
| 114 | 97 |
| 115 } // anonymous namespace | 98 } // anonymous namespace |
| 116 | 99 |
| 117 class SignedSettingsTest : public testing::Test { | 100 class SignedSettingsTest : public testing::Test { |
| 118 public: | 101 public: |
| 119 SignedSettingsTest() | 102 SignedSettingsTest() |
| 120 : fake_email_("fakey@example.com"), | 103 : fake_prop_(kAccountsPrefAllowGuest), |
| 121 fake_domain_("*@example.com"), | |
| 122 fake_prop_(kAccountsPrefAllowGuest), | |
| 123 fake_signature_("false"), | 104 fake_signature_("false"), |
| 124 fake_value_(false), | 105 fake_value_(false), |
| 125 fake_value_signature_( | 106 fake_value_signature_( |
| 126 fake_signature_.c_str(), | 107 fake_signature_.c_str(), |
| 127 fake_signature_.c_str() + fake_signature_.length()), | 108 fake_signature_.c_str() + fake_signature_.length()), |
| 128 message_loop_(MessageLoop::TYPE_UI), | 109 message_loop_(MessageLoop::TYPE_UI), |
| 129 ui_thread_(BrowserThread::UI, &message_loop_), | 110 ui_thread_(BrowserThread::UI, &message_loop_), |
| 130 file_thread_(BrowserThread::FILE), | 111 file_thread_(BrowserThread::FILE), |
| 131 mock_(new MockKeyUtils), | 112 mock_(new MockKeyUtils), |
| 132 injector_(mock_) /* injector_ takes ownership of mock_ */, | 113 injector_(mock_) /* injector_ takes ownership of mock_ */, |
| 133 mock_dbus_thread_manager_(new MockDBusThreadManager) { | 114 mock_dbus_thread_manager_(new MockDBusThreadManager) { |
| 134 } | 115 } |
| 135 | 116 |
| 136 virtual ~SignedSettingsTest() {} | 117 virtual ~SignedSettingsTest() {} |
| 137 | 118 |
| 138 virtual void SetUp() { | 119 virtual void SetUp() { |
| 139 file_thread_.Start(); | 120 file_thread_.Start(); |
| 140 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager_); | 121 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager_); |
| 141 } | 122 } |
| 142 | 123 |
| 143 virtual void TearDown() { | 124 virtual void TearDown() { |
| 144 OwnerKeyUtils::set_factory(NULL); | 125 OwnerKeyUtils::set_factory(NULL); |
| 145 DBusThreadManager::Shutdown(); | 126 DBusThreadManager::Shutdown(); |
| 146 } | 127 } |
| 147 | 128 |
| 148 void mock_service(SignedSettings* s, MockOwnershipService* m) { | 129 void mock_service(SignedSettings* s, MockOwnershipService* m) { |
| 149 s->set_service(m); | 130 s->set_service(m); |
| 150 } | 131 } |
| 151 | 132 |
| 152 em::PolicyData BuildPolicyData(std::vector<std::string> whitelist) { | |
| 153 em::PolicyData to_return; | |
| 154 em::ChromeDeviceSettingsProto pol; | |
| 155 em::GuestModeEnabledProto* allow = pol.mutable_guest_mode_enabled(); | |
| 156 allow->set_guest_mode_enabled(false); | |
| 157 pol.mutable_device_proxy_settings()->set_proxy_mode("direct"); | |
| 158 | |
| 159 if (!whitelist.empty()) { | |
| 160 em::UserWhitelistProto* whitelist_proto = pol.mutable_user_whitelist(); | |
| 161 for (std::vector<std::string>::const_iterator it = whitelist.begin(); | |
| 162 it != whitelist.end(); | |
| 163 ++it) { | |
| 164 whitelist_proto->add_user_whitelist(*it); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 to_return.set_policy_type(SignedSettings::kDevicePolicyType); | |
| 169 to_return.set_policy_value(pol.SerializeAsString()); | |
| 170 return to_return; | |
| 171 } | |
| 172 | |
| 173 void SetAllowNewUsers(bool desired, em::PolicyData* poldata) { | |
| 174 em::ChromeDeviceSettingsProto pol; | |
| 175 pol.ParseFromString(poldata->policy_value()); | |
| 176 em::AllowNewUsersProto* allow = pol.mutable_allow_new_users(); | |
| 177 allow->set_allow_new_users(desired); | |
| 178 poldata->set_policy_value(pol.SerializeAsString()); | |
| 179 } | |
| 180 | |
| 181 void FailingStorePropertyOp(const OwnerManager::KeyOpCode return_code) { | |
| 182 NormalDelegate<bool> d(false); | |
| 183 scoped_refptr<SignedSettings> s( | |
| 184 SignedSettings::CreateStorePropertyOp(fake_prop_, fake_value_, &d)); | |
| 185 d.expect_failure(SignedSettings::MapKeyOpCode(return_code)); | |
| 186 | |
| 187 mock_service(s.get(), &m_); | |
| 188 EXPECT_CALL(m_, StartSigningAttempt(_, _)) | |
| 189 .Times(1); | |
| 190 EXPECT_CALL(m_, GetStatus(_)) | |
| 191 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | |
| 192 EXPECT_CALL(m_, has_cached_policy()) | |
| 193 .WillOnce(Return(true)); | |
| 194 em::PolicyData fake_pol; | |
| 195 EXPECT_CALL(m_, cached_policy()) | |
| 196 .WillOnce(ReturnRef(fake_pol)); | |
| 197 | |
| 198 s->Execute(); | |
| 199 s->OnKeyOpComplete(return_code, std::vector<uint8>()); | |
| 200 message_loop_.RunAllPending(); | |
| 201 } | |
| 202 | |
| 203 void FailingStorePolicyOp(const OwnerManager::KeyOpCode return_code) { | 133 void FailingStorePolicyOp(const OwnerManager::KeyOpCode return_code) { |
| 204 NormalDelegate<bool> d(false); | 134 NormalDelegate<bool> d(false); |
| 205 d.expect_failure(SignedSettings::MapKeyOpCode(return_code)); | 135 d.expect_failure(SignedSettings::MapKeyOpCode(return_code)); |
| 206 | 136 |
| 207 em::PolicyFetchResponse fake_policy; | 137 em::PolicyFetchResponse fake_policy; |
| 208 fake_policy.set_policy_data(fake_prop_); | 138 fake_policy.set_policy_data(fake_prop_); |
| 209 std::string serialized; | 139 std::string serialized; |
| 210 ASSERT_TRUE(fake_policy.SerializeToString(&serialized)); | 140 ASSERT_TRUE(fake_policy.SerializeToString(&serialized)); |
| 211 | 141 |
| 212 scoped_refptr<SignedSettings> s( | 142 scoped_refptr<SignedSettings> s( |
| 213 SignedSettings::CreateStorePolicyOp(&fake_policy, &d)); | 143 SignedSettings::CreateStorePolicyOp(&fake_policy, &d)); |
| 214 | 144 |
| 215 mock_service(s.get(), &m_); | 145 mock_service(s.get(), &m_); |
| 216 EXPECT_CALL(m_, StartSigningAttempt(StrEq(fake_prop_), _)) | 146 EXPECT_CALL(m_, StartSigningAttempt(StrEq(fake_prop_), _)) |
| 217 .Times(1); | 147 .Times(1); |
| 218 | 148 |
| 219 s->Execute(); | 149 s->Execute(); |
| 220 s->OnKeyOpComplete(return_code, std::vector<uint8>()); | 150 s->OnKeyOpComplete(return_code, std::vector<uint8>()); |
| 221 message_loop_.RunAllPending(); | 151 message_loop_.RunAllPending(); |
| 222 } | 152 } |
| 223 | 153 |
| 154 em::PolicyData BuildPolicyData(std::vector<std::string> whitelist) { |
| 155 em::PolicyData to_return; |
| 156 em::ChromeDeviceSettingsProto pol; |
| 157 em::GuestModeEnabledProto* allow = pol.mutable_guest_mode_enabled(); |
| 158 allow->set_guest_mode_enabled(false); |
| 159 pol.mutable_device_proxy_settings()->set_proxy_mode("direct"); |
| 160 |
| 161 if (!whitelist.empty()) { |
| 162 em::UserWhitelistProto* whitelist_proto = pol.mutable_user_whitelist(); |
| 163 for (std::vector<std::string>::const_iterator it = whitelist.begin(); |
| 164 it != whitelist.end(); |
| 165 ++it) { |
| 166 whitelist_proto->add_user_whitelist(*it); |
| 167 } |
| 168 } |
| 169 |
| 170 to_return.set_policy_type(chromeos::kDevicePolicyType); |
| 171 to_return.set_policy_value(pol.SerializeAsString()); |
| 172 return to_return; |
| 173 } |
| 174 |
| 224 em::PolicyFetchResponse BuildProto(const std::string& data, | 175 em::PolicyFetchResponse BuildProto(const std::string& data, |
| 225 const std::string& sig, | 176 const std::string& sig, |
| 226 std::string* out_serialized) { | 177 std::string* out_serialized) { |
| 227 em::PolicyFetchResponse fake_policy; | 178 em::PolicyFetchResponse fake_policy; |
| 228 if (!data.empty()) | 179 if (!data.empty()) |
| 229 fake_policy.set_policy_data(data); | 180 fake_policy.set_policy_data(data); |
| 230 if (!sig.empty()) | 181 if (!sig.empty()) |
| 231 fake_policy.set_policy_data_signature(sig); | 182 fake_policy.set_policy_data_signature(sig); |
| 232 EXPECT_TRUE(fake_policy.SerializeToString(out_serialized)); | 183 EXPECT_TRUE(fake_policy.SerializeToString(out_serialized)); |
| 233 return fake_policy; | 184 return fake_policy; |
| 234 } | 185 } |
| 235 | 186 |
| 236 void DoRetrieveProperty(const std::string& name, | |
| 237 const base::Value* value, | |
| 238 em::PolicyData* fake_pol) { | |
| 239 PolicyDelegate d(value); | |
| 240 d.expect_success(); | |
| 241 scoped_refptr<SignedSettings> s( | |
| 242 SignedSettings::CreateRetrievePropertyOp(name, &d)); | |
| 243 mock_service(s.get(), &m_); | |
| 244 EXPECT_CALL(m_, GetStatus(_)) | |
| 245 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | |
| 246 EXPECT_CALL(m_, has_cached_policy()) | |
| 247 .WillOnce(Return(true)); | |
| 248 | |
| 249 EXPECT_CALL(m_, cached_policy()) | |
| 250 .WillOnce(ReturnRef(*fake_pol)); | |
| 251 | |
| 252 s->Execute(); | |
| 253 message_loop_.RunAllPending(); | |
| 254 } | |
| 255 | |
| 256 const std::string fake_email_; | |
| 257 const std::string fake_domain_; | |
| 258 const std::string fake_prop_; | 187 const std::string fake_prop_; |
| 259 const std::string fake_signature_; | 188 const std::string fake_signature_; |
| 260 const base::FundamentalValue fake_value_; | 189 const base::FundamentalValue fake_value_; |
| 261 const std::vector<uint8> fake_value_signature_; | 190 const std::vector<uint8> fake_value_signature_; |
| 262 MockOwnershipService m_; | 191 MockOwnershipService m_; |
| 263 | 192 |
| 264 ScopedTempDir tmpdir_; | |
| 265 FilePath tmpfile_; | |
| 266 | |
| 267 MessageLoop message_loop_; | 193 MessageLoop message_loop_; |
| 268 content::TestBrowserThread ui_thread_; | 194 content::TestBrowserThread ui_thread_; |
| 269 content::TestBrowserThread file_thread_; | 195 content::TestBrowserThread file_thread_; |
| 270 | 196 |
| 271 std::vector<uint8> fake_public_key_; | |
| 272 scoped_ptr<crypto::RSAPrivateKey> fake_private_key_; | |
| 273 | |
| 274 MockKeyUtils* mock_; | 197 MockKeyUtils* mock_; |
| 275 MockInjector injector_; | 198 MockInjector injector_; |
| 276 MockDBusThreadManager* mock_dbus_thread_manager_; | 199 MockDBusThreadManager* mock_dbus_thread_manager_; |
| 277 | 200 |
| 278 ScopedStubCrosEnabler stub_cros_enabler_; | 201 ScopedStubCrosEnabler stub_cros_enabler_; |
| 279 }; | 202 }; |
| 280 | 203 |
| 281 ACTION_P(Retrieve, policy_blob) { arg0.Run(policy_blob); } | 204 ACTION_P(Retrieve, policy_blob) { arg0.Run(policy_blob); } |
| 282 ACTION_P(Store, success) { arg1.Run(success); } | 205 ACTION_P(Store, success) { arg1.Run(success); } |
| 283 ACTION_P(FinishKeyOp, s) { arg2->OnKeyOpComplete(OwnerManager::SUCCESS, s); } | |
| 284 | |
| 285 TEST_F(SignedSettingsTest, StoreProperty) { | |
| 286 NormalDelegate<bool> d(true); | |
| 287 d.expect_success(); | |
| 288 scoped_refptr<SignedSettings> s( | |
| 289 SignedSettings::CreateStorePropertyOp(fake_prop_, fake_value_, &d)); | |
| 290 | |
| 291 mock_service(s.get(), &m_); | |
| 292 EXPECT_CALL(m_, StartSigningAttempt(_, _)) | |
| 293 .Times(1); | |
| 294 EXPECT_CALL(m_, GetStatus(_)) | |
| 295 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | |
| 296 EXPECT_CALL(m_, has_cached_policy()) | |
| 297 .WillOnce(Return(true)); | |
| 298 em::PolicyData in_pol = | |
| 299 BuildPolicyData(std::vector<std::string>(1, fake_email_)); | |
| 300 EXPECT_CALL(m_, cached_policy()) | |
| 301 .WillOnce(ReturnRef(in_pol)); | |
| 302 em::PolicyData out_pol; | |
| 303 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | |
| 304 .WillOnce(SaveArg<0>(&out_pol)); | |
| 305 | |
| 306 MockSessionManagerClient* client = | |
| 307 mock_dbus_thread_manager_->mock_session_manager_client(); | |
| 308 EXPECT_CALL(*client, StorePolicy(_, _)) | |
| 309 .WillOnce(Store(true)) | |
| 310 .RetiresOnSaturation(); | |
| 311 | |
| 312 s->Execute(); | |
| 313 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | |
| 314 message_loop_.RunAllPending(); | |
| 315 | |
| 316 ASSERT_TRUE(out_pol.has_policy_value()); | |
| 317 em::ChromeDeviceSettingsProto pol; | |
| 318 pol.ParseFromString(out_pol.policy_value()); | |
| 319 ASSERT_TRUE(pol.has_guest_mode_enabled()); | |
| 320 ASSERT_TRUE(pol.guest_mode_enabled().has_guest_mode_enabled()); | |
| 321 ASSERT_FALSE(pol.guest_mode_enabled().guest_mode_enabled()); | |
| 322 } | |
| 323 | |
| 324 TEST_F(SignedSettingsTest, StorePropertyNoKey) { | |
| 325 FailingStorePropertyOp(OwnerManager::KEY_UNAVAILABLE); | |
| 326 } | |
| 327 | |
| 328 TEST_F(SignedSettingsTest, StorePropertyFailed) { | |
| 329 FailingStorePropertyOp(OwnerManager::OPERATION_FAILED); | |
| 330 } | |
| 331 | |
| 332 TEST_F(SignedSettingsTest, RetrieveProperty) { | |
| 333 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | |
| 334 base::FundamentalValue fake_value(false); | |
| 335 DoRetrieveProperty(fake_prop_, &fake_value, &fake_pol); | |
| 336 } | |
| 337 | |
| 338 TEST_F(SignedSettingsTest, RetrieveOwnerProperty) { | |
| 339 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | |
| 340 fake_pol.set_username(fake_email_); | |
| 341 base::StringValue fake_value(fake_email_); | |
| 342 DoRetrieveProperty(kDeviceOwner, &fake_value, &fake_pol); | |
| 343 } | |
| 344 | |
| 345 TEST_F(SignedSettingsTest, ExplicitlyAllowNewUsers) { | |
| 346 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | |
| 347 SetAllowNewUsers(true, &fake_pol); | |
| 348 base::FundamentalValue fake_value(true); | |
| 349 DoRetrieveProperty(kAccountsPrefAllowNewUser, &fake_value, &fake_pol); | |
| 350 } | |
| 351 | |
| 352 TEST_F(SignedSettingsTest, ExplicitlyDisallowNewUsers) { | |
| 353 std::vector<std::string> whitelist(1, fake_email_ + "m"); | |
| 354 em::PolicyData fake_pol = BuildPolicyData(whitelist); | |
| 355 SetAllowNewUsers(false, &fake_pol); | |
| 356 base::FundamentalValue fake_value(false); | |
| 357 DoRetrieveProperty(kAccountsPrefAllowNewUser, &fake_value, &fake_pol); | |
| 358 } | |
| 359 | |
| 360 TEST_F(SignedSettingsTest, ImplicitlyDisallowNewUsers) { | |
| 361 std::vector<std::string> whitelist(1, fake_email_ + "m"); | |
| 362 em::PolicyData fake_pol = BuildPolicyData(whitelist); | |
| 363 base::FundamentalValue fake_value(false); | |
| 364 DoRetrieveProperty(kAccountsPrefAllowNewUser, &fake_value, &fake_pol); | |
| 365 } | |
| 366 | |
| 367 TEST_F(SignedSettingsTest, AccidentallyDisallowNewUsers) { | |
| 368 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | |
| 369 SetAllowNewUsers(false, &fake_pol); | |
| 370 base::FundamentalValue fake_value(true); | |
| 371 DoRetrieveProperty(kAccountsPrefAllowNewUser, &fake_value, &fake_pol); | |
| 372 } | |
| 373 | |
| 374 TEST_F(SignedSettingsTest, RetrievePropertyNotFound) { | |
| 375 PolicyDelegate d(&fake_value_); | |
| 376 d.expect_failure(SignedSettings::NOT_FOUND); | |
| 377 scoped_refptr<SignedSettings> s( | |
| 378 SignedSettings::CreateRetrievePropertyOp("unknown_prop", &d)); | |
| 379 mock_service(s.get(), &m_); | |
| 380 EXPECT_CALL(m_, GetStatus(_)) | |
| 381 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | |
| 382 EXPECT_CALL(m_, has_cached_policy()) | |
| 383 .WillOnce(Return(true)); | |
| 384 | |
| 385 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | |
| 386 EXPECT_CALL(m_, cached_policy()) | |
| 387 .WillOnce(ReturnRef(fake_pol)); | |
| 388 | |
| 389 s->Execute(); | |
| 390 message_loop_.RunAllPending(); | |
| 391 } | |
| 392 | |
| 393 TEST_F(SignedSettingsTest, RetrievePolicyToRetrieveProperty) { | |
| 394 base::FundamentalValue fake_value(false); | |
| 395 PolicyDelegate d(&fake_value); | |
| 396 d.expect_success(); | |
| 397 scoped_refptr<SignedSettings> s( | |
| 398 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); | |
| 399 | |
| 400 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | |
| 401 std::string data = fake_pol.SerializeAsString(); | |
| 402 std::string signed_serialized; | |
| 403 em::PolicyFetchResponse signed_policy = BuildProto(data, | |
| 404 fake_signature_, | |
| 405 &signed_serialized); | |
| 406 MockSessionManagerClient* client = | |
| 407 mock_dbus_thread_manager_->mock_session_manager_client(); | |
| 408 EXPECT_CALL(*client, RetrievePolicy(_)) | |
| 409 .WillOnce(Retrieve(signed_serialized)) | |
| 410 .RetiresOnSaturation(); | |
| 411 | |
| 412 mock_service(s.get(), &m_); | |
| 413 | |
| 414 EXPECT_CALL(m_, GetStatus(_)) | |
| 415 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)) | |
| 416 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | |
| 417 EXPECT_CALL(m_, has_cached_policy()) | |
| 418 .WillOnce(Return(false)) | |
| 419 .WillOnce(Return(true)); | |
| 420 em::PolicyData out_pol; | |
| 421 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | |
| 422 .WillOnce(SaveArg<0>(&out_pol)); | |
| 423 EXPECT_CALL(m_, cached_policy()) | |
| 424 .WillOnce(ReturnRef(out_pol)); | |
| 425 | |
| 426 EXPECT_CALL(m_, StartVerifyAttempt(data, fake_value_signature_, _)) | |
| 427 .WillOnce(FinishKeyOp(fake_value_signature_)) | |
| 428 .RetiresOnSaturation(); | |
| 429 | |
| 430 s->Execute(); | |
| 431 message_loop_.RunAllPending(); | |
| 432 } | |
| 433 | 206 |
| 434 TEST_F(SignedSettingsTest, SignAndStorePolicy) { | 207 TEST_F(SignedSettingsTest, SignAndStorePolicy) { |
| 435 NormalDelegate<bool> d(true); | 208 NormalDelegate<bool> d(true); |
| 436 d.expect_success(); | 209 d.expect_success(); |
| 437 | 210 |
| 438 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 211 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
| 439 std::string data_serialized = in_pol.SerializeAsString(); | 212 std::string data_serialized = in_pol.SerializeAsString(); |
| 440 std::string serialized; | 213 std::string serialized; |
| 441 em::PolicyFetchResponse fake_policy = BuildProto(data_serialized, | 214 em::PolicyFetchResponse fake_policy = BuildProto(data_serialized, |
| 442 std::string(), | 215 std::string(), |
| 443 &serialized); | 216 &serialized); |
| 444 scoped_refptr<SignedSettings> s( | 217 scoped_refptr<SignedSettings> s( |
| 445 SignedSettings::CreateStorePolicyOp(&fake_policy, &d)); | 218 SignedSettings::CreateStorePolicyOp(&fake_policy, &d)); |
| 446 | 219 |
| 447 mock_service(s.get(), &m_); | 220 mock_service(s.get(), &m_); |
| 448 EXPECT_CALL(m_, StartSigningAttempt(StrEq(data_serialized), _)) | 221 EXPECT_CALL(m_, StartSigningAttempt(StrEq(data_serialized), _)) |
| 449 .Times(1); | 222 .Times(1); |
| 450 em::PolicyData out_pol; | 223 em::PolicyData out_pol; |
| 451 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | |
| 452 .WillOnce(SaveArg<0>(&out_pol)); | |
| 453 | 224 |
| 454 // Ask for signature over unsigned policy. | 225 // Ask for signature over unsigned policy. |
| 455 s->Execute(); | 226 s->Execute(); |
| 456 message_loop_.RunAllPending(); | 227 message_loop_.RunAllPending(); |
| 457 | 228 |
| 458 // Fake out a successful signing. | 229 // Fake out a successful signing. |
| 459 std::string signed_serialized; | 230 std::string signed_serialized; |
| 460 em::PolicyFetchResponse signed_policy = BuildProto(data_serialized, | 231 em::PolicyFetchResponse signed_policy = BuildProto(data_serialized, |
| 461 fake_signature_, | 232 fake_signature_, |
| 462 &signed_serialized); | 233 &signed_serialized); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 482 scoped_refptr<SignedSettings> s( | 253 scoped_refptr<SignedSettings> s( |
| 483 SignedSettings::CreateStorePolicyOp(&signed_policy, &d)); | 254 SignedSettings::CreateStorePolicyOp(&signed_policy, &d)); |
| 484 MockSessionManagerClient* client = | 255 MockSessionManagerClient* client = |
| 485 mock_dbus_thread_manager_->mock_session_manager_client(); | 256 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 486 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) | 257 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) |
| 487 .WillOnce(Store(true)) | 258 .WillOnce(Store(true)) |
| 488 .RetiresOnSaturation(); | 259 .RetiresOnSaturation(); |
| 489 | 260 |
| 490 mock_service(s.get(), &m_); | 261 mock_service(s.get(), &m_); |
| 491 em::PolicyData out_pol; | 262 em::PolicyData out_pol; |
| 492 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | |
| 493 .WillOnce(SaveArg<0>(&out_pol)); | |
| 494 | 263 |
| 495 s->Execute(); | 264 s->Execute(); |
| 496 message_loop_.RunAllPending(); | 265 message_loop_.RunAllPending(); |
| 497 } | 266 } |
| 498 | 267 |
| 499 TEST_F(SignedSettingsTest, StorePolicyNoKey) { | 268 TEST_F(SignedSettingsTest, StorePolicyNoKey) { |
| 500 FailingStorePolicyOp(OwnerManager::KEY_UNAVAILABLE); | 269 FailingStorePolicyOp(OwnerManager::KEY_UNAVAILABLE); |
| 501 } | 270 } |
| 502 | 271 |
| 503 TEST_F(SignedSettingsTest, StorePolicyFailed) { | 272 TEST_F(SignedSettingsTest, StorePolicyFailed) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 533 MockSessionManagerClient* client = | 302 MockSessionManagerClient* client = |
| 534 mock_dbus_thread_manager_->mock_session_manager_client(); | 303 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 535 EXPECT_CALL(*client, RetrievePolicy(_)) | 304 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 536 .WillOnce(Retrieve(signed_serialized)) | 305 .WillOnce(Retrieve(signed_serialized)) |
| 537 .RetiresOnSaturation(); | 306 .RetiresOnSaturation(); |
| 538 | 307 |
| 539 mock_service(s.get(), &m_); | 308 mock_service(s.get(), &m_); |
| 540 EXPECT_CALL(m_, StartVerifyAttempt(serialized, fake_value_signature_, _)) | 309 EXPECT_CALL(m_, StartVerifyAttempt(serialized, fake_value_signature_, _)) |
| 541 .Times(1); | 310 .Times(1); |
| 542 em::PolicyData out_pol; | 311 em::PolicyData out_pol; |
| 543 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | |
| 544 .WillOnce(SaveArg<0>(&out_pol)); | |
| 545 | 312 |
| 546 s->Execute(); | 313 s->Execute(); |
| 547 message_loop_.RunAllPending(); | 314 message_loop_.RunAllPending(); |
| 548 | 315 |
| 549 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | 316 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); |
| 550 message_loop_.RunAllPending(); | 317 message_loop_.RunAllPending(); |
| 551 } | 318 } |
| 552 | 319 |
| 553 TEST_F(SignedSettingsTest, RetrieveNullPolicy) { | 320 TEST_F(SignedSettingsTest, RetrieveNullPolicy) { |
| 554 em::PolicyFetchResponse policy; | 321 em::PolicyFetchResponse policy; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 .Times(1); | 389 .Times(1); |
| 623 | 390 |
| 624 s->Execute(); | 391 s->Execute(); |
| 625 message_loop_.RunAllPending(); | 392 message_loop_.RunAllPending(); |
| 626 | 393 |
| 627 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); | 394 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); |
| 628 message_loop_.RunAllPending(); | 395 message_loop_.RunAllPending(); |
| 629 } | 396 } |
| 630 | 397 |
| 631 } // namespace chromeos | 398 } // namespace chromeos |
| OLD | NEW |