Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/lib/mobile/mobile_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ class _YourSSHMobileAppState extends State<YourSSHMobileApp> {
debugShowCheckedModeBanner: false,
themeMode: ThemeMode.dark,
theme: buildMobileTheme(),
builder: ysRootBuilderTouch,
// The lock wraps the whole navigator, so pushed routes and dialogs are
// covered too. It sits outside ysRootBuilderTouch's FToaster so toasts
// stay under the lock as well.
builder: (c, child) => AppLockGate(
child: ysRootBuilderTouch(c, child),
),
navigatorObservers: [mobileRouteObserver],
home: const AppLockGate(child: MobileHomeShell()),
home: const MobileHomeShell(),
),
);
}
Expand Down
18 changes: 17 additions & 1 deletion app/lib/mobile/security/app_lock_gate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,23 @@ class _AppLockGateState extends State<AppLockGate> with WidgetsBindingObserver {
@override
Widget build(BuildContext context) {
if (!_locked) return widget.child;
// Nothing of the app is built while locked: only this screen.
// The child (navigator, pushed routes, dialogs, toasts) stays mounted so
// sessions and routes survive the unlock, but offstage with tickers off:
// nothing of it is painted, so neither the screen nor the app-switcher
// snapshot can show it. The lock screen is built outside the Navigator, so
// it brings its own FTheme (the gate sits above the app's FTheme/FToaster).
return Stack(
fit: StackFit.expand,
children: [
Offstage(
child: TickerMode(enabled: false, child: widget.child),
),
FTheme(data: ysThemeDataTouch(), child: _lockScreen()),
],
);
}

Widget _lockScreen() {
return Scaffold(
backgroundColor: YsColors.background,
body: Center(
Expand Down
91 changes: 89 additions & 2 deletions app/test/mobile/app_lock_gate_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:yourssh/mobile/security/app_lock_gate.dart';
import 'package:yourssh/theme/app_theme.dart';
import 'package:yourssh_ui/yourssh_ui.dart';

import '../helpers/ys_test_app.dart';
Expand Down Expand Up @@ -37,16 +38,17 @@ void main() {
expect(find.text('Unlock'), findsOneWidget);
});

testWidgets('lock screen: wording, FButton >= 44 px, nothing behind it',
testWidgets('lock screen: wording, FButton >= 44 px, child offstage',
(tester) async {
await _pump(tester, enabled: true, auth: () async => false);
expect(find.text('YourSSH is locked'), findsOneWidget);
expect(find.byType(FButton), findsOneWidget);
final size = tester.getSize(find.byType(FButton));
expect(size.height, greaterThanOrEqualTo(44));
expect(size.width, greaterThanOrEqualTo(44));
// The child stays mounted (sessions/routes survive) but offstage.
expect(find.byKey(_childKey), findsNothing);
expect(find.byKey(_childKey, skipOffstage: false), findsNothing);
expect(find.byKey(_childKey, skipOffstage: false), findsOneWidget);
});

testWidgets('Unlock retries auth and unlocks on success', (tester) async {
Expand All @@ -58,4 +60,89 @@ void main() {
expect(calls, 2);
expect(find.byKey(_childKey), findsOneWidget);
});

group('gate in MaterialApp.builder covers every route', () {
final nav = GlobalKey<NavigatorState>();
var calls = 0;
var allow = false;

Future<void> pumpApp(WidgetTester t) async {
calls = 0;
await t.pumpWidget(MaterialApp(
navigatorKey: nav,
theme: ysMaterialTheme(),
// Mirrors mobile_app.dart: gate outside the toaster so toasts stay
// under the lock too.
builder: (c, child) => AppLockGate(
enabledOverride: true,
authenticator: () async {
calls++;
return allow;
},
child: ysRootBuilderTouch(c, child),
),
home: const Text('home'),
));
await t.pumpAndSettle();
}

testWidgets('pushed route is covered while locked and survives unlock',
(t) async {
allow = false;
await pumpApp(t);
nav.currentState!
.push(MaterialPageRoute(builder: (_) => const Text('terminal')));
await t.pumpAndSettle();
expect(find.text('YourSSH is locked'), findsOneWidget);
expect(find.text('terminal'), findsNothing);
expect(find.text('terminal', skipOffstage: false), findsOneWidget);
allow = true;
await t.tap(find.text('Unlock'));
await t.pumpAndSettle();
expect(find.text('terminal'), findsOneWidget);
});

testWidgets('backgrounding re-locks over the current route, no prompt loop',
(t) async {
allow = true;
await pumpApp(t);
nav.currentState!
.push(MaterialPageRoute(builder: (_) => const Text('terminal')));
await t.pumpAndSettle();
expect(find.text('terminal'), findsOneWidget);
expect(calls, 1);
t.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
await t.pump();
expect(find.text('terminal'), findsNothing);
expect(find.text('YourSSH is locked'), findsOneWidget);
t.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
await t.pumpAndSettle();
expect(find.text('terminal'), findsOneWidget);
expect(calls, 2);
});

testWidgets('a dialog on the root navigator is covered while locked',
(t) async {
allow = false;
await pumpApp(t);
showDialog<void>(
context: nav.currentContext!,
builder: (_) => const AlertDialog(content: Text('secret dialog')));
await t.pumpAndSettle();
expect(find.text('YourSSH is locked'), findsOneWidget);
expect(find.text('secret dialog'), findsNothing);
expect(find.text('secret dialog', skipOffstage: false), findsOneWidget);
});

testWidgets('a toast shown while locked does not paint above the lock',
(t) async {
allow = false;
await pumpApp(t);
showFToast(
context: nav.currentContext!, title: const Text('secret toast'));
await t.pumpAndSettle();
expect(find.text('YourSSH is locked'), findsOneWidget);
expect(find.text('secret toast'), findsNothing);
});
});
}
Loading