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

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

Issue 10878015: [Sync] Move keystore key handling to SyncEncryptionHandlerImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 3 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/internal_api/test/fake_sync_manager.cc » ('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 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 void(const SyncProtocolError&)); // NOLINT 686 void(const SyncProtocolError&)); // NOLINT
687 }; 687 };
688 688
689 class SyncEncryptionHandlerObserverMock 689 class SyncEncryptionHandlerObserverMock
690 : public SyncEncryptionHandler::Observer { 690 : public SyncEncryptionHandler::Observer {
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_METHOD2(OnBootstrapTokenUpdated,
697 void(const std::string&, BootstrapTokenType type)); // NOLINT
697 MOCK_METHOD2(OnEncryptedTypesChanged, 698 MOCK_METHOD2(OnEncryptedTypesChanged,
698 void(ModelTypeSet, bool)); // NOLINT 699 void(ModelTypeSet, bool)); // NOLINT
699 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT 700 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT
700 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT 701 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT
701 MOCK_METHOD1(OnPassphraseStateChanged, void(PassphraseState)); // NOLINT 702 MOCK_METHOD1(OnPassphraseStateChanged, void(PassphraseState)); // NOLINT
702 }; 703 };
703 704
704 } // namespace 705 } // namespace
705 706
706 class SyncManagerTest : public testing::Test, 707 class SyncManagerTest : public testing::Test,
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 SESSIONS, 1495 SESSIONS,
1495 true /* is encrypted */)); 1496 true /* is encrypted */));
1496 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1497 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1497 trans.GetWrappedTrans(), 1498 trans.GetWrappedTrans(),
1498 THEMES, 1499 THEMES,
1499 true /* is encrypted */)); 1500 true /* is encrypted */));
1500 } 1501 }
1501 1502
1502 // Trigger's a ReEncryptEverything with new passphrase. 1503 // Trigger's a ReEncryptEverything with new passphrase.
1503 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 1504 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
1504 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1505 EXPECT_CALL(encryption_observer_,
1506 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1505 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1507 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1506 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1508 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1507 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1509 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1508 EXPECT_CALL(encryption_observer_, 1510 EXPECT_CALL(encryption_observer_,
1509 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); 1511 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1510 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1512 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1511 "new_passphrase", true); 1513 "new_passphrase", true);
1512 EXPECT_TRUE(EncryptEverythingEnabledForTest()); 1514 EXPECT_TRUE(EncryptEverythingEnabledForTest());
1513 { 1515 {
1514 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1516 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1515 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(ModelTypeSet::All())); 1517 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(ModelTypeSet::All()));
1516 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1518 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1517 trans.GetWrappedTrans(), 1519 trans.GetWrappedTrans(),
1518 BOOKMARKS, 1520 BOOKMARKS,
1519 true /* is encrypted */)); 1521 true /* is encrypted */));
1520 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1522 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1521 trans.GetWrappedTrans(), 1523 trans.GetWrappedTrans(),
1522 SESSIONS, 1524 SESSIONS,
1523 true /* is encrypted */)); 1525 true /* is encrypted */));
1524 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1526 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1525 trans.GetWrappedTrans(), 1527 trans.GetWrappedTrans(),
1526 THEMES, 1528 THEMES,
1527 true /* is encrypted */)); 1529 true /* is encrypted */));
1528 } 1530 }
1529 // Calling EncryptDataTypes with an empty encrypted types should not trigger 1531 // Calling EncryptDataTypes with an empty encrypted types should not trigger
1530 // a reencryption and should just notify immediately. 1532 // a reencryption and should just notify immediately.
1531 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 1533 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
1532 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)).Times(0); 1534 EXPECT_CALL(encryption_observer_,
1535 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)).Times(0);
1533 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()).Times(0); 1536 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()).Times(0);
1534 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()).Times(0); 1537 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()).Times(0);
1535 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); 1538 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything();
1536 } 1539 }
1537 1540
1538 // Test that when there are no pending keys and the cryptographer is not 1541 // Test that when there are no pending keys and the cryptographer is not
1539 // initialized, we add a key based on the current GAIA password. 1542 // initialized, we add a key based on the current GAIA password.
1540 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) 1543 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase)
1541 TEST_F(SyncManagerTest, SetInitialGaiaPass) { 1544 TEST_F(SyncManagerTest, SetInitialGaiaPass) {
1542 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); 1545 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED));
1543 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1546 EXPECT_CALL(encryption_observer_,
1547 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1544 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1548 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1545 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1549 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1546 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1550 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1547 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1551 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1548 "new_passphrase", 1552 "new_passphrase",
1549 false); 1553 false);
1550 EXPECT_EQ(IMPLICIT_PASSPHRASE, 1554 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1551 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1555 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1552 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1556 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1553 { 1557 {
(...skipping 13 matching lines...) Expand all
1567 TEST_F(SyncManagerTest, UpdateGaiaPass) { 1571 TEST_F(SyncManagerTest, UpdateGaiaPass) {
1568 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1572 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1569 Cryptographer verifier(&encryptor_); 1573 Cryptographer verifier(&encryptor_);
1570 { 1574 {
1571 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1575 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1572 Cryptographer* cryptographer = trans.GetCryptographer(); 1576 Cryptographer* cryptographer = trans.GetCryptographer();
1573 std::string bootstrap_token; 1577 std::string bootstrap_token;
1574 cryptographer->GetBootstrapToken(&bootstrap_token); 1578 cryptographer->GetBootstrapToken(&bootstrap_token);
1575 verifier.Bootstrap(bootstrap_token); 1579 verifier.Bootstrap(bootstrap_token);
1576 } 1580 }
1577 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1581 EXPECT_CALL(encryption_observer_,
1582 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1578 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1583 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1579 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1584 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1580 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1585 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1581 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1586 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1582 "new_passphrase", 1587 "new_passphrase",
1583 false); 1588 false);
1584 EXPECT_EQ(IMPLICIT_PASSPHRASE, 1589 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1585 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1590 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1586 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1591 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1587 { 1592 {
(...skipping 26 matching lines...) Expand all
1614 1619
1615 WriteNode password_node(&trans); 1620 WriteNode password_node(&trans);
1616 WriteNode::InitUniqueByCreationResult result = 1621 WriteNode::InitUniqueByCreationResult result =
1617 password_node.InitUniqueByCreation(PASSWORDS, 1622 password_node.InitUniqueByCreation(PASSWORDS,
1618 root_node, "foo"); 1623 root_node, "foo");
1619 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 1624 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
1620 sync_pb::PasswordSpecificsData data; 1625 sync_pb::PasswordSpecificsData data;
1621 data.set_password_value("secret"); 1626 data.set_password_value("secret");
1622 password_node.SetPasswordSpecifics(data); 1627 password_node.SetPasswordSpecifics(data);
1623 } 1628 }
1624 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1629 EXPECT_CALL(encryption_observer_,
1630 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1625 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1631 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1626 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1632 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1627 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1633 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1628 EXPECT_CALL(encryption_observer_, 1634 EXPECT_CALL(encryption_observer_,
1629 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); 1635 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1630 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1636 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1631 "new_passphrase", 1637 "new_passphrase",
1632 true); 1638 true);
1633 EXPECT_EQ(CUSTOM_PASSPHRASE, 1639 EXPECT_EQ(CUSTOM_PASSPHRASE,
1634 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1640 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 KeyParams params = {"localhost", "dummy", "passphrase2"}; 1677 KeyParams params = {"localhost", "dummy", "passphrase2"};
1672 other_cryptographer.AddKey(params); 1678 other_cryptographer.AddKey(params);
1673 WriteNode node(&trans); 1679 WriteNode node(&trans);
1674 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1680 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1675 sync_pb::NigoriSpecifics nigori; 1681 sync_pb::NigoriSpecifics nigori;
1676 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1682 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1677 cryptographer->SetPendingKeys(nigori.encrypted()); 1683 cryptographer->SetPendingKeys(nigori.encrypted());
1678 EXPECT_TRUE(cryptographer->has_pending_keys()); 1684 EXPECT_TRUE(cryptographer->has_pending_keys());
1679 node.SetNigoriSpecifics(nigori); 1685 node.SetNigoriSpecifics(nigori);
1680 } 1686 }
1681 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1687 EXPECT_CALL(encryption_observer_,
1688 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1682 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1689 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1683 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1690 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1684 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1691 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1685 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); 1692 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2");
1686 EXPECT_EQ(IMPLICIT_PASSPHRASE, 1693 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1687 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1694 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1688 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1695 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1689 { 1696 {
1690 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1697 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1691 Cryptographer* cryptographer = trans.GetCryptographer(); 1698 Cryptographer* cryptographer = trans.GetCryptographer();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 cryptographer->SetPendingKeys(nigori.encrypted()); 1732 cryptographer->SetPendingKeys(nigori.encrypted());
1726 1733
1727 // other_cryptographer now contains all encryption keys, and is encrypting 1734 // other_cryptographer now contains all encryption keys, and is encrypting
1728 // with the newest gaia. 1735 // with the newest gaia.
1729 KeyParams new_params = {"localhost", "dummy", "new_gaia"}; 1736 KeyParams new_params = {"localhost", "dummy", "new_gaia"};
1730 other_cryptographer.AddKey(new_params); 1737 other_cryptographer.AddKey(new_params);
1731 } 1738 }
1732 // The bootstrap token should have been updated. Save it to ensure it's based 1739 // The bootstrap token should have been updated. Save it to ensure it's based
1733 // on the new GAIA password. 1740 // on the new GAIA password.
1734 std::string bootstrap_token; 1741 std::string bootstrap_token;
1735 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)) 1742 EXPECT_CALL(encryption_observer_,
1743 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN))
1736 .WillOnce(SaveArg<0>(&bootstrap_token)); 1744 .WillOnce(SaveArg<0>(&bootstrap_token));
1737 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_)); 1745 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_));
1738 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1746 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1739 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1747 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1740 "new_gaia", 1748 "new_gaia",
1741 false); 1749 false);
1742 EXPECT_EQ(IMPLICIT_PASSPHRASE, 1750 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1743 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1751 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1744 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1752 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1745 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 1753 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
1746 { 1754 {
1747 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1755 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1748 Cryptographer* cryptographer = trans.GetCryptographer(); 1756 Cryptographer* cryptographer = trans.GetCryptographer();
1749 EXPECT_TRUE(cryptographer->is_initialized()); 1757 EXPECT_TRUE(cryptographer->is_initialized());
1750 EXPECT_FALSE(cryptographer->is_ready()); 1758 EXPECT_FALSE(cryptographer->is_ready());
1751 // Verify we're encrypting with the new key, even though we have pending 1759 // Verify we're encrypting with the new key, even though we have pending
1752 // keys. 1760 // keys.
1753 sync_pb::EncryptedData encrypted; 1761 sync_pb::EncryptedData encrypted;
1754 other_cryptographer.GetKeys(&encrypted); 1762 other_cryptographer.GetKeys(&encrypted);
1755 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); 1763 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted));
1756 } 1764 }
1757 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1765 EXPECT_CALL(encryption_observer_,
1766 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1758 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1767 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1759 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1768 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1760 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1769 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1761 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1770 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1762 "old_gaia", 1771 "old_gaia",
1763 false); 1772 false);
1764 EXPECT_EQ(IMPLICIT_PASSPHRASE, 1773 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1765 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1774 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1766 { 1775 {
1767 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1776 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 other_cryptographer.AddKey(params); 1809 other_cryptographer.AddKey(params);
1801 WriteNode node(&trans); 1810 WriteNode node(&trans);
1802 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1811 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1803 sync_pb::NigoriSpecifics nigori; 1812 sync_pb::NigoriSpecifics nigori;
1804 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1813 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1805 cryptographer->SetPendingKeys(nigori.encrypted()); 1814 cryptographer->SetPendingKeys(nigori.encrypted());
1806 EXPECT_TRUE(cryptographer->has_pending_keys()); 1815 EXPECT_TRUE(cryptographer->has_pending_keys());
1807 nigori.set_using_explicit_passphrase(true); 1816 nigori.set_using_explicit_passphrase(true);
1808 node.SetNigoriSpecifics(nigori); 1817 node.SetNigoriSpecifics(nigori);
1809 } 1818 }
1810 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1819 EXPECT_CALL(encryption_observer_,
1820 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1811 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1821 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1812 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1822 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1813 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1823 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1814 EXPECT_CALL(encryption_observer_, 1824 EXPECT_CALL(encryption_observer_,
1815 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); 1825 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1816 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); 1826 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit");
1817 EXPECT_EQ(CUSTOM_PASSPHRASE, 1827 EXPECT_EQ(CUSTOM_PASSPHRASE,
1818 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1828 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1819 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1829 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1820 { 1830 {
(...skipping 22 matching lines...) Expand all
1843 KeyParams params = {"localhost", "dummy", "passphrase"}; 1853 KeyParams params = {"localhost", "dummy", "passphrase"};
1844 other_cryptographer.AddKey(params); 1854 other_cryptographer.AddKey(params);
1845 WriteNode node(&trans); 1855 WriteNode node(&trans);
1846 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1856 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1847 sync_pb::NigoriSpecifics nigori; 1857 sync_pb::NigoriSpecifics nigori;
1848 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1858 other_cryptographer.GetKeys(nigori.mutable_encrypted());
1849 node.SetNigoriSpecifics(nigori); 1859 node.SetNigoriSpecifics(nigori);
1850 cryptographer->SetPendingKeys(nigori.encrypted()); 1860 cryptographer->SetPendingKeys(nigori.encrypted());
1851 EXPECT_FALSE(cryptographer->is_ready()); 1861 EXPECT_FALSE(cryptographer->is_ready());
1852 } 1862 }
1853 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1863 EXPECT_CALL(encryption_observer_,
1864 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1854 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1865 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1855 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1866 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1856 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1867 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1857 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1868 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1858 "passphrase", 1869 "passphrase",
1859 false); 1870 false);
1860 EXPECT_EQ(IMPLICIT_PASSPHRASE, 1871 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1861 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1872 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
1862 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1873 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1863 { 1874 {
(...skipping 11 matching lines...) Expand all
1875 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1886 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1876 ReadNode root_node(&trans); 1887 ReadNode root_node(&trans);
1877 root_node.InitByRootLookup(); 1888 root_node.InitByRootLookup();
1878 1889
1879 WriteNode password_node(&trans); 1890 WriteNode password_node(&trans);
1880 WriteNode::InitUniqueByCreationResult result = 1891 WriteNode::InitUniqueByCreationResult result =
1881 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); 1892 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag);
1882 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 1893 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
1883 node_id = password_node.GetId(); 1894 node_id = password_node.GetId();
1884 } 1895 }
1885 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 1896 EXPECT_CALL(encryption_observer_,
1897 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1886 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1898 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1887 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1899 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1888 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1900 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1889 EXPECT_CALL(encryption_observer_, 1901 EXPECT_CALL(encryption_observer_,
1890 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); 1902 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1891 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1903 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1892 "new_passphrase", 1904 "new_passphrase",
1893 true); 1905 true);
1894 EXPECT_EQ(CUSTOM_PASSPHRASE, 1906 EXPECT_EQ(CUSTOM_PASSPHRASE,
1895 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1907 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2101 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); 2113 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME));
2102 Cryptographer* cryptographer = trans.GetCryptographer(); 2114 Cryptographer* cryptographer = trans.GetCryptographer();
2103 EXPECT_TRUE(cryptographer->is_ready()); 2115 EXPECT_TRUE(cryptographer->is_ready());
2104 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( 2116 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey(
2105 specifics.encrypted())); 2117 specifics.encrypted()));
2106 } 2118 }
2107 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); 2119 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag));
2108 2120
2109 // Set a new passphrase. Should set is_unsynced. 2121 // Set a new passphrase. Should set is_unsynced.
2110 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 2122 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
2111 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 2123 EXPECT_CALL(encryption_observer_,
2124 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
2112 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 2125 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
2113 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 2126 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2114 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 2127 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2115 EXPECT_CALL(encryption_observer_, 2128 EXPECT_CALL(encryption_observer_,
2116 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); 2129 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
2117 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 2130 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
2118 "new_passphrase", 2131 "new_passphrase",
2119 true); 2132 true);
2120 { 2133 {
2121 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2134 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
2299 } 2312 }
2300 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, 2313 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag,
2301 BaseNode::GenerateSyncableHash(PASSWORDS, 2314 BaseNode::GenerateSyncableHash(PASSWORDS,
2302 client_tag), 2315 client_tag),
2303 entity_specifics); 2316 entity_specifics);
2304 // New node shouldn't start off unsynced. 2317 // New node shouldn't start off unsynced.
2305 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); 2318 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag));
2306 2319
2307 // Set a new passphrase. Should set is_unsynced. 2320 // Set a new passphrase. Should set is_unsynced.
2308 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 2321 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
2309 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); 2322 EXPECT_CALL(encryption_observer_,
2323 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
2310 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 2324 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
2311 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 2325 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2312 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 2326 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2313 EXPECT_CALL(encryption_observer_, 2327 EXPECT_CALL(encryption_observer_,
2314 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); 2328 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
2315 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 2329 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
2316 "new_passphrase", 2330 "new_passphrase",
2317 true); 2331 true);
2318 EXPECT_EQ(CUSTOM_PASSPHRASE, 2332 EXPECT_EQ(CUSTOM_PASSPHRASE,
2319 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 2333 sync_manager_.GetEncryptionHandler()->GetPassphraseState());
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
2872 2886
2873 // Verify only the non-disabled types remain after cleanup. 2887 // Verify only the non-disabled types remain after cleanup.
2874 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); 2888 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types);
2875 EXPECT_TRUE(new_enabled_types.Equals( 2889 EXPECT_TRUE(new_enabled_types.Equals(
2876 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); 2890 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types)));
2877 EXPECT_TRUE(disabled_types.Equals( 2891 EXPECT_TRUE(disabled_types.Equals(
2878 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 2892 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
2879 } 2893 }
2880 2894
2881 } // namespace 2895 } // namespace
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl.cc ('k') | sync/internal_api/test/fake_sync_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698