Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: sync/internal_api/sync_manager_impl_unittest.cc

Issue 10824410: [Sync] Refactor passphrase state handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/internal_api/sync_manager_impl.cc ('k') | sync/protocol/client_debug_info.proto » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Unit tests for the SyncApi. Note that a lot of the underlying 5 // Unit tests for the SyncApi. Note that a lot of the underlying
6 // functionality is provided by the Syncable layer, which has its own 6 // functionality is provided by the Syncable layer, which has its own
7 // unit tests. We'll test SyncApi specific things in this harness. 7 // unit tests. We'll test SyncApi specific things in this harness.
8 8
9 #include <cstddef> 9 #include <cstddef>
10 #include <map> 10 #include <map>
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 public: 691 public:
692 MOCK_METHOD2(OnPassphraseRequired, 692 MOCK_METHOD2(OnPassphraseRequired,
693 void(PassphraseRequiredReason, 693 void(PassphraseRequiredReason,
694 const sync_pb::EncryptedData&)); // NOLINT 694 const sync_pb::EncryptedData&)); // NOLINT
695 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT 695 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT
696 MOCK_METHOD1(OnBootstrapTokenUpdated, void(const std::string&)); // NOLINT 696 MOCK_METHOD1(OnBootstrapTokenUpdated, void(const std::string&)); // NOLINT
697 MOCK_METHOD2(OnEncryptedTypesChanged, 697 MOCK_METHOD2(OnEncryptedTypesChanged,
698 void(ModelTypeSet, bool)); // NOLINT 698 void(ModelTypeSet, bool)); // NOLINT
699 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT 699 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT
700 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT 700 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT
701 MOCK_METHOD1(OnPassphraseStateChanged, void(PassphraseState)); // NOLINT
701 }; 702 };
702 703
703 } // namespace 704 } // namespace
704 705
705 class SyncManagerTest : public testing::Test, 706 class SyncManagerTest : public testing::Test,
706 public SyncManager::ChangeDelegate { 707 public SyncManager::ChangeDelegate {
707 protected: 708 protected:
708 enum NigoriStatus { 709 enum NigoriStatus {
709 DONT_WRITE_NIGORI, 710 DONT_WRITE_NIGORI,
710 WRITE_TO_NIGORI 711 WRITE_TO_NIGORI
(...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 THEMES, 1498 THEMES,
1498 true /* is encrypted */)); 1499 true /* is encrypted */));
1499 } 1500 }
1500 1501
1501 // Trigger's a ReEncryptEverything with new passphrase. 1502 // Trigger's a ReEncryptEverything with new passphrase.
1502 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 1503 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
1503 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1504 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1504 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1505 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1505 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1506 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1506 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1507 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1508 EXPECT_CALL(encryption_observer_,
1509 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1507 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1510 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1508 "new_passphrase", true); 1511 "new_passphrase", true);
1509 EXPECT_TRUE(EncryptEverythingEnabledForTest()); 1512 EXPECT_TRUE(EncryptEverythingEnabledForTest());
1510 { 1513 {
1511 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1514 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1512 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(ModelTypeSet::All())); 1515 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(ModelTypeSet::All()));
1513 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1516 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1514 trans.GetWrappedTrans(), 1517 trans.GetWrappedTrans(),
1515 BOOKMARKS, 1518 BOOKMARKS,
1516 true /* is encrypted */)); 1519 true /* is encrypted */));
(...skipping 20 matching lines...) Expand all
1537 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) 1540 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase)
1538 TEST_F(SyncManagerTest, SetInitialGaiaPass) { 1541 TEST_F(SyncManagerTest, SetInitialGaiaPass) {
1539 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); 1542 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED));
1540 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1543 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1541 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1544 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1542 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1545 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1543 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1546 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1544 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1547 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1545 "new_passphrase", 1548 "new_passphrase",
1546 false); 1549 false);
1547 EXPECT_FALSE( 1550 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1548 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1551 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1549 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1552 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1550 { 1553 {
1551 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1554 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1552 ReadNode node(&trans); 1555 ReadNode node(&trans);
1553 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1556 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1554 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); 1557 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
1555 Cryptographer* cryptographer = trans.GetCryptographer(); 1558 Cryptographer* cryptographer = trans.GetCryptographer();
1556 EXPECT_TRUE(cryptographer->is_ready()); 1559 EXPECT_TRUE(cryptographer->is_ready());
1557 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); 1560 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted()));
1558 } 1561 }
(...skipping 12 matching lines...) Expand all
1571 cryptographer->GetBootstrapToken(&bootstrap_token); 1574 cryptographer->GetBootstrapToken(&bootstrap_token);
1572 verifier.Bootstrap(bootstrap_token); 1575 verifier.Bootstrap(bootstrap_token);
1573 } 1576 }
1574 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1577 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1575 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1578 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1576 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1579 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1577 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1580 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1578 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1581 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1579 "new_passphrase", 1582 "new_passphrase",
1580 false); 1583 false);
1581 EXPECT_FALSE( 1584 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1582 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1585 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1583 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1586 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1584 { 1587 {
1585 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1588 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1586 Cryptographer* cryptographer = trans.GetCryptographer(); 1589 Cryptographer* cryptographer = trans.GetCryptographer();
1587 EXPECT_TRUE(cryptographer->is_ready()); 1590 EXPECT_TRUE(cryptographer->is_ready());
1588 // Verify the default key has changed. 1591 // Verify the default key has changed.
1589 sync_pb::EncryptedData encrypted; 1592 sync_pb::EncryptedData encrypted;
1590 cryptographer->GetKeys(&encrypted); 1593 cryptographer->GetKeys(&encrypted);
1591 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); 1594 EXPECT_FALSE(verifier.CanDecrypt(encrypted));
1592 } 1595 }
(...skipping 22 matching lines...) Expand all
1615 root_node, "foo"); 1618 root_node, "foo");
1616 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 1619 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
1617 sync_pb::PasswordSpecificsData data; 1620 sync_pb::PasswordSpecificsData data;
1618 data.set_password_value("secret"); 1621 data.set_password_value("secret");
1619 password_node.SetPasswordSpecifics(data); 1622 password_node.SetPasswordSpecifics(data);
1620 } 1623 }
1621 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1624 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1622 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1625 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1623 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1626 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1624 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1627 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1628 EXPECT_CALL(encryption_observer_,
1629 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1625 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1630 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1626 "new_passphrase", 1631 "new_passphrase",
1627 true); 1632 true);
1628 EXPECT_TRUE( 1633 EXPECT_EQ(CUSTOM_PASSPHRASE,
1629 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1634 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1630 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1635 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1631 { 1636 {
1632 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1637 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1633 Cryptographer* cryptographer = trans.GetCryptographer(); 1638 Cryptographer* cryptographer = trans.GetCryptographer();
1634 EXPECT_TRUE(cryptographer->is_ready()); 1639 EXPECT_TRUE(cryptographer->is_ready());
1635 // Verify the default key has changed. 1640 // Verify the default key has changed.
1636 sync_pb::EncryptedData encrypted; 1641 sync_pb::EncryptedData encrypted;
1637 cryptographer->GetKeys(&encrypted); 1642 cryptographer->GetKeys(&encrypted);
1638 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); 1643 EXPECT_FALSE(verifier.CanDecrypt(encrypted));
1639 1644
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1676 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1672 cryptographer->SetPendingKeys(nigori.encrypted()); 1677 cryptographer->SetPendingKeys(nigori.encrypted());
1673 EXPECT_TRUE(cryptographer->has_pending_keys()); 1678 EXPECT_TRUE(cryptographer->has_pending_keys());
1674 node.SetNigoriSpecifics(nigori); 1679 node.SetNigoriSpecifics(nigori);
1675 } 1680 }
1676 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1681 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1677 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1682 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1678 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1683 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1679 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1684 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1680 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); 1685 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2");
1681 EXPECT_FALSE( 1686 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1682 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1687 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1683 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1688 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1684 { 1689 {
1685 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1690 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1686 Cryptographer* cryptographer = trans.GetCryptographer(); 1691 Cryptographer* cryptographer = trans.GetCryptographer();
1687 EXPECT_TRUE(cryptographer->is_ready()); 1692 EXPECT_TRUE(cryptographer->is_ready());
1688 // Verify we're encrypting with the new key. 1693 // Verify we're encrypting with the new key.
1689 sync_pb::EncryptedData encrypted; 1694 sync_pb::EncryptedData encrypted;
1690 cryptographer->GetKeys(&encrypted); 1695 cryptographer->GetKeys(&encrypted);
1691 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); 1696 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted));
1692 } 1697 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1727 // The bootstrap token should have been updated. Save it to ensure it's based 1732 // The bootstrap token should have been updated. Save it to ensure it's based
1728 // on the new GAIA password. 1733 // on the new GAIA password.
1729 std::string bootstrap_token; 1734 std::string bootstrap_token;
1730 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)) 1735 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_))
1731 .WillOnce(SaveArg<0>(&bootstrap_token)); 1736 .WillOnce(SaveArg<0>(&bootstrap_token));
1732 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_)); 1737 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_));
1733 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1738 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1734 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1739 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1735 "new_gaia", 1740 "new_gaia",
1736 false); 1741 false);
1737 EXPECT_FALSE( 1742 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1738 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1743 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1739 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1744 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1740 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 1745 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
1741 { 1746 {
1742 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1747 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1743 Cryptographer* cryptographer = trans.GetCryptographer(); 1748 Cryptographer* cryptographer = trans.GetCryptographer();
1744 EXPECT_TRUE(cryptographer->is_initialized()); 1749 EXPECT_TRUE(cryptographer->is_initialized());
1745 EXPECT_FALSE(cryptographer->is_ready()); 1750 EXPECT_FALSE(cryptographer->is_ready());
1746 // Verify we're encrypting with the new key, even though we have pending 1751 // Verify we're encrypting with the new key, even though we have pending
1747 // keys. 1752 // keys.
1748 sync_pb::EncryptedData encrypted; 1753 sync_pb::EncryptedData encrypted;
1749 other_cryptographer.GetKeys(&encrypted); 1754 other_cryptographer.GetKeys(&encrypted);
1750 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); 1755 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted));
1751 } 1756 }
1752 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1757 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1753 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1758 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1754 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1759 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1755 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1760 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1756 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1761 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1757 "old_gaia", 1762 "old_gaia",
1758 false); 1763 false);
1759 EXPECT_FALSE( 1764 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1760 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1765 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1761 { 1766 {
1762 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1767 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1763 Cryptographer* cryptographer = trans.GetCryptographer(); 1768 Cryptographer* cryptographer = trans.GetCryptographer();
1764 EXPECT_TRUE(cryptographer->is_ready()); 1769 EXPECT_TRUE(cryptographer->is_ready());
1765 1770
1766 // Verify we're encrypting with the new key. 1771 // Verify we're encrypting with the new key.
1767 sync_pb::EncryptedData encrypted; 1772 sync_pb::EncryptedData encrypted;
1768 other_cryptographer.GetKeys(&encrypted); 1773 other_cryptographer.GetKeys(&encrypted);
1769 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); 1774 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted));
1770 1775
(...skipping 28 matching lines...) Expand all
1799 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1804 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1800 cryptographer->SetPendingKeys(nigori.encrypted()); 1805 cryptographer->SetPendingKeys(nigori.encrypted());
1801 EXPECT_TRUE(cryptographer->has_pending_keys()); 1806 EXPECT_TRUE(cryptographer->has_pending_keys());
1802 nigori.set_using_explicit_passphrase(true); 1807 nigori.set_using_explicit_passphrase(true);
1803 node.SetNigoriSpecifics(nigori); 1808 node.SetNigoriSpecifics(nigori);
1804 } 1809 }
1805 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1810 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1806 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1811 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1807 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1812 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1808 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1813 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1814 EXPECT_CALL(encryption_observer_,
1815 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1809 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); 1816 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit");
1810 EXPECT_TRUE( 1817 EXPECT_EQ(CUSTOM_PASSPHRASE,
1811 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1818 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1812 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1819 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1813 { 1820 {
1814 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1821 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1815 Cryptographer* cryptographer = trans.GetCryptographer(); 1822 Cryptographer* cryptographer = trans.GetCryptographer();
1816 EXPECT_TRUE(cryptographer->is_ready()); 1823 EXPECT_TRUE(cryptographer->is_ready());
1817 // Verify we're encrypting with the new key. 1824 // Verify we're encrypting with the new key.
1818 sync_pb::EncryptedData encrypted; 1825 sync_pb::EncryptedData encrypted;
1819 cryptographer->GetKeys(&encrypted); 1826 cryptographer->GetKeys(&encrypted);
1820 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); 1827 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted));
1821 } 1828 }
(...skipping 21 matching lines...) Expand all
1843 cryptographer->SetPendingKeys(nigori.encrypted()); 1850 cryptographer->SetPendingKeys(nigori.encrypted());
1844 EXPECT_FALSE(cryptographer->is_ready()); 1851 EXPECT_FALSE(cryptographer->is_ready());
1845 } 1852 }
1846 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1853 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1847 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1854 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1848 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1855 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1849 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1856 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1850 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1857 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1851 "passphrase", 1858 "passphrase",
1852 false); 1859 false);
1853 EXPECT_FALSE( 1860 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1854 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1861 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1855 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1862 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1856 { 1863 {
1857 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1864 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1858 Cryptographer* cryptographer = trans.GetCryptographer(); 1865 Cryptographer* cryptographer = trans.GetCryptographer();
1859 EXPECT_TRUE(cryptographer->is_ready()); 1866 EXPECT_TRUE(cryptographer->is_ready());
1860 } 1867 }
1861 } 1868 }
1862 1869
1863 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { 1870 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) {
1864 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1871 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1865 int64 node_id = 0; 1872 int64 node_id = 0;
1866 std::string tag = "foo"; 1873 std::string tag = "foo";
1867 { 1874 {
1868 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1875 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1869 ReadNode root_node(&trans); 1876 ReadNode root_node(&trans);
1870 root_node.InitByRootLookup(); 1877 root_node.InitByRootLookup();
1871 1878
1872 WriteNode password_node(&trans); 1879 WriteNode password_node(&trans);
1873 WriteNode::InitUniqueByCreationResult result = 1880 WriteNode::InitUniqueByCreationResult result =
1874 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); 1881 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag);
1875 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 1882 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
1876 node_id = password_node.GetId(); 1883 node_id = password_node.GetId();
1877 } 1884 }
1878 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1885 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1879 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1886 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1880 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1887 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1881 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1888 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1889 EXPECT_CALL(encryption_observer_,
1890 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1882 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1891 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1883 "new_passphrase", 1892 "new_passphrase",
1884 true); 1893 true);
1885 EXPECT_TRUE( 1894 EXPECT_EQ(CUSTOM_PASSPHRASE,
1886 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1895 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1887 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1896 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1888 { 1897 {
1889 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1898 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1890 ReadNode password_node(&trans); 1899 ReadNode password_node(&trans);
1891 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, 1900 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY,
1892 password_node.InitByClientTagLookup(PASSWORDS, 1901 password_node.InitByClientTagLookup(PASSWORDS,
1893 tag)); 1902 tag));
1894 } 1903 }
1895 { 1904 {
1896 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1905 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2096 specifics.encrypted())); 2105 specifics.encrypted()));
2097 } 2106 }
2098 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); 2107 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag));
2099 2108
2100 // Set a new passphrase. Should set is_unsynced. 2109 // Set a new passphrase. Should set is_unsynced.
2101 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 2110 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
2102 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 2111 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
2103 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 2112 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
2104 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 2113 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2105 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 2114 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2115 EXPECT_CALL(encryption_observer_,
2116 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
2106 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 2117 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
2107 "new_passphrase", 2118 "new_passphrase",
2108 true); 2119 true);
2109 { 2120 {
2110 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2121 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2111 ReadNode node(&trans); 2122 ReadNode node(&trans);
2112 EXPECT_EQ(BaseNode::INIT_OK, 2123 EXPECT_EQ(BaseNode::INIT_OK,
2113 node.InitByClientTagLookup(BOOKMARKS, client_tag)); 2124 node.InitByClientTagLookup(BOOKMARKS, client_tag));
2114 const syncable::Entry* node_entry = node.GetEntry(); 2125 const syncable::Entry* node_entry = node.GetEntry();
2115 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2126 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2292 entity_specifics); 2303 entity_specifics);
2293 // New node shouldn't start off unsynced. 2304 // New node shouldn't start off unsynced.
2294 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); 2305 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag));
2295 2306
2296 // Set a new passphrase. Should set is_unsynced. 2307 // Set a new passphrase. Should set is_unsynced.
2297 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 2308 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
2298 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 2309 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
2299 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 2310 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
2300 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 2311 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2301 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 2312 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2313 EXPECT_CALL(encryption_observer_,
2314 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
2302 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 2315 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
2303 "new_passphrase", 2316 "new_passphrase",
2304 true); 2317 true);
2305 EXPECT_TRUE( 2318 EXPECT_EQ(CUSTOM_PASSPHRASE,
2306 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 2319 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
2307 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); 2320 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag));
2308 } 2321 }
2309 2322
2310 // Passwords have their own handling for encryption. Verify it does not result 2323 // Passwords have their own handling for encryption. Verify it does not result
2311 // in unnecessary writes via ReencryptEverything. 2324 // in unnecessary writes via ReencryptEverything.
2312 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { 2325 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) {
2313 std::string client_tag = "title"; 2326 std::string client_tag = "title";
2314 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 2327 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
2315 sync_pb::EntitySpecifics entity_specifics; 2328 sync_pb::EntitySpecifics entity_specifics;
2316 { 2329 {
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
2859 2872
2860 // Verify only the non-disabled types remain after cleanup. 2873 // Verify only the non-disabled types remain after cleanup.
2861 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); 2874 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types);
2862 EXPECT_TRUE(new_enabled_types.Equals( 2875 EXPECT_TRUE(new_enabled_types.Equals(
2863 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); 2876 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types)));
2864 EXPECT_TRUE(disabled_types.Equals( 2877 EXPECT_TRUE(disabled_types.Equals(
2865 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 2878 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
2866 } 2879 }
2867 2880
2868 } // namespace 2881 } // namespace
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl.cc ('k') | sync/protocol/client_debug_info.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698