diff --git a/mobile/lib/shared/hosted/hosted_identity_service.dart b/mobile/lib/shared/hosted/hosted_identity_service.dart index af988a29e4..ffe0db3138 100644 --- a/mobile/lib/shared/hosted/hosted_identity_service.dart +++ b/mobile/lib/shared/hosted/hosted_identity_service.dart @@ -206,7 +206,9 @@ class HostedIdentityService { return _result(saved, bound, subject); } } - if (statusKeys.isEmpty && bound != null && !matchingDevice) { + // Backups for other identities cannot recover the account-bound key. + // Offer the same explicit import as an account with no backups. + if (bound != null && !statusKeys.contains(bound) && !matchingDevice) { return HostedIdentityResult( HostedIdentityState.needsSetup, pubkey: bound, diff --git a/mobile/test/features/onboarding/hosted_journeys_test.dart b/mobile/test/features/onboarding/hosted_journeys_test.dart index 3c68339ba4..1b3c9e23ea 100644 --- a/mobile/test/features/onboarding/hosted_journeys_test.dart +++ b/mobile/test/features/onboarding/hosted_journeys_test.dart @@ -347,44 +347,53 @@ void main() { }); } - journey('linked account without backup imports its key without replacing it', ( - tester, - f, - ) async { - await f.initialize(localIdentity: false); - f.offerProfile = false; - await f.mount(tester); - // Account restoration may resume independently of the Add choices. - await f.flow.signInAccount(); - await f.settle(tester); - expect(f.flow.stage, HostedFlowStage.setupIdentity); - expect(f.probes, isEmpty); - expect(find.text('Create my Buzz identity'), findsNothing); - expect(find.text('Import existing identity'), findsOneWidget); - await f.tap(tester, 'Import existing identity'); - await tester.enterText( - find.byType(TextField).hitTestable(), - f.secondKeys.nsec, + for (final hasUnrelatedBackup in [false, true]) { + journey( + 'linked account imports its missing key (unrelated backup: $hasUnrelatedBackup)', + (tester, f) async { + await f.initialize(localIdentity: false); + f.offerProfile = false; + if (hasUnrelatedBackup) f.cloudKeys.add(f.secondKeys); + await f.mount(tester); + // Account restoration may resume independently of the Add choices. + await f.flow.signInAccount(); + await f.settle(tester); + expect(f.flow.stage, HostedFlowStage.setupIdentity); + expect(f.probes, isEmpty); + expect(find.text('Create my Buzz identity'), findsNothing); + expect(find.text('Import existing identity'), findsOneWidget); + await f.tap(tester, 'Import existing identity'); + await tester.enterText( + find.byType(TextField).hitTestable(), + f.secondKeys.nsec, + ); + await f.tap(tester, 'Preview identity'); + await f.tap(tester, 'Import this identity'); + expect( + find.text( + 'This key doesn’t match the identity linked to your Builderlab account.', + ), + findsOneWidget, + ); + expect(await f.store.read(), isNull); + expect(f.bound, f.keys.public); + await tester.enterText( + find.byType(TextField).hitTestable(), + f.keys.nsec, + ); + await f.tap(tester, 'Preview identity'); + await f.tap(tester, 'Import this identity'); + expect(await f.store.read(), isNull); + await f.tap(tester, 'Back up and continue'); + expect((await f.store.read())!.pubkey, f.keys.public); + expect((await f.store.read())!.backup, isNotNull); + expect( + f.requests.where((r) => r.url.path.endsWith('/recovery')), + isEmpty, + ); + }, ); - await f.tap(tester, 'Preview identity'); - await f.tap(tester, 'Import this identity'); - expect( - find.text( - 'This key doesn’t match the identity linked to your Builderlab account.', - ), - findsOneWidget, - ); - expect(await f.store.read(), isNull); - expect(f.bound, f.keys.public); - await tester.enterText(find.byType(TextField).hitTestable(), f.keys.nsec); - await f.tap(tester, 'Preview identity'); - await f.tap(tester, 'Import this identity'); - expect(await f.store.read(), isNull); - await f.tap(tester, 'Back up and continue'); - expect((await f.store.read())!.pubkey, f.keys.public); - expect((await f.store.read())!.backup, isNotNull); - expect(f.requests.where((r) => r.url.path.endsWith('/recovery')), isEmpty); - }); + } journey('system Back leaves community link entry', (tester, f) async { await f.initialize(); diff --git a/mobile/test/shared/hosted/hosted_multi_backup_recovery_test.dart b/mobile/test/shared/hosted/hosted_multi_backup_recovery_test.dart index 99dc002f22..3d527f776d 100644 --- a/mobile/test/shared/hosted/hosted_multi_backup_recovery_test.dart +++ b/mobile/test/shared/hosted/hosted_multi_backup_recovery_test.dart @@ -252,10 +252,12 @@ void main() { test('missing bound backup never accepts a different selected key', () async { bound = keys[2].public; - expect( - (await (await service()).resolve(selectedPubkey: keys[0].public)).state, - HostedIdentityState.mismatch, + final result = await (await service()).resolve( + selectedPubkey: keys[0].public, ); + expect(result.state, HostedIdentityState.needsSetup); + expect(result.pubkey, bound); + expect(result.canCreate, isFalse); expect(await store.read(), isNull); });