Skip to content

Commit 0d4fd74

Browse files
wesbillmanBrain
andauthored
fix(mobile): offer linked identity import when only other backups exist (#9053)
A fresh phone signing into an account linked to identity A gets a misleading identity-mismatch error when the account has only a backup for identity B. The existing import option was offered only when the entire backup list was empty. Offer the same import option whenever the linked identity has no listed backup. Import still rejects a different key, requires the existing backup-consent step, and prohibits creating a replacement identity. This fallback does not change account bindings or automatically recover a private key that was never backed up. Updated against main `6dbd159676908806109f23d1964159d96a35760a`, preserving the consent flow added since the original PR. Validation: - Both focused files passed with public Builderlab onboarding enabled: 67 tests. The journey covers empty and unrelated backups, wrong-key rejection, and matching-key import after “Back up and continue.” - In an isolated source tree with separate Git metadata and build output, restoring the old production condition failed the unrelated-backup journey (`blocked` instead of `setupIdentity`). Restoring the fix passed all 42 journeys; restored source hashes match the PR. - Wes exercised the original preview's transition to the import screen on November 4. This conflict repair preserves that production change; no new device run was performed. That native evidence covers the screen transition, not a completed real-account key import. - Required pre-push checks passed, including mobile formatting/analysis, the hook's mobile and crypto test suites, and file-size checks. [GitHub CI passed](https://github.com/block/buzz/actions/runs/45211217031) on `14e45a26e9873e75846e9a052f70bffd13139f6d`, including public-build tests and the Android build. The conflict/consent review finding is addressed in this revision. Existing-user backup enrollment and automatic fresh-device recovery are separate from this narrowly scoped fallback fix. Signed-off-by: Wes <wesbillman@users.noreply.github.com> Co-authored-by: Brain <1a02c72794dcd0f07058a353bc3a81f4028b8c77c92c87fce6d5c8b85970a20b@buzz.block.builderlab.xyz>
1 parent 2e3bebe commit 0d4fd74

3 files changed

Lines changed: 54 additions & 41 deletions

File tree

‎mobile/lib/shared/hosted/hosted_identity_service.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ class HostedIdentityService {
206206
return _result(saved, bound, subject);
207207
}
208208
}
209-
if (statusKeys.isEmpty && bound != null && !matchingDevice) {
209+
// Backups for other identities cannot recover the account-bound key.
210+
// Offer the same explicit import as an account with no backups.
211+
if (bound != null && !statusKeys.contains(bound) && !matchingDevice) {
210212
return HostedIdentityResult(
211213
HostedIdentityState.needsSetup,
212214
pubkey: bound,

‎mobile/test/features/onboarding/hosted_journeys_test.dart‎

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -347,44 +347,53 @@ void main() {
347347
});
348348
}
349349

350-
journey('linked account without backup imports its key without replacing it', (
351-
tester,
352-
f,
353-
) async {
354-
await f.initialize(localIdentity: false);
355-
f.offerProfile = false;
356-
await f.mount(tester);
357-
// Account restoration may resume independently of the Add choices.
358-
await f.flow.signInAccount();
359-
await f.settle(tester);
360-
expect(f.flow.stage, HostedFlowStage.setupIdentity);
361-
expect(f.probes, isEmpty);
362-
expect(find.text('Create my Buzz identity'), findsNothing);
363-
expect(find.text('Import existing identity'), findsOneWidget);
364-
await f.tap(tester, 'Import existing identity');
365-
await tester.enterText(
366-
find.byType(TextField).hitTestable(),
367-
f.secondKeys.nsec,
368-
);
369-
await f.tap(tester, 'Preview identity');
370-
await f.tap(tester, 'Import this identity');
371-
expect(
372-
find.text(
373-
'This key doesn’t match the identity linked to your Builderlab account.',
374-
),
375-
findsOneWidget,
350+
for (final hasUnrelatedBackup in [false, true]) {
351+
journey(
352+
'linked account imports its missing key (unrelated backup: $hasUnrelatedBackup)',
353+
(tester, f) async {
354+
await f.initialize(localIdentity: false);
355+
f.offerProfile = false;
356+
if (hasUnrelatedBackup) f.cloudKeys.add(f.secondKeys);
357+
await f.mount(tester);
358+
// Account restoration may resume independently of the Add choices.
359+
await f.flow.signInAccount();
360+
await f.settle(tester);
361+
expect(f.flow.stage, HostedFlowStage.setupIdentity);
362+
expect(f.probes, isEmpty);
363+
expect(find.text('Create my Buzz identity'), findsNothing);
364+
expect(find.text('Import existing identity'), findsOneWidget);
365+
await f.tap(tester, 'Import existing identity');
366+
await tester.enterText(
367+
find.byType(TextField).hitTestable(),
368+
f.secondKeys.nsec,
369+
);
370+
await f.tap(tester, 'Preview identity');
371+
await f.tap(tester, 'Import this identity');
372+
expect(
373+
find.text(
374+
'This key doesn’t match the identity linked to your Builderlab account.',
375+
),
376+
findsOneWidget,
377+
);
378+
expect(await f.store.read(), isNull);
379+
expect(f.bound, f.keys.public);
380+
await tester.enterText(
381+
find.byType(TextField).hitTestable(),
382+
f.keys.nsec,
383+
);
384+
await f.tap(tester, 'Preview identity');
385+
await f.tap(tester, 'Import this identity');
386+
expect(await f.store.read(), isNull);
387+
await f.tap(tester, 'Back up and continue');
388+
expect((await f.store.read())!.pubkey, f.keys.public);
389+
expect((await f.store.read())!.backup, isNotNull);
390+
expect(
391+
f.requests.where((r) => r.url.path.endsWith('/recovery')),
392+
isEmpty,
393+
);
394+
},
376395
);
377-
expect(await f.store.read(), isNull);
378-
expect(f.bound, f.keys.public);
379-
await tester.enterText(find.byType(TextField).hitTestable(), f.keys.nsec);
380-
await f.tap(tester, 'Preview identity');
381-
await f.tap(tester, 'Import this identity');
382-
expect(await f.store.read(), isNull);
383-
await f.tap(tester, 'Back up and continue');
384-
expect((await f.store.read())!.pubkey, f.keys.public);
385-
expect((await f.store.read())!.backup, isNotNull);
386-
expect(f.requests.where((r) => r.url.path.endsWith('/recovery')), isEmpty);
387-
});
396+
}
388397

389398
journey('system Back leaves community link entry', (tester, f) async {
390399
await f.initialize();

‎mobile/test/shared/hosted/hosted_multi_backup_recovery_test.dart‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,12 @@ void main() {
252252

253253
test('missing bound backup never accepts a different selected key', () async {
254254
bound = keys[2].public;
255-
expect(
256-
(await (await service()).resolve(selectedPubkey: keys[0].public)).state,
257-
HostedIdentityState.mismatch,
255+
final result = await (await service()).resolve(
256+
selectedPubkey: keys[0].public,
258257
);
258+
expect(result.state, HostedIdentityState.needsSetup);
259+
expect(result.pubkey, bound);
260+
expect(result.canCreate, isFalse);
259261
expect(await store.read(), isNull);
260262
});
261263

0 commit comments

Comments
 (0)