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