New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply device id v2 #4159
Merged
+576
−211
Merged
Apply device id v2 #4159
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6805ec2
deviceIdV2 and extra SAVE_INIT_DATA for migration
darkdh fd69880
Delete and create new device record to apply device id v2
darkdh 3382a50
Save this device object id for future update
darkdh 8e9e192
Propagate device id v2 for existing devices and delete device by devi…
darkdh de60324
fix sync unittest and lint
darkdh 6d76b38
Add test for device id v2 migration
darkdh f5ba9dd
bump deps for https://github.com/brave/sync/pull/362
bridiver a5c94c1
convert sync endpoint to gn config
bridiver 474c06f
always point to production for now
bridiver 33adbef
Bump brave-sync commit to production(master branch)
darkdh File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Loading status checks…
Add test for device id v2 migration
- Loading branch information
| @@ -527,7 +527,7 @@ TEST_F(BraveSyncServiceTest, OnDeleteDeviceWhenSelfDeleted) { | ||
| "beef01", "device1")); | ||
| records.push_back( | ||
| SimpleDeviceRecord(SyncRecord::Action::A_CREATE, object_id_2, "2", | ||
| "beef02","device2")); | ||
| "beef02", "device2")); | ||
| EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())).Times(1); | ||
| sync_service()->OnResolvedPreferences(records); | ||
|
|
||
| @@ -1145,3 +1145,117 @@ TEST_F(BraveSyncServiceTest, InitialFetchesStartWithZero) { | ||
| sync_service()->FetchSyncRecords(true, false, false, 1000); | ||
| } | ||
| } | ||
|
|
||
| TEST_F(BraveSyncServiceTest, DeviceIdV2Migration) { | ||
| EXPECT_CALL(*sync_client(), OnSyncEnabledChanged); | ||
| EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())) | ||
| .Times(AtLeast(2)); | ||
| sync_service()->OnSetupSyncNewToSync("device0"); | ||
| EXPECT_TRUE( | ||
| profile()->GetPrefs()->GetBoolean(brave_sync::prefs::kSyncEnabled)); | ||
|
|
||
| // Service gets seed from client via BraveSyncServiceImpl::OnSaveInitData | ||
| const auto binary_seed = brave_sync::Uint8Array(16, 77); | ||
|
|
||
| // emulate device without device id v2 | ||
| sync_service()->OnSaveInitData(binary_seed, {0}, ""); | ||
| std::string expected_seed = brave_sync::StrFromUint8Array(binary_seed); | ||
| EXPECT_EQ(sync_service()->GetSeed(), expected_seed); | ||
| EXPECT_EQ(brave_sync_prefs()->GetThisDeviceIdV2(), ""); | ||
|
|
||
| RecordsList records; | ||
| records.push_back( | ||
| SimpleDeviceRecord(SyncRecord::Action::A_CREATE, "", "0", "", | ||
| "device0")); | ||
| records.push_back( | ||
| SimpleDeviceRecord(SyncRecord::Action::A_CREATE, "", "1", "", | ||
| "device1")); | ||
| sync_service()->OnResolvedPreferences(records); | ||
| brave_sync_prefs()->SetLastFetchTime(base::Time::Now()); | ||
|
|
||
| auto devices = brave_sync_prefs()->GetSyncDevices(); | ||
|
|
||
| EXPECT_TRUE(DevicesContains(devices.get(), "0", "", "device0")); | ||
| EXPECT_TRUE(DevicesContains(devices.get(), "1", "", "device1")); | ||
|
|
||
| const std::string device_id_v2 = "beef00"; | ||
| // sync library will call SAVE_INIT_DATA to propagate device id v2 | ||
| sync_service()->OnSaveInitData(binary_seed, {0}, device_id_v2); | ||
| EXPECT_EQ(brave_sync_prefs()->GetThisDeviceIdV2(), device_id_v2); | ||
|
|
||
| EXPECT_CALL(*sync_client(), | ||
| SendSyncRecords("PREFERENCES", | ||
| ContainsDeviceRecord(SyncRecord::Action::A_DELETE, | ||
| "device0", device_id_v2))) | ||
| .Times(1); | ||
| EXPECT_CALL(*sync_client(), | ||
| SendSyncRecords("PREFERENCES", | ||
| ContainsDeviceRecord(SyncRecord::Action::A_CREATE, | ||
| "device0", device_id_v2))) | ||
| .Times(1); | ||
|
|
||
| base::WaitableEvent we; | ||
| brave_sync::GetRecordsCallback on_get_records = | ||
| base::BindOnce(&OnGetRecordsStub); | ||
| sync_service()->OnPollSyncCycle(std::move(on_get_records), &we); | ||
| } | ||
|
|
||
| TEST_F(BraveSyncServiceTest, DeviceIdV2MigrationDupDeviceId) { | ||
| EXPECT_CALL(*sync_client(), OnSyncEnabledChanged); | ||
| EXPECT_CALL(*observer(), OnSyncStateChanged(sync_service())) | ||
| .Times(AtLeast(2)); | ||
| sync_service()->OnSetupSyncHaveCode(kTestWords1, "device1"); | ||
| EXPECT_TRUE( | ||
| profile()->GetPrefs()->GetBoolean(brave_sync::prefs::kSyncEnabled)); | ||
|
|
||
| // Service gets seed from client via BraveSyncServiceImpl::OnSaveInitData | ||
| const auto binary_seed = brave_sync::Uint8Array(16, 77); | ||
|
|
||
| // emulate device with dup device id and without device id v2 | ||
| sync_service()->OnSaveInitData(binary_seed, {1}, ""); | ||
| std::string expected_seed = brave_sync::StrFromUint8Array(binary_seed); | ||
| EXPECT_EQ(sync_service()->GetSeed(), expected_seed); | ||
| EXPECT_EQ(brave_sync_prefs()->GetThisDeviceIdV2(), ""); | ||
|
|
||
| RecordsList records; | ||
| records.push_back( | ||
| SimpleDeviceRecord(SyncRecord::Action::A_CREATE, "", "0", "", | ||
| "device0")); | ||
| records.push_back( | ||
| SimpleDeviceRecord(SyncRecord::Action::A_CREATE, "", "1", "", | ||
| "device1")); | ||
| records.push_back( | ||
| SimpleDeviceRecord(SyncRecord::Action::A_CREATE, "", "1", "", | ||
| "device2")); | ||
| sync_service()->OnResolvedPreferences(records); | ||
| brave_sync_prefs()->SetLastFetchTime(base::Time::Now()); | ||
|
|
||
| auto devices = brave_sync_prefs()->GetSyncDevices(); | ||
|
|
||
| EXPECT_TRUE(DevicesContains(devices.get(), "0", "", "device0")); | ||
| EXPECT_TRUE(DevicesContains(devices.get(), "1", "", "device1")); | ||
|
This conversation was marked as resolved
by AlexeyBarabash
darkdh
Author
Member
|
||
| EXPECT_TRUE(DevicesContains(devices.get(), "1", "", "device2")); | ||
|
|
||
| const std::string device_id_v2 = "beef01"; | ||
| // sync library will call SAVE_INIT_DATA to propagate device id v2 | ||
| sync_service()->OnSaveInitData(binary_seed, {1}, device_id_v2); | ||
| EXPECT_EQ(brave_sync_prefs()->GetThisDeviceIdV2(), device_id_v2); | ||
|
|
||
| // It will send DELETE record twice because two device records has same device | ||
| // id | ||
| EXPECT_CALL(*sync_client(), | ||
| SendSyncRecords("PREFERENCES", | ||
| ContainsDeviceRecord(SyncRecord::Action::A_DELETE, | ||
| "device1", device_id_v2))) | ||
| .Times(2); | ||
| EXPECT_CALL(*sync_client(), | ||
| SendSyncRecords("PREFERENCES", | ||
| ContainsDeviceRecord(SyncRecord::Action::A_CREATE, | ||
| "device1", device_id_v2))) | ||
| .Times(1); | ||
|
|
||
| base::WaitableEvent we; | ||
| brave_sync::GetRecordsCallback on_get_records = | ||
| base::BindOnce(&OnGetRecordsStub); | ||
| sync_service()->OnPollSyncCycle(std::move(on_get_records), &we); | ||
| } | ||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
These lines are equal, looks it is done to underline the situation.
Maybe change that to refer devices as array by index?