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/mock_login_library.h" | |
14 #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" |
| 15 #include "chrome/browser/chromeos/dbus/mock_session_manager_client.h" |
15 #include "chrome/browser/chromeos/login/mock_owner_key_utils.h" | 16 #include "chrome/browser/chromeos/login/mock_owner_key_utils.h" |
16 #include "chrome/browser/chromeos/login/mock_ownership_service.h" | 17 #include "chrome/browser/chromeos/login/mock_ownership_service.h" |
17 #include "chrome/browser/chromeos/login/owner_manager_unittest.h" | 18 #include "chrome/browser/chromeos/login/owner_manager_unittest.h" |
18 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" | 19 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" |
19 #include "chrome/browser/policy/proto/device_management_backend.pb.h" | 20 #include "chrome/browser/policy/proto/device_management_backend.pb.h" |
20 #include "content/browser/browser_thread.h" | 21 #include "content/browser/browser_thread.h" |
21 #include "crypto/rsa_private_key.h" | 22 #include "crypto/rsa_private_key.h" |
22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 | 25 |
25 using ::testing::A; | 26 using ::testing::A; |
26 using ::testing::AnyNumber; | 27 using ::testing::AnyNumber; |
27 using ::testing::InvokeArgument; | |
28 using ::testing::Return; | 28 using ::testing::Return; |
29 using ::testing::ReturnRef; | 29 using ::testing::ReturnRef; |
30 using ::testing::SaveArg; | 30 using ::testing::SaveArg; |
31 using ::testing::StrEq; | 31 using ::testing::StrEq; |
32 using ::testing::WithArg; | 32 using ::testing::WithArg; |
33 using ::testing::_; | 33 using ::testing::_; |
34 using google::protobuf::RepeatedPtrField; | 34 using google::protobuf::RepeatedPtrField; |
35 | 35 |
36 namespace em = enterprise_management; | 36 namespace em = enterprise_management; |
37 namespace chromeos { | 37 namespace chromeos { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 } | 113 } |
114 | 114 |
115 virtual ~SignedSettingsTest() {} | 115 virtual ~SignedSettingsTest() {} |
116 | 116 |
117 virtual void SetUp() { | 117 virtual void SetUp() { |
118 file_thread_.Start(); | 118 file_thread_.Start(); |
| 119 DBusThreadManager::Initialize(); |
119 } | 120 } |
120 | 121 |
121 virtual void TearDown() { | 122 virtual void TearDown() { |
122 OwnerKeyUtils::set_factory(NULL); | 123 OwnerKeyUtils::set_factory(NULL); |
| 124 DBusThreadManager::Shutdown(); |
123 } | 125 } |
124 | 126 |
125 void mock_service(SignedSettings* s, MockOwnershipService* m) { | 127 void mock_service(SignedSettings* s, MockOwnershipService* m) { |
126 s->set_service(m); | 128 s->set_service(m); |
127 } | 129 } |
128 | 130 |
129 em::PolicyData BuildPolicyData(std::vector<std::string> whitelist) { | 131 em::PolicyData BuildPolicyData(std::vector<std::string> whitelist) { |
130 em::PolicyData to_return; | 132 em::PolicyData to_return; |
131 em::ChromeDeviceSettingsProto pol; | 133 em::ChromeDeviceSettingsProto pol; |
132 em::GuestModeEnabledProto* allow = pol.mutable_guest_mode_enabled(); | 134 em::GuestModeEnabledProto* allow = pol.mutable_guest_mode_enabled(); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 | 226 |
225 mock_service(s.get(), &m_); | 227 mock_service(s.get(), &m_); |
226 EXPECT_CALL(m_, StartSigningAttempt(StrEq(fake_prop_), _)) | 228 EXPECT_CALL(m_, StartSigningAttempt(StrEq(fake_prop_), _)) |
227 .Times(1); | 229 .Times(1); |
228 | 230 |
229 s->Execute(); | 231 s->Execute(); |
230 s->OnKeyOpComplete(return_code, std::vector<uint8>()); | 232 s->OnKeyOpComplete(return_code, std::vector<uint8>()); |
231 message_loop_.RunAllPending(); | 233 message_loop_.RunAllPending(); |
232 } | 234 } |
233 | 235 |
234 MockLoginLibrary* MockLoginLib() { | |
235 chromeos::CrosLibrary::TestApi* test_api = | |
236 chromeos::CrosLibrary::Get()->GetTestApi(); | |
237 | |
238 // Mocks, ownership transferred to CrosLibrary class on creation. | |
239 MockLoginLibrary* mock_library; | |
240 MockLibraryLoader* loader; | |
241 | |
242 loader = new MockLibraryLoader(); | |
243 ON_CALL(*loader, Load(_)) | |
244 .WillByDefault(Return(true)); | |
245 EXPECT_CALL(*loader, Load(_)) | |
246 .Times(AnyNumber()); | |
247 | |
248 test_api->SetLibraryLoader(loader, true); | |
249 | |
250 mock_library = new MockLoginLibrary(); | |
251 test_api->SetLoginLibrary(mock_library, true); | |
252 return mock_library; | |
253 } | |
254 | |
255 void UnMockLoginLib() { | |
256 // Prevent bogus gMock leak check from firing. | |
257 chromeos::CrosLibrary::TestApi* test_api = | |
258 chromeos::CrosLibrary::Get()->GetTestApi(); | |
259 test_api->SetLibraryLoader(NULL, false); | |
260 test_api->SetLoginLibrary(NULL, false); | |
261 } | |
262 | |
263 em::PolicyFetchResponse BuildProto(const std::string& data, | 236 em::PolicyFetchResponse BuildProto(const std::string& data, |
264 const std::string& sig, | 237 const std::string& sig, |
265 std::string* out_serialized) { | 238 std::string* out_serialized) { |
266 em::PolicyFetchResponse fake_policy; | 239 em::PolicyFetchResponse fake_policy; |
267 if (!data.empty()) | 240 if (!data.empty()) |
268 fake_policy.set_policy_data(data); | 241 fake_policy.set_policy_data(data); |
269 if (!sig.empty()) | 242 if (!sig.empty()) |
270 fake_policy.set_policy_data_signature(sig); | 243 fake_policy.set_policy_data_signature(sig); |
271 EXPECT_TRUE(fake_policy.SerializeToString(out_serialized)); | 244 EXPECT_TRUE(fake_policy.SerializeToString(out_serialized)); |
272 return fake_policy; | 245 return fake_policy; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 .WillOnce(Return(true)); | 506 .WillOnce(Return(true)); |
534 | 507 |
535 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 508 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
536 EXPECT_CALL(m_, cached_policy()) | 509 EXPECT_CALL(m_, cached_policy()) |
537 .WillOnce(ReturnRef(fake_pol)); | 510 .WillOnce(ReturnRef(fake_pol)); |
538 | 511 |
539 s->Execute(); | 512 s->Execute(); |
540 message_loop_.RunAllPending(); | 513 message_loop_.RunAllPending(); |
541 } | 514 } |
542 | 515 |
543 ACTION_P(Retrieve, s) { (*arg0)((void*)arg1, s.c_str(), s.length()); } | 516 ACTION_P(Retrieve, policy_blob) { arg0.Run(policy_blob); } |
| 517 ACTION_P(Store, success) { arg1.Run(success); } |
544 ACTION_P(FinishKeyOp, s) { arg2->OnKeyOpComplete(OwnerManager::SUCCESS, s); } | 518 ACTION_P(FinishKeyOp, s) { arg2->OnKeyOpComplete(OwnerManager::SUCCESS, s); } |
545 | 519 |
546 TEST_F(SignedSettingsTest, RetrievePolicyToRetrieveProperty) { | 520 TEST_F(SignedSettingsTest, RetrievePolicyToRetrieveProperty) { |
547 NormalDelegate<std::string> d(fake_value_); | 521 NormalDelegate<std::string> d(fake_value_); |
548 d.expect_success(); | 522 d.expect_success(); |
549 scoped_refptr<SignedSettings> s( | 523 scoped_refptr<SignedSettings> s( |
550 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); | 524 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); |
551 | 525 |
552 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 526 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
553 std::string data = fake_pol.SerializeAsString(); | 527 std::string data = fake_pol.SerializeAsString(); |
554 std::string signed_serialized; | 528 std::string signed_serialized; |
555 em::PolicyFetchResponse signed_policy = BuildProto(data, | 529 em::PolicyFetchResponse signed_policy = BuildProto(data, |
556 fake_value_, | 530 fake_value_, |
557 &signed_serialized); | 531 &signed_serialized); |
558 MockLoginLibrary* lib = MockLoginLib(); | 532 MockSessionManagerClient* client = new MockSessionManagerClient; |
559 EXPECT_CALL(*lib, RequestRetrievePolicy(_, _)) | 533 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
| 534 EXPECT_CALL(*client, RetrievePolicy(_)) |
560 .WillOnce(Retrieve(signed_serialized)) | 535 .WillOnce(Retrieve(signed_serialized)) |
561 .RetiresOnSaturation(); | 536 .RetiresOnSaturation(); |
562 | 537 |
563 mock_service(s.get(), &m_); | 538 mock_service(s.get(), &m_); |
564 | 539 |
565 EXPECT_CALL(m_, GetStatus(_)) | 540 EXPECT_CALL(m_, GetStatus(_)) |
566 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)) | 541 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)) |
567 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 542 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); |
568 EXPECT_CALL(m_, has_cached_policy()) | 543 EXPECT_CALL(m_, has_cached_policy()) |
569 .WillOnce(Return(false)) | 544 .WillOnce(Return(false)) |
570 .WillOnce(Return(true)); | 545 .WillOnce(Return(true)); |
571 em::PolicyData out_pol; | 546 em::PolicyData out_pol; |
572 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 547 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
573 .WillOnce(SaveArg<0>(&out_pol)); | 548 .WillOnce(SaveArg<0>(&out_pol)); |
574 EXPECT_CALL(m_, cached_policy()) | 549 EXPECT_CALL(m_, cached_policy()) |
575 .WillOnce(ReturnRef(out_pol)); | 550 .WillOnce(ReturnRef(out_pol)); |
576 | 551 |
577 std::vector<uint8> fake_sig(fake_value_.c_str(), | 552 std::vector<uint8> fake_sig(fake_value_.c_str(), |
578 fake_value_.c_str() + fake_value_.length()); | 553 fake_value_.c_str() + fake_value_.length()); |
579 EXPECT_CALL(m_, StartVerifyAttempt(data, fake_sig, _)) | 554 EXPECT_CALL(m_, StartVerifyAttempt(data, fake_sig, _)) |
580 .WillOnce(FinishKeyOp(fake_sig)) | 555 .WillOnce(FinishKeyOp(fake_sig)) |
581 .RetiresOnSaturation(); | 556 .RetiresOnSaturation(); |
582 | 557 |
583 s->Execute(); | 558 s->Execute(); |
584 message_loop_.RunAllPending(); | 559 message_loop_.RunAllPending(); |
585 UnMockLoginLib(); | |
586 } | 560 } |
587 | 561 |
588 TEST_F(SignedSettingsTest, SignAndStorePolicy) { | 562 TEST_F(SignedSettingsTest, SignAndStorePolicy) { |
589 NormalDelegate<bool> d(true); | 563 NormalDelegate<bool> d(true); |
590 d.expect_success(); | 564 d.expect_success(); |
591 | 565 |
592 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 566 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
593 std::string data_serialized = in_pol.SerializeAsString(); | 567 std::string data_serialized = in_pol.SerializeAsString(); |
594 std::string serialized; | 568 std::string serialized; |
595 em::PolicyFetchResponse fake_policy = BuildProto(data_serialized, | 569 em::PolicyFetchResponse fake_policy = BuildProto(data_serialized, |
(...skipping 14 matching lines...) Expand all Loading... |
610 message_loop_.RunAllPending(); | 584 message_loop_.RunAllPending(); |
611 | 585 |
612 // Fake out a successful signing. | 586 // Fake out a successful signing. |
613 std::string signed_serialized; | 587 std::string signed_serialized; |
614 em::PolicyFetchResponse signed_policy = BuildProto(data_serialized, | 588 em::PolicyFetchResponse signed_policy = BuildProto(data_serialized, |
615 fake_value_, | 589 fake_value_, |
616 &signed_serialized); | 590 &signed_serialized); |
617 std::vector<uint8> fake_sig(fake_value_.c_str(), | 591 std::vector<uint8> fake_sig(fake_value_.c_str(), |
618 fake_value_.c_str() + fake_value_.length()); | 592 fake_value_.c_str() + fake_value_.length()); |
619 | 593 |
620 MockLoginLibrary* lib = MockLoginLib(); | 594 MockSessionManagerClient* client = new MockSessionManagerClient;; |
621 EXPECT_CALL(*lib, RequestStorePolicy(StrEq(signed_serialized), _, s.get())) | 595 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
622 .WillOnce(InvokeArgument<1>(static_cast<void*>(s.get()), true)) | 596 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) |
| 597 .WillOnce(Store(true)) |
623 .RetiresOnSaturation(); | 598 .RetiresOnSaturation(); |
624 s->OnKeyOpComplete(OwnerManager::SUCCESS, fake_sig); | 599 s->OnKeyOpComplete(OwnerManager::SUCCESS, fake_sig); |
625 message_loop_.RunAllPending(); | 600 message_loop_.RunAllPending(); |
626 UnMockLoginLib(); | |
627 } | 601 } |
628 | 602 |
629 TEST_F(SignedSettingsTest, StoreSignedPolicy) { | 603 TEST_F(SignedSettingsTest, StoreSignedPolicy) { |
630 NormalDelegate<bool> d(true); | 604 NormalDelegate<bool> d(true); |
631 d.expect_success(); | 605 d.expect_success(); |
632 | 606 |
633 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 607 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
634 std::string serialized = in_pol.SerializeAsString(); | 608 std::string serialized = in_pol.SerializeAsString(); |
635 std::string signed_serialized; | 609 std::string signed_serialized; |
636 em::PolicyFetchResponse signed_policy = BuildProto(serialized, | 610 em::PolicyFetchResponse signed_policy = BuildProto(serialized, |
637 fake_value_, | 611 fake_value_, |
638 &signed_serialized); | 612 &signed_serialized); |
639 scoped_refptr<SignedSettings> s( | 613 scoped_refptr<SignedSettings> s( |
640 SignedSettings::CreateStorePolicyOp(&signed_policy, &d)); | 614 SignedSettings::CreateStorePolicyOp(&signed_policy, &d)); |
641 MockLoginLibrary* lib = MockLoginLib(); | 615 MockSessionManagerClient* client = new MockSessionManagerClient;; |
642 EXPECT_CALL(*lib, RequestStorePolicy(StrEq(signed_serialized), _, s.get())) | 616 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
643 .WillOnce(InvokeArgument<1>(static_cast<void*>(s.get()), true)) | 617 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) |
| 618 .WillOnce(Store(true)) |
644 .RetiresOnSaturation(); | 619 .RetiresOnSaturation(); |
645 | 620 |
646 mock_service(s.get(), &m_); | 621 mock_service(s.get(), &m_); |
647 em::PolicyData out_pol; | 622 em::PolicyData out_pol; |
648 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 623 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
649 .WillOnce(SaveArg<0>(&out_pol)); | 624 .WillOnce(SaveArg<0>(&out_pol)); |
650 | 625 |
651 s->Execute(); | 626 s->Execute(); |
652 message_loop_.RunAllPending(); | 627 message_loop_.RunAllPending(); |
653 UnMockLoginLib(); | |
654 } | 628 } |
655 | 629 |
656 TEST_F(SignedSettingsTest, StorePolicyNoKey) { | 630 TEST_F(SignedSettingsTest, StorePolicyNoKey) { |
657 FailingStorePolicyOp(OwnerManager::KEY_UNAVAILABLE); | 631 FailingStorePolicyOp(OwnerManager::KEY_UNAVAILABLE); |
658 } | 632 } |
659 | 633 |
660 TEST_F(SignedSettingsTest, StorePolicyFailed) { | 634 TEST_F(SignedSettingsTest, StorePolicyFailed) { |
661 FailingStorePolicyOp(OwnerManager::OPERATION_FAILED); | 635 FailingStorePolicyOp(OwnerManager::OPERATION_FAILED); |
662 } | 636 } |
663 | 637 |
(...skipping 16 matching lines...) Expand all Loading... |
680 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 654 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
681 std::string serialized = in_pol.SerializeAsString(); | 655 std::string serialized = in_pol.SerializeAsString(); |
682 std::string signed_serialized; | 656 std::string signed_serialized; |
683 em::PolicyFetchResponse signed_policy = BuildProto(serialized, | 657 em::PolicyFetchResponse signed_policy = BuildProto(serialized, |
684 fake_value_, | 658 fake_value_, |
685 &signed_serialized); | 659 &signed_serialized); |
686 ProtoDelegate d(signed_policy); | 660 ProtoDelegate d(signed_policy); |
687 d.expect_success(); | 661 d.expect_success(); |
688 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 662 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
689 | 663 |
690 MockLoginLibrary* lib = MockLoginLib(); | 664 MockSessionManagerClient* client = new MockSessionManagerClient;; |
691 EXPECT_CALL(*lib, RequestRetrievePolicy(_, s.get())) | 665 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
692 .WillOnce(InvokeArgument<0>(static_cast<void*>(s.get()), | 666 EXPECT_CALL(*client, RetrievePolicy(_)) |
693 signed_serialized.c_str(), | 667 .WillOnce(Retrieve(signed_serialized)) |
694 signed_serialized.length())) | |
695 .RetiresOnSaturation(); | 668 .RetiresOnSaturation(); |
696 | 669 |
697 mock_service(s.get(), &m_); | 670 mock_service(s.get(), &m_); |
698 std::vector<uint8> fake_sig(fake_value_.c_str(), | 671 std::vector<uint8> fake_sig(fake_value_.c_str(), |
699 fake_value_.c_str() + fake_value_.length()); | 672 fake_value_.c_str() + fake_value_.length()); |
700 EXPECT_CALL(m_, StartVerifyAttempt(serialized, fake_sig, _)) | 673 EXPECT_CALL(m_, StartVerifyAttempt(serialized, fake_sig, _)) |
701 .Times(1); | 674 .Times(1); |
702 em::PolicyData out_pol; | 675 em::PolicyData out_pol; |
703 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 676 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
704 .WillOnce(SaveArg<0>(&out_pol)); | 677 .WillOnce(SaveArg<0>(&out_pol)); |
705 | 678 |
706 s->Execute(); | 679 s->Execute(); |
707 message_loop_.RunAllPending(); | 680 message_loop_.RunAllPending(); |
708 UnMockLoginLib(); | |
709 | 681 |
710 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | 682 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); |
711 message_loop_.RunAllPending(); | 683 message_loop_.RunAllPending(); |
712 } | 684 } |
713 | 685 |
714 TEST_F(SignedSettingsTest, RetrieveNullPolicy) { | 686 TEST_F(SignedSettingsTest, RetrieveNullPolicy) { |
715 em::PolicyFetchResponse policy; | 687 em::PolicyFetchResponse policy; |
716 ProtoDelegate d(policy); | 688 ProtoDelegate d(policy); |
717 d.expect_failure(SignedSettings::NOT_FOUND); | 689 d.expect_failure(SignedSettings::NOT_FOUND); |
718 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 690 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
719 | 691 |
720 MockLoginLibrary* lib = MockLoginLib(); | 692 MockSessionManagerClient* client = new MockSessionManagerClient;; |
721 EXPECT_CALL(*lib, RequestRetrievePolicy(_, s.get())) | 693 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
722 .WillOnce(InvokeArgument<0>(static_cast<void*>(s.get()), | 694 EXPECT_CALL(*client, RetrievePolicy(_)) |
723 static_cast<const char*>(NULL), | 695 .WillOnce(Retrieve("")) |
724 0)) | |
725 .RetiresOnSaturation(); | 696 .RetiresOnSaturation(); |
726 | 697 |
727 s->Execute(); | 698 s->Execute(); |
728 message_loop_.RunAllPending(); | 699 message_loop_.RunAllPending(); |
729 UnMockLoginLib(); | |
730 } | 700 } |
731 | 701 |
732 TEST_F(SignedSettingsTest, RetrieveEmptyPolicy) { | 702 TEST_F(SignedSettingsTest, RetrieveEmptyPolicy) { |
733 std::string serialized; | 703 std::string serialized; |
734 em::PolicyFetchResponse policy = BuildProto("", "", &serialized); | 704 em::PolicyFetchResponse policy = BuildProto("", "", &serialized); |
735 ProtoDelegate d(policy); | 705 ProtoDelegate d(policy); |
736 d.expect_failure(SignedSettings::NOT_FOUND); | 706 d.expect_failure(SignedSettings::NOT_FOUND); |
737 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 707 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
738 | 708 |
739 MockLoginLibrary* lib = MockLoginLib(); | 709 MockSessionManagerClient* client = new MockSessionManagerClient;; |
740 EXPECT_CALL(*lib, RequestRetrievePolicy(_, s.get())) | 710 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
741 .WillOnce(InvokeArgument<0>(static_cast<void*>(s.get()), "", 0)) | 711 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 712 .WillOnce(Retrieve("")) |
742 .RetiresOnSaturation(); | 713 .RetiresOnSaturation(); |
743 | 714 |
744 s->Execute(); | 715 s->Execute(); |
745 message_loop_.RunAllPending(); | 716 message_loop_.RunAllPending(); |
746 UnMockLoginLib(); | |
747 } | 717 } |
748 | 718 |
749 TEST_F(SignedSettingsTest, RetrieveUnsignedPolicy) { | 719 TEST_F(SignedSettingsTest, RetrieveUnsignedPolicy) { |
750 std::string serialized; | 720 std::string serialized; |
751 em::PolicyFetchResponse policy = BuildProto(fake_prop_, | 721 em::PolicyFetchResponse policy = BuildProto(fake_prop_, |
752 std::string(), | 722 std::string(), |
753 &serialized); | 723 &serialized); |
754 ProtoDelegate d(policy); | 724 ProtoDelegate d(policy); |
755 d.expect_failure(SignedSettings::BAD_SIGNATURE); | 725 d.expect_failure(SignedSettings::BAD_SIGNATURE); |
756 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 726 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
757 | 727 |
758 MockLoginLibrary* lib = MockLoginLib(); | 728 MockSessionManagerClient* client = new MockSessionManagerClient;; |
759 EXPECT_CALL(*lib, RequestRetrievePolicy(_, s.get())) | 729 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
760 .WillOnce(InvokeArgument<0>(static_cast<void*>(s.get()), | 730 EXPECT_CALL(*client, RetrievePolicy(_)) |
761 serialized.c_str(), | 731 .WillOnce(Retrieve(serialized)) |
762 serialized.length())) | |
763 .RetiresOnSaturation(); | 732 .RetiresOnSaturation(); |
764 | 733 |
765 s->Execute(); | 734 s->Execute(); |
766 message_loop_.RunAllPending(); | 735 message_loop_.RunAllPending(); |
767 UnMockLoginLib(); | |
768 } | 736 } |
769 | 737 |
770 TEST_F(SignedSettingsTest, RetrieveMalsignedPolicy) { | 738 TEST_F(SignedSettingsTest, RetrieveMalsignedPolicy) { |
771 std::string signed_serialized; | 739 std::string signed_serialized; |
772 em::PolicyFetchResponse signed_policy = BuildProto(fake_prop_, | 740 em::PolicyFetchResponse signed_policy = BuildProto(fake_prop_, |
773 fake_value_, | 741 fake_value_, |
774 &signed_serialized); | 742 &signed_serialized); |
775 ProtoDelegate d(signed_policy); | 743 ProtoDelegate d(signed_policy); |
776 d.expect_failure(SignedSettings::BAD_SIGNATURE); | 744 d.expect_failure(SignedSettings::BAD_SIGNATURE); |
777 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 745 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
778 | 746 |
779 MockLoginLibrary* lib = MockLoginLib(); | 747 MockSessionManagerClient* client = new MockSessionManagerClient;; |
780 EXPECT_CALL(*lib, RequestRetrievePolicy(_, s.get())) | 748 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
781 .WillOnce(InvokeArgument<0>(static_cast<void*>(s.get()), | 749 EXPECT_CALL(*client, RetrievePolicy(_)) |
782 signed_serialized.c_str(), | 750 .WillOnce(Retrieve(signed_serialized)) |
783 signed_serialized.length())) | |
784 .RetiresOnSaturation(); | 751 .RetiresOnSaturation(); |
785 | 752 |
786 mock_service(s.get(), &m_); | 753 mock_service(s.get(), &m_); |
787 std::vector<uint8> fake_sig(fake_value_.c_str(), | 754 std::vector<uint8> fake_sig(fake_value_.c_str(), |
788 fake_value_.c_str() + fake_value_.length()); | 755 fake_value_.c_str() + fake_value_.length()); |
789 EXPECT_CALL(m_, StartVerifyAttempt(fake_prop_, fake_sig, _)) | 756 EXPECT_CALL(m_, StartVerifyAttempt(fake_prop_, fake_sig, _)) |
790 .Times(1); | 757 .Times(1); |
791 | 758 |
792 s->Execute(); | 759 s->Execute(); |
793 message_loop_.RunAllPending(); | 760 message_loop_.RunAllPending(); |
794 UnMockLoginLib(); | |
795 | 761 |
796 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); | 762 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); |
797 message_loop_.RunAllPending(); | 763 message_loop_.RunAllPending(); |
798 } | 764 } |
799 | 765 |
800 } // namespace chromeos | 766 } // namespace chromeos |
OLD | NEW |