| 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" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 12 #include "chrome/browser/chromeos/cros/mock_library_loader.h" | 12 #include "chrome/browser/chromeos/cros/mock_library_loader.h" |
| 13 #include "chrome/browser/chromeos/cros_settings_names.h" | 13 #include "chrome/browser/chromeos/cros_settings_names.h" |
| 14 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" | 14 #include "chrome/browser/chromeos/dbus/mock_dbus_thread_manager.h" |
| 15 #include "chrome/browser/chromeos/dbus/mock_session_manager_client.h" | 15 #include "chrome/browser/chromeos/dbus/mock_session_manager_client.h" |
| 16 #include "chrome/browser/chromeos/login/mock_owner_key_utils.h" | 16 #include "chrome/browser/chromeos/login/mock_owner_key_utils.h" |
| 17 #include "chrome/browser/chromeos/login/mock_ownership_service.h" | 17 #include "chrome/browser/chromeos/login/mock_ownership_service.h" |
| 18 #include "chrome/browser/chromeos/login/owner_manager_unittest.h" | 18 #include "chrome/browser/chromeos/login/owner_manager_unittest.h" |
| 19 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" | 19 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" |
| 20 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 20 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
| 21 #include "content/test/test_browser_thread.h" | 21 #include "content/test/test_browser_thread.h" |
| 22 #include "crypto/rsa_private_key.h" | 22 #include "crypto/rsa_private_key.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 public: | 102 public: |
| 103 SignedSettingsTest() | 103 SignedSettingsTest() |
| 104 : fake_email_("fakey@example.com"), | 104 : fake_email_("fakey@example.com"), |
| 105 fake_domain_("*@example.com"), | 105 fake_domain_("*@example.com"), |
| 106 fake_prop_(kAccountsPrefAllowGuest), | 106 fake_prop_(kAccountsPrefAllowGuest), |
| 107 fake_value_("false"), | 107 fake_value_("false"), |
| 108 message_loop_(MessageLoop::TYPE_UI), | 108 message_loop_(MessageLoop::TYPE_UI), |
| 109 ui_thread_(BrowserThread::UI, &message_loop_), | 109 ui_thread_(BrowserThread::UI, &message_loop_), |
| 110 file_thread_(BrowserThread::FILE), | 110 file_thread_(BrowserThread::FILE), |
| 111 mock_(new MockKeyUtils), | 111 mock_(new MockKeyUtils), |
| 112 injector_(mock_) /* injector_ takes ownership of mock_ */ { | 112 injector_(mock_) /* injector_ takes ownership of mock_ */, |
| 113 mock_dbus_thread_manager_(new MockDBusThreadManager) { |
| 113 } | 114 } |
| 114 | 115 |
| 115 virtual ~SignedSettingsTest() {} | 116 virtual ~SignedSettingsTest() {} |
| 116 | 117 |
| 117 virtual void SetUp() { | 118 virtual void SetUp() { |
| 118 file_thread_.Start(); | 119 file_thread_.Start(); |
| 119 DBusThreadManager::Initialize(); | 120 DBusThreadManager::InitializeForTesting(mock_dbus_thread_manager_); |
| 120 } | 121 } |
| 121 | 122 |
| 122 virtual void TearDown() { | 123 virtual void TearDown() { |
| 123 OwnerKeyUtils::set_factory(NULL); | 124 OwnerKeyUtils::set_factory(NULL); |
| 124 DBusThreadManager::Shutdown(); | 125 DBusThreadManager::Shutdown(); |
| 125 } | 126 } |
| 126 | 127 |
| 127 void mock_service(SignedSettings* s, MockOwnershipService* m) { | 128 void mock_service(SignedSettings* s, MockOwnershipService* m) { |
| 128 s->set_service(m); | 129 s->set_service(m); |
| 129 } | 130 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 277 |
| 277 MessageLoop message_loop_; | 278 MessageLoop message_loop_; |
| 278 content::TestBrowserThread ui_thread_; | 279 content::TestBrowserThread ui_thread_; |
| 279 content::TestBrowserThread file_thread_; | 280 content::TestBrowserThread file_thread_; |
| 280 | 281 |
| 281 std::vector<uint8> fake_public_key_; | 282 std::vector<uint8> fake_public_key_; |
| 282 scoped_ptr<crypto::RSAPrivateKey> fake_private_key_; | 283 scoped_ptr<crypto::RSAPrivateKey> fake_private_key_; |
| 283 | 284 |
| 284 MockKeyUtils* mock_; | 285 MockKeyUtils* mock_; |
| 285 MockInjector injector_; | 286 MockInjector injector_; |
| 287 MockDBusThreadManager* mock_dbus_thread_manager_; |
| 286 | 288 |
| 287 ScopedStubCrosEnabler stub_cros_enabler_; | 289 ScopedStubCrosEnabler stub_cros_enabler_; |
| 288 }; | 290 }; |
| 289 | 291 |
| 292 ACTION_P(Retrieve, policy_blob) { arg0.Run(policy_blob); } |
| 293 ACTION_P(Store, success) { arg1.Run(success); } |
| 294 ACTION_P(FinishKeyOp, s) { arg2->OnKeyOpComplete(OwnerManager::SUCCESS, s); } |
| 295 |
| 290 TEST_F(SignedSettingsTest, CheckWhitelist) { | 296 TEST_F(SignedSettingsTest, CheckWhitelist) { |
| 291 NormalDelegate<bool> d(true); | 297 NormalDelegate<bool> d(true); |
| 292 d.expect_success(); | 298 d.expect_success(); |
| 293 scoped_refptr<SignedSettings> s( | 299 scoped_refptr<SignedSettings> s( |
| 294 SignedSettings::CreateCheckWhitelistOp(fake_email_, &d)); | 300 SignedSettings::CreateCheckWhitelistOp(fake_email_, &d)); |
| 295 | 301 |
| 296 mock_service(s.get(), &m_); | 302 mock_service(s.get(), &m_); |
| 297 EXPECT_CALL(m_, has_cached_policy()) | 303 EXPECT_CALL(m_, has_cached_policy()) |
| 298 .WillOnce(Return(true)); | 304 .WillOnce(Return(true)); |
| 299 | 305 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 356 |
| 351 TEST_F(SignedSettingsTest, Whitelist) { | 357 TEST_F(SignedSettingsTest, Whitelist) { |
| 352 NormalDelegate<bool> d(true); | 358 NormalDelegate<bool> d(true); |
| 353 d.expect_success(); | 359 d.expect_success(); |
| 354 scoped_refptr<SignedSettings> s( | 360 scoped_refptr<SignedSettings> s( |
| 355 SignedSettings::CreateWhitelistOp(fake_email_, true, &d)); | 361 SignedSettings::CreateWhitelistOp(fake_email_, true, &d)); |
| 356 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 362 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
| 357 em::PolicyData out_pol; | 363 em::PolicyData out_pol; |
| 358 ExpectWhitelistOp(s.get(), &in_pol, &out_pol); | 364 ExpectWhitelistOp(s.get(), &in_pol, &out_pol); |
| 359 | 365 |
| 366 MockSessionManagerClient* client = |
| 367 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 368 EXPECT_CALL(*client, StorePolicy(_, _)) |
| 369 .WillOnce(Store(true)) |
| 370 .RetiresOnSaturation(); |
| 371 |
| 360 s->Execute(); | 372 s->Execute(); |
| 361 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | 373 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); |
| 362 message_loop_.RunAllPending(); | 374 message_loop_.RunAllPending(); |
| 363 | 375 |
| 364 ASSERT_TRUE(CheckWhitelist(fake_email_, out_pol)); | 376 ASSERT_TRUE(CheckWhitelist(fake_email_, out_pol)); |
| 365 } | 377 } |
| 366 | 378 |
| 367 TEST_F(SignedSettingsTest, AddToExistingWhitelist) { | 379 TEST_F(SignedSettingsTest, AddToExistingWhitelist) { |
| 368 NormalDelegate<bool> d(true); | 380 NormalDelegate<bool> d(true); |
| 369 d.expect_success(); | 381 d.expect_success(); |
| 370 scoped_refptr<SignedSettings> s( | 382 scoped_refptr<SignedSettings> s( |
| 371 SignedSettings::CreateWhitelistOp(fake_email_, true, &d)); | 383 SignedSettings::CreateWhitelistOp(fake_email_, true, &d)); |
| 372 em::PolicyData in_pol = | 384 em::PolicyData in_pol = |
| 373 BuildPolicyData(std::vector<std::string>(1, fake_domain_)); | 385 BuildPolicyData(std::vector<std::string>(1, fake_domain_)); |
| 374 em::PolicyData out_pol; | 386 em::PolicyData out_pol; |
| 375 ExpectWhitelistOp(s.get(), &in_pol, &out_pol); | 387 ExpectWhitelistOp(s.get(), &in_pol, &out_pol); |
| 376 | 388 |
| 389 MockSessionManagerClient* client = |
| 390 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 391 EXPECT_CALL(*client, StorePolicy(_, _)) |
| 392 .WillOnce(Store(true)) |
| 393 .RetiresOnSaturation(); |
| 394 |
| 377 s->Execute(); | 395 s->Execute(); |
| 378 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | 396 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); |
| 379 message_loop_.RunAllPending(); | 397 message_loop_.RunAllPending(); |
| 380 | 398 |
| 381 ASSERT_TRUE(CheckWhitelist(fake_email_, out_pol)); | 399 ASSERT_TRUE(CheckWhitelist(fake_email_, out_pol)); |
| 382 } | 400 } |
| 383 | 401 |
| 384 TEST_F(SignedSettingsTest, Unwhitelist) { | 402 TEST_F(SignedSettingsTest, Unwhitelist) { |
| 385 NormalDelegate<bool> d(true); | 403 NormalDelegate<bool> d(true); |
| 386 d.expect_success(); | 404 d.expect_success(); |
| 387 scoped_refptr<SignedSettings> s( | 405 scoped_refptr<SignedSettings> s( |
| 388 SignedSettings::CreateWhitelistOp(fake_email_, false, &d)); | 406 SignedSettings::CreateWhitelistOp(fake_email_, false, &d)); |
| 389 em::PolicyData in_pol = | 407 em::PolicyData in_pol = |
| 390 BuildPolicyData(std::vector<std::string>(1, fake_email_)); | 408 BuildPolicyData(std::vector<std::string>(1, fake_email_)); |
| 391 em::PolicyData out_pol; | 409 em::PolicyData out_pol; |
| 392 ExpectWhitelistOp(s.get(), &in_pol, &out_pol); | 410 ExpectWhitelistOp(s.get(), &in_pol, &out_pol); |
| 393 | 411 |
| 412 MockSessionManagerClient* client = |
| 413 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 414 EXPECT_CALL(*client, StorePolicy(_, _)) |
| 415 .WillOnce(Store(true)) |
| 416 .RetiresOnSaturation(); |
| 417 |
| 394 s->Execute(); | 418 s->Execute(); |
| 395 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | 419 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); |
| 396 message_loop_.RunAllPending(); | 420 message_loop_.RunAllPending(); |
| 397 | 421 |
| 398 ASSERT_FALSE(CheckWhitelist(fake_email_, out_pol)); | 422 ASSERT_FALSE(CheckWhitelist(fake_email_, out_pol)); |
| 399 } | 423 } |
| 400 | 424 |
| 401 TEST_F(SignedSettingsTest, RemoveFromExistingWhitelist) { | 425 TEST_F(SignedSettingsTest, RemoveFromExistingWhitelist) { |
| 402 NormalDelegate<bool> d(true); | 426 NormalDelegate<bool> d(true); |
| 403 d.expect_success(); | 427 d.expect_success(); |
| 404 scoped_refptr<SignedSettings> s( | 428 scoped_refptr<SignedSettings> s( |
| 405 SignedSettings::CreateWhitelistOp(fake_email_, false, &d)); | 429 SignedSettings::CreateWhitelistOp(fake_email_, false, &d)); |
| 406 std::vector<std::string> whitelist(1, fake_domain_); | 430 std::vector<std::string> whitelist(1, fake_domain_); |
| 407 whitelist.push_back(fake_email_); | 431 whitelist.push_back(fake_email_); |
| 408 whitelist.push_back(fake_email_ + "m"); | 432 whitelist.push_back(fake_email_ + "m"); |
| 409 em::PolicyData in_pol = BuildPolicyData(whitelist); | 433 em::PolicyData in_pol = BuildPolicyData(whitelist); |
| 410 em::PolicyData out_pol; | 434 em::PolicyData out_pol; |
| 411 ExpectWhitelistOp(s.get(), &in_pol, &out_pol); | 435 ExpectWhitelistOp(s.get(), &in_pol, &out_pol); |
| 412 | 436 |
| 437 MockSessionManagerClient* client = |
| 438 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 439 EXPECT_CALL(*client, StorePolicy(_, _)) |
| 440 .WillOnce(Store(true)) |
| 441 .RetiresOnSaturation(); |
| 442 |
| 413 s->Execute(); | 443 s->Execute(); |
| 414 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | 444 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); |
| 415 message_loop_.RunAllPending(); | 445 message_loop_.RunAllPending(); |
| 416 | 446 |
| 417 ASSERT_FALSE(CheckWhitelist(fake_email_, out_pol)); | 447 ASSERT_FALSE(CheckWhitelist(fake_email_, out_pol)); |
| 418 } | 448 } |
| 419 | 449 |
| 420 TEST_F(SignedSettingsTest, StoreProperty) { | 450 TEST_F(SignedSettingsTest, StoreProperty) { |
| 421 NormalDelegate<bool> d(true); | 451 NormalDelegate<bool> d(true); |
| 422 d.expect_success(); | 452 d.expect_success(); |
| 423 scoped_refptr<SignedSettings> s( | 453 scoped_refptr<SignedSettings> s( |
| 424 SignedSettings::CreateStorePropertyOp(fake_prop_, fake_value_, &d)); | 454 SignedSettings::CreateStorePropertyOp(fake_prop_, fake_value_, &d)); |
| 425 | 455 |
| 426 mock_service(s.get(), &m_); | 456 mock_service(s.get(), &m_); |
| 427 EXPECT_CALL(m_, StartSigningAttempt(_, _)) | 457 EXPECT_CALL(m_, StartSigningAttempt(_, _)) |
| 428 .Times(1); | 458 .Times(1); |
| 429 EXPECT_CALL(m_, GetStatus(_)) | 459 EXPECT_CALL(m_, GetStatus(_)) |
| 430 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 460 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); |
| 431 EXPECT_CALL(m_, has_cached_policy()) | 461 EXPECT_CALL(m_, has_cached_policy()) |
| 432 .WillOnce(Return(true)); | 462 .WillOnce(Return(true)); |
| 433 em::PolicyData in_pol = | 463 em::PolicyData in_pol = |
| 434 BuildPolicyData(std::vector<std::string>(1, fake_email_)); | 464 BuildPolicyData(std::vector<std::string>(1, fake_email_)); |
| 435 EXPECT_CALL(m_, cached_policy()) | 465 EXPECT_CALL(m_, cached_policy()) |
| 436 .WillOnce(ReturnRef(in_pol)); | 466 .WillOnce(ReturnRef(in_pol)); |
| 437 em::PolicyData out_pol; | 467 em::PolicyData out_pol; |
| 438 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 468 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
| 439 .WillOnce(SaveArg<0>(&out_pol)); | 469 .WillOnce(SaveArg<0>(&out_pol)); |
| 440 | 470 |
| 471 MockSessionManagerClient* client = |
| 472 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 473 EXPECT_CALL(*client, StorePolicy(_, _)) |
| 474 .WillOnce(Store(true)) |
| 475 .RetiresOnSaturation(); |
| 476 |
| 441 s->Execute(); | 477 s->Execute(); |
| 442 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | 478 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); |
| 443 message_loop_.RunAllPending(); | 479 message_loop_.RunAllPending(); |
| 444 | 480 |
| 445 ASSERT_TRUE(out_pol.has_policy_value()); | 481 ASSERT_TRUE(out_pol.has_policy_value()); |
| 446 em::ChromeDeviceSettingsProto pol; | 482 em::ChromeDeviceSettingsProto pol; |
| 447 pol.ParseFromString(out_pol.policy_value()); | 483 pol.ParseFromString(out_pol.policy_value()); |
| 448 ASSERT_TRUE(pol.has_guest_mode_enabled()); | 484 ASSERT_TRUE(pol.has_guest_mode_enabled()); |
| 449 ASSERT_TRUE(pol.guest_mode_enabled().has_guest_mode_enabled()); | 485 ASSERT_TRUE(pol.guest_mode_enabled().has_guest_mode_enabled()); |
| 450 ASSERT_FALSE(pol.guest_mode_enabled().guest_mode_enabled()); | 486 ASSERT_FALSE(pol.guest_mode_enabled().guest_mode_enabled()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 .WillOnce(Return(true)); | 542 .WillOnce(Return(true)); |
| 507 | 543 |
| 508 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 544 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 509 EXPECT_CALL(m_, cached_policy()) | 545 EXPECT_CALL(m_, cached_policy()) |
| 510 .WillOnce(ReturnRef(fake_pol)); | 546 .WillOnce(ReturnRef(fake_pol)); |
| 511 | 547 |
| 512 s->Execute(); | 548 s->Execute(); |
| 513 message_loop_.RunAllPending(); | 549 message_loop_.RunAllPending(); |
| 514 } | 550 } |
| 515 | 551 |
| 516 ACTION_P(Retrieve, policy_blob) { arg0.Run(policy_blob); } | |
| 517 ACTION_P(Store, success) { arg1.Run(success); } | |
| 518 ACTION_P(FinishKeyOp, s) { arg2->OnKeyOpComplete(OwnerManager::SUCCESS, s); } | |
| 519 | |
| 520 TEST_F(SignedSettingsTest, RetrievePolicyToRetrieveProperty) { | 552 TEST_F(SignedSettingsTest, RetrievePolicyToRetrieveProperty) { |
| 521 NormalDelegate<std::string> d(fake_value_); | 553 NormalDelegate<std::string> d(fake_value_); |
| 522 d.expect_success(); | 554 d.expect_success(); |
| 523 scoped_refptr<SignedSettings> s( | 555 scoped_refptr<SignedSettings> s( |
| 524 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); | 556 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); |
| 525 | 557 |
| 526 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 558 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 527 std::string data = fake_pol.SerializeAsString(); | 559 std::string data = fake_pol.SerializeAsString(); |
| 528 std::string signed_serialized; | 560 std::string signed_serialized; |
| 529 em::PolicyFetchResponse signed_policy = BuildProto(data, | 561 em::PolicyFetchResponse signed_policy = BuildProto(data, |
| 530 fake_value_, | 562 fake_value_, |
| 531 &signed_serialized); | 563 &signed_serialized); |
| 532 MockSessionManagerClient* client = new MockSessionManagerClient; | 564 MockSessionManagerClient* client = |
| 533 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 565 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 534 EXPECT_CALL(*client, RetrievePolicy(_)) | 566 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 535 .WillOnce(Retrieve(signed_serialized)) | 567 .WillOnce(Retrieve(signed_serialized)) |
| 536 .RetiresOnSaturation(); | 568 .RetiresOnSaturation(); |
| 537 | 569 |
| 538 mock_service(s.get(), &m_); | 570 mock_service(s.get(), &m_); |
| 539 | 571 |
| 540 EXPECT_CALL(m_, GetStatus(_)) | 572 EXPECT_CALL(m_, GetStatus(_)) |
| 541 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)) | 573 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)) |
| 542 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 574 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); |
| 543 EXPECT_CALL(m_, has_cached_policy()) | 575 EXPECT_CALL(m_, has_cached_policy()) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 message_loop_.RunAllPending(); | 616 message_loop_.RunAllPending(); |
| 585 | 617 |
| 586 // Fake out a successful signing. | 618 // Fake out a successful signing. |
| 587 std::string signed_serialized; | 619 std::string signed_serialized; |
| 588 em::PolicyFetchResponse signed_policy = BuildProto(data_serialized, | 620 em::PolicyFetchResponse signed_policy = BuildProto(data_serialized, |
| 589 fake_value_, | 621 fake_value_, |
| 590 &signed_serialized); | 622 &signed_serialized); |
| 591 std::vector<uint8> fake_sig(fake_value_.c_str(), | 623 std::vector<uint8> fake_sig(fake_value_.c_str(), |
| 592 fake_value_.c_str() + fake_value_.length()); | 624 fake_value_.c_str() + fake_value_.length()); |
| 593 | 625 |
| 594 MockSessionManagerClient* client = new MockSessionManagerClient;; | 626 MockSessionManagerClient* client = |
| 595 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 627 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 596 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) | 628 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) |
| 597 .WillOnce(Store(true)) | 629 .WillOnce(Store(true)) |
| 598 .RetiresOnSaturation(); | 630 .RetiresOnSaturation(); |
| 599 s->OnKeyOpComplete(OwnerManager::SUCCESS, fake_sig); | 631 s->OnKeyOpComplete(OwnerManager::SUCCESS, fake_sig); |
| 600 message_loop_.RunAllPending(); | 632 message_loop_.RunAllPending(); |
| 601 } | 633 } |
| 602 | 634 |
| 603 TEST_F(SignedSettingsTest, StoreSignedPolicy) { | 635 TEST_F(SignedSettingsTest, StoreSignedPolicy) { |
| 604 NormalDelegate<bool> d(true); | 636 NormalDelegate<bool> d(true); |
| 605 d.expect_success(); | 637 d.expect_success(); |
| 606 | 638 |
| 607 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 639 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
| 608 std::string serialized = in_pol.SerializeAsString(); | 640 std::string serialized = in_pol.SerializeAsString(); |
| 609 std::string signed_serialized; | 641 std::string signed_serialized; |
| 610 em::PolicyFetchResponse signed_policy = BuildProto(serialized, | 642 em::PolicyFetchResponse signed_policy = BuildProto(serialized, |
| 611 fake_value_, | 643 fake_value_, |
| 612 &signed_serialized); | 644 &signed_serialized); |
| 613 scoped_refptr<SignedSettings> s( | 645 scoped_refptr<SignedSettings> s( |
| 614 SignedSettings::CreateStorePolicyOp(&signed_policy, &d)); | 646 SignedSettings::CreateStorePolicyOp(&signed_policy, &d)); |
| 615 MockSessionManagerClient* client = new MockSessionManagerClient;; | 647 MockSessionManagerClient* client = |
| 616 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 648 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 617 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) | 649 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) |
| 618 .WillOnce(Store(true)) | 650 .WillOnce(Store(true)) |
| 619 .RetiresOnSaturation(); | 651 .RetiresOnSaturation(); |
| 620 | 652 |
| 621 mock_service(s.get(), &m_); | 653 mock_service(s.get(), &m_); |
| 622 em::PolicyData out_pol; | 654 em::PolicyData out_pol; |
| 623 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 655 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
| 624 .WillOnce(SaveArg<0>(&out_pol)); | 656 .WillOnce(SaveArg<0>(&out_pol)); |
| 625 | 657 |
| 626 s->Execute(); | 658 s->Execute(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 654 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 686 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
| 655 std::string serialized = in_pol.SerializeAsString(); | 687 std::string serialized = in_pol.SerializeAsString(); |
| 656 std::string signed_serialized; | 688 std::string signed_serialized; |
| 657 em::PolicyFetchResponse signed_policy = BuildProto(serialized, | 689 em::PolicyFetchResponse signed_policy = BuildProto(serialized, |
| 658 fake_value_, | 690 fake_value_, |
| 659 &signed_serialized); | 691 &signed_serialized); |
| 660 ProtoDelegate d(signed_policy); | 692 ProtoDelegate d(signed_policy); |
| 661 d.expect_success(); | 693 d.expect_success(); |
| 662 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 694 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
| 663 | 695 |
| 664 MockSessionManagerClient* client = new MockSessionManagerClient;; | 696 MockSessionManagerClient* client = |
| 665 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 697 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 666 EXPECT_CALL(*client, RetrievePolicy(_)) | 698 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 667 .WillOnce(Retrieve(signed_serialized)) | 699 .WillOnce(Retrieve(signed_serialized)) |
| 668 .RetiresOnSaturation(); | 700 .RetiresOnSaturation(); |
| 669 | 701 |
| 670 mock_service(s.get(), &m_); | 702 mock_service(s.get(), &m_); |
| 671 std::vector<uint8> fake_sig(fake_value_.c_str(), | 703 std::vector<uint8> fake_sig(fake_value_.c_str(), |
| 672 fake_value_.c_str() + fake_value_.length()); | 704 fake_value_.c_str() + fake_value_.length()); |
| 673 EXPECT_CALL(m_, StartVerifyAttempt(serialized, fake_sig, _)) | 705 EXPECT_CALL(m_, StartVerifyAttempt(serialized, fake_sig, _)) |
| 674 .Times(1); | 706 .Times(1); |
| 675 em::PolicyData out_pol; | 707 em::PolicyData out_pol; |
| 676 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 708 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
| 677 .WillOnce(SaveArg<0>(&out_pol)); | 709 .WillOnce(SaveArg<0>(&out_pol)); |
| 678 | 710 |
| 679 s->Execute(); | 711 s->Execute(); |
| 680 message_loop_.RunAllPending(); | 712 message_loop_.RunAllPending(); |
| 681 | 713 |
| 682 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | 714 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); |
| 683 message_loop_.RunAllPending(); | 715 message_loop_.RunAllPending(); |
| 684 } | 716 } |
| 685 | 717 |
| 686 TEST_F(SignedSettingsTest, RetrieveNullPolicy) { | 718 TEST_F(SignedSettingsTest, RetrieveNullPolicy) { |
| 687 em::PolicyFetchResponse policy; | 719 em::PolicyFetchResponse policy; |
| 688 ProtoDelegate d(policy); | 720 ProtoDelegate d(policy); |
| 689 d.expect_failure(SignedSettings::NOT_FOUND); | 721 d.expect_failure(SignedSettings::NOT_FOUND); |
| 690 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 722 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
| 691 | 723 |
| 692 MockSessionManagerClient* client = new MockSessionManagerClient;; | 724 MockSessionManagerClient* client = |
| 693 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 725 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 694 EXPECT_CALL(*client, RetrievePolicy(_)) | 726 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 695 .WillOnce(Retrieve("")) | 727 .WillOnce(Retrieve("")) |
| 696 .RetiresOnSaturation(); | 728 .RetiresOnSaturation(); |
| 697 | 729 |
| 698 s->Execute(); | 730 s->Execute(); |
| 699 message_loop_.RunAllPending(); | 731 message_loop_.RunAllPending(); |
| 700 } | 732 } |
| 701 | 733 |
| 702 TEST_F(SignedSettingsTest, RetrieveEmptyPolicy) { | 734 TEST_F(SignedSettingsTest, RetrieveEmptyPolicy) { |
| 703 std::string serialized; | 735 std::string serialized; |
| 704 em::PolicyFetchResponse policy = BuildProto("", "", &serialized); | 736 em::PolicyFetchResponse policy = BuildProto("", "", &serialized); |
| 705 ProtoDelegate d(policy); | 737 ProtoDelegate d(policy); |
| 706 d.expect_failure(SignedSettings::NOT_FOUND); | 738 d.expect_failure(SignedSettings::NOT_FOUND); |
| 707 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 739 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
| 708 | 740 |
| 709 MockSessionManagerClient* client = new MockSessionManagerClient;; | 741 MockSessionManagerClient* client = |
| 710 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 742 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 711 EXPECT_CALL(*client, RetrievePolicy(_)) | 743 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 712 .WillOnce(Retrieve("")) | 744 .WillOnce(Retrieve("")) |
| 713 .RetiresOnSaturation(); | 745 .RetiresOnSaturation(); |
| 714 | 746 |
| 715 s->Execute(); | 747 s->Execute(); |
| 716 message_loop_.RunAllPending(); | 748 message_loop_.RunAllPending(); |
| 717 } | 749 } |
| 718 | 750 |
| 719 TEST_F(SignedSettingsTest, RetrieveUnsignedPolicy) { | 751 TEST_F(SignedSettingsTest, RetrieveUnsignedPolicy) { |
| 720 std::string serialized; | 752 std::string serialized; |
| 721 em::PolicyFetchResponse policy = BuildProto(fake_prop_, | 753 em::PolicyFetchResponse policy = BuildProto(fake_prop_, |
| 722 std::string(), | 754 std::string(), |
| 723 &serialized); | 755 &serialized); |
| 724 ProtoDelegate d(policy); | 756 ProtoDelegate d(policy); |
| 725 d.expect_failure(SignedSettings::BAD_SIGNATURE); | 757 d.expect_failure(SignedSettings::BAD_SIGNATURE); |
| 726 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 758 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
| 727 | 759 |
| 728 MockSessionManagerClient* client = new MockSessionManagerClient;; | 760 MockSessionManagerClient* client = |
| 729 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 761 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 730 EXPECT_CALL(*client, RetrievePolicy(_)) | 762 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 731 .WillOnce(Retrieve(serialized)) | 763 .WillOnce(Retrieve(serialized)) |
| 732 .RetiresOnSaturation(); | 764 .RetiresOnSaturation(); |
| 733 | 765 |
| 734 s->Execute(); | 766 s->Execute(); |
| 735 message_loop_.RunAllPending(); | 767 message_loop_.RunAllPending(); |
| 736 } | 768 } |
| 737 | 769 |
| 738 TEST_F(SignedSettingsTest, RetrieveMalsignedPolicy) { | 770 TEST_F(SignedSettingsTest, RetrieveMalsignedPolicy) { |
| 739 std::string signed_serialized; | 771 std::string signed_serialized; |
| 740 em::PolicyFetchResponse signed_policy = BuildProto(fake_prop_, | 772 em::PolicyFetchResponse signed_policy = BuildProto(fake_prop_, |
| 741 fake_value_, | 773 fake_value_, |
| 742 &signed_serialized); | 774 &signed_serialized); |
| 743 ProtoDelegate d(signed_policy); | 775 ProtoDelegate d(signed_policy); |
| 744 d.expect_failure(SignedSettings::BAD_SIGNATURE); | 776 d.expect_failure(SignedSettings::BAD_SIGNATURE); |
| 745 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 777 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
| 746 | 778 |
| 747 MockSessionManagerClient* client = new MockSessionManagerClient;; | 779 MockSessionManagerClient* client = |
| 748 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 780 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 749 EXPECT_CALL(*client, RetrievePolicy(_)) | 781 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 750 .WillOnce(Retrieve(signed_serialized)) | 782 .WillOnce(Retrieve(signed_serialized)) |
| 751 .RetiresOnSaturation(); | 783 .RetiresOnSaturation(); |
| 752 | 784 |
| 753 mock_service(s.get(), &m_); | 785 mock_service(s.get(), &m_); |
| 754 std::vector<uint8> fake_sig(fake_value_.c_str(), | 786 std::vector<uint8> fake_sig(fake_value_.c_str(), |
| 755 fake_value_.c_str() + fake_value_.length()); | 787 fake_value_.c_str() + fake_value_.length()); |
| 756 EXPECT_CALL(m_, StartVerifyAttempt(fake_prop_, fake_sig, _)) | 788 EXPECT_CALL(m_, StartVerifyAttempt(fake_prop_, fake_sig, _)) |
| 757 .Times(1); | 789 .Times(1); |
| 758 | 790 |
| 759 s->Execute(); | 791 s->Execute(); |
| 760 message_loop_.RunAllPending(); | 792 message_loop_.RunAllPending(); |
| 761 | 793 |
| 762 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); | 794 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); |
| 763 message_loop_.RunAllPending(); | 795 message_loop_.RunAllPending(); |
| 764 } | 796 } |
| 765 | 797 |
| 766 } // namespace chromeos | 798 } // namespace chromeos |
| OLD | NEW |