| 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" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 virtual void compare_expected(T to_compare) = 0; | 71 virtual void compare_expected(T to_compare) = 0; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 template <class T> | 74 template <class T> |
| 75 class NormalDelegate : public DummyDelegate<T> { | 75 class NormalDelegate : public DummyDelegate<T> { |
| 76 public: | 76 public: |
| 77 explicit NormalDelegate(T to_expect) : DummyDelegate<T>(to_expect) {} | 77 explicit NormalDelegate(T to_expect) : DummyDelegate<T>(to_expect) {} |
| 78 virtual ~NormalDelegate() {} | 78 virtual ~NormalDelegate() {} |
| 79 protected: | 79 protected: |
| 80 virtual void compare_expected(T to_compare) { | 80 virtual void compare_expected(T to_compare) { |
| 81 EXPECT_EQ(this->expected_, to_compare); // without this-> this won't build. | 81 // without this-> this won't build. |
| 82 EXPECT_EQ(this->expected_, to_compare); |
| 82 } | 83 } |
| 83 }; | 84 }; |
| 84 | 85 |
| 86 // Specialized version for Value objects because these compare differently. |
| 87 class PolicyDelegate : public DummyDelegate<const base::Value*> { |
| 88 public: |
| 89 explicit PolicyDelegate(const base::Value* to_expect) |
| 90 : DummyDelegate<const base::Value*>(to_expect) {} |
| 91 virtual ~PolicyDelegate() {} |
| 92 protected: |
| 93 virtual void compare_expected(const base::Value* to_compare) { |
| 94 // without this-> this won't build. |
| 95 EXPECT_TRUE(this->expected_->Equals(to_compare)); |
| 96 } |
| 97 }; |
| 98 |
| 85 class ProtoDelegate : public DummyDelegate<const em::PolicyFetchResponse&> { | 99 class ProtoDelegate : public DummyDelegate<const em::PolicyFetchResponse&> { |
| 86 public: | 100 public: |
| 87 explicit ProtoDelegate(const em::PolicyFetchResponse& e) | 101 explicit ProtoDelegate(const em::PolicyFetchResponse& e) |
| 88 : DummyDelegate<const em::PolicyFetchResponse&>(e) { | 102 : DummyDelegate<const em::PolicyFetchResponse&>(e) { |
| 89 } | 103 } |
| 90 virtual ~ProtoDelegate() {} | 104 virtual ~ProtoDelegate() {} |
| 91 protected: | 105 protected: |
| 92 virtual void compare_expected(const em::PolicyFetchResponse& to_compare) { | 106 virtual void compare_expected(const em::PolicyFetchResponse& to_compare) { |
| 93 std::string ex_string, comp_string; | 107 std::string ex_string, comp_string; |
| 94 EXPECT_TRUE(expected_.SerializeToString(&ex_string)); | 108 EXPECT_TRUE(expected_.SerializeToString(&ex_string)); |
| 95 EXPECT_TRUE(to_compare.SerializeToString(&comp_string)); | 109 EXPECT_TRUE(to_compare.SerializeToString(&comp_string)); |
| 96 EXPECT_EQ(ex_string, comp_string); | 110 EXPECT_EQ(ex_string, comp_string); |
| 97 } | 111 } |
| 98 }; | 112 }; |
| 99 | 113 |
| 100 } // anonymous namespace | 114 } // anonymous namespace |
| 101 | 115 |
| 102 class SignedSettingsTest : public testing::Test { | 116 class SignedSettingsTest : public testing::Test { |
| 103 public: | 117 public: |
| 104 SignedSettingsTest() | 118 SignedSettingsTest() |
| 105 : fake_email_("fakey@example.com"), | 119 : fake_email_("fakey@example.com"), |
| 106 fake_domain_("*@example.com"), | 120 fake_domain_("*@example.com"), |
| 107 fake_prop_(kAccountsPrefAllowGuest), | 121 fake_prop_(kAccountsPrefAllowGuest), |
| 108 fake_value_("false"), | 122 fake_signature_("false"), |
| 123 fake_value_(false), |
| 124 fake_value_signature_( |
| 125 fake_signature_.c_str(), |
| 126 fake_signature_.c_str() + fake_signature_.length()), |
| 109 message_loop_(MessageLoop::TYPE_UI), | 127 message_loop_(MessageLoop::TYPE_UI), |
| 110 ui_thread_(BrowserThread::UI, &message_loop_), | 128 ui_thread_(BrowserThread::UI, &message_loop_), |
| 111 file_thread_(BrowserThread::FILE), | 129 file_thread_(BrowserThread::FILE), |
| 112 mock_(new MockKeyUtils), | 130 mock_(new MockKeyUtils), |
| 113 injector_(mock_) /* injector_ takes ownership of mock_ */, | 131 injector_(mock_) /* injector_ takes ownership of mock_ */, |
| 114 mock_dbus_thread_manager_(new MockDBusThreadManager) { | 132 mock_dbus_thread_manager_(new MockDBusThreadManager) { |
| 115 } | 133 } |
| 116 | 134 |
| 117 virtual ~SignedSettingsTest() {} | 135 virtual ~SignedSettingsTest() {} |
| 118 | 136 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 em::PolicyFetchResponse fake_policy; | 259 em::PolicyFetchResponse fake_policy; |
| 242 if (!data.empty()) | 260 if (!data.empty()) |
| 243 fake_policy.set_policy_data(data); | 261 fake_policy.set_policy_data(data); |
| 244 if (!sig.empty()) | 262 if (!sig.empty()) |
| 245 fake_policy.set_policy_data_signature(sig); | 263 fake_policy.set_policy_data_signature(sig); |
| 246 EXPECT_TRUE(fake_policy.SerializeToString(out_serialized)); | 264 EXPECT_TRUE(fake_policy.SerializeToString(out_serialized)); |
| 247 return fake_policy; | 265 return fake_policy; |
| 248 } | 266 } |
| 249 | 267 |
| 250 void DoRetrieveProperty(const std::string& name, | 268 void DoRetrieveProperty(const std::string& name, |
| 251 const std::string& value, | 269 const base::Value* value, |
| 252 em::PolicyData* fake_pol) { | 270 em::PolicyData* fake_pol) { |
| 253 NormalDelegate<std::string> d(value); | 271 PolicyDelegate d(value); |
| 254 d.expect_success(); | 272 d.expect_success(); |
| 255 scoped_refptr<SignedSettings> s( | 273 scoped_refptr<SignedSettings> s( |
| 256 SignedSettings::CreateRetrievePropertyOp(name, &d)); | 274 SignedSettings::CreateRetrievePropertyOp(name, &d)); |
| 257 mock_service(s.get(), &m_); | 275 mock_service(s.get(), &m_); |
| 258 EXPECT_CALL(m_, GetStatus(_)) | 276 EXPECT_CALL(m_, GetStatus(_)) |
| 259 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 277 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); |
| 260 EXPECT_CALL(m_, has_cached_policy()) | 278 EXPECT_CALL(m_, has_cached_policy()) |
| 261 .WillOnce(Return(true)); | 279 .WillOnce(Return(true)); |
| 262 | 280 |
| 263 EXPECT_CALL(m_, cached_policy()) | 281 EXPECT_CALL(m_, cached_policy()) |
| 264 .WillOnce(ReturnRef(*fake_pol)); | 282 .WillOnce(ReturnRef(*fake_pol)); |
| 265 | 283 |
| 266 s->Execute(); | 284 s->Execute(); |
| 267 message_loop_.RunAllPending(); | 285 message_loop_.RunAllPending(); |
| 268 } | 286 } |
| 269 | 287 |
| 270 const std::string fake_email_; | 288 const std::string fake_email_; |
| 271 const std::string fake_domain_; | 289 const std::string fake_domain_; |
| 272 const std::string fake_prop_; | 290 const std::string fake_prop_; |
| 273 const std::string fake_value_; | 291 const std::string fake_signature_; |
| 292 const base::FundamentalValue fake_value_; |
| 293 const std::vector<uint8> fake_value_signature_; |
| 274 MockOwnershipService m_; | 294 MockOwnershipService m_; |
| 275 | 295 |
| 276 ScopedTempDir tmpdir_; | 296 ScopedTempDir tmpdir_; |
| 277 FilePath tmpfile_; | 297 FilePath tmpfile_; |
| 278 | 298 |
| 279 MessageLoop message_loop_; | 299 MessageLoop message_loop_; |
| 280 content::TestBrowserThread ui_thread_; | 300 content::TestBrowserThread ui_thread_; |
| 281 content::TestBrowserThread file_thread_; | 301 content::TestBrowserThread file_thread_; |
| 282 | 302 |
| 283 std::vector<uint8> fake_public_key_; | 303 std::vector<uint8> fake_public_key_; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 TEST_F(SignedSettingsTest, StorePropertyNoKey) { | 510 TEST_F(SignedSettingsTest, StorePropertyNoKey) { |
| 491 FailingStorePropertyOp(OwnerManager::KEY_UNAVAILABLE); | 511 FailingStorePropertyOp(OwnerManager::KEY_UNAVAILABLE); |
| 492 } | 512 } |
| 493 | 513 |
| 494 TEST_F(SignedSettingsTest, StorePropertyFailed) { | 514 TEST_F(SignedSettingsTest, StorePropertyFailed) { |
| 495 FailingStorePropertyOp(OwnerManager::OPERATION_FAILED); | 515 FailingStorePropertyOp(OwnerManager::OPERATION_FAILED); |
| 496 } | 516 } |
| 497 | 517 |
| 498 TEST_F(SignedSettingsTest, RetrieveProperty) { | 518 TEST_F(SignedSettingsTest, RetrieveProperty) { |
| 499 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 519 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 500 DoRetrieveProperty(fake_prop_, fake_value_, &fake_pol); | 520 base::FundamentalValue fake_value(false); |
| 521 DoRetrieveProperty(fake_prop_, &fake_value, &fake_pol); |
| 501 } | 522 } |
| 502 | 523 |
| 503 TEST_F(SignedSettingsTest, RetrieveOwnerProperty) { | 524 TEST_F(SignedSettingsTest, RetrieveOwnerProperty) { |
| 504 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 525 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 505 fake_pol.set_username(fake_email_); | 526 fake_pol.set_username(fake_email_); |
| 506 DoRetrieveProperty(kDeviceOwner, fake_email_, &fake_pol); | 527 base::StringValue fake_value(fake_email_); |
| 528 DoRetrieveProperty(kDeviceOwner, &fake_value, &fake_pol); |
| 507 } | 529 } |
| 508 | 530 |
| 509 TEST_F(SignedSettingsTest, ExplicitlyAllowNewUsers) { | 531 TEST_F(SignedSettingsTest, ExplicitlyAllowNewUsers) { |
| 510 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 532 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 511 SetAllowNewUsers(true, &fake_pol); | 533 SetAllowNewUsers(true, &fake_pol); |
| 512 DoRetrieveProperty(kAccountsPrefAllowNewUser, "true", &fake_pol); | 534 base::FundamentalValue fake_value(true); |
| 535 DoRetrieveProperty(kAccountsPrefAllowNewUser, &fake_value, &fake_pol); |
| 513 } | 536 } |
| 514 | 537 |
| 515 TEST_F(SignedSettingsTest, ExplicitlyDisallowNewUsers) { | 538 TEST_F(SignedSettingsTest, ExplicitlyDisallowNewUsers) { |
| 516 std::vector<std::string> whitelist(1, fake_email_ + "m"); | 539 std::vector<std::string> whitelist(1, fake_email_ + "m"); |
| 517 em::PolicyData fake_pol = BuildPolicyData(whitelist); | 540 em::PolicyData fake_pol = BuildPolicyData(whitelist); |
| 518 SetAllowNewUsers(false, &fake_pol); | 541 SetAllowNewUsers(false, &fake_pol); |
| 519 DoRetrieveProperty(kAccountsPrefAllowNewUser, "false", &fake_pol); | 542 base::FundamentalValue fake_value(false); |
| 543 DoRetrieveProperty(kAccountsPrefAllowNewUser, &fake_value, &fake_pol); |
| 520 } | 544 } |
| 521 | 545 |
| 522 TEST_F(SignedSettingsTest, ImplicitlyDisallowNewUsers) { | 546 TEST_F(SignedSettingsTest, ImplicitlyDisallowNewUsers) { |
| 523 std::vector<std::string> whitelist(1, fake_email_ + "m"); | 547 std::vector<std::string> whitelist(1, fake_email_ + "m"); |
| 524 em::PolicyData fake_pol = BuildPolicyData(whitelist); | 548 em::PolicyData fake_pol = BuildPolicyData(whitelist); |
| 525 DoRetrieveProperty(kAccountsPrefAllowNewUser, "false", &fake_pol); | 549 base::FundamentalValue fake_value(false); |
| 550 DoRetrieveProperty(kAccountsPrefAllowNewUser, &fake_value, &fake_pol); |
| 526 } | 551 } |
| 527 | 552 |
| 528 TEST_F(SignedSettingsTest, AccidentallyDisallowNewUsers) { | 553 TEST_F(SignedSettingsTest, AccidentallyDisallowNewUsers) { |
| 529 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 554 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 530 SetAllowNewUsers(false, &fake_pol); | 555 SetAllowNewUsers(false, &fake_pol); |
| 531 DoRetrieveProperty(kAccountsPrefAllowNewUser, "true", &fake_pol); | 556 base::FundamentalValue fake_value(true); |
| 557 DoRetrieveProperty(kAccountsPrefAllowNewUser, &fake_value, &fake_pol); |
| 532 } | 558 } |
| 533 | 559 |
| 534 TEST_F(SignedSettingsTest, RetrievePropertyNotFound) { | 560 TEST_F(SignedSettingsTest, RetrievePropertyNotFound) { |
| 535 NormalDelegate<std::string> d(fake_value_); | 561 PolicyDelegate d(&fake_value_); |
| 536 d.expect_failure(SignedSettings::NOT_FOUND); | 562 d.expect_failure(SignedSettings::NOT_FOUND); |
| 537 scoped_refptr<SignedSettings> s( | 563 scoped_refptr<SignedSettings> s( |
| 538 SignedSettings::CreateRetrievePropertyOp("unknown_prop", &d)); | 564 SignedSettings::CreateRetrievePropertyOp("unknown_prop", &d)); |
| 539 mock_service(s.get(), &m_); | 565 mock_service(s.get(), &m_); |
| 540 EXPECT_CALL(m_, GetStatus(_)) | 566 EXPECT_CALL(m_, GetStatus(_)) |
| 541 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 567 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); |
| 542 EXPECT_CALL(m_, has_cached_policy()) | 568 EXPECT_CALL(m_, has_cached_policy()) |
| 543 .WillOnce(Return(true)); | 569 .WillOnce(Return(true)); |
| 544 | 570 |
| 545 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 571 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 546 EXPECT_CALL(m_, cached_policy()) | 572 EXPECT_CALL(m_, cached_policy()) |
| 547 .WillOnce(ReturnRef(fake_pol)); | 573 .WillOnce(ReturnRef(fake_pol)); |
| 548 | 574 |
| 549 s->Execute(); | 575 s->Execute(); |
| 550 message_loop_.RunAllPending(); | 576 message_loop_.RunAllPending(); |
| 551 } | 577 } |
| 552 | 578 |
| 553 TEST_F(SignedSettingsTest, RetrievePolicyToRetrieveProperty) { | 579 TEST_F(SignedSettingsTest, RetrievePolicyToRetrieveProperty) { |
| 554 NormalDelegate<std::string> d(fake_value_); | 580 base::FundamentalValue fake_value(false); |
| 581 PolicyDelegate d(&fake_value); |
| 555 d.expect_success(); | 582 d.expect_success(); |
| 556 scoped_refptr<SignedSettings> s( | 583 scoped_refptr<SignedSettings> s( |
| 557 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); | 584 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); |
| 558 | 585 |
| 559 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 586 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 560 std::string data = fake_pol.SerializeAsString(); | 587 std::string data = fake_pol.SerializeAsString(); |
| 561 std::string signed_serialized; | 588 std::string signed_serialized; |
| 562 em::PolicyFetchResponse signed_policy = BuildProto(data, | 589 em::PolicyFetchResponse signed_policy = BuildProto(data, |
| 563 fake_value_, | 590 fake_signature_, |
| 564 &signed_serialized); | 591 &signed_serialized); |
| 565 MockSessionManagerClient* client = | 592 MockSessionManagerClient* client = |
| 566 mock_dbus_thread_manager_->mock_session_manager_client(); | 593 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 567 EXPECT_CALL(*client, RetrievePolicy(_)) | 594 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 568 .WillOnce(Retrieve(signed_serialized)) | 595 .WillOnce(Retrieve(signed_serialized)) |
| 569 .RetiresOnSaturation(); | 596 .RetiresOnSaturation(); |
| 570 | 597 |
| 571 mock_service(s.get(), &m_); | 598 mock_service(s.get(), &m_); |
| 572 | 599 |
| 573 EXPECT_CALL(m_, GetStatus(_)) | 600 EXPECT_CALL(m_, GetStatus(_)) |
| 574 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)) | 601 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)) |
| 575 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 602 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); |
| 576 EXPECT_CALL(m_, has_cached_policy()) | 603 EXPECT_CALL(m_, has_cached_policy()) |
| 577 .WillOnce(Return(false)) | 604 .WillOnce(Return(false)) |
| 578 .WillOnce(Return(true)); | 605 .WillOnce(Return(true)); |
| 579 em::PolicyData out_pol; | 606 em::PolicyData out_pol; |
| 580 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 607 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
| 581 .WillOnce(SaveArg<0>(&out_pol)); | 608 .WillOnce(SaveArg<0>(&out_pol)); |
| 582 EXPECT_CALL(m_, cached_policy()) | 609 EXPECT_CALL(m_, cached_policy()) |
| 583 .WillOnce(ReturnRef(out_pol)); | 610 .WillOnce(ReturnRef(out_pol)); |
| 584 | 611 |
| 585 std::vector<uint8> fake_sig(fake_value_.c_str(), | 612 EXPECT_CALL(m_, StartVerifyAttempt(data, fake_value_signature_, _)) |
| 586 fake_value_.c_str() + fake_value_.length()); | 613 .WillOnce(FinishKeyOp(fake_value_signature_)) |
| 587 EXPECT_CALL(m_, StartVerifyAttempt(data, fake_sig, _)) | |
| 588 .WillOnce(FinishKeyOp(fake_sig)) | |
| 589 .RetiresOnSaturation(); | 614 .RetiresOnSaturation(); |
| 590 | 615 |
| 591 s->Execute(); | 616 s->Execute(); |
| 592 message_loop_.RunAllPending(); | 617 message_loop_.RunAllPending(); |
| 593 } | 618 } |
| 594 | 619 |
| 595 TEST_F(SignedSettingsTest, SignAndStorePolicy) { | 620 TEST_F(SignedSettingsTest, SignAndStorePolicy) { |
| 596 NormalDelegate<bool> d(true); | 621 NormalDelegate<bool> d(true); |
| 597 d.expect_success(); | 622 d.expect_success(); |
| 598 | 623 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 612 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 637 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
| 613 .WillOnce(SaveArg<0>(&out_pol)); | 638 .WillOnce(SaveArg<0>(&out_pol)); |
| 614 | 639 |
| 615 // Ask for signature over unsigned policy. | 640 // Ask for signature over unsigned policy. |
| 616 s->Execute(); | 641 s->Execute(); |
| 617 message_loop_.RunAllPending(); | 642 message_loop_.RunAllPending(); |
| 618 | 643 |
| 619 // Fake out a successful signing. | 644 // Fake out a successful signing. |
| 620 std::string signed_serialized; | 645 std::string signed_serialized; |
| 621 em::PolicyFetchResponse signed_policy = BuildProto(data_serialized, | 646 em::PolicyFetchResponse signed_policy = BuildProto(data_serialized, |
| 622 fake_value_, | 647 fake_signature_, |
| 623 &signed_serialized); | 648 &signed_serialized); |
| 624 std::vector<uint8> fake_sig(fake_value_.c_str(), | |
| 625 fake_value_.c_str() + fake_value_.length()); | |
| 626 | |
| 627 MockSessionManagerClient* client = | 649 MockSessionManagerClient* client = |
| 628 mock_dbus_thread_manager_->mock_session_manager_client(); | 650 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 629 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) | 651 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) |
| 630 .WillOnce(Store(true)) | 652 .WillOnce(Store(true)) |
| 631 .RetiresOnSaturation(); | 653 .RetiresOnSaturation(); |
| 632 s->OnKeyOpComplete(OwnerManager::SUCCESS, fake_sig); | 654 s->OnKeyOpComplete(OwnerManager::SUCCESS, fake_value_signature_); |
| 633 message_loop_.RunAllPending(); | 655 message_loop_.RunAllPending(); |
| 634 } | 656 } |
| 635 | 657 |
| 636 TEST_F(SignedSettingsTest, StoreSignedPolicy) { | 658 TEST_F(SignedSettingsTest, StoreSignedPolicy) { |
| 637 NormalDelegate<bool> d(true); | 659 NormalDelegate<bool> d(true); |
| 638 d.expect_success(); | 660 d.expect_success(); |
| 639 | 661 |
| 640 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 662 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
| 641 std::string serialized = in_pol.SerializeAsString(); | 663 std::string serialized = in_pol.SerializeAsString(); |
| 642 std::string signed_serialized; | 664 std::string signed_serialized; |
| 643 em::PolicyFetchResponse signed_policy = BuildProto(serialized, | 665 em::PolicyFetchResponse signed_policy = BuildProto(serialized, |
| 644 fake_value_, | 666 fake_signature_, |
| 645 &signed_serialized); | 667 &signed_serialized); |
| 646 scoped_refptr<SignedSettings> s( | 668 scoped_refptr<SignedSettings> s( |
| 647 SignedSettings::CreateStorePolicyOp(&signed_policy, &d)); | 669 SignedSettings::CreateStorePolicyOp(&signed_policy, &d)); |
| 648 MockSessionManagerClient* client = | 670 MockSessionManagerClient* client = |
| 649 mock_dbus_thread_manager_->mock_session_manager_client(); | 671 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 650 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) | 672 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) |
| 651 .WillOnce(Store(true)) | 673 .WillOnce(Store(true)) |
| 652 .RetiresOnSaturation(); | 674 .RetiresOnSaturation(); |
| 653 | 675 |
| 654 mock_service(s.get(), &m_); | 676 mock_service(s.get(), &m_); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 681 | 703 |
| 682 s->Execute(); | 704 s->Execute(); |
| 683 message_loop_.RunAllPending(); | 705 message_loop_.RunAllPending(); |
| 684 } | 706 } |
| 685 | 707 |
| 686 TEST_F(SignedSettingsTest, RetrievePolicy) { | 708 TEST_F(SignedSettingsTest, RetrievePolicy) { |
| 687 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 709 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
| 688 std::string serialized = in_pol.SerializeAsString(); | 710 std::string serialized = in_pol.SerializeAsString(); |
| 689 std::string signed_serialized; | 711 std::string signed_serialized; |
| 690 em::PolicyFetchResponse signed_policy = BuildProto(serialized, | 712 em::PolicyFetchResponse signed_policy = BuildProto(serialized, |
| 691 fake_value_, | 713 fake_signature_, |
| 692 &signed_serialized); | 714 &signed_serialized); |
| 693 ProtoDelegate d(signed_policy); | 715 ProtoDelegate d(signed_policy); |
| 694 d.expect_success(); | 716 d.expect_success(); |
| 695 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 717 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
| 696 | 718 |
| 697 MockSessionManagerClient* client = | 719 MockSessionManagerClient* client = |
| 698 mock_dbus_thread_manager_->mock_session_manager_client(); | 720 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 699 EXPECT_CALL(*client, RetrievePolicy(_)) | 721 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 700 .WillOnce(Retrieve(signed_serialized)) | 722 .WillOnce(Retrieve(signed_serialized)) |
| 701 .RetiresOnSaturation(); | 723 .RetiresOnSaturation(); |
| 702 | 724 |
| 703 mock_service(s.get(), &m_); | 725 mock_service(s.get(), &m_); |
| 704 std::vector<uint8> fake_sig(fake_value_.c_str(), | 726 EXPECT_CALL(m_, StartVerifyAttempt(serialized, fake_value_signature_, _)) |
| 705 fake_value_.c_str() + fake_value_.length()); | |
| 706 EXPECT_CALL(m_, StartVerifyAttempt(serialized, fake_sig, _)) | |
| 707 .Times(1); | 727 .Times(1); |
| 708 em::PolicyData out_pol; | 728 em::PolicyData out_pol; |
| 709 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 729 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
| 710 .WillOnce(SaveArg<0>(&out_pol)); | 730 .WillOnce(SaveArg<0>(&out_pol)); |
| 711 | 731 |
| 712 s->Execute(); | 732 s->Execute(); |
| 713 message_loop_.RunAllPending(); | 733 message_loop_.RunAllPending(); |
| 714 | 734 |
| 715 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | 735 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); |
| 716 message_loop_.RunAllPending(); | 736 message_loop_.RunAllPending(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 .WillOnce(Retrieve(serialized)) | 784 .WillOnce(Retrieve(serialized)) |
| 765 .RetiresOnSaturation(); | 785 .RetiresOnSaturation(); |
| 766 | 786 |
| 767 s->Execute(); | 787 s->Execute(); |
| 768 message_loop_.RunAllPending(); | 788 message_loop_.RunAllPending(); |
| 769 } | 789 } |
| 770 | 790 |
| 771 TEST_F(SignedSettingsTest, RetrieveMalsignedPolicy) { | 791 TEST_F(SignedSettingsTest, RetrieveMalsignedPolicy) { |
| 772 std::string signed_serialized; | 792 std::string signed_serialized; |
| 773 em::PolicyFetchResponse signed_policy = BuildProto(fake_prop_, | 793 em::PolicyFetchResponse signed_policy = BuildProto(fake_prop_, |
| 774 fake_value_, | 794 fake_signature_, |
| 775 &signed_serialized); | 795 &signed_serialized); |
| 776 ProtoDelegate d(signed_policy); | 796 ProtoDelegate d(signed_policy); |
| 777 d.expect_failure(SignedSettings::BAD_SIGNATURE); | 797 d.expect_failure(SignedSettings::BAD_SIGNATURE); |
| 778 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 798 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
| 779 | 799 |
| 780 MockSessionManagerClient* client = | 800 MockSessionManagerClient* client = |
| 781 mock_dbus_thread_manager_->mock_session_manager_client(); | 801 mock_dbus_thread_manager_->mock_session_manager_client(); |
| 782 EXPECT_CALL(*client, RetrievePolicy(_)) | 802 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 783 .WillOnce(Retrieve(signed_serialized)) | 803 .WillOnce(Retrieve(signed_serialized)) |
| 784 .RetiresOnSaturation(); | 804 .RetiresOnSaturation(); |
| 785 | 805 |
| 786 mock_service(s.get(), &m_); | 806 mock_service(s.get(), &m_); |
| 787 std::vector<uint8> fake_sig(fake_value_.c_str(), | 807 EXPECT_CALL(m_, StartVerifyAttempt(fake_prop_, fake_value_signature_, _)) |
| 788 fake_value_.c_str() + fake_value_.length()); | |
| 789 EXPECT_CALL(m_, StartVerifyAttempt(fake_prop_, fake_sig, _)) | |
| 790 .Times(1); | 808 .Times(1); |
| 791 | 809 |
| 792 s->Execute(); | 810 s->Execute(); |
| 793 message_loop_.RunAllPending(); | 811 message_loop_.RunAllPending(); |
| 794 | 812 |
| 795 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); | 813 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); |
| 796 message_loop_.RunAllPending(); | 814 message_loop_.RunAllPending(); |
| 797 } | 815 } |
| 798 | 816 |
| 799 } // namespace chromeos | 817 } // namespace chromeos |
| OLD | NEW |