| 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 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1355 const ModelTypeSet encrypted_types = GetEncryptedTypes(); | 1355 const ModelTypeSet encrypted_types = GetEncryptedTypes(); |
| 1356 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); | 1356 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); |
| 1357 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1357 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1358 | 1358 |
| 1359 { | 1359 { |
| 1360 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1360 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1361 ReadNode node(&trans); | 1361 ReadNode node(&trans); |
| 1362 EXPECT_EQ(BaseNode::INIT_OK, | 1362 EXPECT_EQ(BaseNode::INIT_OK, |
| 1363 node.InitByIdLookup(GetIdForDataType(NIGORI))); | 1363 node.InitByIdLookup(GetIdForDataType(NIGORI))); |
| 1364 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); | 1364 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); |
| 1365 EXPECT_TRUE(nigori.has_encrypted()); | 1365 EXPECT_TRUE(nigori.has_encryption_keybag()); |
| 1366 Cryptographer* cryptographer = trans.GetCryptographer(); | 1366 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1367 EXPECT_TRUE(cryptographer->is_ready()); | 1367 EXPECT_TRUE(cryptographer->is_ready()); |
| 1368 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); | 1368 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag())); |
| 1369 } | 1369 } |
| 1370 } | 1370 } |
| 1371 | 1371 |
| 1372 // Attempt to refresh encryption when nigori not downloaded. | 1372 // Attempt to refresh encryption when nigori not downloaded. |
| 1373 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { | 1373 TEST_F(SyncManagerTest, RefreshEncryptionNotReady) { |
| 1374 // Don't set up encryption (no nigori node created). | 1374 // Don't set up encryption (no nigori node created). |
| 1375 | 1375 |
| 1376 // Should fail. Triggers an OnPassphraseRequired because the cryptographer | 1376 // Should fail. Triggers an OnPassphraseRequired because the cryptographer |
| 1377 // is not ready. | 1377 // is not ready. |
| 1378 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)).Times(1); | 1378 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)).Times(1); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1400 const ModelTypeSet encrypted_types = GetEncryptedTypes(); | 1400 const ModelTypeSet encrypted_types = GetEncryptedTypes(); |
| 1401 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. | 1401 EXPECT_TRUE(encrypted_types.Has(PASSWORDS)); // Hardcoded. |
| 1402 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1402 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1403 | 1403 |
| 1404 { | 1404 { |
| 1405 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1405 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1406 ReadNode node(&trans); | 1406 ReadNode node(&trans); |
| 1407 EXPECT_EQ(BaseNode::INIT_OK, | 1407 EXPECT_EQ(BaseNode::INIT_OK, |
| 1408 node.InitByIdLookup(GetIdForDataType(NIGORI))); | 1408 node.InitByIdLookup(GetIdForDataType(NIGORI))); |
| 1409 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); | 1409 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); |
| 1410 EXPECT_TRUE(nigori.has_encrypted()); | 1410 EXPECT_TRUE(nigori.has_encryption_keybag()); |
| 1411 Cryptographer* cryptographer = trans.GetCryptographer(); | 1411 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1412 EXPECT_TRUE(cryptographer->is_ready()); | 1412 EXPECT_TRUE(cryptographer->is_ready()); |
| 1413 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); | 1413 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag())); |
| 1414 } | 1414 } |
| 1415 } | 1415 } |
| 1416 | 1416 |
| 1417 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { | 1417 TEST_F(SyncManagerTest, EncryptDataTypesWithNoData) { |
| 1418 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1418 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1419 EXPECT_CALL(encryption_observer_, | 1419 EXPECT_CALL(encryption_observer_, |
| 1420 OnEncryptedTypesChanged( | 1420 OnEncryptedTypesChanged( |
| 1421 HasModelTypes(UserTypes()), true)); | 1421 HasModelTypes(UserTypes()), true)); |
| 1422 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1422 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1423 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); | 1423 sync_manager_.GetEncryptionHandler()->EnableEncryptEverything(); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 } | 1495 } |
| 1496 | 1496 |
| 1497 // Trigger's a ReEncryptEverything with new passphrase. | 1497 // Trigger's a ReEncryptEverything with new passphrase. |
| 1498 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 1498 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 1499 EXPECT_CALL(encryption_observer_, | 1499 EXPECT_CALL(encryption_observer_, |
| 1500 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1500 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1501 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1501 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1502 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1502 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1503 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1503 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1504 EXPECT_CALL(encryption_observer_, | 1504 EXPECT_CALL(encryption_observer_, |
| 1505 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); | 1505 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); |
| 1506 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1506 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1507 "new_passphrase", true); | 1507 "new_passphrase", true); |
| 1508 EXPECT_TRUE(EncryptEverythingEnabledForTest()); | 1508 EXPECT_TRUE(EncryptEverythingEnabledForTest()); |
| 1509 { | 1509 { |
| 1510 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1510 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1511 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(UserTypes())); | 1511 EXPECT_TRUE(GetEncryptedTypesWithTrans(&trans).Equals(UserTypes())); |
| 1512 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( | 1512 EXPECT_TRUE(syncable::VerifyDataTypeEncryptionForTest( |
| 1513 trans.GetWrappedTrans(), | 1513 trans.GetWrappedTrans(), |
| 1514 BOOKMARKS, | 1514 BOOKMARKS, |
| 1515 true /* is encrypted */)); | 1515 true /* is encrypted */)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1539 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); | 1539 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); |
| 1540 EXPECT_CALL(encryption_observer_, | 1540 EXPECT_CALL(encryption_observer_, |
| 1541 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1541 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1542 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1542 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1543 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1543 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1544 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1544 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1545 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1545 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1546 "new_passphrase", | 1546 "new_passphrase", |
| 1547 false); | 1547 false); |
| 1548 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1548 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1549 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1549 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1550 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1550 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1551 { | 1551 { |
| 1552 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1552 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1553 ReadNode node(&trans); | 1553 ReadNode node(&trans); |
| 1554 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1554 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1555 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); | 1555 sync_pb::NigoriSpecifics nigori = node.GetNigoriSpecifics(); |
| 1556 Cryptographer* cryptographer = trans.GetCryptographer(); | 1556 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1557 EXPECT_TRUE(cryptographer->is_ready()); | 1557 EXPECT_TRUE(cryptographer->is_ready()); |
| 1558 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encrypted())); | 1558 EXPECT_TRUE(cryptographer->CanDecrypt(nigori.encryption_keybag())); |
| 1559 } | 1559 } |
| 1560 } | 1560 } |
| 1561 | 1561 |
| 1562 // Test that when there are no pending keys and we have on the old GAIA | 1562 // Test that when there are no pending keys and we have on the old GAIA |
| 1563 // password, we update and re-encrypt everything with the new GAIA password. | 1563 // password, we update and re-encrypt everything with the new GAIA password. |
| 1564 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) | 1564 // (case 1 in SyncManager::SyncInternal::SetEncryptionPassphrase) |
| 1565 TEST_F(SyncManagerTest, UpdateGaiaPass) { | 1565 TEST_F(SyncManagerTest, UpdateGaiaPass) { |
| 1566 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1566 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1567 Cryptographer verifier(&encryptor_); | 1567 Cryptographer verifier(&encryptor_); |
| 1568 { | 1568 { |
| 1569 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1569 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1570 Cryptographer* cryptographer = trans.GetCryptographer(); | 1570 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1571 std::string bootstrap_token; | 1571 std::string bootstrap_token; |
| 1572 cryptographer->GetBootstrapToken(&bootstrap_token); | 1572 cryptographer->GetBootstrapToken(&bootstrap_token); |
| 1573 verifier.Bootstrap(bootstrap_token); | 1573 verifier.Bootstrap(bootstrap_token); |
| 1574 } | 1574 } |
| 1575 EXPECT_CALL(encryption_observer_, | 1575 EXPECT_CALL(encryption_observer_, |
| 1576 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1576 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1577 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1577 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1578 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1578 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1579 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1579 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1580 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1580 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1581 "new_passphrase", | 1581 "new_passphrase", |
| 1582 false); | 1582 false); |
| 1583 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1583 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1584 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1584 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1585 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1585 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1586 { | 1586 { |
| 1587 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1587 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1588 Cryptographer* cryptographer = trans.GetCryptographer(); | 1588 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1589 EXPECT_TRUE(cryptographer->is_ready()); | 1589 EXPECT_TRUE(cryptographer->is_ready()); |
| 1590 // Verify the default key has changed. | 1590 // Verify the default key has changed. |
| 1591 sync_pb::EncryptedData encrypted; | 1591 sync_pb::EncryptedData encrypted; |
| 1592 cryptographer->GetKeys(&encrypted); | 1592 cryptographer->GetKeys(&encrypted); |
| 1593 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); | 1593 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); |
| 1594 } | 1594 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1619 sync_pb::PasswordSpecificsData data; | 1619 sync_pb::PasswordSpecificsData data; |
| 1620 data.set_password_value("secret"); | 1620 data.set_password_value("secret"); |
| 1621 password_node.SetPasswordSpecifics(data); | 1621 password_node.SetPasswordSpecifics(data); |
| 1622 } | 1622 } |
| 1623 EXPECT_CALL(encryption_observer_, | 1623 EXPECT_CALL(encryption_observer_, |
| 1624 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1624 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1625 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1625 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1626 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1626 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1627 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1627 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1628 EXPECT_CALL(encryption_observer_, | 1628 EXPECT_CALL(encryption_observer_, |
| 1629 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); | 1629 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); |
| 1630 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1630 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1631 "new_passphrase", | 1631 "new_passphrase", |
| 1632 true); | 1632 true); |
| 1633 EXPECT_EQ(CUSTOM_PASSPHRASE, | 1633 EXPECT_EQ(CUSTOM_PASSPHRASE, |
| 1634 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1634 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1635 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1635 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1636 { | 1636 { |
| 1637 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1637 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1638 Cryptographer* cryptographer = trans.GetCryptographer(); | 1638 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1639 EXPECT_TRUE(cryptographer->is_ready()); | 1639 EXPECT_TRUE(cryptographer->is_ready()); |
| 1640 // Verify the default key has changed. | 1640 // Verify the default key has changed. |
| 1641 sync_pb::EncryptedData encrypted; | 1641 sync_pb::EncryptedData encrypted; |
| 1642 cryptographer->GetKeys(&encrypted); | 1642 cryptographer->GetKeys(&encrypted); |
| 1643 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); | 1643 EXPECT_FALSE(verifier.CanDecrypt(encrypted)); |
| 1644 | 1644 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1666 cryptographer->GetBootstrapToken(&bootstrap_token); | 1666 cryptographer->GetBootstrapToken(&bootstrap_token); |
| 1667 other_cryptographer.Bootstrap(bootstrap_token); | 1667 other_cryptographer.Bootstrap(bootstrap_token); |
| 1668 | 1668 |
| 1669 // Now update the nigori to reflect the new keys, and update the | 1669 // Now update the nigori to reflect the new keys, and update the |
| 1670 // cryptographer to have pending keys. | 1670 // cryptographer to have pending keys. |
| 1671 KeyParams params = {"localhost", "dummy", "passphrase2"}; | 1671 KeyParams params = {"localhost", "dummy", "passphrase2"}; |
| 1672 other_cryptographer.AddKey(params); | 1672 other_cryptographer.AddKey(params); |
| 1673 WriteNode node(&trans); | 1673 WriteNode node(&trans); |
| 1674 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1674 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1675 sync_pb::NigoriSpecifics nigori; | 1675 sync_pb::NigoriSpecifics nigori; |
| 1676 other_cryptographer.GetKeys(nigori.mutable_encrypted()); | 1676 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); |
| 1677 cryptographer->SetPendingKeys(nigori.encrypted()); | 1677 cryptographer->SetPendingKeys(nigori.encryption_keybag()); |
| 1678 EXPECT_TRUE(cryptographer->has_pending_keys()); | 1678 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 1679 node.SetNigoriSpecifics(nigori); | 1679 node.SetNigoriSpecifics(nigori); |
| 1680 } | 1680 } |
| 1681 EXPECT_CALL(encryption_observer_, | 1681 EXPECT_CALL(encryption_observer_, |
| 1682 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1682 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1683 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1683 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1684 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1684 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1685 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1685 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1686 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); | 1686 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("passphrase2"); |
| 1687 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1687 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1688 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1688 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1689 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1689 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1690 { | 1690 { |
| 1691 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1691 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1692 Cryptographer* cryptographer = trans.GetCryptographer(); | 1692 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1693 EXPECT_TRUE(cryptographer->is_ready()); | 1693 EXPECT_TRUE(cryptographer->is_ready()); |
| 1694 // Verify we're encrypting with the new key. | 1694 // Verify we're encrypting with the new key. |
| 1695 sync_pb::EncryptedData encrypted; | 1695 sync_pb::EncryptedData encrypted; |
| 1696 cryptographer->GetKeys(&encrypted); | 1696 cryptographer->GetKeys(&encrypted); |
| 1697 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); | 1697 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); |
| 1698 } | 1698 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1714 cryptographer->GetBootstrapToken(&bootstrap_token); | 1714 cryptographer->GetBootstrapToken(&bootstrap_token); |
| 1715 other_cryptographer.Bootstrap(bootstrap_token); | 1715 other_cryptographer.Bootstrap(bootstrap_token); |
| 1716 | 1716 |
| 1717 // Now update the nigori to reflect the new keys, and update the | 1717 // Now update the nigori to reflect the new keys, and update the |
| 1718 // cryptographer to have pending keys. | 1718 // cryptographer to have pending keys. |
| 1719 KeyParams params = {"localhost", "dummy", "old_gaia"}; | 1719 KeyParams params = {"localhost", "dummy", "old_gaia"}; |
| 1720 other_cryptographer.AddKey(params); | 1720 other_cryptographer.AddKey(params); |
| 1721 WriteNode node(&trans); | 1721 WriteNode node(&trans); |
| 1722 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1722 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1723 sync_pb::NigoriSpecifics nigori; | 1723 sync_pb::NigoriSpecifics nigori; |
| 1724 other_cryptographer.GetKeys(nigori.mutable_encrypted()); | 1724 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); |
| 1725 node.SetNigoriSpecifics(nigori); | 1725 node.SetNigoriSpecifics(nigori); |
| 1726 cryptographer->SetPendingKeys(nigori.encrypted()); | 1726 cryptographer->SetPendingKeys(nigori.encryption_keybag()); |
| 1727 | 1727 |
| 1728 // other_cryptographer now contains all encryption keys, and is encrypting | 1728 // other_cryptographer now contains all encryption keys, and is encrypting |
| 1729 // with the newest gaia. | 1729 // with the newest gaia. |
| 1730 KeyParams new_params = {"localhost", "dummy", "new_gaia"}; | 1730 KeyParams new_params = {"localhost", "dummy", "new_gaia"}; |
| 1731 other_cryptographer.AddKey(new_params); | 1731 other_cryptographer.AddKey(new_params); |
| 1732 } | 1732 } |
| 1733 // The bootstrap token should have been updated. Save it to ensure it's based | 1733 // The bootstrap token should have been updated. Save it to ensure it's based |
| 1734 // on the new GAIA password. | 1734 // on the new GAIA password. |
| 1735 std::string bootstrap_token; | 1735 std::string bootstrap_token; |
| 1736 EXPECT_CALL(encryption_observer_, | 1736 EXPECT_CALL(encryption_observer_, |
| 1737 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)) | 1737 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)) |
| 1738 .WillOnce(SaveArg<0>(&bootstrap_token)); | 1738 .WillOnce(SaveArg<0>(&bootstrap_token)); |
| 1739 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_)); | 1739 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_,_)); |
| 1740 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1740 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1741 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1741 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1742 "new_gaia", | 1742 "new_gaia", |
| 1743 false); | 1743 false); |
| 1744 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1744 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1745 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1745 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1746 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1746 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1747 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 1747 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 1748 { | 1748 { |
| 1749 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1749 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1750 Cryptographer* cryptographer = trans.GetCryptographer(); | 1750 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1751 EXPECT_TRUE(cryptographer->is_initialized()); | 1751 EXPECT_TRUE(cryptographer->is_initialized()); |
| 1752 EXPECT_FALSE(cryptographer->is_ready()); | 1752 EXPECT_FALSE(cryptographer->is_ready()); |
| 1753 // Verify we're encrypting with the new key, even though we have pending | 1753 // Verify we're encrypting with the new key, even though we have pending |
| 1754 // keys. | 1754 // keys. |
| 1755 sync_pb::EncryptedData encrypted; | 1755 sync_pb::EncryptedData encrypted; |
| 1756 other_cryptographer.GetKeys(&encrypted); | 1756 other_cryptographer.GetKeys(&encrypted); |
| 1757 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); | 1757 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); |
| 1758 } | 1758 } |
| 1759 EXPECT_CALL(encryption_observer_, | 1759 EXPECT_CALL(encryption_observer_, |
| 1760 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1760 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1761 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1761 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1762 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1762 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1763 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1763 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1764 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1764 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1765 "old_gaia", | 1765 "old_gaia", |
| 1766 false); | 1766 false); |
| 1767 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1767 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1768 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1768 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1769 { | 1769 { |
| 1770 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1770 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1771 Cryptographer* cryptographer = trans.GetCryptographer(); | 1771 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1772 EXPECT_TRUE(cryptographer->is_ready()); | 1772 EXPECT_TRUE(cryptographer->is_ready()); |
| 1773 | 1773 |
| 1774 // Verify we're encrypting with the new key. | 1774 // Verify we're encrypting with the new key. |
| 1775 sync_pb::EncryptedData encrypted; | 1775 sync_pb::EncryptedData encrypted; |
| 1776 other_cryptographer.GetKeys(&encrypted); | 1776 other_cryptographer.GetKeys(&encrypted); |
| 1777 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); | 1777 EXPECT_TRUE(cryptographer->CanDecrypt(encrypted)); |
| 1778 | 1778 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1797 cryptographer->GetBootstrapToken(&bootstrap_token); | 1797 cryptographer->GetBootstrapToken(&bootstrap_token); |
| 1798 other_cryptographer.Bootstrap(bootstrap_token); | 1798 other_cryptographer.Bootstrap(bootstrap_token); |
| 1799 | 1799 |
| 1800 // Now update the nigori to reflect the new keys, and update the | 1800 // Now update the nigori to reflect the new keys, and update the |
| 1801 // cryptographer to have pending keys. | 1801 // cryptographer to have pending keys. |
| 1802 KeyParams params = {"localhost", "dummy", "explicit"}; | 1802 KeyParams params = {"localhost", "dummy", "explicit"}; |
| 1803 other_cryptographer.AddKey(params); | 1803 other_cryptographer.AddKey(params); |
| 1804 WriteNode node(&trans); | 1804 WriteNode node(&trans); |
| 1805 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1805 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1806 sync_pb::NigoriSpecifics nigori; | 1806 sync_pb::NigoriSpecifics nigori; |
| 1807 other_cryptographer.GetKeys(nigori.mutable_encrypted()); | 1807 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); |
| 1808 cryptographer->SetPendingKeys(nigori.encrypted()); | 1808 cryptographer->SetPendingKeys(nigori.encryption_keybag()); |
| 1809 EXPECT_TRUE(cryptographer->has_pending_keys()); | 1809 EXPECT_TRUE(cryptographer->has_pending_keys()); |
| 1810 nigori.set_using_explicit_passphrase(true); | 1810 nigori.set_keybag_is_frozen(true); |
| 1811 node.SetNigoriSpecifics(nigori); | 1811 node.SetNigoriSpecifics(nigori); |
| 1812 } | 1812 } |
| 1813 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1814 EXPECT_CALL(encryption_observer_, |
| 1815 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); |
| 1816 EXPECT_CALL(encryption_observer_, OnPassphraseRequired(_, _)); |
| 1817 EXPECT_CALL(encryption_observer_, OnEncryptedTypesChanged(_, false)); |
| 1818 sync_manager_.GetEncryptionHandler()->Init(); |
| 1813 EXPECT_CALL(encryption_observer_, | 1819 EXPECT_CALL(encryption_observer_, |
| 1814 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1820 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1815 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1821 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1816 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1822 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1817 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1823 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1818 EXPECT_CALL(encryption_observer_, | |
| 1819 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); | |
| 1820 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); | 1824 sync_manager_.GetEncryptionHandler()->SetDecryptionPassphrase("explicit"); |
| 1821 EXPECT_EQ(CUSTOM_PASSPHRASE, | 1825 EXPECT_EQ(CUSTOM_PASSPHRASE, |
| 1822 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1826 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1823 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1827 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1824 { | 1828 { |
| 1825 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1829 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1826 Cryptographer* cryptographer = trans.GetCryptographer(); | 1830 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1827 EXPECT_TRUE(cryptographer->is_ready()); | 1831 EXPECT_TRUE(cryptographer->is_ready()); |
| 1828 // Verify we're encrypting with the new key. | 1832 // Verify we're encrypting with the new key. |
| 1829 sync_pb::EncryptedData encrypted; | 1833 sync_pb::EncryptedData encrypted; |
| 1830 cryptographer->GetKeys(&encrypted); | 1834 cryptographer->GetKeys(&encrypted); |
| 1831 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); | 1835 EXPECT_TRUE(other_cryptographer.CanDecrypt(encrypted)); |
| 1832 } | 1836 } |
| 1833 } | 1837 } |
| 1834 | 1838 |
| 1835 // Manually set the pending keys in the cryptographer/nigori to reflect the data | 1839 // Manually set the pending keys in the cryptographer/nigori to reflect the data |
| 1836 // being encrypted with a new (unprovided) GAIA password, then supply the | 1840 // being encrypted with a new (unprovided) GAIA password, then supply the |
| 1837 // password as a user-provided password. | 1841 // password as a user-provided password. |
| 1838 // This is the android case 7/8. | 1842 // This is the android case 7/8. |
| 1839 TEST_F(SyncManagerTest, SupplyPendingGAIAPassUserProvided) { | 1843 TEST_F(SyncManagerTest, SupplyPendingGAIAPassUserProvided) { |
| 1840 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); | 1844 EXPECT_FALSE(SetUpEncryption(DONT_WRITE_NIGORI, UNINITIALIZED)); |
| 1841 Cryptographer other_cryptographer(&encryptor_); | 1845 Cryptographer other_cryptographer(&encryptor_); |
| 1842 { | 1846 { |
| 1843 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1847 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1844 Cryptographer* cryptographer = trans.GetCryptographer(); | 1848 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1845 // Now update the nigori to reflect the new keys, and update the | 1849 // Now update the nigori to reflect the new keys, and update the |
| 1846 // cryptographer to have pending keys. | 1850 // cryptographer to have pending keys. |
| 1847 KeyParams params = {"localhost", "dummy", "passphrase"}; | 1851 KeyParams params = {"localhost", "dummy", "passphrase"}; |
| 1848 other_cryptographer.AddKey(params); | 1852 other_cryptographer.AddKey(params); |
| 1849 WriteNode node(&trans); | 1853 WriteNode node(&trans); |
| 1850 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); | 1854 EXPECT_EQ(BaseNode::INIT_OK, node.InitByTagLookup(kNigoriTag)); |
| 1851 sync_pb::NigoriSpecifics nigori; | 1855 sync_pb::NigoriSpecifics nigori; |
| 1852 other_cryptographer.GetKeys(nigori.mutable_encrypted()); | 1856 other_cryptographer.GetKeys(nigori.mutable_encryption_keybag()); |
| 1853 node.SetNigoriSpecifics(nigori); | 1857 node.SetNigoriSpecifics(nigori); |
| 1854 cryptographer->SetPendingKeys(nigori.encrypted()); | 1858 cryptographer->SetPendingKeys(nigori.encryption_keybag()); |
| 1855 EXPECT_FALSE(cryptographer->is_ready()); | 1859 EXPECT_FALSE(cryptographer->is_ready()); |
| 1856 } | 1860 } |
| 1857 EXPECT_CALL(encryption_observer_, | 1861 EXPECT_CALL(encryption_observer_, |
| 1858 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1862 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1859 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1863 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1860 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1864 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1861 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1865 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1862 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1866 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1863 "passphrase", | 1867 "passphrase", |
| 1864 false); | 1868 false); |
| 1865 EXPECT_EQ(IMPLICIT_PASSPHRASE, | 1869 EXPECT_EQ(IMPLICIT_PASSPHRASE, |
| 1866 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1870 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1867 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1871 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1868 { | 1872 { |
| 1869 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1873 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1870 Cryptographer* cryptographer = trans.GetCryptographer(); | 1874 Cryptographer* cryptographer = trans.GetCryptographer(); |
| 1871 EXPECT_TRUE(cryptographer->is_ready()); | 1875 EXPECT_TRUE(cryptographer->is_ready()); |
| 1872 } | 1876 } |
| 1873 } | 1877 } |
| 1874 | 1878 |
| 1875 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { | 1879 TEST_F(SyncManagerTest, SetPassphraseWithEmptyPasswordNode) { |
| 1876 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 1880 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 1877 int64 node_id = 0; | 1881 int64 node_id = 0; |
| 1878 std::string tag = "foo"; | 1882 std::string tag = "foo"; |
| 1879 { | 1883 { |
| 1880 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1884 WriteTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1881 ReadNode root_node(&trans); | 1885 ReadNode root_node(&trans); |
| 1882 root_node.InitByRootLookup(); | 1886 root_node.InitByRootLookup(); |
| 1883 | 1887 |
| 1884 WriteNode password_node(&trans); | 1888 WriteNode password_node(&trans); |
| 1885 WriteNode::InitUniqueByCreationResult result = | 1889 WriteNode::InitUniqueByCreationResult result = |
| 1886 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); | 1890 password_node.InitUniqueByCreation(PASSWORDS, root_node, tag); |
| 1887 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); | 1891 EXPECT_EQ(WriteNode::INIT_SUCCESS, result); |
| 1888 node_id = password_node.GetId(); | 1892 node_id = password_node.GetId(); |
| 1889 } | 1893 } |
| 1890 EXPECT_CALL(encryption_observer_, | 1894 EXPECT_CALL(encryption_observer_, |
| 1891 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 1895 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 1892 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 1896 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 1893 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 1897 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 1894 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 1898 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 1895 EXPECT_CALL(encryption_observer_, | 1899 EXPECT_CALL(encryption_observer_, |
| 1896 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); | 1900 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); |
| 1897 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 1901 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1898 "new_passphrase", | 1902 "new_passphrase", |
| 1899 true); | 1903 true); |
| 1900 EXPECT_EQ(CUSTOM_PASSPHRASE, | 1904 EXPECT_EQ(CUSTOM_PASSPHRASE, |
| 1901 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 1905 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 1902 EXPECT_FALSE(EncryptEverythingEnabledForTest()); | 1906 EXPECT_FALSE(EncryptEverythingEnabledForTest()); |
| 1903 { | 1907 { |
| 1904 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1908 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 1905 ReadNode password_node(&trans); | 1909 ReadNode password_node(&trans); |
| 1906 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, | 1910 EXPECT_EQ(BaseNode::INIT_FAILED_DECRYPT_IF_NECESSARY, |
| 1907 password_node.InitByClientTagLookup(PASSWORDS, | 1911 password_node.InitByClientTagLookup(PASSWORDS, |
| 1908 tag)); | 1912 tag)); |
| 1909 } | 1913 } |
| 1910 { | 1914 { |
| 1911 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 1915 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2113 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); | 2117 EXPECT_TRUE(ResetUnsyncedEntry(BOOKMARKS, client_tag)); |
| 2114 | 2118 |
| 2115 // Set a new passphrase. Should set is_unsynced. | 2119 // Set a new passphrase. Should set is_unsynced. |
| 2116 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 2120 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2117 EXPECT_CALL(encryption_observer_, | 2121 EXPECT_CALL(encryption_observer_, |
| 2118 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 2122 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 2119 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 2123 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 2120 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2124 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2121 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 2125 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2122 EXPECT_CALL(encryption_observer_, | 2126 EXPECT_CALL(encryption_observer_, |
| 2123 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); | 2127 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); |
| 2124 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 2128 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 2125 "new_passphrase", | 2129 "new_passphrase", |
| 2126 true); | 2130 true); |
| 2127 { | 2131 { |
| 2128 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); | 2132 ReadTransaction trans(FROM_HERE, sync_manager_.GetUserShare()); |
| 2129 ReadNode node(&trans); | 2133 ReadNode node(&trans); |
| 2130 EXPECT_EQ(BaseNode::INIT_OK, | 2134 EXPECT_EQ(BaseNode::INIT_OK, |
| 2131 node.InitByClientTagLookup(BOOKMARKS, client_tag)); | 2135 node.InitByClientTagLookup(BOOKMARKS, client_tag)); |
| 2132 const syncable::Entry* node_entry = node.GetEntry(); | 2136 const syncable::Entry* node_entry = node.GetEntry(); |
| 2133 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); | 2137 const sync_pb::EntitySpecifics& specifics = node_entry->Get(SPECIFICS); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2312 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2316 EXPECT_FALSE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2313 | 2317 |
| 2314 // Set a new passphrase. Should set is_unsynced. | 2318 // Set a new passphrase. Should set is_unsynced. |
| 2315 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); | 2319 testing::Mock::VerifyAndClearExpectations(&encryption_observer_); |
| 2316 EXPECT_CALL(encryption_observer_, | 2320 EXPECT_CALL(encryption_observer_, |
| 2317 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); | 2321 OnBootstrapTokenUpdated(_, PASSPHRASE_BOOTSTRAP_TOKEN)); |
| 2318 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); | 2322 EXPECT_CALL(encryption_observer_, OnPassphraseAccepted()); |
| 2319 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); | 2323 EXPECT_CALL(encryption_observer_, OnEncryptionComplete()); |
| 2320 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); | 2324 EXPECT_CALL(encryption_observer_, OnCryptographerStateChanged(_)); |
| 2321 EXPECT_CALL(encryption_observer_, | 2325 EXPECT_CALL(encryption_observer_, |
| 2322 OnPassphraseStateChanged(CUSTOM_PASSPHRASE)); | 2326 OnPassphraseTypeChanged(CUSTOM_PASSPHRASE)); |
| 2323 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( | 2327 sync_manager_.GetEncryptionHandler()->SetEncryptionPassphrase( |
| 2324 "new_passphrase", | 2328 "new_passphrase", |
| 2325 true); | 2329 true); |
| 2326 EXPECT_EQ(CUSTOM_PASSPHRASE, | 2330 EXPECT_EQ(CUSTOM_PASSPHRASE, |
| 2327 sync_manager_.GetEncryptionHandler()->GetPassphraseState()); | 2331 sync_manager_.GetEncryptionHandler()->GetPassphraseType()); |
| 2328 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); | 2332 EXPECT_TRUE(ResetUnsyncedEntry(PASSWORDS, client_tag)); |
| 2329 } | 2333 } |
| 2330 | 2334 |
| 2331 // Passwords have their own handling for encryption. Verify it does not result | 2335 // Passwords have their own handling for encryption. Verify it does not result |
| 2332 // in unnecessary writes via ReencryptEverything. | 2336 // in unnecessary writes via ReencryptEverything. |
| 2333 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { | 2337 TEST_F(SyncManagerTest, UpdatePasswordReencryptEverything) { |
| 2334 std::string client_tag = "title"; | 2338 std::string client_tag = "title"; |
| 2335 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); | 2339 EXPECT_TRUE(SetUpEncryption(WRITE_TO_NIGORI, DEFAULT_ENCRYPTION)); |
| 2336 sync_pb::EntitySpecifics entity_specifics; | 2340 sync_pb::EntitySpecifics entity_specifics; |
| 2337 { | 2341 { |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2880 | 2884 |
| 2881 // Verify only the non-disabled types remain after cleanup. | 2885 // Verify only the non-disabled types remain after cleanup. |
| 2882 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); | 2886 sync_manager_.PurgeDisabledTypes(enabled_types, new_enabled_types); |
| 2883 EXPECT_TRUE(new_enabled_types.Equals( | 2887 EXPECT_TRUE(new_enabled_types.Equals( |
| 2884 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); | 2888 Union(sync_manager_.InitialSyncEndedTypes(), partial_enabled_types))); |
| 2885 EXPECT_TRUE(disabled_types.Equals( | 2889 EXPECT_TRUE(disabled_types.Equals( |
| 2886 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); | 2890 sync_manager_.GetTypesWithEmptyProgressMarkerToken(ModelTypeSet::All()))); |
| 2887 } | 2891 } |
| 2888 | 2892 |
| 2889 } // namespace | 2893 } // namespace |
| OLD | NEW |