mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
## Summary Switch Community currently shows only device-saved communities, leaving account destinations behind a separate Find step. It now merges saved communities with supported account destinations directly, keeps Add Community, and removes the redundant Find action from that Add route. Initial onboarding and identity recovery keep their discovery entry. Find lists supported account addresses before hosted identity setup; hosted selection still performs binding, backup, and admission, while external selection opens the existing identity flow. Mobile also saves QR/address additions and explicit removals through Builder Lab's existing known-communities account APIs. A per-account local journal retries transient failures, survives restarts, pauses in the background, and fences requests against account changes. External secure addresses use the existing self-hosted entry flow; account destinations never imply membership or bypass admission. Remote list omissions do not delete local identities. Explicit additions store an account owner and revision atomically with local credentials. Legacy/unclaimed destinations remain local-only until explicitly added while signed in; signing into another account never claims retained destinations. Restart reconciliation lets a committed re-add supersede an older removal even if the retry-journal write failed. Local deletion and its credential-free account-removal intent commit in one storage write, independent of the account-only retry journal. Removing one of several local identities owned by the same account at an address retains its account destination until that account’s last identity is removed. Another account’s saved identity does not block removal or lose its credentials during recovery. Offline edits retain the stored account subject without treating it as network authorization. Discovery-only intent survives browser callbacks, app restart, and retry. Onboarding recovery controls have a Material ancestor in the actual route. Pending status is fenced to the current subject; interrupted older removals offer explicit local completion, and denied requests offer browser reauthentication. Same-host ports have distinct labels and confirmations, and unsupported hosted ports are excluded. This changes the mobile client and its public-build CI test list only: no relay endpoints, events, migrations, or backend deployment. ### Related issue No duplicate found among open known-communities/switcher issues and PRs. Related picker editing work: #6632 (renaming communities). ### Testing Validated after merging main (`02535e1b53`) at `c4ee037f7e710962f176540abf88d26e98c2823c`. Wes’s follow-up fixes cover push-revocation commit ordering, same-account removal confirmation, and recovery after completed hosted admission. The merge also preserves main’s toolbar and session protections; a test override now accepts the updated relay subscription parameter. - Formatting, static analysis, and differential file-size checks pass. - Prior full CI and security review passed on `3adb117aae`; security checks also passed on `cf3836ecb`. Fresh CI and security review are required for this head. - Mutation checks fail when either the initiating-account removal guard or the rendered-status subject fence is removed; both guards were restored before final validation. - CI explicitly runs the public-only account discovery and synchronization journeys. - Added journeys cover paused removal across A→B, offline restart, journal read/write failures, duplicate local identities in either removal order, delayed status reads across accounts, real browser handoff after denial, unbound external discovery, and local same-host port removal. - Earlier journeys cover pairing acknowledgement and restart after journal-write failure, same-subject setup completion, offline/rejected removal with reopen/retry, and fresh external-only/mixed account entry. - Regression coverage includes discovery deduplication and retry, hosted and external selection, Add without Find, account-only removal, shared authentication/removal persistence, restart recovery, latest-intent ordering, account changes, and retry pause/resume. - `just mobile-check`, `just file-size-check`, and `just mobile-test`: 4,954 default-build tests passed (71 skipped), plus 27 crypto-package tests. - Full public-account suite: 5,012 passed, 12 skipped, one pre-existing failure in `fullscreen_onboarding_test.dart` ("Home stays hidden until community choice and admission"). The same assertion was reproduced on clean base `8cce12f591`: expected both communities imported, actual only the selected community. - Follow-up regression journeys cover both A/B same-address removal orderings, recovery preserving B’s saved key, the production onboarding widget composition, and retained discovery intent with callback/retry plus normal-sign-in controls. - Native/live-account and human testing remain outstanding. The tests use fake network/storage boundaries; live account API behavior, cross-device synchronization, native accessibility, and timeout/late-server-commit ordering still require integration verification. - The three expanded recovery/removal journeys pass and each fails when the corresponding fix is removed. A durably journaled revocation now finishes the confirmed removal even if the account changes during journaling; pre-journal account mismatches still abort. Confirmation copy counts only same-account identities. Explicit account recovery retires a completed join target while preserving in-progress targets. ### Preview Sample-data Flutter widget renders: saved-only and combined lists. These illustrate the picker layout, not a device session or live account sync. | Saved-only | Combined | | --- | --- | |  |  | ### Manual verification 1. Sign into a public account with a community saved on another device. Open Switch Community; verify it appears alongside local choices and Add. 2. Select a hosted and an external community; verify the existing identity/admission flow opens. Add should not offer Find again. 3. Add a community by QR/address, then check the account list on desktop. Remove it on mobile and verify the account entry disappears while other devices retain their local credentials. 4. Repeat removal offline, restart, then reconnect/resume. Verify the queued removal reaches the account service without switching identities. 5. On a fresh device, verify external-only and mixed account lists offer external entry. Check two ports on the same host remain distinguishable. 6. Sign out of account A and into B; retained A destinations must not upload to B. Explicitly add a B destination and verify it syncs. 7. Reject or interrupt account removal; verify visible pending/failure status. A denied session must open browser sign-in through “Sign in again” and retry after exchange; setup-required accounts retain their setup action. 8. Keep two local identities owned by the same account at one address; removing the first must keep the account entry, and removing the last must queue account removal. Repeat with A and B at that address; removing A must preserve B’s saved credentials and still sync A’s removal. 9. Restart offline with a stored account, add/remove an external community, then reconnect as the same account and verify convergence. Explicit sign-out must not claim new local-only entries. 10. Start Find my communities, restart during browser authentication, then return or retry. External destinations must appear before hosted identity setup; normal sign-in must retain its identity checks. --------- Signed-off-by: kenny lopez <klopez4212@gmail.com> Signed-off-by: Tom Brow <tomb@squareup.com> Co-authored-by: Terp <5856f6900e8e0a4e0ea1f4f8d2ee33e4753d2119bc122f94ecafc660b46c0511@buzz.block.builderlab.xyz> Co-authored-by: Tom Brow <tomb@block.xyz> Co-authored-by: Tom Brow <tomb@squareup.com> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
542 lines
18 KiB
Dart
542 lines
18 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
import 'dart:convert';
|
|
|
|
import 'package:buzz/app.dart';
|
|
import 'package:buzz/features/age_gate/age_restriction_page.dart';
|
|
import 'package:buzz/features/age_gate/age_signal_push_bootstrap.dart';
|
|
import 'package:buzz/features/age_gate/age_signal_provider.dart';
|
|
import 'package:buzz/features/channels/unread_badge/unread_badge_provider.dart';
|
|
import 'package:buzz/features/home/home_page.dart';
|
|
import 'package:buzz/features/pairing/pairing_provider.dart';
|
|
import 'package:buzz/shared/auth/auth.dart';
|
|
import 'package:buzz/shared/huddle/huddle.dart';
|
|
import 'package:nostr/nostr.dart' as nostr;
|
|
import '../../shared/community/community_storage_test.dart'
|
|
show FakeSecureStorage;
|
|
import 'package:buzz/shared/push/push_bootstrap.dart';
|
|
import 'package:buzz/shared/relay/relay.dart';
|
|
import 'package:buzz/shared/theme/theme_provider.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
setUp(() => FlutterSecureStorage.setMockInitialValues({}));
|
|
const appBadgeChannel = MethodChannel('app_badge_plus');
|
|
|
|
tearDown(() {
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(ageSignalChannel, null);
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(appBadgeChannel, null);
|
|
});
|
|
|
|
testWidgets(
|
|
'an in-flight credential commit cannot reopen restricted access',
|
|
(tester) async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final storage = _PausedCommunityStorage();
|
|
final age = _MutableAgeSignalNotifier();
|
|
var connections = 0;
|
|
final relay = RelaySessionNotifier(
|
|
socketFactory:
|
|
({
|
|
required wsUrl,
|
|
required nsec,
|
|
required onMessage,
|
|
required onConnected,
|
|
required onDisconnected,
|
|
}) {
|
|
connections++;
|
|
throw StateError(
|
|
'Restricted authentication must not open a socket',
|
|
);
|
|
},
|
|
);
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
communityStorageProvider.overrideWithValue(storage),
|
|
communitySnapshotWriterProvider.overrideWithValue((_) async {}),
|
|
ageSignalProvider.overrideWith(() => age),
|
|
relaySessionProvider.overrideWith(() => relay),
|
|
pairingProvider.overrideWith(
|
|
() => PairingNotifier(
|
|
credentialValidator:
|
|
({required relayUrl, required nsec}) async {},
|
|
),
|
|
),
|
|
],
|
|
);
|
|
addTearDown(container.dispose);
|
|
await container.read(authProvider.future);
|
|
final listener = container.listen(relaySessionProvider, (_, _) {});
|
|
addTearDown(listener.close);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(container: container, child: const App()),
|
|
);
|
|
await tester.pump();
|
|
final code = base64Url.encode(
|
|
utf8.encode(
|
|
jsonEncode({
|
|
'relayUrl': 'https://relay.example',
|
|
'nsec': nostr.Keys.generate().nsec,
|
|
}),
|
|
),
|
|
);
|
|
final pairing = container.read(pairingProvider.notifier).pair(code);
|
|
await tester.pump();
|
|
expect(storage.started.isCompleted, isTrue);
|
|
age.setState(AgeSignalState.restricted);
|
|
await tester.pump();
|
|
expect(find.byType(AgeRestrictionPage), findsOneWidget);
|
|
storage.release.complete();
|
|
await pairing;
|
|
await tester.pump();
|
|
expect((await storage.loadAll()), hasLength(1));
|
|
expect(
|
|
(await container.read(authProvider.future)).status,
|
|
AuthStatus.authenticated,
|
|
);
|
|
expect(container.read(pairingProvider).status, PairingStatus.idle);
|
|
expect(find.byType(AgeRestrictionPage), findsOneWidget);
|
|
expect(
|
|
container.read(relaySessionProvider).status,
|
|
SessionStatus.disconnected,
|
|
);
|
|
expect(connections, 0);
|
|
expect(
|
|
container.read(huddleSessionProvider).phase,
|
|
HuddleSessionPhase.idle,
|
|
);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
listener.close();
|
|
container.dispose();
|
|
await tester.pump(const Duration(milliseconds: 1));
|
|
},
|
|
);
|
|
|
|
test('backs off repeated snapshot transition failures', () {
|
|
expect(ageSignalPushSnapshotRetryDelay(0), const Duration(seconds: 5));
|
|
expect(ageSignalPushSnapshotRetryDelay(1), const Duration(seconds: 10));
|
|
expect(ageSignalPushSnapshotRetryDelay(5), const Duration(seconds: 160));
|
|
expect(ageSignalPushSnapshotRetryDelay(6), const Duration(minutes: 5));
|
|
expect(ageSignalPushSnapshotRetryDelay(100), const Duration(minutes: 5));
|
|
});
|
|
|
|
for (final restrict in [false, true]) {
|
|
testWidgets('pending legacy pairing follows restriction=$restrict', (
|
|
tester,
|
|
) async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final age = _MutableAgeSignalNotifier();
|
|
final auth = _RecordingPairAuthNotifier();
|
|
final validation = Completer<void>();
|
|
final pairing = PairingNotifier(
|
|
credentialValidator: ({required relayUrl, required nsec}) =>
|
|
validation.future,
|
|
);
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
authProvider.overrideWith(() => auth),
|
|
ageSignalProvider.overrideWith(() => age),
|
|
pairingProvider.overrideWith(() => pairing),
|
|
],
|
|
);
|
|
addTearDown(container.dispose);
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(container: container, child: const App()),
|
|
);
|
|
await tester.pump();
|
|
final code = base64Url.encode(
|
|
utf8.encode(
|
|
jsonEncode({
|
|
'relayUrl': 'https://relay.example',
|
|
'nsec': 'pending-key',
|
|
}),
|
|
),
|
|
);
|
|
final pending = container.read(pairingProvider.notifier).pair(code);
|
|
expect(container.read(pairingProvider).status, PairingStatus.connecting);
|
|
if (restrict) age.setState(AgeSignalState.restricted);
|
|
await tester.pump();
|
|
validation.complete();
|
|
await pending;
|
|
expect(auth.imports, restrict ? 0 : 1);
|
|
expect(
|
|
container.read(pairingProvider).status,
|
|
restrict ? PairingStatus.idle : PairingStatus.success,
|
|
);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
});
|
|
}
|
|
|
|
testWidgets('blocks authenticated app content', (tester) async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
authProvider.overrideWith(() => _AuthenticatedAuthNotifier()),
|
|
ageSignalProvider.overrideWith(() => _BlockingAgeSignalNotifier()),
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
],
|
|
child: const AgeSignalPushBootstrap(child: App()),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
expect(find.byType(AgeRestrictionPage), findsOneWidget);
|
|
expect(find.byType(HomePage), findsNothing);
|
|
});
|
|
|
|
testWidgets('clears the app badge only after a confirmed restriction', (
|
|
tester,
|
|
) async {
|
|
final badgeCounts = <int>[];
|
|
final ageSignal = _MutableAgeSignalNotifier();
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(appBadgeChannel, (call) async {
|
|
if (call.method == 'updateBadge') {
|
|
badgeCounts.add(
|
|
(call.arguments as Map<Object?, Object?>)['count']! as int,
|
|
);
|
|
}
|
|
return null;
|
|
});
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
authProvider.overrideWith(() => _UnauthenticatedAuthNotifier()),
|
|
ageSignalProvider.overrideWith(() => ageSignal),
|
|
unreadBadgeProvider.overrideWithValue(
|
|
const UnreadBadgeState(highPriorityCount: 7),
|
|
),
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
],
|
|
child: const App(),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
expect(badgeCounts, isNotEmpty);
|
|
expect(badgeCounts.last, 7);
|
|
|
|
ageSignal.setState(AgeSignalState.allowed);
|
|
await tester.pump();
|
|
expect(badgeCounts.last, 7);
|
|
|
|
ageSignal.setState(AgeSignalState.restricted);
|
|
await tester.pump();
|
|
expect(badgeCounts.last, 0);
|
|
});
|
|
|
|
testWidgets(
|
|
'opens app and restores push snapshots without a native age check',
|
|
(tester) async {
|
|
final relaySession = _CountingRelaySessionNotifier();
|
|
var requests = 0;
|
|
var snapshotRestorations = 0;
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(ageSignalChannel, (call) {
|
|
requests += 1;
|
|
throw PlatformException(code: 'unavailable');
|
|
});
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
authProvider.overrideWith(() => _AuthenticatedAuthNotifier()),
|
|
relaySessionProvider.overrideWith(() => relaySession),
|
|
ageAllowedNotificationRestorerProvider.overrideWithValue(() async {
|
|
snapshotRestorations += 1;
|
|
if (snapshotRestorations == 1) {
|
|
throw StateError('injected restoration failure');
|
|
}
|
|
}),
|
|
ageSignalPushSnapshotRetryWaitProvider.overrideWithValue(
|
|
(_) async {},
|
|
),
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
],
|
|
child: const AgeSignalPushBootstrap(child: App()),
|
|
),
|
|
);
|
|
|
|
await tester.pump();
|
|
await tester.pump();
|
|
|
|
expect(find.bySemanticsLabel('Checking age eligibility'), findsNothing);
|
|
expect(find.byType(HomePage), findsOneWidget);
|
|
// Home may also host a nested conversation navigator.
|
|
expect(find.byType(MaterialApp), findsOneWidget);
|
|
expect(relaySession.builds, 1);
|
|
expect(requests, ageGatingEnabled ? 1 : 0);
|
|
await tester.pump();
|
|
await tester.pump();
|
|
expect(snapshotRestorations, 2);
|
|
},
|
|
);
|
|
|
|
for (final outcome in ['minor', 'adult', 'error', 'malformed', 'timeout']) {
|
|
testWidgets('normal app and push start before native $outcome result', (
|
|
tester,
|
|
) async {
|
|
final response = Completer<Object?>();
|
|
var requests = 0;
|
|
var restrictions = 0;
|
|
final relaySession = _CountingRelaySessionNotifier();
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(ageSignalChannel, (_) {
|
|
requests += 1;
|
|
return response.future;
|
|
});
|
|
SharedPreferences.setMockInitialValues({});
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
authProvider.overrideWith(() => _AuthenticatedAuthNotifier()),
|
|
relaySessionProvider.overrideWith(() => relaySession),
|
|
ageSignalProvider.overrideWith(
|
|
() =>
|
|
AgeSignalNotifier(requestTimeout: const Duration(seconds: 1)),
|
|
),
|
|
ageAllowedNotificationRestorerProvider.overrideWithValue(
|
|
() async {},
|
|
),
|
|
ageRestrictedNotificationPurgerProvider.overrideWithValue(() async {
|
|
restrictions++;
|
|
}),
|
|
savedPrefsProvider.overrideWithValue(prefs),
|
|
],
|
|
child: const AgeSignalPushBootstrap(child: App()),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
expect(find.byType(HomePage), findsOneWidget);
|
|
expect(find.byType(BuzzPushBootstrap), findsOneWidget);
|
|
expect(relaySession.builds, 1);
|
|
expect(requests, 1);
|
|
|
|
if (outcome == 'timeout') {
|
|
await tester.pump(const Duration(seconds: 2));
|
|
response.complete({'status': 'signal', 'ageUpper': 17});
|
|
} else if (outcome == 'error') {
|
|
response.completeError(PlatformException(code: 'unavailable'));
|
|
} else if (outcome == 'malformed') {
|
|
response.complete({'status': 'signal', 'ageUpper': '17'});
|
|
} else {
|
|
response.complete({
|
|
'status': 'signal',
|
|
'ageUpper': outcome == 'minor' ? 17 : 18,
|
|
});
|
|
}
|
|
await tester.pump();
|
|
await tester.pump();
|
|
final restricted = outcome == 'minor';
|
|
expect(restrictions, restricted ? 1 : 0);
|
|
expect(
|
|
find.byType(AgeRestrictionPage),
|
|
restricted ? findsOneWidget : findsNothing,
|
|
);
|
|
expect(find.byType(HomePage), restricted ? findsNothing : findsOneWidget);
|
|
expect(
|
|
find.byType(BuzzPushBootstrap),
|
|
restricted ? findsNothing : findsOneWidget,
|
|
);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
});
|
|
}
|
|
|
|
testWidgets(
|
|
'purges restricted notifications before community storage recovers',
|
|
(tester) async {
|
|
var purges = 0;
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
retry: (_, _) => null,
|
|
overrides: [
|
|
ageSignalProvider.overrideWith(() => _BlockingAgeSignalNotifier()),
|
|
communityListProvider.overrideWith(
|
|
() => _UnavailableCommunityListNotifier(),
|
|
),
|
|
ageRestrictedNotificationPurgerProvider.overrideWithValue(() async {
|
|
purges += 1;
|
|
}),
|
|
],
|
|
child: const AgeSignalPushBootstrap(child: SizedBox()),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
|
|
expect(purges, 1);
|
|
},
|
|
);
|
|
|
|
testWidgets('retries a failed restricted notification purge', (tester) async {
|
|
var purges = 0;
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
ageSignalProvider.overrideWith(() => _BlockingAgeSignalNotifier()),
|
|
communityListProvider.overrideWith(
|
|
() => _UnavailableCommunityListNotifier(),
|
|
),
|
|
ageRestrictedNotificationPurgerProvider.overrideWithValue(() async {
|
|
purges += 1;
|
|
if (purges == 1) {
|
|
throw StateError('injected notification purge failure');
|
|
}
|
|
}),
|
|
ageSignalPushSnapshotRetryWaitProvider.overrideWithValue(
|
|
(_) async {},
|
|
),
|
|
],
|
|
child: const AgeSignalPushBootstrap(child: SizedBox()),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
await tester.pump();
|
|
|
|
expect(purges, 2);
|
|
});
|
|
|
|
testWidgets(
|
|
'retries a successful purge for interactions donated by stale extensions',
|
|
(tester) async {
|
|
var purges = 0;
|
|
final scheduledMaintenance = <VoidCallback>[];
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
ageSignalProvider.overrideWith(() => _BlockingAgeSignalNotifier()),
|
|
communityListProvider.overrideWith(
|
|
() => _UnavailableCommunityListNotifier(),
|
|
),
|
|
ageRestrictedNotificationPurgerProvider.overrideWithValue(() async {
|
|
purges += 1;
|
|
}),
|
|
ageRestrictedNotificationMaintenanceScheduleProvider
|
|
.overrideWithValue((callback) {
|
|
scheduledMaintenance.add(callback);
|
|
return () {};
|
|
}),
|
|
],
|
|
child: const AgeSignalPushBootstrap(child: SizedBox()),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
expect(purges, 1);
|
|
expect(scheduledMaintenance, hasLength(1));
|
|
|
|
for (
|
|
var attempt = 0;
|
|
attempt < ageRestrictedNotificationMaintenancePurgeLimit;
|
|
attempt += 1
|
|
) {
|
|
scheduledMaintenance.removeAt(0)();
|
|
await tester.pump();
|
|
await tester.pump();
|
|
}
|
|
|
|
expect(purges, 1 + ageRestrictedNotificationMaintenancePurgeLimit);
|
|
expect(scheduledMaintenance, isEmpty);
|
|
},
|
|
);
|
|
}
|
|
|
|
class _AuthenticatedAuthNotifier extends AuthNotifier {
|
|
@override
|
|
Future<AuthState> build() async {
|
|
return const AuthState(status: AuthStatus.authenticated);
|
|
}
|
|
}
|
|
|
|
class _UnauthenticatedAuthNotifier extends AuthNotifier {
|
|
@override
|
|
Future<AuthState> build() async {
|
|
return const AuthState(status: AuthStatus.unauthenticated);
|
|
}
|
|
}
|
|
|
|
class _MutableAgeSignalNotifier extends AgeSignalNotifier {
|
|
@override
|
|
AgeSignalState build() => AgeSignalState.allowed;
|
|
|
|
@override
|
|
Future<void> request() async {}
|
|
|
|
void setState(AgeSignalState next) => state = next;
|
|
}
|
|
|
|
class _BlockingAgeSignalNotifier extends AgeSignalNotifier {
|
|
@override
|
|
AgeSignalState build() => AgeSignalState.restricted;
|
|
|
|
@override
|
|
Future<void> request() async {}
|
|
}
|
|
|
|
class _CountingRelaySessionNotifier extends RelaySessionNotifier {
|
|
int builds = 0;
|
|
|
|
@override
|
|
SessionState build() {
|
|
builds += 1;
|
|
return const SessionState(status: SessionStatus.disconnected);
|
|
}
|
|
}
|
|
|
|
class _UnavailableCommunityListNotifier extends CommunityListNotifier {
|
|
@override
|
|
Future<List<Community>> build() async {
|
|
throw StateError('secure storage unavailable');
|
|
}
|
|
}
|
|
|
|
class _RecordingPairAuthNotifier extends _UnauthenticatedAuthNotifier {
|
|
int imports = 0;
|
|
|
|
@override
|
|
Future<void> authenticateWithCommunity(
|
|
Community community, {
|
|
bool Function()? shouldContinue,
|
|
bool activate = true,
|
|
}) async {
|
|
if (shouldContinue != null && !shouldContinue()) return;
|
|
imports += 1;
|
|
}
|
|
}
|
|
|
|
class _PausedCommunityStorage extends CommunityStorage {
|
|
_PausedCommunityStorage() : super(secure: FakeSecureStorage());
|
|
final started = Completer<void>();
|
|
final release = Completer<void>();
|
|
|
|
@override
|
|
Future<void> save(Community community) async {
|
|
started.complete();
|
|
await release.future;
|
|
await super.save(community);
|
|
}
|
|
}
|