OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 workers()->push_back( | 58 workers()->push_back( |
59 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 59 make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
60 workers()->push_back( | 60 workers()->push_back( |
61 make_scoped_refptr(new FakeModelWorker(GROUP_PASSWORD))); | 61 make_scoped_refptr(new FakeModelWorker(GROUP_PASSWORD))); |
62 (*mutable_routing_info())[BOOKMARKS] = GROUP_UI; | 62 (*mutable_routing_info())[BOOKMARKS] = GROUP_UI; |
63 (*mutable_routing_info())[PASSWORDS] = GROUP_PASSWORD; | 63 (*mutable_routing_info())[PASSWORDS] = GROUP_PASSWORD; |
64 (*mutable_routing_info())[NIGORI] = GROUP_PASSIVE; | 64 (*mutable_routing_info())[NIGORI] = GROUP_PASSIVE; |
65 SyncerCommandTest::SetUp(); | 65 SyncerCommandTest::SetUp(); |
66 entry_factory_.reset(new TestEntryFactory(directory())); | 66 entry_factory_.reset(new TestEntryFactory(directory())); |
67 ExpectNoGroupsToChange(apply_updates_command_); | 67 ExpectNoGroupsToChange(apply_updates_command_); |
68 | |
69 syncable::ReadTransaction trans(FROM_HERE, directory()); | |
70 directory()->GetCryptographer(&trans)->SetNigoriHandler( | |
71 &fake_encryption_handler_); | |
72 fake_encryption_handler_.set_cryptographer( | |
73 directory()->GetCryptographer(&trans)); | |
74 } | 68 } |
75 | 69 |
76 protected: | 70 protected: |
77 DISALLOW_COPY_AND_ASSIGN(ApplyUpdatesCommandTest); | 71 DISALLOW_COPY_AND_ASSIGN(ApplyUpdatesCommandTest); |
78 | 72 |
79 ApplyUpdatesCommand apply_updates_command_; | 73 ApplyUpdatesCommand apply_updates_command_; |
80 FakeEncryptor encryptor_; | |
81 TestIdFactory id_factory_; | 74 TestIdFactory id_factory_; |
82 scoped_ptr<TestEntryFactory> entry_factory_; | 75 scoped_ptr<TestEntryFactory> entry_factory_; |
83 FakeSyncEncryptionHandler fake_encryption_handler_; | |
84 }; | 76 }; |
85 | 77 |
86 TEST_F(ApplyUpdatesCommandTest, Simple) { | 78 TEST_F(ApplyUpdatesCommandTest, Simple) { |
87 string root_server_id = syncable::GetNullId().GetServerId(); | 79 string root_server_id = syncable::GetNullId().GetServerId(); |
88 entry_factory_->CreateUnappliedNewItemWithParent("parent", | 80 entry_factory_->CreateUnappliedNewItemWithParent("parent", |
89 DefaultBookmarkSpecifics(), | 81 DefaultBookmarkSpecifics(), |
90 root_server_id); | 82 root_server_id); |
91 entry_factory_->CreateUnappliedNewItemWithParent("child", | 83 entry_factory_->CreateUnappliedNewItemWithParent("child", |
92 DefaultBookmarkSpecifics(), | 84 DefaultBookmarkSpecifics(), |
93 "parent"); | 85 "parent"); |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 << "conflict"; | 451 << "conflict"; |
460 EXPECT_EQ(1, status->conflict_progress()->EncryptionConflictingItemsSize()) | 452 EXPECT_EQ(1, status->conflict_progress()->EncryptionConflictingItemsSize()) |
461 << "The updates that can't be decrypted should be in encryption " | 453 << "The updates that can't be decrypted should be in encryption " |
462 << "conflict"; | 454 << "conflict"; |
463 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount()) | 455 EXPECT_EQ(0, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
464 << "No update that can't be decrypted should be applied"; | 456 << "No update that can't be decrypted should be applied"; |
465 } | 457 } |
466 } | 458 } |
467 | 459 |
468 TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) { | 460 TEST_F(ApplyUpdatesCommandTest, SomeUndecryptablePassword) { |
| 461 Cryptographer* cryptographer; |
469 // Only decryptable password updates should be applied. | 462 // Only decryptable password updates should be applied. |
470 { | 463 { |
471 sync_pb::EntitySpecifics specifics; | 464 sync_pb::EntitySpecifics specifics; |
472 sync_pb::PasswordSpecificsData data; | 465 sync_pb::PasswordSpecificsData data; |
473 data.set_origin("http://example.com/1"); | 466 data.set_origin("http://example.com/1"); |
474 { | 467 { |
475 syncable::ReadTransaction trans(FROM_HERE, directory()); | 468 syncable::ReadTransaction trans(FROM_HERE, directory()); |
476 Cryptographer* cryptographer = directory()->GetCryptographer(&trans); | 469 cryptographer = directory()->GetCryptographer(&trans); |
477 | 470 |
478 KeyParams params = {"localhost", "dummy", "foobar"}; | 471 KeyParams params = {"localhost", "dummy", "foobar"}; |
479 cryptographer->AddKey(params); | 472 cryptographer->AddKey(params); |
480 | 473 |
481 cryptographer->Encrypt(data, | 474 cryptographer->Encrypt(data, |
482 specifics.mutable_password()->mutable_encrypted()); | 475 specifics.mutable_password()->mutable_encrypted()); |
483 } | 476 } |
484 entry_factory_->CreateUnappliedNewItem("item1", specifics, false); | 477 entry_factory_->CreateUnappliedNewItem("item1", specifics, false); |
485 } | 478 } |
486 { | 479 { |
487 // Create a new cryptographer, independent of the one in the session. | 480 // Create a new cryptographer, independent of the one in the session. |
488 Cryptographer cryptographer(&encryptor_); | 481 Cryptographer other_cryptographer(cryptographer->encryptor()); |
489 KeyParams params = {"localhost", "dummy", "bazqux"}; | 482 KeyParams params = {"localhost", "dummy", "bazqux"}; |
490 cryptographer.AddKey(params); | 483 other_cryptographer.AddKey(params); |
491 | 484 |
492 sync_pb::EntitySpecifics specifics; | 485 sync_pb::EntitySpecifics specifics; |
493 sync_pb::PasswordSpecificsData data; | 486 sync_pb::PasswordSpecificsData data; |
494 data.set_origin("http://example.com/2"); | 487 data.set_origin("http://example.com/2"); |
495 | 488 |
496 cryptographer.Encrypt(data, | 489 other_cryptographer.Encrypt(data, |
497 specifics.mutable_password()->mutable_encrypted()); | 490 specifics.mutable_password()->mutable_encrypted()); |
498 entry_factory_->CreateUnappliedNewItem("item2", specifics, false); | 491 entry_factory_->CreateUnappliedNewItem("item2", specifics, false); |
499 } | 492 } |
500 | 493 |
501 ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD); | 494 ExpectGroupToChange(apply_updates_command_, GROUP_PASSWORD); |
502 apply_updates_command_.ExecuteImpl(session()); | 495 apply_updates_command_.ExecuteImpl(session()); |
503 | 496 |
504 sessions::StatusController* status = session()->mutable_status_controller(); | 497 sessions::StatusController* status = session()->mutable_status_controller(); |
505 EXPECT_TRUE(status->HasConflictingUpdates()) | 498 EXPECT_TRUE(status->HasConflictingUpdates()) |
506 << "Updates that can't be decrypted should trigger the syncer to have " | 499 << "Updates that can't be decrypted should trigger the syncer to have " |
(...skipping 18 matching lines...) Expand all Loading... |
525 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) { | 518 TEST_F(ApplyUpdatesCommandTest, NigoriUpdate) { |
526 // Storing the cryptographer separately is bad, but for this test we | 519 // Storing the cryptographer separately is bad, but for this test we |
527 // know it's safe. | 520 // know it's safe. |
528 Cryptographer* cryptographer; | 521 Cryptographer* cryptographer; |
529 ModelTypeSet encrypted_types; | 522 ModelTypeSet encrypted_types; |
530 encrypted_types.Put(PASSWORDS); | 523 encrypted_types.Put(PASSWORDS); |
531 encrypted_types.Put(NIGORI); | 524 encrypted_types.Put(NIGORI); |
532 { | 525 { |
533 syncable::ReadTransaction trans(FROM_HERE, directory()); | 526 syncable::ReadTransaction trans(FROM_HERE, directory()); |
534 cryptographer = directory()->GetCryptographer(&trans); | 527 cryptographer = directory()->GetCryptographer(&trans); |
535 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); | 528 EXPECT_TRUE(directory()->GetNigoriHandler()->GetEncryptedTypes(&trans) |
| 529 .Equals(encrypted_types)); |
536 } | 530 } |
537 | 531 |
538 // Nigori node updates should update the Cryptographer. | 532 // Nigori node updates should update the Cryptographer. |
539 Cryptographer other_cryptographer(&encryptor_); | 533 Cryptographer other_cryptographer(cryptographer->encryptor()); |
540 KeyParams params = {"localhost", "dummy", "foobar"}; | 534 KeyParams params = {"localhost", "dummy", "foobar"}; |
541 other_cryptographer.AddKey(params); | 535 other_cryptographer.AddKey(params); |
542 | 536 |
543 sync_pb::EntitySpecifics specifics; | 537 sync_pb::EntitySpecifics specifics; |
544 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 538 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
545 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 539 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
546 nigori->set_encrypt_everything(true); | 540 nigori->set_encrypt_everything(true); |
547 entry_factory_->CreateUnappliedNewItem( | 541 entry_factory_->CreateUnappliedNewItem( |
548 ModelTypeToRootTag(NIGORI), specifics, true); | 542 ModelTypeToRootTag(NIGORI), specifics, true); |
549 EXPECT_FALSE(cryptographer->has_pending_keys()); | 543 EXPECT_FALSE(cryptographer->has_pending_keys()); |
550 | 544 |
551 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); | 545 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); |
552 apply_updates_command_.ExecuteImpl(session()); | 546 apply_updates_command_.ExecuteImpl(session()); |
553 | 547 |
554 sessions::StatusController* status = session()->mutable_status_controller(); | 548 sessions::StatusController* status = session()->mutable_status_controller(); |
555 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 549 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
556 ASSERT_TRUE(status->update_progress()); | 550 ASSERT_TRUE(status->update_progress()); |
557 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) | 551 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) |
558 << "All updates should have been attempted"; | 552 << "All updates should have been attempted"; |
559 ASSERT_TRUE(status->conflict_progress()); | 553 ASSERT_TRUE(status->conflict_progress()); |
560 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize()) | 554 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize()) |
561 << "The nigori update shouldn't be in conflict"; | 555 << "The nigori update shouldn't be in conflict"; |
562 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) | 556 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
563 << "The nigori update should be applied"; | 557 << "The nigori update should be applied"; |
564 | 558 |
565 EXPECT_FALSE(cryptographer->is_ready()); | 559 EXPECT_FALSE(cryptographer->is_ready()); |
566 EXPECT_TRUE(cryptographer->has_pending_keys()); | 560 EXPECT_TRUE(cryptographer->has_pending_keys()); |
567 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(ModelTypeSet::All())); | 561 { |
| 562 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 563 EXPECT_TRUE(directory()->GetNigoriHandler()->GetEncryptedTypes(&trans) |
| 564 .Equals(ModelTypeSet::All())); |
| 565 } |
568 } | 566 } |
569 | 567 |
570 TEST_F(ApplyUpdatesCommandTest, NigoriUpdateForDisabledTypes) { | 568 TEST_F(ApplyUpdatesCommandTest, NigoriUpdateForDisabledTypes) { |
571 // Storing the cryptographer separately is bad, but for this test we | 569 // Storing the cryptographer separately is bad, but for this test we |
572 // know it's safe. | 570 // know it's safe. |
573 Cryptographer* cryptographer; | 571 Cryptographer* cryptographer; |
574 ModelTypeSet encrypted_types; | 572 ModelTypeSet encrypted_types; |
575 encrypted_types.Put(PASSWORDS); | 573 encrypted_types.Put(PASSWORDS); |
576 encrypted_types.Put(NIGORI); | 574 encrypted_types.Put(NIGORI); |
577 { | 575 { |
578 syncable::ReadTransaction trans(FROM_HERE, directory()); | 576 syncable::ReadTransaction trans(FROM_HERE, directory()); |
579 cryptographer = directory()->GetCryptographer(&trans); | 577 cryptographer = directory()->GetCryptographer(&trans); |
580 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); | 578 EXPECT_TRUE(directory()->GetNigoriHandler()->GetEncryptedTypes(&trans) |
| 579 .Equals(encrypted_types)); |
581 } | 580 } |
582 | 581 |
583 // Nigori node updates should update the Cryptographer. | 582 // Nigori node updates should update the Cryptographer. |
584 Cryptographer other_cryptographer(&encryptor_); | 583 Cryptographer other_cryptographer(cryptographer->encryptor()); |
585 KeyParams params = {"localhost", "dummy", "foobar"}; | 584 KeyParams params = {"localhost", "dummy", "foobar"}; |
586 other_cryptographer.AddKey(params); | 585 other_cryptographer.AddKey(params); |
587 | 586 |
588 sync_pb::EntitySpecifics specifics; | 587 sync_pb::EntitySpecifics specifics; |
589 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 588 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
590 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 589 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
591 nigori->set_encrypt_everything(true); | 590 nigori->set_encrypt_everything(true); |
592 entry_factory_->CreateUnappliedNewItem( | 591 entry_factory_->CreateUnappliedNewItem( |
593 ModelTypeToRootTag(NIGORI), specifics, true); | 592 ModelTypeToRootTag(NIGORI), specifics, true); |
594 EXPECT_FALSE(cryptographer->has_pending_keys()); | 593 EXPECT_FALSE(cryptographer->has_pending_keys()); |
595 | 594 |
596 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); | 595 ExpectGroupToChange(apply_updates_command_, GROUP_PASSIVE); |
597 apply_updates_command_.ExecuteImpl(session()); | 596 apply_updates_command_.ExecuteImpl(session()); |
598 | 597 |
599 sessions::StatusController* status = session()->mutable_status_controller(); | 598 sessions::StatusController* status = session()->mutable_status_controller(); |
600 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); | 599 sessions::ScopedModelSafeGroupRestriction r(status, GROUP_PASSIVE); |
601 ASSERT_TRUE(status->update_progress()); | 600 ASSERT_TRUE(status->update_progress()); |
602 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) | 601 EXPECT_EQ(1, status->update_progress()->AppliedUpdatesSize()) |
603 << "All updates should have been attempted"; | 602 << "All updates should have been attempted"; |
604 ASSERT_TRUE(status->conflict_progress()); | 603 ASSERT_TRUE(status->conflict_progress()); |
605 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize()) | 604 EXPECT_EQ(0, status->conflict_progress()->SimpleConflictingItemsSize()) |
606 << "The nigori update shouldn't be in conflict"; | 605 << "The nigori update shouldn't be in conflict"; |
607 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) | 606 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
608 << "The nigori update should be applied"; | 607 << "The nigori update should be applied"; |
609 | 608 |
610 EXPECT_FALSE(cryptographer->is_ready()); | 609 EXPECT_FALSE(cryptographer->is_ready()); |
611 EXPECT_TRUE(cryptographer->has_pending_keys()); | 610 EXPECT_TRUE(cryptographer->has_pending_keys()); |
612 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(ModelTypeSet::All())); | 611 { |
| 612 syncable::ReadTransaction trans(FROM_HERE, directory()); |
| 613 EXPECT_TRUE(directory()->GetNigoriHandler()->GetEncryptedTypes(&trans) |
| 614 .Equals(ModelTypeSet::All())); |
| 615 } |
613 } | 616 } |
614 | 617 |
615 // Create some local unsynced and unencrypted data. Apply a nigori update that | 618 // Create some local unsynced and unencrypted data. Apply a nigori update that |
616 // turns on encryption for the unsynced data. Ensure we properly encrypt the | 619 // turns on encryption for the unsynced data. Ensure we properly encrypt the |
617 // data as part of the nigori update. Apply another nigori update with no | 620 // data as part of the nigori update. Apply another nigori update with no |
618 // changes. Ensure we ignore already-encrypted unsynced data and that nothing | 621 // changes. Ensure we ignore already-encrypted unsynced data and that nothing |
619 // breaks. | 622 // breaks. |
620 TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { | 623 TEST_F(ApplyUpdatesCommandTest, EncryptUnsyncedChanges) { |
621 // Storing the cryptographer separately is bad, but for this test we | 624 // Storing the cryptographer separately is bad, but for this test we |
622 // know it's safe. | 625 // know it's safe. |
623 Cryptographer* cryptographer; | 626 Cryptographer* cryptographer; |
624 ModelTypeSet encrypted_types; | 627 ModelTypeSet encrypted_types; |
625 encrypted_types.Put(PASSWORDS); | 628 encrypted_types.Put(PASSWORDS); |
626 encrypted_types.Put(NIGORI); | 629 encrypted_types.Put(NIGORI); |
627 { | 630 { |
628 syncable::ReadTransaction trans(FROM_HERE, directory()); | 631 syncable::ReadTransaction trans(FROM_HERE, directory()); |
629 cryptographer = directory()->GetCryptographer(&trans); | 632 cryptographer = directory()->GetCryptographer(&trans); |
630 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); | 633 EXPECT_TRUE(directory()->GetNigoriHandler()->GetEncryptedTypes(&trans) |
| 634 .Equals(encrypted_types)); |
631 | 635 |
632 // With default encrypted_types, this should be true. | 636 // With default encrypted_types, this should be true. |
633 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 637 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
634 | 638 |
635 Syncer::UnsyncedMetaHandles handles; | 639 Syncer::UnsyncedMetaHandles handles; |
636 GetUnsyncedEntries(&trans, &handles); | 640 GetUnsyncedEntries(&trans, &handles); |
637 EXPECT_TRUE(handles.empty()); | 641 EXPECT_TRUE(handles.empty()); |
638 } | 642 } |
639 | 643 |
640 // Create unsynced bookmarks without encryption. | 644 // Create unsynced bookmarks without encryption. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) | 701 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
698 << "The nigori update should be applied"; | 702 << "The nigori update should be applied"; |
699 } | 703 } |
700 EXPECT_FALSE(cryptographer->has_pending_keys()); | 704 EXPECT_FALSE(cryptographer->has_pending_keys()); |
701 EXPECT_TRUE(cryptographer->is_ready()); | 705 EXPECT_TRUE(cryptographer->is_ready()); |
702 { | 706 { |
703 syncable::ReadTransaction trans(FROM_HERE, directory()); | 707 syncable::ReadTransaction trans(FROM_HERE, directory()); |
704 | 708 |
705 // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes | 709 // If ProcessUnsyncedChangesForEncryption worked, all our unsynced changes |
706 // should be encrypted now. | 710 // should be encrypted now. |
707 EXPECT_TRUE(ModelTypeSet::All().Equals( | 711 EXPECT_TRUE(directory()->GetNigoriHandler()->GetEncryptedTypes(&trans) |
708 cryptographer->GetEncryptedTypes())); | 712 .Equals(ModelTypeSet::All())); |
709 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 713 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
710 | 714 |
711 Syncer::UnsyncedMetaHandles handles; | 715 Syncer::UnsyncedMetaHandles handles; |
712 GetUnsyncedEntries(&trans, &handles); | 716 GetUnsyncedEntries(&trans, &handles); |
713 EXPECT_EQ(2*batch_s+1, handles.size()); | 717 EXPECT_EQ(2*batch_s+1, handles.size()); |
714 } | 718 } |
715 | 719 |
716 // Simulate another nigori update that doesn't change anything. | 720 // Simulate another nigori update that doesn't change anything. |
717 { | 721 { |
718 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); | 722 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); |
(...skipping 18 matching lines...) Expand all Loading... |
737 << "No updates should be in conflict"; | 741 << "No updates should be in conflict"; |
738 EXPECT_EQ(2, status->update_progress()->SuccessfullyAppliedUpdateCount()) | 742 EXPECT_EQ(2, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
739 << "The nigori update should be applied"; | 743 << "The nigori update should be applied"; |
740 } | 744 } |
741 EXPECT_FALSE(cryptographer->has_pending_keys()); | 745 EXPECT_FALSE(cryptographer->has_pending_keys()); |
742 EXPECT_TRUE(cryptographer->is_ready()); | 746 EXPECT_TRUE(cryptographer->is_ready()); |
743 { | 747 { |
744 syncable::ReadTransaction trans(FROM_HERE, directory()); | 748 syncable::ReadTransaction trans(FROM_HERE, directory()); |
745 | 749 |
746 // All our changes should still be encrypted. | 750 // All our changes should still be encrypted. |
747 EXPECT_TRUE(ModelTypeSet::All().Equals( | 751 EXPECT_TRUE(directory()->GetNigoriHandler()->GetEncryptedTypes(&trans) |
748 cryptographer->GetEncryptedTypes())); | 752 .Equals(ModelTypeSet::All())); |
749 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 753 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
750 | 754 |
751 Syncer::UnsyncedMetaHandles handles; | 755 Syncer::UnsyncedMetaHandles handles; |
752 GetUnsyncedEntries(&trans, &handles); | 756 GetUnsyncedEntries(&trans, &handles); |
753 EXPECT_EQ(2*batch_s+1, handles.size()); | 757 EXPECT_EQ(2*batch_s+1, handles.size()); |
754 } | 758 } |
755 } | 759 } |
756 | 760 |
757 TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) { | 761 TEST_F(ApplyUpdatesCommandTest, CannotEncryptUnsyncedChanges) { |
758 // Storing the cryptographer separately is bad, but for this test we | 762 // Storing the cryptographer separately is bad, but for this test we |
759 // know it's safe. | 763 // know it's safe. |
760 Cryptographer* cryptographer; | 764 Cryptographer* cryptographer; |
761 ModelTypeSet encrypted_types; | 765 ModelTypeSet encrypted_types; |
762 encrypted_types.Put(PASSWORDS); | 766 encrypted_types.Put(PASSWORDS); |
763 encrypted_types.Put(NIGORI); | 767 encrypted_types.Put(NIGORI); |
764 { | 768 { |
765 syncable::ReadTransaction trans(FROM_HERE, directory()); | 769 syncable::ReadTransaction trans(FROM_HERE, directory()); |
766 cryptographer = directory()->GetCryptographer(&trans); | 770 cryptographer = directory()->GetCryptographer(&trans); |
767 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals(encrypted_types)); | 771 EXPECT_TRUE(directory()->GetNigoriHandler()->GetEncryptedTypes(&trans) |
| 772 .Equals(encrypted_types)); |
768 | 773 |
769 // With default encrypted_types, this should be true. | 774 // With default encrypted_types, this should be true. |
770 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 775 EXPECT_TRUE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
771 | 776 |
772 Syncer::UnsyncedMetaHandles handles; | 777 Syncer::UnsyncedMetaHandles handles; |
773 GetUnsyncedEntries(&trans, &handles); | 778 GetUnsyncedEntries(&trans, &handles); |
774 EXPECT_TRUE(handles.empty()); | 779 EXPECT_TRUE(handles.empty()); |
775 } | 780 } |
776 | 781 |
777 // Create unsynced bookmarks without encryption. | 782 // Create unsynced bookmarks without encryption. |
(...skipping 13 matching lines...) Expand all Loading... |
791 // Next five items are children of the root. | 796 // Next five items are children of the root. |
792 for (; i < 2*batch_s; ++i) { | 797 for (; i < 2*batch_s; ++i) { |
793 entry_factory_->CreateUnsyncedItem( | 798 entry_factory_->CreateUnsyncedItem( |
794 id_factory_.NewLocalId(), id_factory_.root(), | 799 id_factory_.NewLocalId(), id_factory_.root(), |
795 base::StringPrintf("Item %"PRIuS"", i), false, | 800 base::StringPrintf("Item %"PRIuS"", i), false, |
796 BOOKMARKS, NULL); | 801 BOOKMARKS, NULL); |
797 } | 802 } |
798 | 803 |
799 // We encrypt with new keys, triggering the local cryptographer to be unready | 804 // We encrypt with new keys, triggering the local cryptographer to be unready |
800 // and unable to decrypt data (once updated). | 805 // and unable to decrypt data (once updated). |
801 Cryptographer other_cryptographer(&encryptor_); | 806 Cryptographer other_cryptographer(cryptographer->encryptor()); |
802 KeyParams params = {"localhost", "dummy", "foobar"}; | 807 KeyParams params = {"localhost", "dummy", "foobar"}; |
803 other_cryptographer.AddKey(params); | 808 other_cryptographer.AddKey(params); |
804 sync_pb::EntitySpecifics specifics; | 809 sync_pb::EntitySpecifics specifics; |
805 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); | 810 sync_pb::NigoriSpecifics* nigori = specifics.mutable_nigori(); |
806 other_cryptographer.GetKeys(nigori->mutable_encrypted()); | 811 other_cryptographer.GetKeys(nigori->mutable_encrypted()); |
807 nigori->set_encrypt_everything(true); | 812 nigori->set_encrypt_everything(true); |
808 encrypted_types.Put(BOOKMARKS); | 813 encrypted_types.Put(BOOKMARKS); |
809 entry_factory_->CreateUnappliedNewItem( | 814 entry_factory_->CreateUnappliedNewItem( |
810 ModelTypeToRootTag(NIGORI), specifics, true); | 815 ModelTypeToRootTag(NIGORI), specifics, true); |
811 EXPECT_FALSE(cryptographer->has_pending_keys()); | 816 EXPECT_FALSE(cryptographer->has_pending_keys()); |
(...skipping 25 matching lines...) Expand all Loading... |
837 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) | 842 EXPECT_EQ(1, status->update_progress()->SuccessfullyAppliedUpdateCount()) |
838 << "The nigori update should be applied"; | 843 << "The nigori update should be applied"; |
839 EXPECT_FALSE(cryptographer->is_ready()); | 844 EXPECT_FALSE(cryptographer->is_ready()); |
840 EXPECT_TRUE(cryptographer->has_pending_keys()); | 845 EXPECT_TRUE(cryptographer->has_pending_keys()); |
841 { | 846 { |
842 syncable::ReadTransaction trans(FROM_HERE, directory()); | 847 syncable::ReadTransaction trans(FROM_HERE, directory()); |
843 | 848 |
844 // Since we have pending keys, we would have failed to encrypt, but the | 849 // Since we have pending keys, we would have failed to encrypt, but the |
845 // cryptographer should be updated. | 850 // cryptographer should be updated. |
846 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); | 851 EXPECT_FALSE(VerifyUnsyncedChangesAreEncrypted(&trans, encrypted_types)); |
847 EXPECT_TRUE(cryptographer->GetEncryptedTypes().Equals( | 852 EXPECT_TRUE(directory()->GetNigoriHandler()->GetEncryptedTypes(&trans) |
848 ModelTypeSet().All())); | 853 .Equals(ModelTypeSet::All())); |
849 EXPECT_FALSE(cryptographer->is_ready()); | 854 EXPECT_FALSE(cryptographer->is_ready()); |
850 EXPECT_TRUE(cryptographer->has_pending_keys()); | 855 EXPECT_TRUE(cryptographer->has_pending_keys()); |
851 | 856 |
852 Syncer::UnsyncedMetaHandles handles; | 857 Syncer::UnsyncedMetaHandles handles; |
853 GetUnsyncedEntries(&trans, &handles); | 858 GetUnsyncedEntries(&trans, &handles); |
854 EXPECT_EQ(2*batch_s+1, handles.size()); | 859 EXPECT_EQ(2*batch_s+1, handles.size()); |
855 } | 860 } |
856 } | 861 } |
857 | 862 |
858 } // namespace syncer | 863 } // namespace syncer |
OLD | NEW |