OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #include "sync/internal_api/sync_encryption_handler_impl.h" | 5 #include "sync/internal_api/sync_encryption_handler_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 virtual void TearDown() { | 84 virtual void TearDown() { |
85 PumpLoop(); | 85 PumpLoop(); |
86 test_user_share_.TearDown(); | 86 test_user_share_.TearDown(); |
87 } | 87 } |
88 | 88 |
89 protected: | 89 protected: |
90 void SetUpEncryption() { | 90 void SetUpEncryption() { |
91 encryption_handler_.reset( | 91 encryption_handler_.reset( |
92 new SyncEncryptionHandlerImpl(user_share(), | 92 new SyncEncryptionHandlerImpl(user_share(), |
93 &encryptor_, | 93 &encryptor_, |
94 "", "" /* bootstrap tokens */)); | 94 std::string(), |
| 95 std::string() /* bootstrap tokens */)); |
95 encryption_handler_->AddObserver(&observer_); | 96 encryption_handler_->AddObserver(&observer_); |
96 } | 97 } |
97 | 98 |
98 void CreateRootForType(ModelType model_type) { | 99 void CreateRootForType(ModelType model_type) { |
99 syncer::syncable::Directory* directory = user_share()->directory.get(); | 100 syncer::syncable::Directory* directory = user_share()->directory.get(); |
100 | 101 |
101 std::string tag_name = ModelTypeToRootTag(model_type); | 102 std::string tag_name = ModelTypeToRootTag(model_type); |
102 | 103 |
103 syncable::WriteTransaction wtrans(FROM_HERE, syncable::UNITTEST, directory); | 104 syncable::WriteTransaction wtrans(FROM_HERE, syncable::UNITTEST, directory); |
104 syncable::MutableEntry node(&wtrans, | 105 syncable::MutableEntry node(&wtrans, |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 }; | 341 }; |
341 | 342 |
342 // Verify that the encrypted types are being written to and read from the | 343 // Verify that the encrypted types are being written to and read from the |
343 // nigori node properly. | 344 // nigori node properly. |
344 TEST_F(SyncEncryptionHandlerImplTest, NigoriEncryptionTypes) { | 345 TEST_F(SyncEncryptionHandlerImplTest, NigoriEncryptionTypes) { |
345 sync_pb::NigoriSpecifics nigori; | 346 sync_pb::NigoriSpecifics nigori; |
346 | 347 |
347 StrictMock<SyncEncryptionHandlerObserverMock> observer2; | 348 StrictMock<SyncEncryptionHandlerObserverMock> observer2; |
348 SyncEncryptionHandlerImpl handler2(user_share(), | 349 SyncEncryptionHandlerImpl handler2(user_share(), |
349 &encryptor_, | 350 &encryptor_, |
350 "", "" /* bootstrap tokens */); | 351 std::string(), |
| 352 std::string() /* bootstrap tokens */); |
351 handler2.AddObserver(&observer2); | 353 handler2.AddObserver(&observer2); |
352 | 354 |
353 // Just set the sensitive types (shouldn't trigger any notifications). | 355 // Just set the sensitive types (shouldn't trigger any notifications). |
354 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); | 356 ModelTypeSet encrypted_types(SyncEncryptionHandler::SensitiveTypes()); |
355 { | 357 { |
356 WriteTransaction trans(FROM_HERE, user_share()); | 358 WriteTransaction trans(FROM_HERE, user_share()); |
357 encryption_handler()->MergeEncryptedTypes( | 359 encryption_handler()->MergeEncryptedTypes( |
358 encrypted_types, | 360 encrypted_types, |
359 trans.GetWrappedTrans()); | 361 trans.GetWrappedTrans()); |
360 encryption_handler()->UpdateNigoriFromEncryptedTypes( | 362 encryption_handler()->UpdateNigoriFromEncryptedTypes( |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 // triggers a non-backwards compatible migration. Then verify that the | 606 // triggers a non-backwards compatible migration. Then verify that the |
605 // bootstrap token can be correctly parsed by the encryption handler at startup | 607 // bootstrap token can be correctly parsed by the encryption handler at startup |
606 // time. | 608 // time. |
607 TEST_F(SyncEncryptionHandlerImplTest, SetKeystoreMigratesAndUpdatesBootstrap) { | 609 TEST_F(SyncEncryptionHandlerImplTest, SetKeystoreMigratesAndUpdatesBootstrap) { |
608 // Passing no keys should do nothing. | 610 // Passing no keys should do nothing. |
609 EXPECT_CALL(*observer(), OnBootstrapTokenUpdated(_, _)).Times(0); | 611 EXPECT_CALL(*observer(), OnBootstrapTokenUpdated(_, _)).Times(0); |
610 { | 612 { |
611 WriteTransaction trans(FROM_HERE, user_share()); | 613 WriteTransaction trans(FROM_HERE, user_share()); |
612 EXPECT_FALSE(GetCryptographer()->is_initialized()); | 614 EXPECT_FALSE(GetCryptographer()->is_initialized()); |
613 EXPECT_TRUE(encryption_handler()->NeedKeystoreKey(trans.GetWrappedTrans())); | 615 EXPECT_TRUE(encryption_handler()->NeedKeystoreKey(trans.GetWrappedTrans())); |
614 EXPECT_FALSE( | 616 EXPECT_FALSE(encryption_handler()->SetKeystoreKeys( |
615 encryption_handler()->SetKeystoreKeys(BuildEncryptionKeyProto(""), | 617 BuildEncryptionKeyProto(std::string()), trans.GetWrappedTrans())); |
616 trans.GetWrappedTrans())); | |
617 EXPECT_TRUE(encryption_handler()->NeedKeystoreKey(trans.GetWrappedTrans())); | 618 EXPECT_TRUE(encryption_handler()->NeedKeystoreKey(trans.GetWrappedTrans())); |
618 } | 619 } |
619 Mock::VerifyAndClearExpectations(observer()); | 620 Mock::VerifyAndClearExpectations(observer()); |
620 | 621 |
621 // Build a set of keystore keys. | 622 // Build a set of keystore keys. |
622 const char kRawOldKeystoreKey[] = "old_keystore_key"; | 623 const char kRawOldKeystoreKey[] = "old_keystore_key"; |
623 std::string old_keystore_key; | 624 std::string old_keystore_key; |
624 base::Base64Encode(kRawOldKeystoreKey, &old_keystore_key); | 625 base::Base64Encode(kRawOldKeystoreKey, &old_keystore_key); |
625 google::protobuf::RepeatedPtrField<google::protobuf::string> keys; | 626 google::protobuf::RepeatedPtrField<google::protobuf::string> keys; |
626 keys.Add()->assign(kRawOldKeystoreKey); | 627 keys.Add()->assign(kRawOldKeystoreKey); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 keystore_list->GetString(0, &test_string); | 673 keystore_list->GetString(0, &test_string); |
673 ASSERT_EQ(old_keystore_key, test_string); | 674 ASSERT_EQ(old_keystore_key, test_string); |
674 keystore_list->GetString(1, &test_string); | 675 keystore_list->GetString(1, &test_string); |
675 ASSERT_EQ(kKeystoreKey, test_string); | 676 ASSERT_EQ(kKeystoreKey, test_string); |
676 | 677 |
677 | 678 |
678 // Now make sure a new encryption handler can correctly parse the bootstrap | 679 // Now make sure a new encryption handler can correctly parse the bootstrap |
679 // token. | 680 // token. |
680 SyncEncryptionHandlerImpl handler2(user_share(), | 681 SyncEncryptionHandlerImpl handler2(user_share(), |
681 &encryptor_, | 682 &encryptor_, |
682 "", // Cryptographer bootstrap. | 683 std::string(), // Cryptographer bootstrap. |
683 keystore_bootstrap); | 684 keystore_bootstrap); |
684 | 685 |
685 { | 686 { |
686 WriteTransaction trans(FROM_HERE, user_share()); | 687 WriteTransaction trans(FROM_HERE, user_share()); |
687 EXPECT_FALSE(handler2.NeedKeystoreKey(trans.GetWrappedTrans())); | 688 EXPECT_FALSE(handler2.NeedKeystoreKey(trans.GetWrappedTrans())); |
688 } | 689 } |
689 } | 690 } |
690 | 691 |
691 // Ensure GetKeystoreDecryptor only updates the keystore decryptor token if it | 692 // Ensure GetKeystoreDecryptor only updates the keystore decryptor token if it |
692 // wasn't already set properly. Otherwise, the decryptor should remain the | 693 // wasn't already set properly. Otherwise, the decryptor should remain the |
(...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2272 encryption_handler()->SetKeystoreKeys(keys, | 2273 encryption_handler()->SetKeystoreKeys(keys, |
2273 trans.GetWrappedTrans()); | 2274 trans.GetWrappedTrans()); |
2274 } | 2275 } |
2275 PumpLoop(); | 2276 PumpLoop(); |
2276 Mock::VerifyAndClearExpectations(observer()); | 2277 Mock::VerifyAndClearExpectations(observer()); |
2277 | 2278 |
2278 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCustomPass); | 2279 VerifyMigratedNigoriWithTimestamp(1, CUSTOM_PASSPHRASE, kCustomPass); |
2279 } | 2280 } |
2280 | 2281 |
2281 } // namespace syncer | 2282 } // namespace syncer |
OLD | NEW |