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

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

Issue 10916036: [Sync] Implement keystore migration support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments 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
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 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_METHOD2(OnBootstrapTokenUpdated, 696 MOCK_METHOD2(OnBootstrapTokenUpdated,
697 void(const std::string&, BootstrapTokenType type)); // NOLINT 697 void(const std::string&, BootstrapTokenType type)); // NOLINT
698 MOCK_METHOD2(OnEncryptedTypesChanged, 698 MOCK_METHOD2(OnEncryptedTypesChanged,
699 void(ModelTypeSet, bool)); // NOLINT 699 void(ModelTypeSet, bool)); // NOLINT
700 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT 700 MOCK_METHOD0(OnEncryptionComplete, void()); // NOLINT
701 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT 701 MOCK_METHOD1(OnCryptographerStateChanged, void(Cryptographer*)); // NOLINT
702 MOCK_METHOD1(OnPassphraseStateChanged, void(PassphraseState)); // NOLINT 702 MOCK_METHOD1(OnPassphraseTypeChanged, void(PassphraseType)); // NOLINT
703 }; 703 };
704 704
705 } // namespace 705 } // namespace
706 706
707 class SyncManagerTest : public testing::Test, 707 class SyncManagerTest : public testing::Test,
708 public SyncManager::ChangeDelegate { 708 public SyncManager::ChangeDelegate {
709 protected: 709 protected:
710 enum NigoriStatus { 710 enum NigoriStatus {
711 DONT_WRITE_NIGORI, 711 DONT_WRITE_NIGORI,
712 WRITE_TO_NIGORI 712 WRITE_TO_NIGORI
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 if (!cryptographer) 825 if (!cryptographer)
826 return false; 826 return false;
827 if (encryption_status != UNINITIALIZED) { 827 if (encryption_status != UNINITIALIZED) {
828 KeyParams params = {"localhost", "dummy", "foobar"}; 828 KeyParams params = {"localhost", "dummy", "foobar"};
829 cryptographer->AddKey(params); 829 cryptographer->AddKey(params);
830 } else { 830 } else {
831 DCHECK_NE(nigori_status, WRITE_TO_NIGORI); 831 DCHECK_NE(nigori_status, WRITE_TO_NIGORI);
832 } 832 }
833 if (nigori_status == WRITE_TO_NIGORI) { 833 if (nigori_status == WRITE_TO_NIGORI) {
834 sync_pb::NigoriSpecifics nigori; 834 sync_pb::NigoriSpecifics nigori;
835 cryptographer->GetKeys(nigori.mutable_encrypted()); 835 cryptographer->GetKeys(nigori.mutable_encryption_keybag());
836 share->directory->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes( 836 share->directory->GetNigoriHandler()->UpdateNigoriFromEncryptedTypes(
837 &nigori, 837 &nigori,
838 trans.GetWrappedTrans()); 838 trans.GetWrappedTrans());
839 WriteNode node(&trans); 839 WriteNode node(&trans);
840 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(nigori_id)); 840 EXPECT_EQ(BaseNode::INIT_OK, node.InitByIdLookup(nigori_id));
841 node.SetNigoriSpecifics(nigori); 841 node.SetNigoriSpecifics(nigori);
842 } 842 }
843 return cryptographer->is_ready(); 843 return cryptographer->is_ready();
844 } 844 }
845 845
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 const ModelTypeSet encrypted_types = GetEncryptedTypes(); 1361 const ModelTypeSet encrypted_types = GetEncryptedTypes();
1362 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); 1362 EXPECT_TRUE(encrypted_types.Has(PASSWORDS));
1363 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1363 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1364 1364
1365 { 1365 {
1366 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1366 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1367 ReadNode node(&trans); 1367 ReadNode node(&trans);
1368 EXPECT_EQ(BaseNode::INIT_OK, 1368 EXPECT_EQ(BaseNode::INIT_OK,
1369 node.InitByIdLookup(GetIdForDataType(NIGORI))); 1369 node.InitByIdLookup(GetIdForDataType(NIGORI)));
1370 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); 1370 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
1371 EXPECT_TRUE(nigori.has_encrypted()); 1371 EXPECT_TRUE(nigori.has_encryption_keybag());
1372 Cryptographer* cryptographer = trans.GetCryptographer(); 1372 Cryptographer* cryptographer = trans.GetCryptographer();
1373 EXPECT_TRUE(cryptographer->is_ready()); 1373 EXPECT_TRUE(cryptographer->is_ready());
1374 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); 1374 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag()));
1375 } 1375 }
1376 } 1376 }
1377 1377
1378 // Attempt to refresh encryption when nigori not downloaded. 1378 // Attempt to refresh encryption when nigori not downloaded.
1379 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { 1379 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) {
1380 // Don't set up encryption (no nigori node created). 1380 // Don't set up encryption (no nigori node created).
1381 1381
1382 // Should fail. Triggers an OnPassphraseRequired because the cryptographer 1382 // Should fail. Triggers an OnPassphraseRequired because the cryptographer
1383 // is not ready. 1383 // is not ready.
1384 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)).Times(1); 1384 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)).Times(1);
(...skipping 21 matching lines...) Expand all
1406 const ModelTypeSet encrypted_types = GetEncryptedTypes(); 1406 const ModelTypeSet encrypted_types = GetEncryptedTypes();
1407 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. 1407 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded.
1408 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1408 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1409 1409
1410 { 1410 {
1411 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1411 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1412 ReadNode node(&trans); 1412 ReadNode node(&trans);
1413 EXPECT_EQ(BaseNode::INIT_OK, 1413 EXPECT_EQ(BaseNode::INIT_OK,
1414 node.InitByIdLookup(GetIdForDataType(NIGORI))); 1414 node.InitByIdLookup(GetIdForDataType(NIGORI)));
1415 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); 1415 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
1416 EXPECT_TRUE(nigori.has_encrypted()); 1416 EXPECT_TRUE(nigori.has_encryption_keybag());
1417 Cryptographer* cryptographer = trans.GetCryptographer(); 1417 Cryptographer* cryptographer = trans.GetCryptographer();
1418 EXPECT_TRUE(cryptographer->is_ready()); 1418 EXPECT_TRUE(cryptographer->is_ready());
1419 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); 1419 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag()));
1420 } 1420 }
1421 } 1421 }
1422 1422
1423 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { 1423 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) {
1424 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1424 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1425 EXPECT_CALL(encryption_observer_, 1425 EXPECT_CALL(encryption_observer_,
1426 OnEncryptedTypesChanged( 1426 OnEncryptedTypesChanged(
1427 HasModelTypes(ModelTypeSet::All()), true)); 1427 HasModelTypes(ModelTypeSet::All()), true));
1428 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1428 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1429 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); 1429 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 } 1501 }
1502 1502
1503 // Trigger's a ReEncryptEverything with new passphrase. 1503 // Trigger's a ReEncryptEverything with new passphrase.
1504 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 1504 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
1505 EXPECT_CALL(encryption_observer_, 1505 EXPECT_CALL(encryption_observer_,
1506 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1506 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1507 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1507 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1508 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1508 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1509 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1509 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1510 EXPECT_CALL(encryption_observer_, 1510 EXPECT_CALL(encryption_observer_,
1511 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); 1511 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
1512 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1512 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1513 "new_passphrase", true); 1513 "new_passphrase", true);
1514 EXPECT_TRUE(EncryptEverythingEnabledForTest()); 1514 EXPECT_TRUE(EncryptEverythingEnabledForTest());
1515 { 1515 {
1516 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1516 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1517 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(ModelTypeSet::All())); 1517 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(ModelTypeSet::All()));
1518 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( 1518 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest(
1519 trans.GetWrappedTrans(), 1519 trans.GetWrappedTrans(),
1520 BOOKMARKS, 1520 BOOKMARKS,
1521 true /* is encrypted */)); 1521 true /* is encrypted */));
(...skipping 23 matching lines...) Expand all
1545 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); 1545 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED));
1546 EXPECT_CALL(encryption_observer_, 1546 EXPECT_CALL(encryption_observer_,
1547 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1547 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1548 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1548 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1549 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1549 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1550 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1550 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1551 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1551 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1552 "new_passphrase", 1552 "new_passphrase",
1553 false); 1553 false);
1554 EXPECT_EQ(IMPLICIT_PASSPHRASE, 1554 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1555 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1555 sync_manager_.GetEncryptionHandler()->GetPassphraseType());
1556 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1556 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1557 { 1557 {
1558 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1558 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1559 ReadNode node(&trans); 1559 ReadNode node(&trans);
1560 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1560 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1561 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); 1561 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics();
1562 Cryptographer* cryptographer = trans.GetCryptographer(); 1562 Cryptographer* cryptographer = trans.GetCryptographer();
1563 EXPECT_TRUE(cryptographer->is_ready()); 1563 EXPECT_TRUE(cryptographer->is_ready());
1564 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); 1564 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag()));
1565 } 1565 }
1566 } 1566 }
1567 1567
1568 // Test that when there are no pending keys and we have on the old GAIA 1568 // Test that when there are no pending keys and we have on the old GAIA
1569 // password, we update and re-encrypt everything with the new GAIA password. 1569 // password, we update and re-encrypt everything with the new GAIA password.
1570 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) 1570 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase)
1571 TEST_F(SyncManagerTest, UpdateGaiaPass) { 1571 TEST_F(SyncManagerTest, UpdateGaiaPass) {
1572 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1572 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1573 Cryptographer verifier(&encryptor_); 1573 Cryptographer verifier(&encryptor_);
1574 { 1574 {
1575 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1575 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1576 Cryptographer* cryptographer = trans.GetCryptographer(); 1576 Cryptographer* cryptographer = trans.GetCryptographer();
1577 std::string bootstrap_token; 1577 std::string bootstrap_token;
1578 cryptographer->GetBootstrapToken(&bootstrap_token); 1578 cryptographer->GetBootstrapToken(&bootstrap_token);
1579 verifier.Bootstrap(bootstrap_token); 1579 verifier.Bootstrap(bootstrap_token);
1580 } 1580 }
1581 EXPECT_CALL(encryption_observer_, 1581 EXPECT_CALL(encryption_observer_,
1582 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1582 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1583 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1583 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1584 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1584 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1585 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1585 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1586 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1586 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1587 "new_passphrase", 1587 "new_passphrase",
1588 false); 1588 false);
1589 EXPECT_EQ(IMPLICIT_PASSPHRASE, 1589 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1590 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1590 sync_manager_.GetEncryptionHandler()->GetPassphraseType());
1591 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1591 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1592 { 1592 {
1593 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1593 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1594 Cryptographer* cryptographer = trans.GetCryptographer(); 1594 Cryptographer* cryptographer = trans.GetCryptographer();
1595 EXPECT_TRUE(cryptographer->is_ready()); 1595 EXPECT_TRUE(cryptographer->is_ready());
1596 // Verify the default key has changed. 1596 // Verify the default key has changed.
1597 sync_pb::EncryptedData encrypted; 1597 sync_pb::EncryptedData encrypted;
1598 cryptographer->GetKeys(&encrypted); 1598 cryptographer->GetKeys(&encrypted);
1599 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); 1599 EXPECT_FALSE(verifier.CanDecrypt(encrypted));
1600 } 1600 }
(...skipping 24 matching lines...) Expand all
1625 sync_pb::PasswordSpecificsData data; 1625 sync_pb::PasswordSpecificsData data;
1626 data.set_password_value("secret"); 1626 data.set_password_value("secret");
1627 password_node.SetPasswordSpecifics(data); 1627 password_node.SetPasswordSpecifics(data);
1628 } 1628 }
1629 EXPECT_CALL(encryption_observer_, 1629 EXPECT_CALL(encryption_observer_,
1630 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1630 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1631 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1631 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1632 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1632 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1633 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1633 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1634 EXPECT_CALL(encryption_observer_, 1634 EXPECT_CALL(encryption_observer_,
1635 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); 1635 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
1636 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1636 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1637 "new_passphrase", 1637 "new_passphrase",
1638 true); 1638 true);
1639 EXPECT_EQ(CUSTOM_PASSPHRASE, 1639 EXPECT_EQ(CUSTOM_PASSPHRASE,
1640 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1640 sync_manager_.GetEncryptionHandler()->GetPassphraseType());
1641 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1641 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1642 { 1642 {
1643 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1643 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1644 Cryptographer* cryptographer = trans.GetCryptographer(); 1644 Cryptographer* cryptographer = trans.GetCryptographer();
1645 EXPECT_TRUE(cryptographer->is_ready()); 1645 EXPECT_TRUE(cryptographer->is_ready());
1646 // Verify the default key has changed. 1646 // Verify the default key has changed.
1647 sync_pb::EncryptedData encrypted; 1647 sync_pb::EncryptedData encrypted;
1648 cryptographer->GetKeys(&encrypted); 1648 cryptographer->GetKeys(&encrypted);
1649 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); 1649 EXPECT_FALSE(verifier.CanDecrypt(encrypted));
1650 1650
(...skipping 21 matching lines...) Expand all
1672 cryptographer->GetBootstrapToken(&bootstrap_token); 1672 cryptographer->GetBootstrapToken(&bootstrap_token);
1673 other_cryptographer.Bootstrap(bootstrap_token); 1673 other_cryptographer.Bootstrap(bootstrap_token);
1674 1674
1675 // Now update the nigori to reflect the new keys, and update the 1675 // Now update the nigori to reflect the new keys, and update the
1676 // cryptographer to have pending keys. 1676 // cryptographer to have pending keys.
1677 KeyParams params = {"localhost", "dummy", "passphrase2"}; 1677 KeyParams params = {"localhost", "dummy", "passphrase2"};
1678 other_cryptographer.AddKey(params); 1678 other_cryptographer.AddKey(params);
1679 WriteNode node(&trans); 1679 WriteNode node(&trans);
1680 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1680 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1681 sync_pb::NigoriSpecifics nigori; 1681 sync_pb::NigoriSpecifics nigori;
1682 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1682 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
1683 cryptographer->SetPendingKeys(nigori.encrypted()); 1683 cryptographer->SetPendingKeys(nigori.encryption_keybag());
1684 EXPECT_TRUE(cryptographer->has_pending_keys()); 1684 EXPECT_TRUE(cryptographer->has_pending_keys());
1685 node.SetNigoriSpecifics(nigori); 1685 node.SetNigoriSpecifics(nigori);
1686 } 1686 }
1687 EXPECT_CALL(encryption_observer_, 1687 EXPECT_CALL(encryption_observer_,
1688 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1688 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1689 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1689 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1690 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1690 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1691 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1691 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1692 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); 1692 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2");
1693 EXPECT_EQ(IMPLICIT_PASSPHRASE, 1693 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1694 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1694 sync_manager_.GetEncryptionHandler()->GetPassphraseType());
1695 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1695 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1696 { 1696 {
1697 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1697 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1698 Cryptographer* cryptographer = trans.GetCryptographer(); 1698 Cryptographer* cryptographer = trans.GetCryptographer();
1699 EXPECT_TRUE(cryptographer->is_ready()); 1699 EXPECT_TRUE(cryptographer->is_ready());
1700 // Verify we're encrypting with the new key. 1700 // Verify we're encrypting with the new key.
1701 sync_pb::EncryptedData encrypted; 1701 sync_pb::EncryptedData encrypted;
1702 cryptographer->GetKeys(&encrypted); 1702 cryptographer->GetKeys(&encrypted);
1703 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); 1703 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted));
1704 } 1704 }
(...skipping 15 matching lines...) Expand all
1720 cryptographer->GetBootstrapToken(&bootstrap_token); 1720 cryptographer->GetBootstrapToken(&bootstrap_token);
1721 other_cryptographer.Bootstrap(bootstrap_token); 1721 other_cryptographer.Bootstrap(bootstrap_token);
1722 1722
1723 // Now update the nigori to reflect the new keys, and update the 1723 // Now update the nigori to reflect the new keys, and update the
1724 // cryptographer to have pending keys. 1724 // cryptographer to have pending keys.
1725 KeyParams params = {"localhost", "dummy", "old_gaia"}; 1725 KeyParams params = {"localhost", "dummy", "old_gaia"};
1726 other_cryptographer.AddKey(params); 1726 other_cryptographer.AddKey(params);
1727 WriteNode node(&trans); 1727 WriteNode node(&trans);
1728 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1728 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1729 sync_pb::NigoriSpecifics nigori; 1729 sync_pb::NigoriSpecifics nigori;
1730 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1730 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
1731 node.SetNigoriSpecifics(nigori); 1731 node.SetNigoriSpecifics(nigori);
1732 cryptographer->SetPendingKeys(nigori.encrypted()); 1732 cryptographer->SetPendingKeys(nigori.encryption_keybag());
1733 1733
1734 // other_cryptographer now contains all encryption keys, and is encrypting 1734 // other_cryptographer now contains all encryption keys, and is encrypting
1735 // with the newest gaia. 1735 // with the newest gaia.
1736 KeyParams new_params = {"localhost", "dummy", "new_gaia"}; 1736 KeyParams new_params = {"localhost", "dummy", "new_gaia"};
1737 other_cryptographer.AddKey(new_params); 1737 other_cryptographer.AddKey(new_params);
1738 } 1738 }
1739 // 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
1740 // on the new GAIA password. 1740 // on the new GAIA password.
1741 std::string bootstrap_token; 1741 std::string bootstrap_token;
1742 EXPECT_CALL(encryption_observer_, 1742 EXPECT_CALL(encryption_observer_,
1743 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)) 1743 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN))
1744 .WillOnce(SaveArg<0>(&bootstrap_token)); 1744 .WillOnce(SaveArg<0>(&bootstrap_token));
1745 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_)); 1745 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_));
1746 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1746 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1747 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1747 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1748 "new_gaia", 1748 "new_gaia",
1749 false); 1749 false);
1750 EXPECT_EQ(IMPLICIT_PASSPHRASE, 1750 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1751 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1751 sync_manager_.GetEncryptionHandler()->GetPassphraseType());
1752 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1752 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1753 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 1753 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
1754 { 1754 {
1755 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1755 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1756 Cryptographer* cryptographer = trans.GetCryptographer(); 1756 Cryptographer* cryptographer = trans.GetCryptographer();
1757 EXPECT_TRUE(cryptographer->is_initialized()); 1757 EXPECT_TRUE(cryptographer->is_initialized());
1758 EXPECT_FALSE(cryptographer->is_ready()); 1758 EXPECT_FALSE(cryptographer->is_ready());
1759 // 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
1760 // keys. 1760 // keys.
1761 sync_pb::EncryptedData encrypted; 1761 sync_pb::EncryptedData encrypted;
1762 other_cryptographer.GetKeys(&encrypted); 1762 other_cryptographer.GetKeys(&encrypted);
1763 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); 1763 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted));
1764 } 1764 }
1765 EXPECT_CALL(encryption_observer_, 1765 EXPECT_CALL(encryption_observer_,
1766 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1766 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1767 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1767 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1768 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1768 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1769 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1769 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1770 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1770 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1771 "old_gaia", 1771 "old_gaia",
1772 false); 1772 false);
1773 EXPECT_EQ(IMPLICIT_PASSPHRASE, 1773 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1774 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1774 sync_manager_.GetEncryptionHandler()->GetPassphraseType());
1775 { 1775 {
1776 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1776 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1777 Cryptographer* cryptographer = trans.GetCryptographer(); 1777 Cryptographer* cryptographer = trans.GetCryptographer();
1778 EXPECT_TRUE(cryptographer->is_ready()); 1778 EXPECT_TRUE(cryptographer->is_ready());
1779 1779
1780 // Verify we're encrypting with the new key. 1780 // Verify we're encrypting with the new key.
1781 sync_pb::EncryptedData encrypted; 1781 sync_pb::EncryptedData encrypted;
1782 other_cryptographer.GetKeys(&encrypted); 1782 other_cryptographer.GetKeys(&encrypted);
1783 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); 1783 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted));
1784 1784
(...skipping 18 matching lines...) Expand all
1803 cryptographer->GetBootstrapToken(&bootstrap_token); 1803 cryptographer->GetBootstrapToken(&bootstrap_token);
1804 other_cryptographer.Bootstrap(bootstrap_token); 1804 other_cryptographer.Bootstrap(bootstrap_token);
1805 1805
1806 // Now update the nigori to reflect the new keys, and update the 1806 // Now update the nigori to reflect the new keys, and update the
1807 // cryptographer to have pending keys. 1807 // cryptographer to have pending keys.
1808 KeyParams params = {"localhost", "dummy", "explicit"}; 1808 KeyParams params = {"localhost", "dummy", "explicit"};
1809 other_cryptographer.AddKey(params); 1809 other_cryptographer.AddKey(params);
1810 WriteNode node(&trans); 1810 WriteNode node(&trans);
1811 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1811 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1812 sync_pb::NigoriSpecifics nigori; 1812 sync_pb::NigoriSpecifics nigori;
1813 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1813 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
1814 cryptographer->SetPendingKeys(nigori.encrypted()); 1814 cryptographer->SetPendingKeys(nigori.encryption_keybag());
1815 EXPECT_TRUE(cryptographer->has_pending_keys()); 1815 EXPECT_TRUE(cryptographer->has_pending_keys());
1816 nigori.set_using_explicit_passphrase(true); 1816 nigori.set_frozen_keybag(true);
1817 node.SetNigoriSpecifics(nigori); 1817 node.SetNigoriSpecifics(nigori);
1818 } 1818 }
1819 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1820 EXPECT_CALL(encryption_observer_,
1821 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
1822 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _));
1823 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false));
1824 sync_manager_.GetEncryptionHandler()->Init();
1819 EXPECT_CALL(encryption_observer_, 1825 EXPECT_CALL(encryption_observer_,
1820 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1826 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1821 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1827 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1822 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1828 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1823 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1829 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1824 EXPECT_CALL(encryption_observer_,
1825 OnPassphraseStateChanged(CUSTOM_PASSPHRASE));
1826 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); 1830 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit");
1827 EXPECT_EQ(CUSTOM_PASSPHRASE, 1831 EXPECT_EQ(CUSTOM_PASSPHRASE,
1828 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1832 sync_manager_.GetEncryptionHandler()->GetPassphraseType());
1829 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1833 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1830 { 1834 {
1831 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1835 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1832 Cryptographer* cryptographer = trans.GetCryptographer(); 1836 Cryptographer* cryptographer = trans.GetCryptographer();
1833 EXPECT_TRUE(cryptographer->is_ready()); 1837 EXPECT_TRUE(cryptographer->is_ready());
1834 // Verify we're encrypting with the new key. 1838 // Verify we're encrypting with the new key.
1835 sync_pb::EncryptedData encrypted; 1839 sync_pb::EncryptedData encrypted;
1836 cryptographer->GetKeys(&encrypted); 1840 cryptographer->GetKeys(&encrypted);
1837 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); 1841 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted));
1838 } 1842 }
1839 } 1843 }
1840 1844
1841 // Manually set the pending keys in the cryptographer/nigori to reflect the data 1845 // Manually set the pending keys in the cryptographer/nigori to reflect the data
1842 // being encrypted with a new (unprovided) GAIA password, then supply the 1846 // being encrypted with a new (unprovided) GAIA password, then supply the
1843 // password as a user-provided password. 1847 // password as a user-provided password.
1844 // This is the android case 7/8. 1848 // This is the android case 7/8.
1845 TEST_F(SyncManagerTest, SupplyPendingGAIAPassUserProvided) { 1849 TEST_F(SyncManagerTest, SupplyPendingGAIAPassUserProvided) {
1846 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); 1850 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED));
1847 Cryptographer other_cryptographer(&encryptor_); 1851 Cryptographer other_cryptographer(&encryptor_);
1848 { 1852 {
1849 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1853 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1850 Cryptographer* cryptographer = trans.GetCryptographer(); 1854 Cryptographer* cryptographer = trans.GetCryptographer();
1851 // Now update the nigori to reflect the new keys, and update the 1855 // Now update the nigori to reflect the new keys, and update the
1852 // cryptographer to have pending keys. 1856 // cryptographer to have pending keys.
1853 KeyParams params = {"localhost", "dummy", "passphrase"}; 1857 KeyParams params = {"localhost", "dummy", "passphrase"};
1854 other_cryptographer.AddKey(params); 1858 other_cryptographer.AddKey(params);
1855 WriteNode node(&trans); 1859 WriteNode node(&trans);
1856 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); 1860 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag));
1857 sync_pb::NigoriSpecifics nigori; 1861 sync_pb::NigoriSpecifics nigori;
1858 other_cryptographer.GetKeys(nigori.mutable_encrypted()); 1862 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag());
1859 node.SetNigoriSpecifics(nigori); 1863 node.SetNigoriSpecifics(nigori);
1860 cryptographer->SetPendingKeys(nigori.encrypted()); 1864 cryptographer->SetPendingKeys(nigori.encryption_keybag());
1861 EXPECT_FALSE(cryptographer->is_ready()); 1865 EXPECT_FALSE(cryptographer->is_ready());
1862 } 1866 }
1863 EXPECT_CALL(encryption_observer_, 1867 EXPECT_CALL(encryption_observer_,
1864 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1868 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1865 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1869 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1866 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1870 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1867 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1871 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1868 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1872 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1869 "passphrase", 1873 "passphrase",
1870 false); 1874 false);
1871 EXPECT_EQ(IMPLICIT_PASSPHRASE, 1875 EXPECT_EQ(IMPLICIT_PASSPHRASE,
1872 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1876 sync_manager_.GetEncryptionHandler()->GetPassphraseType());
1873 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1877 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1874 { 1878 {
1875 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1879 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1876 Cryptographer* cryptographer = trans.GetCryptographer(); 1880 Cryptographer* cryptographer = trans.GetCryptographer();
1877 EXPECT_TRUE(cryptographer->is_ready()); 1881 EXPECT_TRUE(cryptographer->is_ready());
1878 } 1882 }
1879 } 1883 }
1880 1884
1881 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { 1885 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) {
1882 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 1886 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
1883 int64 node_id = 0; 1887 int64 node_id = 0;
1884 std::string tag = "foo"; 1888 std::string tag = "foo";
1885 { 1889 {
1886 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1890 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1887 ReadNode root_node(&trans); 1891 ReadNode root_node(&trans);
1888 root_node.InitByRootLookup(); 1892 root_node.InitByRootLookup();
1889 1893
1890 WriteNode password_node(&trans); 1894 WriteNode password_node(&trans);
1891 WriteNode::InitUniqueByCreationResult result = 1895 WriteNode::InitUniqueByCreationResult result =
1892 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); 1896 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag);
1893 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); 1897 EXPECT_EQ(WriteNode::INIT_SUCCESS, result);
1894 node_id = password_node.GetId(); 1898 node_id = password_node.GetId();
1895 } 1899 }
1896 EXPECT_CALL(encryption_observer_, 1900 EXPECT_CALL(encryption_observer_,
1897 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 1901 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
1898 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 1902 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
1899 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 1903 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
1900 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 1904 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
1901 EXPECT_CALL(encryption_observer_, 1905 EXPECT_CALL(encryption_observer_,
1902 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); 1906 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
1903 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 1907 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
1904 "new_passphrase", 1908 "new_passphrase",
1905 true); 1909 true);
1906 EXPECT_EQ(CUSTOM_PASSPHRASE, 1910 EXPECT_EQ(CUSTOM_PASSPHRASE,
1907 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 1911 sync_manager_.GetEncryptionHandler()->GetPassphraseType());
1908 EXPECT_FALSE(EncryptEverythingEnabledForTest()); 1912 EXPECT_FALSE(EncryptEverythingEnabledForTest());
1909 { 1913 {
1910 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1914 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
1911 ReadNode password_node(&trans); 1915 ReadNode password_node(&trans);
1912 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, 1916 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY,
1913 password_node.InitByClientTagLookup(PASSWORDS, 1917 password_node.InitByClientTagLookup(PASSWORDS,
1914 tag)); 1918 tag));
1915 } 1919 }
1916 { 1920 {
1917 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 1921 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); 2123 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag));
2120 2124
2121 // Set a new passphrase. Should set is_unsynced. 2125 // Set a new passphrase. Should set is_unsynced.
2122 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 2126 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
2123 EXPECT_CALL(encryption_observer_, 2127 EXPECT_CALL(encryption_observer_,
2124 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 2128 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
2125 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 2129 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
2126 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 2130 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2127 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 2131 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2128 EXPECT_CALL(encryption_observer_, 2132 EXPECT_CALL(encryption_observer_,
2129 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); 2133 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
2130 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 2134 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
2131 "new_passphrase", 2135 "new_passphrase",
2132 true); 2136 true);
2133 { 2137 {
2134 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); 2138 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare());
2135 ReadNode node(&trans); 2139 ReadNode node(&trans);
2136 EXPECT_EQ(BaseNode::INIT_OK, 2140 EXPECT_EQ(BaseNode::INIT_OK,
2137 node.InitByClientTagLookup(BOOKMARKS, client_tag)); 2141 node.InitByClientTagLookup(BOOKMARKS, client_tag));
2138 const syncable::Entry* node_entry = node.GetEntry(); 2142 const syncable::Entry* node_entry = node.GetEntry();
2139 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); 2143 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS);
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
2318 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); 2322 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag));
2319 2323
2320 // Set a new passphrase. Should set is_unsynced. 2324 // Set a new passphrase. Should set is_unsynced.
2321 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); 2325 testing::Mock::VerifyAndClearExpectations(&encryption_observer_);
2322 EXPECT_CALL(encryption_observer_, 2326 EXPECT_CALL(encryption_observer_,
2323 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); 2327 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN));
2324 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); 2328 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted());
2325 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); 2329 EXPECT_CALL(encryption_observer_, OnEncryptionComplete());
2326 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); 2330 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_));
2327 EXPECT_CALL(encryption_observer_, 2331 EXPECT_CALL(encryption_observer_,
2328 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); 2332 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE));
2329 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( 2333 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase(
2330 "new_passphrase", 2334 "new_passphrase",
2331 true); 2335 true);
2332 EXPECT_EQ(CUSTOM_PASSPHRASE, 2336 EXPECT_EQ(CUSTOM_PASSPHRASE,
2333 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); 2337 sync_manager_.GetEncryptionHandler()->GetPassphraseType());
2334 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); 2338 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag));
2335 } 2339 }
2336 2340
2337 // 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
2338 // in unnecessary writes via ReencryptEverything. 2342 // in unnecessary writes via ReencryptEverything.
2339 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { 2343 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) {
2340 std::string client_tag = "title"; 2344 std::string client_tag = "title";
2341 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); 2345 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION));
2342 sync_pb::EntitySpecifics entity_specifics; 2346 sync_pb::EntitySpecifics entity_specifics;
2343 { 2347 {
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
2886 2890
2887 // Verify only the non-disabled types remain after cleanup. 2891 // Verify only the non-disabled types remain after cleanup.
2888 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); 2892 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types);
2889 EXPECT_TRUE(new_enabled_types.Equals( 2893 EXPECT_TRUE(new_enabled_types.Equals(
2890 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); 2894 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types)));
2891 EXPECT_TRUE(disabled_types.Equals( 2895 EXPECT_TRUE(disabled_types.Equals(
2892 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); 2896 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All())));
2893 } 2897 }
2894 2898
2895 } // namespace 2899 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698