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

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: Fix last test 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
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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 public: 693 public:
694 MOCK_METHOD2(OnPassphraseRequired, 694 MOCK_METHOD2(OnPassphraseRequired,
695 void(PassphraseRequiredReason, 695 void(PassphraseRequiredReason,
696 const sync_pb::EncryptedData&)); // NOLINT 696 const sync_pb::EncryptedData&)); // NOLINT
697 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT 697 MOCK_METHOD0(OnPassphraseAccepted, void()); // NOLINT
698 MOCK_METHOD1(OnBootstrapTokenUpdated, void(const std::string&)); // NOLINT 698 MOCK_METHOD1(OnBootstrapTokenUpdated, void(const std::string&)); // NOLINT
699 MOCK_METHOD2(OnEncryptedTypesChanged, 699 MOCK_METHOD2(OnEncryptedTypesChanged,
700 void(ModelTypeSet, bool)); // NOLINT 700 void(ModelTypeSet, bool)); // NOLINT
701 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT 701 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT
702 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT 702 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT
703 MOCK_METHOD1(OnPassphraseStateChanged, void(PassphraseState)); // NOLINT
703 }; 704 };
704 705
705 class SyncNotifierMock : public SyncNotifier { 706 class SyncNotifierMock : public SyncNotifier {
706 public: 707 public:
707 MOCK_METHOD1(RegisterHandler, void(SyncNotifierObserver*)); 708 MOCK_METHOD1(RegisterHandler, void(SyncNotifierObserver*));
708 MOCK_METHOD2(UpdateRegisteredIds, 709 MOCK_METHOD2(UpdateRegisteredIds,
709 void(SyncNotifierObserver*, const ObjectIdSet&)); 710 void(SyncNotifierObserver*, const ObjectIdSet&));
710 MOCK_METHOD1(UnregisterHandler, void(SyncNotifierObserver*)); 711 MOCK_METHOD1(UnregisterHandler, void(SyncNotifierObserver*));
711 MOCK_METHOD1(SetUniqueId, void(const std::string&)); 712 MOCK_METHOD1(SetUniqueId, void(const std::string&));
712 MOCK_METHOD1(SetStateDeprecated, void(const std::string&)); 713 MOCK_METHOD1(SetStateDeprecated, void(const std::string&));
(...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 THEMES, 1518 THEMES,
1518 true /* is encrypted */)); 1519 true /* is encrypted */));
1519 } 1520 }
1520 1521
1521 // Trigger's a ReEncryptEverything with new passphrase. 1522 // Trigger's a ReEncryptEverything with new passphrase.
1522 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 1523 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
1523 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1524 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1524 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1525 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1525 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1526 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1526 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1527 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1528 EXPECT_CALL(encryption_observer_,
1529 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1527 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1530 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1528 "new_passphrase", true); 1531 "new_passphrase", true);
1529 EXPECT_TRUE(EncryptEverythingEnabledForTest()); 1532 EXPECT_TRUE(EncryptEverythingEnabledForTest());
1530 { 1533 {
1531 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1534 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1532 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(ModelTypeSet::All())); 1535 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(ModelTypeSet::All()));
1533 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1536 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1534 trans.GetWrappedTrans(), 1537 trans.GetWrappedTrans(),
1535 BOOKMARKS, 1538 BOOKMARKS,
1536 true /* is encrypted */)); 1539 true /* is encrypted */));
(...skipping 20 matching lines...) Expand all
1557 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) 1560 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase)
1558 TEST_F(SyncManagerTest, SetInitialGaiaPass) { 1561 TEST_F(SyncManagerTest, SetInitialGaiaPass) {
1559 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); 1562 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED));
1560 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1563 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1561 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1564 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1562 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1565 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1563 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1566 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1564 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1567 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1565 "new_passphrase", 1568 "new_passphrase",
1566 false); 1569 false);
1567 EXPECT_FALSE( 1570 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1568 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1571 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1569 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1572 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1570 { 1573 {
1571 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1574 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1572 ReadNode node(&trans); 1575 ReadNode node(&trans);
1573 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1576 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1574 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); 1577 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
1575 Cryptographer* cryptographer = trans.GetCryptographer(); 1578 Cryptographer* cryptographer = trans.GetCryptographer();
1576 EXPECT_TRUE(cryptographer->is_ready()); 1579 EXPECT_TRUE(cryptographer->is_ready());
1577 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); 1580 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted()));
1578 } 1581 }
(...skipping 12 matching lines...) Expand all
1591 cryptographer->GetBootstrapToken(&bootstrap_token); 1594 cryptographer->GetBootstrapToken(&bootstrap_token);
1592 verifier.Bootstrap(bootstrap_token); 1595 verifier.Bootstrap(bootstrap_token);
1593 } 1596 }
1594 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1597 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1595 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1598 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1596 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1599 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1597 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1600 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1598 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1601 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1599 "new_passphrase", 1602 "new_passphrase",
1600 false); 1603 false);
1601 EXPECT_FALSE( 1604 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1602 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1605 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1603 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1606 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1604 { 1607 {
1605 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1608 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1606 Cryptographer* cryptographer = trans.GetCryptographer(); 1609 Cryptographer* cryptographer = trans.GetCryptographer();
1607 EXPECT_TRUE(cryptographer->is_ready()); 1610 EXPECT_TRUE(cryptographer->is_ready());
1608 // Verify the default key has changed. 1611 // Verify the default key has changed.
1609 sync_pb::EncryptedData encrypted; 1612 sync_pb::EncryptedData encrypted;
1610 cryptographer->GetKeys(&encrypted); 1613 cryptographer->GetKeys(&encrypted);
1611 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); 1614 EXPECT_FALSE(verifier.CanDecrypt(encrypted));
1612 } 1615 }
(...skipping 22 matching lines...) Expand all
1635 root_node, "foo"); 1638 root_node, "foo");
1636 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 1639 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
1637 sync_pb::PasswordSpecificsData data; 1640 sync_pb::PasswordSpecificsData data;
1638 data.set_password_value("secret"); 1641 data.set_password_value("secret");
1639 password_node.SetPasswordSpecifics(data); 1642 password_node.SetPasswordSpecifics(data);
1640 } 1643 }
1641 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1644 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1642 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1645 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1643 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1646 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1644 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1647 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1648 EXPECT_CALL(encryption_observer_,
1649 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1645 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1650 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1646 "new_passphrase", 1651 "new_passphrase",
1647 true); 1652 true);
1648 EXPECT_TRUE( 1653 EXPECT_EQ(CUSTOM_PASSPHRASE,
1649 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1654 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1650 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1655 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1651 { 1656 {
1652 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1657 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1653 Cryptographer* cryptographer = trans.GetCryptographer(); 1658 Cryptographer* cryptographer = trans.GetCryptographer();
1654 EXPECT_TRUE(cryptographer->is_ready()); 1659 EXPECT_TRUE(cryptographer->is_ready());
1655 // Verify the default key has changed. 1660 // Verify the default key has changed.
1656 sync_pb::EncryptedData encrypted; 1661 sync_pb::EncryptedData encrypted;
1657 cryptographer->GetKeys(&encrypted); 1662 cryptographer->GetKeys(&encrypted);
1658 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); 1663 EXPECT_FALSE(verifier.CanDecrypt(encrypted));
1659 1664
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1691 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1696 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1692 cryptographer->SetPendingKeys(nigori.encrypted()); 1697 cryptographer->SetPendingKeys(nigori.encrypted());
1693 EXPECT_TRUE(cryptographer->has_pending_keys()); 1698 EXPECT_TRUE(cryptographer->has_pending_keys());
1694 node.SetNigoriSpecifics(nigori); 1699 node.SetNigoriSpecifics(nigori);
1695 } 1700 }
1696 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1701 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1697 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1702 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1698 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1703 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1699 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1704 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1700 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); 1705 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2");
1701 EXPECT_FALSE( 1706 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1702 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1707 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1703 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1708 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1704 { 1709 {
1705 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1710 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1706 Cryptographer* cryptographer = trans.GetCryptographer(); 1711 Cryptographer* cryptographer = trans.GetCryptographer();
1707 EXPECT_TRUE(cryptographer->is_ready()); 1712 EXPECT_TRUE(cryptographer->is_ready());
1708 // Verify we're encrypting with the new key. 1713 // Verify we're encrypting with the new key.
1709 sync_pb::EncryptedData encrypted; 1714 sync_pb::EncryptedData encrypted;
1710 cryptographer->GetKeys(&encrypted); 1715 cryptographer->GetKeys(&encrypted);
1711 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); 1716 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted));
1712 } 1717 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 // The bootstrap token should have been updated. Save it to ensure it's based 1752 // The bootstrap token should have been updated. Save it to ensure it's based
1748 // on the new GAIA password. 1753 // on the new GAIA password.
1749 std::string bootstrap_token; 1754 std::string bootstrap_token;
1750 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)) 1755 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_))
1751 .WillOnce(SaveArg<0>(&bootstrap_token)); 1756 .WillOnce(SaveArg<0>(&bootstrap_token));
1752 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_)); 1757 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_));
1753 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1758 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1754 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1759 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1755 "new_gaia", 1760 "new_gaia",
1756 false); 1761 false);
1757 EXPECT_FALSE( 1762 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1758 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1763 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1759 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1764 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1760 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 1765 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
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_initialized()); 1769 EXPECT_TRUE(cryptographer->is_initialized());
1765 EXPECT_FALSE(cryptographer->is_ready()); 1770 EXPECT_FALSE(cryptographer->is_ready());
1766 // Verify we're encrypting with the new key, even though we have pending 1771 // Verify we're encrypting with the new key, even though we have pending
1767 // keys. 1772 // keys.
1768 sync_pb::EncryptedData encrypted; 1773 sync_pb::EncryptedData encrypted;
1769 other_cryptographer.GetKeys(&encrypted); 1774 other_cryptographer.GetKeys(&encrypted);
1770 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); 1775 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted));
1771 } 1776 }
1772 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1777 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1773 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1778 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1774 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1779 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1775 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1780 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1776 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1781 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1777 "old_gaia", 1782 "old_gaia",
1778 false); 1783 false);
1779 EXPECT_FALSE( 1784 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1780 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1785 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1781 { 1786 {
1782 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1787 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1783 Cryptographer* cryptographer = trans.GetCryptographer(); 1788 Cryptographer* cryptographer = trans.GetCryptographer();
1784 EXPECT_TRUE(cryptographer->is_ready()); 1789 EXPECT_TRUE(cryptographer->is_ready());
1785 1790
1786 // Verify we're encrypting with the new key. 1791 // Verify we're encrypting with the new key.
1787 sync_pb::EncryptedData encrypted; 1792 sync_pb::EncryptedData encrypted;
1788 other_cryptographer.GetKeys(&encrypted); 1793 other_cryptographer.GetKeys(&encrypted);
1789 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); 1794 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted));
1790 1795
(...skipping 28 matching lines...) Expand all
1819 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1824 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1820 cryptographer->SetPendingKeys(nigori.encrypted()); 1825 cryptographer->SetPendingKeys(nigori.encrypted());
1821 EXPECT_TRUE(cryptographer->has_pending_keys()); 1826 EXPECT_TRUE(cryptographer->has_pending_keys());
1822 nigori.set_using_explicit_passphrase(true); 1827 nigori.set_using_explicit_passphrase(true);
1823 node.SetNigoriSpecifics(nigori); 1828 node.SetNigoriSpecifics(nigori);
1824 } 1829 }
1825 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1830 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1826 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1831 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1827 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1832 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1828 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1833 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1834 EXPECT_CALL(encryption_observer_,
1835 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1829 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); 1836 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit");
1830 EXPECT_TRUE( 1837 EXPECT_EQ(CUSTOM_PASSPHRASE,
1831 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1838 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1832 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1839 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1833 { 1840 {
1834 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1841 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1835 Cryptographer* cryptographer = trans.GetCryptographer(); 1842 Cryptographer* cryptographer = trans.GetCryptographer();
1836 EXPECT_TRUE(cryptographer->is_ready()); 1843 EXPECT_TRUE(cryptographer->is_ready());
1837 // Verify we're encrypting with the new key. 1844 // Verify we're encrypting with the new key.
1838 sync_pb::EncryptedData encrypted; 1845 sync_pb::EncryptedData encrypted;
1839 cryptographer->GetKeys(&encrypted); 1846 cryptographer->GetKeys(&encrypted);
1840 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); 1847 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted));
1841 } 1848 }
(...skipping 21 matching lines...) Expand all
1863 cryptographer->SetPendingKeys(nigori.encrypted()); 1870 cryptographer->SetPendingKeys(nigori.encrypted());
1864 EXPECT_FALSE(cryptographer->is_ready()); 1871 EXPECT_FALSE(cryptographer->is_ready());
1865 } 1872 }
1866 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1873 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1867 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1874 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1868 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1875 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1869 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1876 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1870 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1877 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1871 "passphrase", 1878 "passphrase",
1872 false); 1879 false);
1873 EXPECT_FALSE( 1880 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1874 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1881 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1875 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1882 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1876 { 1883 {
1877 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1884 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1878 Cryptographer* cryptographer = trans.GetCryptographer(); 1885 Cryptographer* cryptographer = trans.GetCryptographer();
1879 EXPECT_TRUE(cryptographer->is_ready()); 1886 EXPECT_TRUE(cryptographer->is_ready());
1880 } 1887 }
1881 } 1888 }
1882 1889
1883 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { 1890 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) {
1884 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1891 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1885 int64 node_id = 0; 1892 int64 node_id = 0;
1886 std::string tag = "foo"; 1893 std::string tag = "foo";
1887 { 1894 {
1888 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1895 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1889 ReadNode root_node(&trans); 1896 ReadNode root_node(&trans);
1890 root_node.InitByRootLookup(); 1897 root_node.InitByRootLookup();
1891 1898
1892 WriteNode password_node(&trans); 1899 WriteNode password_node(&trans);
1893 WriteNode::InitUniqueByCreationResult result = 1900 WriteNode::InitUniqueByCreationResult result =
1894 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); 1901 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag);
1895 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 1902 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
1896 node_id = password_node.GetId(); 1903 node_id = password_node.GetId();
1897 } 1904 }
1898 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1905 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
1899 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1906 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1900 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1907 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1901 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1908 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1909 EXPECT_CALL(encryption_observer_,
1910 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1902 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1911 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1903 "new_passphrase", 1912 "new_passphrase",
1904 true); 1913 true);
1905 EXPECT_TRUE( 1914 EXPECT_EQ(CUSTOM_PASSPHRASE,
1906 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 1915 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1907 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1916 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1908 { 1917 {
1909 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1918 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1910 ReadNode password_node(&trans); 1919 ReadNode password_node(&trans);
1911 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, 1920 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY,
1912 password_node.InitByClientTagLookup(PASSWORDS, 1921 password_node.InitByClientTagLookup(PASSWORDS,
1913 tag)); 1922 tag));
1914 } 1923 }
1915 { 1924 {
1916 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1925 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
2115 specifics.encrypted())); 2124 specifics.encrypted()));
2116 } 2125 }
2117 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); 2126 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag));
2118 2127
2119 // Set a new passphrase. Should set is_unsynced. 2128 // Set a new passphrase. Should set is_unsynced.
2120 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 2129 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
2121 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 2130 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
2122 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 2131 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
2123 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 2132 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2124 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 2133 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2134 EXPECT_CALL(encryption_observer_,
2135 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
2125 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 2136 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
2126 "new_passphrase", 2137 "new_passphrase",
2127 true); 2138 true);
2128 { 2139 {
2129 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2140 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2130 ReadNode node(&trans); 2141 ReadNode node(&trans);
2131 EXPECT_EQ(BaseNode::INIT_OK, 2142 EXPECT_EQ(BaseNode::INIT_OK,
2132 node.InitByClientTagLookup(BOOKMARKS, client_tag)); 2143 node.InitByClientTagLookup(BOOKMARKS, client_tag));
2133 const syncable::Entry* node_entry = node.GetEntry(); 2144 const syncable::Entry* node_entry = node.GetEntry();
2134 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2145 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
2310 entity_specifics); 2321 entity_specifics);
2311 // New node shouldn't start off unsynced. 2322 // New node shouldn't start off unsynced.
2312 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); 2323 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag));
2313 2324
2314 // Set a new passphrase. Should set is_unsynced. 2325 // Set a new passphrase. Should set is_unsynced.
2315 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 2326 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
2316 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 2327 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_));
2317 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 2328 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
2318 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 2329 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2319 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 2330 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2331 EXPECT_CALL(encryption_observer_,
2332 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
2320 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 2333 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
2321 "new_passphrase", 2334 "new_passphrase",
2322 true); 2335 true);
2323 EXPECT_TRUE( 2336 EXPECT_EQ(CUSTOM_PASSPHRASE,
akalin 2012/08/22 20:10:39 can you write a test that uses any of the other tw
Nicolas Zea 2012/08/22 20:18:33 Those will be in future CL's once the migration lo
2324 sync_manager_.GetEncryptionHandler()->IsUsingExplicitPassphrase()); 2337 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
2325 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); 2338 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag));
2326 } 2339 }
2327 2340
2328 // Passwords have their own handling for encryption. Verify it does not result 2341 // Passwords have their own handling for encryption. Verify it does not result
2329 // in unnecessary writes via ReencryptEverything. 2342 // in unnecessary writes via ReencryptEverything.
2330 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { 2343 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) {
2331 std::string client_tag = "title"; 2344 std::string client_tag = "title";
2332 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 2345 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
2333 sync_pb::EntitySpecifics entity_specifics; 2346 sync_pb::EntitySpecifics entity_specifics;
2334 { 2347 {
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
2874 2887
2875 // Verify only the non-disabled types remain after cleanup. 2888 // Verify only the non-disabled types remain after cleanup.
2876 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); 2889 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types);
2877 EXPECT_TRUE(new_enabled_types.Equals( 2890 EXPECT_TRUE(new_enabled_types.Equals(
2878 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); 2891 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types)));
2879 EXPECT_TRUE(disabled_types.Equals( 2892 EXPECT_TRUE(disabled_types.Equals(
2880 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 2893 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
2881 } 2894 }
2882 2895
2883 } // namespace 2896 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698