| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 virtual void compare_expected(T to_compare) = 0; | 70 virtual void compare_expected(T to_compare) = 0; |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 template <class T> | 73 template <class T> |
| 74 class NormalDelegate : public DummyDelegate<T> { | 74 class NormalDelegate : public DummyDelegate<T> { |
| 75 public: | 75 public: |
| 76 explicit NormalDelegate(T to_expect) : DummyDelegate<T>(to_expect) {} | 76 explicit NormalDelegate(T to_expect) : DummyDelegate<T>(to_expect) {} |
| 77 virtual ~NormalDelegate() {} | 77 virtual ~NormalDelegate() {} |
| 78 protected: | 78 protected: |
| 79 virtual void compare_expected(T to_compare) { | 79 virtual void compare_expected(T to_compare) { |
| 80 EXPECT_EQ(this->expected_, to_compare); // without this-> this won't build. | 80 // without this-> this won't build. |
| 81 EXPECT_EQ(this->expected_, to_compare); |
| 81 } | 82 } |
| 82 }; | 83 }; |
| 83 | 84 |
| 85 // Specialized version for Value objects because these compare differently. |
| 86 class PolicyDelegate : public DummyDelegate<const base::Value*> { |
| 87 public: |
| 88 explicit PolicyDelegate(const base::Value* to_expect) |
| 89 : DummyDelegate<const base::Value*>(to_expect) {} |
| 90 virtual ~PolicyDelegate() {} |
| 91 protected: |
| 92 virtual void compare_expected(const base::Value* to_compare) { |
| 93 // without this-> this won't build. |
| 94 EXPECT_TRUE(this->expected_->Equals(to_compare)); |
| 95 // We have the ownership of this value. |
| 96 delete to_compare; |
| 97 } |
| 98 }; |
| 99 |
| 84 class ProtoDelegate : public DummyDelegate<const em::PolicyFetchResponse&> { | 100 class ProtoDelegate : public DummyDelegate<const em::PolicyFetchResponse&> { |
| 85 public: | 101 public: |
| 86 explicit ProtoDelegate(const em::PolicyFetchResponse& e) | 102 explicit ProtoDelegate(const em::PolicyFetchResponse& e) |
| 87 : DummyDelegate<const em::PolicyFetchResponse&>(e) { | 103 : DummyDelegate<const em::PolicyFetchResponse&>(e) { |
| 88 } | 104 } |
| 89 virtual ~ProtoDelegate() {} | 105 virtual ~ProtoDelegate() {} |
| 90 protected: | 106 protected: |
| 91 virtual void compare_expected(const em::PolicyFetchResponse& to_compare) { | 107 virtual void compare_expected(const em::PolicyFetchResponse& to_compare) { |
| 92 std::string ex_string, comp_string; | 108 std::string ex_string, comp_string; |
| 93 EXPECT_TRUE(expected_.SerializeToString(&ex_string)); | 109 EXPECT_TRUE(expected_.SerializeToString(&ex_string)); |
| 94 EXPECT_TRUE(to_compare.SerializeToString(&comp_string)); | 110 EXPECT_TRUE(to_compare.SerializeToString(&comp_string)); |
| 95 EXPECT_EQ(ex_string, comp_string); | 111 EXPECT_EQ(ex_string, comp_string); |
| 96 } | 112 } |
| 97 }; | 113 }; |
| 98 | 114 |
| 99 } // anonymous namespace | 115 } // anonymous namespace |
| 100 | 116 |
| 101 class SignedSettingsTest : public testing::Test { | 117 class SignedSettingsTest : public testing::Test { |
| 102 public: | 118 public: |
| 103 SignedSettingsTest() | 119 SignedSettingsTest() |
| 104 : fake_email_("fakey@example.com"), | 120 : fake_email_("fakey@example.com"), |
| 105 fake_domain_("*@example.com"), | 121 fake_domain_("*@example.com"), |
| 106 fake_prop_(kAccountsPrefAllowGuest), | 122 fake_prop_(kAccountsPrefAllowGuest), |
| 107 fake_value_("false"), | 123 fake_signature_("false"), |
| 124 fake_value_(false), |
| 125 fake_value_signature_( |
| 126 fake_signature_.c_str(), |
| 127 fake_signature_.c_str() + fake_signature_.length()), |
| 108 message_loop_(MessageLoop::TYPE_UI), | 128 message_loop_(MessageLoop::TYPE_UI), |
| 109 ui_thread_(BrowserThread::UI, &message_loop_), | 129 ui_thread_(BrowserThread::UI, &message_loop_), |
| 110 file_thread_(BrowserThread::FILE), | 130 file_thread_(BrowserThread::FILE), |
| 111 mock_(new MockKeyUtils), | 131 mock_(new MockKeyUtils), |
| 112 injector_(mock_) /* injector_ takes ownership of mock_ */ { | 132 injector_(mock_) /* injector_ takes ownership of mock_ */ { |
| 113 } | 133 } |
| 114 | 134 |
| 115 virtual ~SignedSettingsTest() {} | 135 virtual ~SignedSettingsTest() {} |
| 116 | 136 |
| 117 virtual void SetUp() { | 137 virtual void SetUp() { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 em::PolicyFetchResponse fake_policy; | 259 em::PolicyFetchResponse fake_policy; |
| 240 if (!data.empty()) | 260 if (!data.empty()) |
| 241 fake_policy.set_policy_data(data); | 261 fake_policy.set_policy_data(data); |
| 242 if (!sig.empty()) | 262 if (!sig.empty()) |
| 243 fake_policy.set_policy_data_signature(sig); | 263 fake_policy.set_policy_data_signature(sig); |
| 244 EXPECT_TRUE(fake_policy.SerializeToString(out_serialized)); | 264 EXPECT_TRUE(fake_policy.SerializeToString(out_serialized)); |
| 245 return fake_policy; | 265 return fake_policy; |
| 246 } | 266 } |
| 247 | 267 |
| 248 void DoRetrieveProperty(const std::string& name, | 268 void DoRetrieveProperty(const std::string& name, |
| 249 const std::string& value, | 269 const base::Value* value, |
| 250 em::PolicyData* fake_pol) { | 270 em::PolicyData* fake_pol) { |
| 251 NormalDelegate<std::string> d(value); | 271 PolicyDelegate d(value); |
| 252 d.expect_success(); | 272 d.expect_success(); |
| 253 scoped_refptr<SignedSettings> s( | 273 scoped_refptr<SignedSettings> s( |
| 254 SignedSettings::CreateRetrievePropertyOp(name, &d)); | 274 SignedSettings::CreateRetrievePropertyOp(name, &d)); |
| 255 mock_service(s.get(), &m_); | 275 mock_service(s.get(), &m_); |
| 256 EXPECT_CALL(m_, GetStatus(_)) | 276 EXPECT_CALL(m_, GetStatus(_)) |
| 257 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 277 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); |
| 258 EXPECT_CALL(m_, has_cached_policy()) | 278 EXPECT_CALL(m_, has_cached_policy()) |
| 259 .WillOnce(Return(true)); | 279 .WillOnce(Return(true)); |
| 260 | 280 |
| 261 EXPECT_CALL(m_, cached_policy()) | 281 EXPECT_CALL(m_, cached_policy()) |
| 262 .WillOnce(ReturnRef(*fake_pol)); | 282 .WillOnce(ReturnRef(*fake_pol)); |
| 263 | 283 |
| 264 s->Execute(); | 284 s->Execute(); |
| 265 message_loop_.RunAllPending(); | 285 message_loop_.RunAllPending(); |
| 266 } | 286 } |
| 267 | 287 |
| 268 const std::string fake_email_; | 288 const std::string fake_email_; |
| 269 const std::string fake_domain_; | 289 const std::string fake_domain_; |
| 270 const std::string fake_prop_; | 290 const std::string fake_prop_; |
| 271 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_; |
| 272 MockOwnershipService m_; | 294 MockOwnershipService m_; |
| 273 | 295 |
| 274 ScopedTempDir tmpdir_; | 296 ScopedTempDir tmpdir_; |
| 275 FilePath tmpfile_; | 297 FilePath tmpfile_; |
| 276 | 298 |
| 277 MessageLoop message_loop_; | 299 MessageLoop message_loop_; |
| 278 BrowserThread ui_thread_; | 300 BrowserThread ui_thread_; |
| 279 BrowserThread file_thread_; | 301 BrowserThread file_thread_; |
| 280 | 302 |
| 281 std::vector<uint8> fake_public_key_; | 303 std::vector<uint8> fake_public_key_; |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 TEST_F(SignedSettingsTest, StorePropertyNoKey) { | 475 TEST_F(SignedSettingsTest, StorePropertyNoKey) { |
| 454 FailingStorePropertyOp(OwnerManager::KEY_UNAVAILABLE); | 476 FailingStorePropertyOp(OwnerManager::KEY_UNAVAILABLE); |
| 455 } | 477 } |
| 456 | 478 |
| 457 TEST_F(SignedSettingsTest, StorePropertyFailed) { | 479 TEST_F(SignedSettingsTest, StorePropertyFailed) { |
| 458 FailingStorePropertyOp(OwnerManager::OPERATION_FAILED); | 480 FailingStorePropertyOp(OwnerManager::OPERATION_FAILED); |
| 459 } | 481 } |
| 460 | 482 |
| 461 TEST_F(SignedSettingsTest, RetrieveProperty) { | 483 TEST_F(SignedSettingsTest, RetrieveProperty) { |
| 462 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 484 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 463 DoRetrieveProperty(fake_prop_, fake_value_, &fake_pol); | 485 base::FundamentalValue fake_value(false); |
| 486 DoRetrieveProperty(fake_prop_, &fake_value, &fake_pol); |
| 464 } | 487 } |
| 465 | 488 |
| 466 TEST_F(SignedSettingsTest, RetrieveOwnerProperty) { | 489 TEST_F(SignedSettingsTest, RetrieveOwnerProperty) { |
| 467 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 490 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 468 fake_pol.set_username(fake_email_); | 491 fake_pol.set_username(fake_email_); |
| 469 DoRetrieveProperty(kDeviceOwner, fake_email_, &fake_pol); | 492 base::StringValue fake_value(fake_email_); |
| 493 DoRetrieveProperty(kDeviceOwner, &fake_value, &fake_pol); |
| 470 } | 494 } |
| 471 | 495 |
| 472 TEST_F(SignedSettingsTest, ExplicitlyAllowNewUsers) { | 496 TEST_F(SignedSettingsTest, ExplicitlyAllowNewUsers) { |
| 473 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 497 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 474 SetAllowNewUsers(true, &fake_pol); | 498 SetAllowNewUsers(true, &fake_pol); |
| 475 DoRetrieveProperty(kAccountsPrefAllowNewUser, "true", &fake_pol); | 499 base::FundamentalValue fake_value(true); |
| 500 DoRetrieveProperty(kAccountsPrefAllowNewUser, &fake_value, &fake_pol); |
| 476 } | 501 } |
| 477 | 502 |
| 478 TEST_F(SignedSettingsTest, ExplicitlyDisallowNewUsers) { | 503 TEST_F(SignedSettingsTest, ExplicitlyDisallowNewUsers) { |
| 479 std::vector<std::string> whitelist(1, fake_email_ + "m"); | 504 std::vector<std::string> whitelist(1, fake_email_ + "m"); |
| 480 em::PolicyData fake_pol = BuildPolicyData(whitelist); | 505 em::PolicyData fake_pol = BuildPolicyData(whitelist); |
| 481 SetAllowNewUsers(false, &fake_pol); | 506 SetAllowNewUsers(false, &fake_pol); |
| 482 DoRetrieveProperty(kAccountsPrefAllowNewUser, "false", &fake_pol); | 507 base::FundamentalValue fake_value(false); |
| 508 DoRetrieveProperty(kAccountsPrefAllowNewUser, &fake_value, &fake_pol); |
| 483 } | 509 } |
| 484 | 510 |
| 485 TEST_F(SignedSettingsTest, ImplicitlyDisallowNewUsers) { | 511 TEST_F(SignedSettingsTest, ImplicitlyDisallowNewUsers) { |
| 486 std::vector<std::string> whitelist(1, fake_email_ + "m"); | 512 std::vector<std::string> whitelist(1, fake_email_ + "m"); |
| 487 em::PolicyData fake_pol = BuildPolicyData(whitelist); | 513 em::PolicyData fake_pol = BuildPolicyData(whitelist); |
| 488 DoRetrieveProperty(kAccountsPrefAllowNewUser, "false", &fake_pol); | 514 base::FundamentalValue fake_value(false); |
| 515 DoRetrieveProperty(kAccountsPrefAllowNewUser, &fake_value, &fake_pol); |
| 489 } | 516 } |
| 490 | 517 |
| 491 TEST_F(SignedSettingsTest, AccidentallyDisallowNewUsers) { | 518 TEST_F(SignedSettingsTest, AccidentallyDisallowNewUsers) { |
| 492 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 519 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 493 SetAllowNewUsers(false, &fake_pol); | 520 SetAllowNewUsers(false, &fake_pol); |
| 494 DoRetrieveProperty(kAccountsPrefAllowNewUser, "true", &fake_pol); | 521 base::FundamentalValue fake_value(true); |
| 522 DoRetrieveProperty(kAccountsPrefAllowNewUser, &fake_value, &fake_pol); |
| 495 } | 523 } |
| 496 | 524 |
| 497 TEST_F(SignedSettingsTest, RetrievePropertyNotFound) { | 525 TEST_F(SignedSettingsTest, RetrievePropertyNotFound) { |
| 498 NormalDelegate<std::string> d(fake_value_); | 526 PolicyDelegate d(&fake_value_); |
| 499 d.expect_failure(SignedSettings::NOT_FOUND); | 527 d.expect_failure(SignedSettings::NOT_FOUND); |
| 500 scoped_refptr<SignedSettings> s( | 528 scoped_refptr<SignedSettings> s( |
| 501 SignedSettings::CreateRetrievePropertyOp("unknown_prop", &d)); | 529 SignedSettings::CreateRetrievePropertyOp("unknown_prop", &d)); |
| 502 mock_service(s.get(), &m_); | 530 mock_service(s.get(), &m_); |
| 503 EXPECT_CALL(m_, GetStatus(_)) | 531 EXPECT_CALL(m_, GetStatus(_)) |
| 504 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 532 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); |
| 505 EXPECT_CALL(m_, has_cached_policy()) | 533 EXPECT_CALL(m_, has_cached_policy()) |
| 506 .WillOnce(Return(true)); | 534 .WillOnce(Return(true)); |
| 507 | 535 |
| 508 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 536 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 509 EXPECT_CALL(m_, cached_policy()) | 537 EXPECT_CALL(m_, cached_policy()) |
| 510 .WillOnce(ReturnRef(fake_pol)); | 538 .WillOnce(ReturnRef(fake_pol)); |
| 511 | 539 |
| 512 s->Execute(); | 540 s->Execute(); |
| 513 message_loop_.RunAllPending(); | 541 message_loop_.RunAllPending(); |
| 514 } | 542 } |
| 515 | 543 |
| 516 ACTION_P(Retrieve, policy_blob) { arg0.Run(policy_blob); } | 544 ACTION_P(Retrieve, policy_blob) { arg0.Run(policy_blob); } |
| 517 ACTION_P(Store, success) { arg1.Run(success); } | 545 ACTION_P(Store, success) { arg1.Run(success); } |
| 518 ACTION_P(FinishKeyOp, s) { arg2->OnKeyOpComplete(OwnerManager::SUCCESS, s); } | 546 ACTION_P(FinishKeyOp, s) { arg2->OnKeyOpComplete(OwnerManager::SUCCESS, s); } |
| 519 | 547 |
| 520 TEST_F(SignedSettingsTest, RetrievePolicyToRetrieveProperty) { | 548 TEST_F(SignedSettingsTest, RetrievePolicyToRetrieveProperty) { |
| 521 NormalDelegate<std::string> d(fake_value_); | 549 base::FundamentalValue fake_value(false); |
| 550 PolicyDelegate d(&fake_value); |
| 522 d.expect_success(); | 551 d.expect_success(); |
| 523 scoped_refptr<SignedSettings> s( | 552 scoped_refptr<SignedSettings> s( |
| 524 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); | 553 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); |
| 525 | 554 |
| 526 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 555 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
| 527 std::string data = fake_pol.SerializeAsString(); | 556 std::string data = fake_pol.SerializeAsString(); |
| 528 std::string signed_serialized; | 557 std::string signed_serialized; |
| 529 em::PolicyFetchResponse signed_policy = BuildProto(data, | 558 em::PolicyFetchResponse signed_policy = BuildProto(data, |
| 530 fake_value_, | 559 fake_signature_, |
| 531 &signed_serialized); | 560 &signed_serialized); |
| 532 MockSessionManagerClient* client = new MockSessionManagerClient; | 561 MockSessionManagerClient* client = new MockSessionManagerClient; |
| 533 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 562 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
| 534 EXPECT_CALL(*client, RetrievePolicy(_)) | 563 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 535 .WillOnce(Retrieve(signed_serialized)) | 564 .WillOnce(Retrieve(signed_serialized)) |
| 536 .RetiresOnSaturation(); | 565 .RetiresOnSaturation(); |
| 537 | 566 |
| 538 mock_service(s.get(), &m_); | 567 mock_service(s.get(), &m_); |
| 539 | 568 |
| 540 EXPECT_CALL(m_, GetStatus(_)) | 569 EXPECT_CALL(m_, GetStatus(_)) |
| 541 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)) | 570 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)) |
| 542 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 571 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); |
| 543 EXPECT_CALL(m_, has_cached_policy()) | 572 EXPECT_CALL(m_, has_cached_policy()) |
| 544 .WillOnce(Return(false)) | 573 .WillOnce(Return(false)) |
| 545 .WillOnce(Return(true)); | 574 .WillOnce(Return(true)); |
| 546 em::PolicyData out_pol; | 575 em::PolicyData out_pol; |
| 547 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 576 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
| 548 .WillOnce(SaveArg<0>(&out_pol)); | 577 .WillOnce(SaveArg<0>(&out_pol)); |
| 549 EXPECT_CALL(m_, cached_policy()) | 578 EXPECT_CALL(m_, cached_policy()) |
| 550 .WillOnce(ReturnRef(out_pol)); | 579 .WillOnce(ReturnRef(out_pol)); |
| 551 | 580 |
| 552 std::vector<uint8> fake_sig(fake_value_.c_str(), | 581 EXPECT_CALL(m_, StartVerifyAttempt(data, fake_value_signature_, _)) |
| 553 fake_value_.c_str() + fake_value_.length()); | 582 .WillOnce(FinishKeyOp(fake_value_signature_)) |
| 554 EXPECT_CALL(m_, StartVerifyAttempt(data, fake_sig, _)) | |
| 555 .WillOnce(FinishKeyOp(fake_sig)) | |
| 556 .RetiresOnSaturation(); | 583 .RetiresOnSaturation(); |
| 557 | 584 |
| 558 s->Execute(); | 585 s->Execute(); |
| 559 message_loop_.RunAllPending(); | 586 message_loop_.RunAllPending(); |
| 560 } | 587 } |
| 561 | 588 |
| 562 TEST_F(SignedSettingsTest, SignAndStorePolicy) { | 589 TEST_F(SignedSettingsTest, SignAndStorePolicy) { |
| 563 NormalDelegate<bool> d(true); | 590 NormalDelegate<bool> d(true); |
| 564 d.expect_success(); | 591 d.expect_success(); |
| 565 | 592 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 579 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 606 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
| 580 .WillOnce(SaveArg<0>(&out_pol)); | 607 .WillOnce(SaveArg<0>(&out_pol)); |
| 581 | 608 |
| 582 // Ask for signature over unsigned policy. | 609 // Ask for signature over unsigned policy. |
| 583 s->Execute(); | 610 s->Execute(); |
| 584 message_loop_.RunAllPending(); | 611 message_loop_.RunAllPending(); |
| 585 | 612 |
| 586 // Fake out a successful signing. | 613 // Fake out a successful signing. |
| 587 std::string signed_serialized; | 614 std::string signed_serialized; |
| 588 em::PolicyFetchResponse signed_policy = BuildProto(data_serialized, | 615 em::PolicyFetchResponse signed_policy = BuildProto(data_serialized, |
| 589 fake_value_, | 616 fake_signature_, |
| 590 &signed_serialized); | 617 &signed_serialized); |
| 591 std::vector<uint8> fake_sig(fake_value_.c_str(), | |
| 592 fake_value_.c_str() + fake_value_.length()); | |
| 593 | |
| 594 MockSessionManagerClient* client = new MockSessionManagerClient;; | 618 MockSessionManagerClient* client = new MockSessionManagerClient;; |
| 595 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 619 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
| 596 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) | 620 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) |
| 597 .WillOnce(Store(true)) | 621 .WillOnce(Store(true)) |
| 598 .RetiresOnSaturation(); | 622 .RetiresOnSaturation(); |
| 599 s->OnKeyOpComplete(OwnerManager::SUCCESS, fake_sig); | 623 s->OnKeyOpComplete(OwnerManager::SUCCESS, fake_value_signature_); |
| 600 message_loop_.RunAllPending(); | 624 message_loop_.RunAllPending(); |
| 601 } | 625 } |
| 602 | 626 |
| 603 TEST_F(SignedSettingsTest, StoreSignedPolicy) { | 627 TEST_F(SignedSettingsTest, StoreSignedPolicy) { |
| 604 NormalDelegate<bool> d(true); | 628 NormalDelegate<bool> d(true); |
| 605 d.expect_success(); | 629 d.expect_success(); |
| 606 | 630 |
| 607 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 631 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
| 608 std::string serialized = in_pol.SerializeAsString(); | 632 std::string serialized = in_pol.SerializeAsString(); |
| 609 std::string signed_serialized; | 633 std::string signed_serialized; |
| 610 em::PolicyFetchResponse signed_policy = BuildProto(serialized, | 634 em::PolicyFetchResponse signed_policy = BuildProto(serialized, |
| 611 fake_value_, | 635 fake_signature_, |
| 612 &signed_serialized); | 636 &signed_serialized); |
| 613 scoped_refptr<SignedSettings> s( | 637 scoped_refptr<SignedSettings> s( |
| 614 SignedSettings::CreateStorePolicyOp(&signed_policy, &d)); | 638 SignedSettings::CreateStorePolicyOp(&signed_policy, &d)); |
| 615 MockSessionManagerClient* client = new MockSessionManagerClient;; | 639 MockSessionManagerClient* client = new MockSessionManagerClient;; |
| 616 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 640 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
| 617 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) | 641 EXPECT_CALL(*client, StorePolicy(signed_serialized, _)) |
| 618 .WillOnce(Store(true)) | 642 .WillOnce(Store(true)) |
| 619 .RetiresOnSaturation(); | 643 .RetiresOnSaturation(); |
| 620 | 644 |
| 621 mock_service(s.get(), &m_); | 645 mock_service(s.get(), &m_); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 648 | 672 |
| 649 s->Execute(); | 673 s->Execute(); |
| 650 message_loop_.RunAllPending(); | 674 message_loop_.RunAllPending(); |
| 651 } | 675 } |
| 652 | 676 |
| 653 TEST_F(SignedSettingsTest, RetrievePolicy) { | 677 TEST_F(SignedSettingsTest, RetrievePolicy) { |
| 654 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 678 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
| 655 std::string serialized = in_pol.SerializeAsString(); | 679 std::string serialized = in_pol.SerializeAsString(); |
| 656 std::string signed_serialized; | 680 std::string signed_serialized; |
| 657 em::PolicyFetchResponse signed_policy = BuildProto(serialized, | 681 em::PolicyFetchResponse signed_policy = BuildProto(serialized, |
| 658 fake_value_, | 682 fake_signature_, |
| 659 &signed_serialized); | 683 &signed_serialized); |
| 660 ProtoDelegate d(signed_policy); | 684 ProtoDelegate d(signed_policy); |
| 661 d.expect_success(); | 685 d.expect_success(); |
| 662 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 686 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
| 663 | 687 |
| 664 MockSessionManagerClient* client = new MockSessionManagerClient;; | 688 MockSessionManagerClient* client = new MockSessionManagerClient;; |
| 665 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 689 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
| 666 EXPECT_CALL(*client, RetrievePolicy(_)) | 690 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 667 .WillOnce(Retrieve(signed_serialized)) | 691 .WillOnce(Retrieve(signed_serialized)) |
| 668 .RetiresOnSaturation(); | 692 .RetiresOnSaturation(); |
| 669 | 693 |
| 670 mock_service(s.get(), &m_); | 694 mock_service(s.get(), &m_); |
| 671 std::vector<uint8> fake_sig(fake_value_.c_str(), | 695 EXPECT_CALL(m_, StartVerifyAttempt(serialized, fake_value_signature_, _)) |
| 672 fake_value_.c_str() + fake_value_.length()); | |
| 673 EXPECT_CALL(m_, StartVerifyAttempt(serialized, fake_sig, _)) | |
| 674 .Times(1); | 696 .Times(1); |
| 675 em::PolicyData out_pol; | 697 em::PolicyData out_pol; |
| 676 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 698 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
| 677 .WillOnce(SaveArg<0>(&out_pol)); | 699 .WillOnce(SaveArg<0>(&out_pol)); |
| 678 | 700 |
| 679 s->Execute(); | 701 s->Execute(); |
| 680 message_loop_.RunAllPending(); | 702 message_loop_.RunAllPending(); |
| 681 | 703 |
| 682 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); | 704 s->OnKeyOpComplete(OwnerManager::SUCCESS, std::vector<uint8>()); |
| 683 message_loop_.RunAllPending(); | 705 message_loop_.RunAllPending(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 .WillOnce(Retrieve(serialized)) | 753 .WillOnce(Retrieve(serialized)) |
| 732 .RetiresOnSaturation(); | 754 .RetiresOnSaturation(); |
| 733 | 755 |
| 734 s->Execute(); | 756 s->Execute(); |
| 735 message_loop_.RunAllPending(); | 757 message_loop_.RunAllPending(); |
| 736 } | 758 } |
| 737 | 759 |
| 738 TEST_F(SignedSettingsTest, RetrieveMalsignedPolicy) { | 760 TEST_F(SignedSettingsTest, RetrieveMalsignedPolicy) { |
| 739 std::string signed_serialized; | 761 std::string signed_serialized; |
| 740 em::PolicyFetchResponse signed_policy = BuildProto(fake_prop_, | 762 em::PolicyFetchResponse signed_policy = BuildProto(fake_prop_, |
| 741 fake_value_, | 763 fake_signature_, |
| 742 &signed_serialized); | 764 &signed_serialized); |
| 743 ProtoDelegate d(signed_policy); | 765 ProtoDelegate d(signed_policy); |
| 744 d.expect_failure(SignedSettings::BAD_SIGNATURE); | 766 d.expect_failure(SignedSettings::BAD_SIGNATURE); |
| 745 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 767 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
| 746 | 768 |
| 747 MockSessionManagerClient* client = new MockSessionManagerClient;; | 769 MockSessionManagerClient* client = new MockSessionManagerClient;; |
| 748 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); | 770 DBusThreadManager::Get()->set_session_manager_client_for_testing(client); |
| 749 EXPECT_CALL(*client, RetrievePolicy(_)) | 771 EXPECT_CALL(*client, RetrievePolicy(_)) |
| 750 .WillOnce(Retrieve(signed_serialized)) | 772 .WillOnce(Retrieve(signed_serialized)) |
| 751 .RetiresOnSaturation(); | 773 .RetiresOnSaturation(); |
| 752 | 774 |
| 753 mock_service(s.get(), &m_); | 775 mock_service(s.get(), &m_); |
| 754 std::vector<uint8> fake_sig(fake_value_.c_str(), | 776 EXPECT_CALL(m_, StartVerifyAttempt(fake_prop_, fake_value_signature_, _)) |
| 755 fake_value_.c_str() + fake_value_.length()); | |
| 756 EXPECT_CALL(m_, StartVerifyAttempt(fake_prop_, fake_sig, _)) | |
| 757 .Times(1); | 777 .Times(1); |
| 758 | 778 |
| 759 s->Execute(); | 779 s->Execute(); |
| 760 message_loop_.RunAllPending(); | 780 message_loop_.RunAllPending(); |
| 761 | 781 |
| 762 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); | 782 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); |
| 763 message_loop_.RunAllPending(); | 783 message_loop_.RunAllPending(); |
| 764 } | 784 } |
| 765 | 785 |
| 766 } // namespace chromeos | 786 } // namespace chromeos |
| OLD | NEW |