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