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 // Speicalize the template for base::Value obects because these compare | |
Mattias Nissler (ping if slow)
2011/10/07 11:02:57
typos!
pastarmovj
2011/10/13 11:25:06
Done.
| |
86 // differently. | |
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), |
124 fake_signature_("false"), | |
107 fake_value_("false"), | 125 fake_value_("false"), |
108 message_loop_(MessageLoop::TYPE_UI), | 126 message_loop_(MessageLoop::TYPE_UI), |
109 ui_thread_(BrowserThread::UI, &message_loop_), | 127 ui_thread_(BrowserThread::UI, &message_loop_), |
110 file_thread_(BrowserThread::FILE), | 128 file_thread_(BrowserThread::FILE), |
111 mock_(new MockKeyUtils), | 129 mock_(new MockKeyUtils), |
112 injector_(mock_) /* injector_ takes ownership of mock_ */ { | 130 injector_(mock_) /* injector_ takes ownership of mock_ */ { |
113 } | 131 } |
114 | 132 |
115 virtual ~SignedSettingsTest() {} | 133 virtual ~SignedSettingsTest() {} |
116 | 134 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 em::PolicyFetchResponse fake_policy; | 284 em::PolicyFetchResponse fake_policy; |
267 if (!data.empty()) | 285 if (!data.empty()) |
268 fake_policy.set_policy_data(data); | 286 fake_policy.set_policy_data(data); |
269 if (!sig.empty()) | 287 if (!sig.empty()) |
270 fake_policy.set_policy_data_signature(sig); | 288 fake_policy.set_policy_data_signature(sig); |
271 EXPECT_TRUE(fake_policy.SerializeToString(out_serialized)); | 289 EXPECT_TRUE(fake_policy.SerializeToString(out_serialized)); |
272 return fake_policy; | 290 return fake_policy; |
273 } | 291 } |
274 | 292 |
275 void DoRetrieveProperty(const std::string& name, | 293 void DoRetrieveProperty(const std::string& name, |
276 const std::string& value, | 294 const base::Value& value, |
277 em::PolicyData* fake_pol) { | 295 em::PolicyData* fake_pol) { |
278 NormalDelegate<std::string> d(value); | 296 NormalDelegate<const base::Value&> d(value); |
279 d.expect_success(); | 297 d.expect_success(); |
280 scoped_refptr<SignedSettings> s( | 298 scoped_refptr<SignedSettings> s( |
281 SignedSettings::CreateRetrievePropertyOp(name, &d)); | 299 SignedSettings::CreateRetrievePropertyOp(name, &d)); |
282 mock_service(s.get(), &m_); | 300 mock_service(s.get(), &m_); |
283 EXPECT_CALL(m_, GetStatus(_)) | 301 EXPECT_CALL(m_, GetStatus(_)) |
284 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 302 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); |
285 EXPECT_CALL(m_, has_cached_policy()) | 303 EXPECT_CALL(m_, has_cached_policy()) |
286 .WillOnce(Return(true)); | 304 .WillOnce(Return(true)); |
287 | 305 |
288 EXPECT_CALL(m_, cached_policy()) | 306 EXPECT_CALL(m_, cached_policy()) |
289 .WillOnce(ReturnRef(*fake_pol)); | 307 .WillOnce(ReturnRef(*fake_pol)); |
290 | 308 |
291 s->Execute(); | 309 s->Execute(); |
292 message_loop_.RunAllPending(); | 310 message_loop_.RunAllPending(); |
293 } | 311 } |
294 | 312 |
295 const std::string fake_email_; | 313 const std::string fake_email_; |
296 const std::string fake_domain_; | 314 const std::string fake_domain_; |
297 const std::string fake_prop_; | 315 const std::string fake_prop_; |
298 const std::string fake_value_; | 316 const std::string fake_signature_; |
317 const base::StringValue fake_value_; | |
299 MockOwnershipService m_; | 318 MockOwnershipService m_; |
300 | 319 |
301 ScopedTempDir tmpdir_; | 320 ScopedTempDir tmpdir_; |
302 FilePath tmpfile_; | 321 FilePath tmpfile_; |
303 | 322 |
304 MessageLoop message_loop_; | 323 MessageLoop message_loop_; |
305 BrowserThread ui_thread_; | 324 BrowserThread ui_thread_; |
306 BrowserThread file_thread_; | 325 BrowserThread file_thread_; |
307 | 326 |
308 std::vector<uint8> fake_public_key_; | 327 std::vector<uint8> fake_public_key_; |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 } | 497 } |
479 | 498 |
480 TEST_F(SignedSettingsTest, StorePropertyNoKey) { | 499 TEST_F(SignedSettingsTest, StorePropertyNoKey) { |
481 FailingStorePropertyOp(OwnerManager::KEY_UNAVAILABLE); | 500 FailingStorePropertyOp(OwnerManager::KEY_UNAVAILABLE); |
482 } | 501 } |
483 | 502 |
484 TEST_F(SignedSettingsTest, StorePropertyFailed) { | 503 TEST_F(SignedSettingsTest, StorePropertyFailed) { |
485 FailingStorePropertyOp(OwnerManager::OPERATION_FAILED); | 504 FailingStorePropertyOp(OwnerManager::OPERATION_FAILED); |
486 } | 505 } |
487 | 506 |
488 TEST_F(SignedSettingsTest, RetrieveProperty) { | 507 TEST_F(SignedSettingsTest, RetrieveProperty) { |
Chris Masone
2011/10/06 16:13:06
Could you put in a new test to validate the whitel
pastarmovj
2011/10/13 11:25:06
I'd rather not do in this CL. A latter step of thi
| |
489 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 508 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
490 DoRetrieveProperty(fake_prop_, fake_value_, &fake_pol); | 509 base::FundamentalValue fake_value(false); |
510 DoRetrieveProperty(fake_prop_, fake_value, &fake_pol); | |
491 } | 511 } |
492 | 512 |
493 TEST_F(SignedSettingsTest, RetrieveOwnerProperty) { | 513 TEST_F(SignedSettingsTest, RetrieveOwnerProperty) { |
494 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 514 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
495 fake_pol.set_username(fake_email_); | 515 fake_pol.set_username(fake_email_); |
496 DoRetrieveProperty(kDeviceOwner, fake_email_, &fake_pol); | 516 base::StringValue fake_value(fake_email_); |
517 DoRetrieveProperty(kDeviceOwner, fake_value, &fake_pol); | |
497 } | 518 } |
498 | 519 |
499 TEST_F(SignedSettingsTest, ExplicitlyAllowNewUsers) { | 520 TEST_F(SignedSettingsTest, ExplicitlyAllowNewUsers) { |
500 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 521 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
501 SetAllowNewUsers(true, &fake_pol); | 522 SetAllowNewUsers(true, &fake_pol); |
502 DoRetrieveProperty(kAccountsPrefAllowNewUser, "true", &fake_pol); | 523 base::FundamentalValue fake_value(true); |
524 DoRetrieveProperty(kAccountsPrefAllowNewUser, fake_value, &fake_pol); | |
503 } | 525 } |
504 | 526 |
505 TEST_F(SignedSettingsTest, ExplicitlyDisallowNewUsers) { | 527 TEST_F(SignedSettingsTest, ExplicitlyDisallowNewUsers) { |
506 std::vector<std::string> whitelist(1, fake_email_ + "m"); | 528 std::vector<std::string> whitelist(1, fake_email_ + "m"); |
507 em::PolicyData fake_pol = BuildPolicyData(whitelist); | 529 em::PolicyData fake_pol = BuildPolicyData(whitelist); |
508 SetAllowNewUsers(false, &fake_pol); | 530 SetAllowNewUsers(false, &fake_pol); |
509 DoRetrieveProperty(kAccountsPrefAllowNewUser, "false", &fake_pol); | 531 base::FundamentalValue fake_value(false); |
532 DoRetrieveProperty(kAccountsPrefAllowNewUser, fake_value, &fake_pol); | |
510 } | 533 } |
511 | 534 |
512 TEST_F(SignedSettingsTest, ImplicitlyDisallowNewUsers) { | 535 TEST_F(SignedSettingsTest, ImplicitlyDisallowNewUsers) { |
513 std::vector<std::string> whitelist(1, fake_email_ + "m"); | 536 std::vector<std::string> whitelist(1, fake_email_ + "m"); |
514 em::PolicyData fake_pol = BuildPolicyData(whitelist); | 537 em::PolicyData fake_pol = BuildPolicyData(whitelist); |
515 DoRetrieveProperty(kAccountsPrefAllowNewUser, "false", &fake_pol); | 538 base::FundamentalValue fake_value(false); |
539 DoRetrieveProperty(kAccountsPrefAllowNewUser, fake_value, &fake_pol); | |
516 } | 540 } |
517 | 541 |
518 TEST_F(SignedSettingsTest, AccidentallyDisallowNewUsers) { | 542 TEST_F(SignedSettingsTest, AccidentallyDisallowNewUsers) { |
519 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 543 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
520 SetAllowNewUsers(false, &fake_pol); | 544 SetAllowNewUsers(false, &fake_pol); |
521 DoRetrieveProperty(kAccountsPrefAllowNewUser, "true", &fake_pol); | 545 base::FundamentalValue fake_value(true); |
546 DoRetrieveProperty(kAccountsPrefAllowNewUser, fake_value, &fake_pol); | |
522 } | 547 } |
523 | 548 |
524 TEST_F(SignedSettingsTest, RetrievePropertyNotFound) { | 549 TEST_F(SignedSettingsTest, RetrievePropertyNotFound) { |
525 NormalDelegate<std::string> d(fake_value_); | 550 NormalDelegate<const base::Value&> d(fake_value_); |
526 d.expect_failure(SignedSettings::NOT_FOUND); | 551 d.expect_failure(SignedSettings::NOT_FOUND); |
527 scoped_refptr<SignedSettings> s( | 552 scoped_refptr<SignedSettings> s( |
528 SignedSettings::CreateRetrievePropertyOp("unknown_prop", &d)); | 553 SignedSettings::CreateRetrievePropertyOp("unknown_prop", &d)); |
529 mock_service(s.get(), &m_); | 554 mock_service(s.get(), &m_); |
530 EXPECT_CALL(m_, GetStatus(_)) | 555 EXPECT_CALL(m_, GetStatus(_)) |
531 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 556 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); |
532 EXPECT_CALL(m_, has_cached_policy()) | 557 EXPECT_CALL(m_, has_cached_policy()) |
533 .WillOnce(Return(true)); | 558 .WillOnce(Return(true)); |
534 | 559 |
535 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 560 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
536 EXPECT_CALL(m_, cached_policy()) | 561 EXPECT_CALL(m_, cached_policy()) |
537 .WillOnce(ReturnRef(fake_pol)); | 562 .WillOnce(ReturnRef(fake_pol)); |
538 | 563 |
539 s->Execute(); | 564 s->Execute(); |
540 message_loop_.RunAllPending(); | 565 message_loop_.RunAllPending(); |
541 } | 566 } |
542 | 567 |
543 ACTION_P(Retrieve, s) { (*arg0)((void*)arg1, s.c_str(), s.length()); } | 568 ACTION_P(Retrieve, s) { (*arg0)((void*)arg1, s.c_str(), s.length()); } |
544 ACTION_P(FinishKeyOp, s) { arg2->OnKeyOpComplete(OwnerManager::SUCCESS, s); } | 569 ACTION_P(FinishKeyOp, s) { arg2->OnKeyOpComplete(OwnerManager::SUCCESS, s); } |
545 | 570 |
546 TEST_F(SignedSettingsTest, RetrievePolicyToRetrieveProperty) { | 571 TEST_F(SignedSettingsTest, RetrievePolicyToRetrieveProperty) { |
547 NormalDelegate<std::string> d(fake_value_); | 572 base::FundamentalValue fake_value(false); |
573 NormalDelegate<const base::Value&> d(fake_value); | |
548 d.expect_success(); | 574 d.expect_success(); |
549 scoped_refptr<SignedSettings> s( | 575 scoped_refptr<SignedSettings> s( |
550 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); | 576 SignedSettings::CreateRetrievePropertyOp(fake_prop_, &d)); |
551 | 577 |
552 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); | 578 em::PolicyData fake_pol = BuildPolicyData(std::vector<std::string>()); |
553 std::string data = fake_pol.SerializeAsString(); | 579 std::string data = fake_pol.SerializeAsString(); |
554 std::string signed_serialized; | 580 std::string signed_serialized; |
555 em::PolicyFetchResponse signed_policy = BuildProto(data, | 581 em::PolicyFetchResponse signed_policy = BuildProto(data, |
556 fake_value_, | 582 fake_signature_, |
557 &signed_serialized); | 583 &signed_serialized); |
558 MockLoginLibrary* lib = MockLoginLib(); | 584 MockLoginLibrary* lib = MockLoginLib(); |
559 EXPECT_CALL(*lib, RequestRetrievePolicy(_, _)) | 585 EXPECT_CALL(*lib, RequestRetrievePolicy(_, _)) |
560 .WillOnce(Retrieve(signed_serialized)) | 586 .WillOnce(Retrieve(signed_serialized)) |
561 .RetiresOnSaturation(); | 587 .RetiresOnSaturation(); |
562 | 588 |
563 mock_service(s.get(), &m_); | 589 mock_service(s.get(), &m_); |
564 | 590 |
565 EXPECT_CALL(m_, GetStatus(_)) | 591 EXPECT_CALL(m_, GetStatus(_)) |
566 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)) | 592 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)) |
567 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); | 593 .WillOnce(Return(OwnershipService::OWNERSHIP_TAKEN)); |
568 EXPECT_CALL(m_, has_cached_policy()) | 594 EXPECT_CALL(m_, has_cached_policy()) |
569 .WillOnce(Return(false)) | 595 .WillOnce(Return(false)) |
570 .WillOnce(Return(true)); | 596 .WillOnce(Return(true)); |
571 em::PolicyData out_pol; | 597 em::PolicyData out_pol; |
572 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 598 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
573 .WillOnce(SaveArg<0>(&out_pol)); | 599 .WillOnce(SaveArg<0>(&out_pol)); |
574 EXPECT_CALL(m_, cached_policy()) | 600 EXPECT_CALL(m_, cached_policy()) |
575 .WillOnce(ReturnRef(out_pol)); | 601 .WillOnce(ReturnRef(out_pol)); |
576 | 602 |
577 std::vector<uint8> fake_sig(fake_value_.c_str(), | 603 std::string string_fake_value; |
578 fake_value_.c_str() + fake_value_.length()); | 604 fake_value_.GetAsString(&string_fake_value); |
605 std::vector<uint8> fake_sig( | |
606 string_fake_value.c_str(), | |
607 string_fake_value.c_str() + string_fake_value.length()); | |
579 EXPECT_CALL(m_, StartVerifyAttempt(data, fake_sig, _)) | 608 EXPECT_CALL(m_, StartVerifyAttempt(data, fake_sig, _)) |
580 .WillOnce(FinishKeyOp(fake_sig)) | 609 .WillOnce(FinishKeyOp(fake_sig)) |
581 .RetiresOnSaturation(); | 610 .RetiresOnSaturation(); |
582 | 611 |
583 s->Execute(); | 612 s->Execute(); |
584 message_loop_.RunAllPending(); | 613 message_loop_.RunAllPending(); |
585 UnMockLoginLib(); | 614 UnMockLoginLib(); |
586 } | 615 } |
587 | 616 |
588 TEST_F(SignedSettingsTest, SignAndStorePolicy) { | 617 TEST_F(SignedSettingsTest, SignAndStorePolicy) { |
(...skipping 16 matching lines...) Expand all Loading... | |
605 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 634 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
606 .WillOnce(SaveArg<0>(&out_pol)); | 635 .WillOnce(SaveArg<0>(&out_pol)); |
607 | 636 |
608 // Ask for signature over unsigned policy. | 637 // Ask for signature over unsigned policy. |
609 s->Execute(); | 638 s->Execute(); |
610 message_loop_.RunAllPending(); | 639 message_loop_.RunAllPending(); |
611 | 640 |
612 // Fake out a successful signing. | 641 // Fake out a successful signing. |
613 std::string signed_serialized; | 642 std::string signed_serialized; |
614 em::PolicyFetchResponse signed_policy = BuildProto(data_serialized, | 643 em::PolicyFetchResponse signed_policy = BuildProto(data_serialized, |
615 fake_value_, | 644 fake_signature_, |
616 &signed_serialized); | 645 &signed_serialized); |
617 std::vector<uint8> fake_sig(fake_value_.c_str(), | 646 std::string string_fake_value; |
618 fake_value_.c_str() + fake_value_.length()); | 647 fake_value_.GetAsString(&string_fake_value); |
648 std::vector<uint8> fake_sig( | |
649 string_fake_value.c_str(), | |
650 string_fake_value.c_str() + string_fake_value.length()); | |
Mattias Nissler (ping if slow)
2011/10/07 11:02:57
seems like a helper for this would be nice now tha
pastarmovj
2011/10/13 11:25:06
Done.
| |
619 | 651 |
620 MockLoginLibrary* lib = MockLoginLib(); | 652 MockLoginLibrary* lib = MockLoginLib(); |
621 EXPECT_CALL(*lib, RequestStorePolicy(StrEq(signed_serialized), _, s.get())) | 653 EXPECT_CALL(*lib, RequestStorePolicy(StrEq(signed_serialized), _, s.get())) |
622 .WillOnce(InvokeArgument<1>(static_cast<void*>(s.get()), true)) | 654 .WillOnce(InvokeArgument<1>(static_cast<void*>(s.get()), true)) |
623 .RetiresOnSaturation(); | 655 .RetiresOnSaturation(); |
624 s->OnKeyOpComplete(OwnerManager::SUCCESS, fake_sig); | 656 s->OnKeyOpComplete(OwnerManager::SUCCESS, fake_sig); |
625 message_loop_.RunAllPending(); | 657 message_loop_.RunAllPending(); |
626 UnMockLoginLib(); | 658 UnMockLoginLib(); |
627 } | 659 } |
628 | 660 |
629 TEST_F(SignedSettingsTest, StoreSignedPolicy) { | 661 TEST_F(SignedSettingsTest, StoreSignedPolicy) { |
630 NormalDelegate<bool> d(true); | 662 NormalDelegate<bool> d(true); |
631 d.expect_success(); | 663 d.expect_success(); |
632 | 664 |
633 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 665 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
634 std::string serialized = in_pol.SerializeAsString(); | 666 std::string serialized = in_pol.SerializeAsString(); |
635 std::string signed_serialized; | 667 std::string signed_serialized; |
636 em::PolicyFetchResponse signed_policy = BuildProto(serialized, | 668 em::PolicyFetchResponse signed_policy = BuildProto(serialized, |
637 fake_value_, | 669 fake_signature_, |
638 &signed_serialized); | 670 &signed_serialized); |
639 scoped_refptr<SignedSettings> s( | 671 scoped_refptr<SignedSettings> s( |
640 SignedSettings::CreateStorePolicyOp(&signed_policy, &d)); | 672 SignedSettings::CreateStorePolicyOp(&signed_policy, &d)); |
641 MockLoginLibrary* lib = MockLoginLib(); | 673 MockLoginLibrary* lib = MockLoginLib(); |
642 EXPECT_CALL(*lib, RequestStorePolicy(StrEq(signed_serialized), _, s.get())) | 674 EXPECT_CALL(*lib, RequestStorePolicy(StrEq(signed_serialized), _, s.get())) |
643 .WillOnce(InvokeArgument<1>(static_cast<void*>(s.get()), true)) | 675 .WillOnce(InvokeArgument<1>(static_cast<void*>(s.get()), true)) |
644 .RetiresOnSaturation(); | 676 .RetiresOnSaturation(); |
645 | 677 |
646 mock_service(s.get(), &m_); | 678 mock_service(s.get(), &m_); |
647 em::PolicyData out_pol; | 679 em::PolicyData out_pol; |
(...skipping 26 matching lines...) Expand all Loading... | |
674 | 706 |
675 s->Execute(); | 707 s->Execute(); |
676 message_loop_.RunAllPending(); | 708 message_loop_.RunAllPending(); |
677 } | 709 } |
678 | 710 |
679 TEST_F(SignedSettingsTest, RetrievePolicy) { | 711 TEST_F(SignedSettingsTest, RetrievePolicy) { |
680 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); | 712 em::PolicyData in_pol = BuildPolicyData(std::vector<std::string>()); |
681 std::string serialized = in_pol.SerializeAsString(); | 713 std::string serialized = in_pol.SerializeAsString(); |
682 std::string signed_serialized; | 714 std::string signed_serialized; |
683 em::PolicyFetchResponse signed_policy = BuildProto(serialized, | 715 em::PolicyFetchResponse signed_policy = BuildProto(serialized, |
684 fake_value_, | 716 fake_signature_, |
685 &signed_serialized); | 717 &signed_serialized); |
686 ProtoDelegate d(signed_policy); | 718 ProtoDelegate d(signed_policy); |
687 d.expect_success(); | 719 d.expect_success(); |
688 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 720 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
689 | 721 |
690 MockLoginLibrary* lib = MockLoginLib(); | 722 MockLoginLibrary* lib = MockLoginLib(); |
691 EXPECT_CALL(*lib, RequestRetrievePolicy(_, s.get())) | 723 EXPECT_CALL(*lib, RequestRetrievePolicy(_, s.get())) |
692 .WillOnce(InvokeArgument<0>(static_cast<void*>(s.get()), | 724 .WillOnce(InvokeArgument<0>(static_cast<void*>(s.get()), |
693 signed_serialized.c_str(), | 725 signed_serialized.c_str(), |
694 signed_serialized.length())) | 726 signed_serialized.length())) |
695 .RetiresOnSaturation(); | 727 .RetiresOnSaturation(); |
696 | 728 |
697 mock_service(s.get(), &m_); | 729 mock_service(s.get(), &m_); |
698 std::vector<uint8> fake_sig(fake_value_.c_str(), | 730 std::string string_fake_value; |
699 fake_value_.c_str() + fake_value_.length()); | 731 fake_value_.GetAsString(&string_fake_value); |
732 std::vector<uint8> fake_sig( | |
733 string_fake_value.c_str(), | |
734 string_fake_value.c_str() + string_fake_value.length()); | |
700 EXPECT_CALL(m_, StartVerifyAttempt(serialized, fake_sig, _)) | 735 EXPECT_CALL(m_, StartVerifyAttempt(serialized, fake_sig, _)) |
701 .Times(1); | 736 .Times(1); |
702 em::PolicyData out_pol; | 737 em::PolicyData out_pol; |
703 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) | 738 EXPECT_CALL(m_, set_cached_policy(A<const em::PolicyData&>())) |
704 .WillOnce(SaveArg<0>(&out_pol)); | 739 .WillOnce(SaveArg<0>(&out_pol)); |
705 | 740 |
706 s->Execute(); | 741 s->Execute(); |
707 message_loop_.RunAllPending(); | 742 message_loop_.RunAllPending(); |
708 UnMockLoginLib(); | 743 UnMockLoginLib(); |
709 | 744 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 .RetiresOnSaturation(); | 798 .RetiresOnSaturation(); |
764 | 799 |
765 s->Execute(); | 800 s->Execute(); |
766 message_loop_.RunAllPending(); | 801 message_loop_.RunAllPending(); |
767 UnMockLoginLib(); | 802 UnMockLoginLib(); |
768 } | 803 } |
769 | 804 |
770 TEST_F(SignedSettingsTest, RetrieveMalsignedPolicy) { | 805 TEST_F(SignedSettingsTest, RetrieveMalsignedPolicy) { |
771 std::string signed_serialized; | 806 std::string signed_serialized; |
772 em::PolicyFetchResponse signed_policy = BuildProto(fake_prop_, | 807 em::PolicyFetchResponse signed_policy = BuildProto(fake_prop_, |
773 fake_value_, | 808 fake_signature_, |
774 &signed_serialized); | 809 &signed_serialized); |
775 ProtoDelegate d(signed_policy); | 810 ProtoDelegate d(signed_policy); |
776 d.expect_failure(SignedSettings::BAD_SIGNATURE); | 811 d.expect_failure(SignedSettings::BAD_SIGNATURE); |
777 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); | 812 scoped_refptr<SignedSettings> s(SignedSettings::CreateRetrievePolicyOp(&d)); |
778 | 813 |
779 MockLoginLibrary* lib = MockLoginLib(); | 814 MockLoginLibrary* lib = MockLoginLib(); |
780 EXPECT_CALL(*lib, RequestRetrievePolicy(_, s.get())) | 815 EXPECT_CALL(*lib, RequestRetrievePolicy(_, s.get())) |
781 .WillOnce(InvokeArgument<0>(static_cast<void*>(s.get()), | 816 .WillOnce(InvokeArgument<0>(static_cast<void*>(s.get()), |
782 signed_serialized.c_str(), | 817 signed_serialized.c_str(), |
783 signed_serialized.length())) | 818 signed_serialized.length())) |
784 .RetiresOnSaturation(); | 819 .RetiresOnSaturation(); |
785 | 820 |
786 mock_service(s.get(), &m_); | 821 mock_service(s.get(), &m_); |
787 std::vector<uint8> fake_sig(fake_value_.c_str(), | 822 std::string string_fake_value; |
788 fake_value_.c_str() + fake_value_.length()); | 823 fake_value_.GetAsString(&string_fake_value); |
824 std::vector<uint8> fake_sig( | |
825 string_fake_value.c_str(), | |
826 string_fake_value.c_str() + string_fake_value.length()); | |
789 EXPECT_CALL(m_, StartVerifyAttempt(fake_prop_, fake_sig, _)) | 827 EXPECT_CALL(m_, StartVerifyAttempt(fake_prop_, fake_sig, _)) |
790 .Times(1); | 828 .Times(1); |
791 | 829 |
792 s->Execute(); | 830 s->Execute(); |
793 message_loop_.RunAllPending(); | 831 message_loop_.RunAllPending(); |
794 UnMockLoginLib(); | 832 UnMockLoginLib(); |
795 | 833 |
796 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); | 834 s->OnKeyOpComplete(OwnerManager::OPERATION_FAILED, std::vector<uint8>()); |
797 message_loop_.RunAllPending(); | 835 message_loop_.RunAllPending(); |
798 } | 836 } |
799 | 837 |
800 } // namespace chromeos | 838 } // namespace chromeos |
OLD | NEW |