| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // 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 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 void(const SyncProtocolError&)); // NOLINT | 688 void(const SyncProtocolError&)); // NOLINT |
| 689 }; | 689 }; |
| 690 | 690 |
| 691 class SyncEncryptionHandlerObserverMock | 691 class SyncEncryptionHandlerObserverMock |
| 692 : public SyncEncryptionHandler::Observer { | 692 : public SyncEncryptionHandler::Observer { |
| 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_METHOD2(OnBootstrapTokenUpdated, |
| 699 void(const std::string&, BootstrapTokenType type)); // NOLINT |
| 699 MOCK_METHOD2(OnEncryptedTypesChanged, | 700 MOCK_METHOD2(OnEncryptedTypesChanged, |
| 700 void(ModelTypeSet, bool)); // NOLINT | 701 void(ModelTypeSet, bool)); // NOLINT |
| 701 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT | 702 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT |
| 702 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT | 703 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT |
| 703 MOCK_METHOD1(OnPassphraseStateChanged, void(PassphraseState)); // NOLINT | 704 MOCK_METHOD1(OnPassphraseStateChanged, void(PassphraseState)); // NOLINT |
| 704 }; | 705 }; |
| 705 | 706 |
| 706 class SyncNotifierMock : public SyncNotifier { | 707 class SyncNotifierMock : public SyncNotifier { |
| 707 public: | 708 public: |
| 708 MOCK_METHOD1(RegisterHandler, void(SyncNotifierObserver*)); | 709 MOCK_METHOD1(RegisterHandler, void(SyncNotifierObserver*)); |
| (...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 SESSIONS, | 1515 SESSIONS, |
| 1515 true /* is encrypted */)); | 1516 true /* is encrypted */)); |
| 1516 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1517 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1517 trans.GetWrappedTrans(), | 1518 trans.GetWrappedTrans(), |
| 1518 THEMES, | 1519 THEMES, |
| 1519 true /* is encrypted */)); | 1520 true /* is encrypted */)); |
| 1520 } | 1521 } |
| 1521 | 1522 |
| 1522 // Trigger's a ReEncryptEverything with new passphrase. | 1523 // Trigger's a ReEncryptEverything with new passphrase. |
| 1523 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 1524 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 1524 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); | 1525 EXPECT_CALL(encryption_observer_, |
| 1526 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1525 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1527 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1526 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1528 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1527 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1529 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1528 EXPECT_CALL(encryption_observer_, | 1530 EXPECT_CALL(encryption_observer_, |
| 1529 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); | 1531 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); |
| 1530 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1532 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1531 "new_passphrase", true); | 1533 "new_passphrase", true); |
| 1532 EXPECT_TRUE(EncryptEverythingEnabledForTest()); | 1534 EXPECT_TRUE(EncryptEverythingEnabledForTest()); |
| 1533 { | 1535 { |
| 1534 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1536 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1535 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(ModelTypeSet::All())); | 1537 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(ModelTypeSet::All())); |
| 1536 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1538 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1537 trans.GetWrappedTrans(), | 1539 trans.GetWrappedTrans(), |
| 1538 BOOKMARKS, | 1540 BOOKMARKS, |
| 1539 true /* is encrypted */)); | 1541 true /* is encrypted */)); |
| 1540 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1542 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1541 trans.GetWrappedTrans(), | 1543 trans.GetWrappedTrans(), |
| 1542 SESSIONS, | 1544 SESSIONS, |
| 1543 true /* is encrypted */)); | 1545 true /* is encrypted */)); |
| 1544 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1546 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1545 trans.GetWrappedTrans(), | 1547 trans.GetWrappedTrans(), |
| 1546 THEMES, | 1548 THEMES, |
| 1547 true /* is encrypted */)); | 1549 true /* is encrypted */)); |
| 1548 } | 1550 } |
| 1549 // Calling EncryptDataTypes with an empty encrypted types should not trigger | 1551 // Calling EncryptDataTypes with an empty encrypted types should not trigger |
| 1550 // a reencryption and should just notify immediately. | 1552 // a reencryption and should just notify immediately. |
| 1551 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 1553 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 1552 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)).Times(0); | 1554 EXPECT_CALL(encryption_observer_, |
| 1555 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)).Times(0); |
| 1553 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()).Times(0); | 1556 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()).Times(0); |
| 1554 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()).Times(0); | 1557 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()).Times(0); |
| 1555 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); | 1558 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); |
| 1556 } | 1559 } |
| 1557 | 1560 |
| 1558 // Test that when there are no pending keys and the cryptographer is not | 1561 // Test that when there are no pending keys and the cryptographer is not |
| 1559 // initialized, we add a key based on the current GAIA password. | 1562 // initialized, we add a key based on the current GAIA password. |
| 1560 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) | 1563 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) |
| 1561 TEST_F(SyncManagerTest, SetInitialGaiaPass) { | 1564 TEST_F(SyncManagerTest, SetInitialGaiaPass) { |
| 1562 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); | 1565 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); |
| 1563 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); | 1566 EXPECT_CALL(encryption_observer_, |
| 1567 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1564 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1568 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1565 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1569 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1566 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1570 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1567 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1571 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1568 "new_passphrase", | 1572 "new_passphrase", |
| 1569 false); | 1573 false); |
| 1570 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1574 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1571 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1575 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); |
| 1572 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1576 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1573 { | 1577 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1587 TEST_F(SyncManagerTest, UpdateGaiaPass) { | 1591 TEST_F(SyncManagerTest, UpdateGaiaPass) { |
| 1588 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1592 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1589 Cryptographer verifier(&encryptor_); | 1593 Cryptographer verifier(&encryptor_); |
| 1590 { | 1594 { |
| 1591 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1595 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1592 Cryptographer* cryptographer = trans.GetCryptographer(); | 1596 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1593 std::string bootstrap_token; | 1597 std::string bootstrap_token; |
| 1594 cryptographer->GetBootstrapToken(&bootstrap_token); | 1598 cryptographer->GetBootstrapToken(&bootstrap_token); |
| 1595 verifier.Bootstrap(bootstrap_token); | 1599 verifier.Bootstrap(bootstrap_token); |
| 1596 } | 1600 } |
| 1597 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); | 1601 EXPECT_CALL(encryption_observer_, |
| 1602 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1598 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1603 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1599 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1604 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1600 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1605 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1601 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1606 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1602 "new_passphrase", | 1607 "new_passphrase", |
| 1603 false); | 1608 false); |
| 1604 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1609 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1605 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1610 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); |
| 1606 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1611 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1607 { | 1612 { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1634 | 1639 |
| 1635 WriteNode password_node(&trans); | 1640 WriteNode password_node(&trans); |
| 1636 WriteNode::InitUniqueByCreationResult result = | 1641 WriteNode::InitUniqueByCreationResult result = |
| 1637 password_node.InitUniqueByCreation(PASSWORDS, | 1642 password_node.InitUniqueByCreation(PASSWORDS, |
| 1638 root_node, "foo"); | 1643 root_node, "foo"); |
| 1639 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 1644 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 1640 sync_pb::PasswordSpecificsData data; | 1645 sync_pb::PasswordSpecificsData data; |
| 1641 data.set_password_value("secret"); | 1646 data.set_password_value("secret"); |
| 1642 password_node.SetPasswordSpecifics(data); | 1647 password_node.SetPasswordSpecifics(data); |
| 1643 } | 1648 } |
| 1644 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); | 1649 EXPECT_CALL(encryption_observer_, |
| 1650 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1645 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1651 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1646 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1652 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1647 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1653 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1648 EXPECT_CALL(encryption_observer_, | 1654 EXPECT_CALL(encryption_observer_, |
| 1649 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); | 1655 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); |
| 1650 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1656 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1651 "new_passphrase", | 1657 "new_passphrase", |
| 1652 true); | 1658 true); |
| 1653 EXPECT_EQ(CUSTOM_PASSPHRASE, | 1659 EXPECT_EQ(CUSTOM_PASSPHRASE, |
| 1654 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1660 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 KeyParams params = {"localhost", "dummy", "passphrase2"}; | 1697 KeyParams params = {"localhost", "dummy", "passphrase2"}; |
| 1692 other_cryptographer.AddKey(params); | 1698 other_cryptographer.AddKey(params); |
| 1693 WriteNode node(&trans); | 1699 WriteNode node(&trans); |
| 1694 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1700 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1695 sync_pb::NigoriSpecifics nigori; | 1701 sync_pb::NigoriSpecifics nigori; |
| 1696 other_cryptographer.GetKeys(nigori.mutable_encrypted()); | 1702 other_cryptographer.GetKeys(nigori.mutable_encrypted()); |
| 1697 cryptographer->SetPendingKeys(nigori.encrypted()); | 1703 cryptographer->SetPendingKeys(nigori.encrypted()); |
| 1698 EXPECT_TRUE(cryptographer->has_pending_keys()); | 1704 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 1699 node.SetNigoriSpecifics(nigori); | 1705 node.SetNigoriSpecifics(nigori); |
| 1700 } | 1706 } |
| 1701 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); | 1707 EXPECT_CALL(encryption_observer_, |
| 1708 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1702 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1709 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1703 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1710 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1704 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1711 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1705 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); | 1712 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); |
| 1706 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1713 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1707 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1714 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); |
| 1708 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1715 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1709 { | 1716 { |
| 1710 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1717 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1711 Cryptographer* cryptographer = trans.GetCryptographer(); | 1718 Cryptographer* cryptographer = trans.GetCryptographer(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1745 cryptographer->SetPendingKeys(nigori.encrypted()); | 1752 cryptographer->SetPendingKeys(nigori.encrypted()); |
| 1746 | 1753 |
| 1747 // other_cryptographer now contains all encryption keys, and is encrypting | 1754 // other_cryptographer now contains all encryption keys, and is encrypting |
| 1748 // with the newest gaia. | 1755 // with the newest gaia. |
| 1749 KeyParams new_params = {"localhost", "dummy", "new_gaia"}; | 1756 KeyParams new_params = {"localhost", "dummy", "new_gaia"}; |
| 1750 other_cryptographer.AddKey(new_params); | 1757 other_cryptographer.AddKey(new_params); |
| 1751 } | 1758 } |
| 1752 // The bootstrap token should have been updated. Save it to ensure it's based | 1759 // The bootstrap token should have been updated. Save it to ensure it's based |
| 1753 // on the new GAIA password. | 1760 // on the new GAIA password. |
| 1754 std::string bootstrap_token; | 1761 std::string bootstrap_token; |
| 1755 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)) | 1762 EXPECT_CALL(encryption_observer_, |
| 1763 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)) |
| 1756 .WillOnce(SaveArg<0>(&bootstrap_token)); | 1764 .WillOnce(SaveArg<0>(&bootstrap_token)); |
| 1757 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_)); | 1765 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_)); |
| 1758 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1766 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1759 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1767 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1760 "new_gaia", | 1768 "new_gaia", |
| 1761 false); | 1769 false); |
| 1762 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1770 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1763 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1771 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); |
| 1764 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1772 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1765 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 1773 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 1766 { | 1774 { |
| 1767 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1775 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1768 Cryptographer* cryptographer = trans.GetCryptographer(); | 1776 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1769 EXPECT_TRUE(cryptographer->is_initialized()); | 1777 EXPECT_TRUE(cryptographer->is_initialized()); |
| 1770 EXPECT_FALSE(cryptographer->is_ready()); | 1778 EXPECT_FALSE(cryptographer->is_ready()); |
| 1771 // Verify we're encrypting with the new key, even though we have pending | 1779 // Verify we're encrypting with the new key, even though we have pending |
| 1772 // keys. | 1780 // keys. |
| 1773 sync_pb::EncryptedData encrypted; | 1781 sync_pb::EncryptedData encrypted; |
| 1774 other_cryptographer.GetKeys(&encrypted); | 1782 other_cryptographer.GetKeys(&encrypted); |
| 1775 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); | 1783 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); |
| 1776 } | 1784 } |
| 1777 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); | 1785 EXPECT_CALL(encryption_observer_, |
| 1786 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1778 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1787 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1779 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1788 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1780 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1789 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1781 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1790 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1782 "old_gaia", | 1791 "old_gaia", |
| 1783 false); | 1792 false); |
| 1784 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1793 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1785 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1794 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); |
| 1786 { | 1795 { |
| 1787 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1796 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1820 other_cryptographer.AddKey(params); | 1829 other_cryptographer.AddKey(params); |
| 1821 WriteNode node(&trans); | 1830 WriteNode node(&trans); |
| 1822 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1831 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1823 sync_pb::NigoriSpecifics nigori; | 1832 sync_pb::NigoriSpecifics nigori; |
| 1824 other_cryptographer.GetKeys(nigori.mutable_encrypted()); | 1833 other_cryptographer.GetKeys(nigori.mutable_encrypted()); |
| 1825 cryptographer->SetPendingKeys(nigori.encrypted()); | 1834 cryptographer->SetPendingKeys(nigori.encrypted()); |
| 1826 EXPECT_TRUE(cryptographer->has_pending_keys()); | 1835 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 1827 nigori.set_using_explicit_passphrase(true); | 1836 nigori.set_using_explicit_passphrase(true); |
| 1828 node.SetNigoriSpecifics(nigori); | 1837 node.SetNigoriSpecifics(nigori); |
| 1829 } | 1838 } |
| 1830 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); | 1839 EXPECT_CALL(encryption_observer_, |
| 1840 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1831 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1841 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1832 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1842 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1833 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1843 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1834 EXPECT_CALL(encryption_observer_, | 1844 EXPECT_CALL(encryption_observer_, |
| 1835 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); | 1845 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); |
| 1836 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); | 1846 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); |
| 1837 EXPECT_EQ(CUSTOM_PASSPHRASE, | 1847 EXPECT_EQ(CUSTOM_PASSPHRASE, |
| 1838 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1848 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); |
| 1839 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1849 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1840 { | 1850 { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1863 KeyParams params = {"localhost", "dummy", "passphrase"}; | 1873 KeyParams params = {"localhost", "dummy", "passphrase"}; |
| 1864 other_cryptographer.AddKey(params); | 1874 other_cryptographer.AddKey(params); |
| 1865 WriteNode node(&trans); | 1875 WriteNode node(&trans); |
| 1866 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1876 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1867 sync_pb::NigoriSpecifics nigori; | 1877 sync_pb::NigoriSpecifics nigori; |
| 1868 other_cryptographer.GetKeys(nigori.mutable_encrypted()); | 1878 other_cryptographer.GetKeys(nigori.mutable_encrypted()); |
| 1869 node.SetNigoriSpecifics(nigori); | 1879 node.SetNigoriSpecifics(nigori); |
| 1870 cryptographer->SetPendingKeys(nigori.encrypted()); | 1880 cryptographer->SetPendingKeys(nigori.encrypted()); |
| 1871 EXPECT_FALSE(cryptographer->is_ready()); | 1881 EXPECT_FALSE(cryptographer->is_ready()); |
| 1872 } | 1882 } |
| 1873 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); | 1883 EXPECT_CALL(encryption_observer_, |
| 1884 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1874 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1885 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1875 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1886 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1876 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1887 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1877 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1888 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1878 "passphrase", | 1889 "passphrase", |
| 1879 false); | 1890 false); |
| 1880 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1891 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1881 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1892 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); |
| 1882 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1893 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1883 { | 1894 { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1895 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1906 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1896 ReadNode root_node(&trans); | 1907 ReadNode root_node(&trans); |
| 1897 root_node.InitByRootLookup(); | 1908 root_node.InitByRootLookup(); |
| 1898 | 1909 |
| 1899 WriteNode password_node(&trans); | 1910 WriteNode password_node(&trans); |
| 1900 WriteNode::InitUniqueByCreationResult result = | 1911 WriteNode::InitUniqueByCreationResult result = |
| 1901 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); | 1912 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); |
| 1902 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 1913 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 1903 node_id = password_node.GetId(); | 1914 node_id = password_node.GetId(); |
| 1904 } | 1915 } |
| 1905 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); | 1916 EXPECT_CALL(encryption_observer_, |
| 1917 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1906 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1918 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1907 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1919 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1908 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1920 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1909 EXPECT_CALL(encryption_observer_, | 1921 EXPECT_CALL(encryption_observer_, |
| 1910 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); | 1922 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); |
| 1911 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1923 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1912 "new_passphrase", | 1924 "new_passphrase", |
| 1913 true); | 1925 true); |
| 1914 EXPECT_EQ(CUSTOM_PASSPHRASE, | 1926 EXPECT_EQ(CUSTOM_PASSPHRASE, |
| 1915 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1927 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2120 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); | 2132 EXPECT_EQ(kEncryptedString, node_entry->Get(NON_UNIQUE_NAME)); |
| 2121 Cryptographer* cryptographer = trans.GetCryptographer(); | 2133 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 2122 EXPECT_TRUE(cryptographer->is_ready()); | 2134 EXPECT_TRUE(cryptographer->is_ready()); |
| 2123 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( | 2135 EXPECT_TRUE(cryptographer->CanDecryptUsingDefaultKey( |
| 2124 specifics.encrypted())); | 2136 specifics.encrypted())); |
| 2125 } | 2137 } |
| 2126 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2138 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2127 | 2139 |
| 2128 // Set a new passphrase. Should set is_unsynced. | 2140 // Set a new passphrase. Should set is_unsynced. |
| 2129 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 2141 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2130 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); | 2142 EXPECT_CALL(encryption_observer_, |
| 2143 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 2131 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 2144 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 2132 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2145 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2133 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 2146 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2134 EXPECT_CALL(encryption_observer_, | 2147 EXPECT_CALL(encryption_observer_, |
| 2135 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); | 2148 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); |
| 2136 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 2149 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 2137 "new_passphrase", | 2150 "new_passphrase", |
| 2138 true); | 2151 true); |
| 2139 { | 2152 { |
| 2140 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2153 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2317 } | 2330 } |
| 2318 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, | 2331 MakeServerNode(sync_manager_.GetUserShare(), PASSWORDS, client_tag, |
| 2319 BaseNode::GenerateSyncableHash(PASSWORDS, | 2332 BaseNode::GenerateSyncableHash(PASSWORDS, |
| 2320 client_tag), | 2333 client_tag), |
| 2321 entity_specifics); | 2334 entity_specifics); |
| 2322 // New node shouldn't start off unsynced. | 2335 // New node shouldn't start off unsynced. |
| 2323 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2336 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2324 | 2337 |
| 2325 // Set a new passphrase. Should set is_unsynced. | 2338 // Set a new passphrase. Should set is_unsynced. |
| 2326 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 2339 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2327 EXPECT_CALL(encryption_observer_, OnBootstrapTokenUpdated(_)); | 2340 EXPECT_CALL(encryption_observer_, |
| 2341 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 2328 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 2342 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 2329 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2343 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2330 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 2344 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2331 EXPECT_CALL(encryption_observer_, | 2345 EXPECT_CALL(encryption_observer_, |
| 2332 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); | 2346 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); |
| 2333 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 2347 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 2334 "new_passphrase", | 2348 "new_passphrase", |
| 2335 true); | 2349 true); |
| 2336 EXPECT_EQ(CUSTOM_PASSPHRASE, | 2350 EXPECT_EQ(CUSTOM_PASSPHRASE, |
| 2337 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 2351 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2887 | 2901 |
| 2888 // Verify only the non-disabled types remain after cleanup. | 2902 // Verify only the non-disabled types remain after cleanup. |
| 2889 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); | 2903 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); |
| 2890 EXPECT_TRUE(new_enabled_types.Equals( | 2904 EXPECT_TRUE(new_enabled_types.Equals( |
| 2891 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); | 2905 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); |
| 2892 EXPECT_TRUE(disabled_types.Equals( | 2906 EXPECT_TRUE(disabled_types.Equals( |
| 2893 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 2907 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
| 2894 } | 2908 } |
| 2895 | 2909 |
| 2896 } // namespace | 2910 } // namespace |
| OLD | NEW |