Recover from zero servers, sign each machine in on its own, offer every route
- Removing the primary machine hands pipelines/runs to the next saved machine on native hosts; removing the last machine returns to the connect screen instead of stranding the app on "Server endpoint not configured". - Add server probes the new machine and asks for its own password in the same page; Settings rows show Connected / Sign in required / Unreachable with the reason and offer Sign in; no other machine's credential is ever reused. - Unreachable addresses explain why: a TLS failure against an IP points at the Tailscale name, a non-Pipelines answer points at the port. - Discovered machines list every advertised route (LAN, Tailscale IP, Tailscale name) as a checklist; chosen routes are saved as one machine. - tool/connection_probe.dart replays the native login and websocket against real addresses for diagnosis.
This commit is contained in:
@@ -116,7 +116,12 @@ void main() {
|
||||
find.byKey(const Key('server-profile-name')),
|
||||
'My Linux',
|
||||
);
|
||||
await tester.ensureVisible(find.text('Save server'));
|
||||
await tester.scrollUntilVisible(
|
||||
find.text('Save server'),
|
||||
120,
|
||||
scrollable: find.byType(Scrollable).last,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Save server'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(saved!.name, 'My Linux');
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/servers/machine_access.dart';
|
||||
import 'package:pipelines_app/core/servers/server_catalog.dart';
|
||||
import 'package:pipelines_app/core/servers/server_catalog_store.dart';
|
||||
import 'package:pipelines_app/features/settings/saved_server_editor.dart';
|
||||
import 'package:pipelines_app/features/settings/saved_server_row.dart';
|
||||
import 'package:pipelines_app/features/settings/saved_servers_section.dart';
|
||||
import 'package:pipelines_app/features/settings/server_connections.dart';
|
||||
|
||||
/// A machine authenticator the test scripts: what each probe answers and
|
||||
/// which password each machine accepts.
|
||||
class FakeAuthenticator extends ChangeNotifier implements MachineAuthenticator {
|
||||
final verdicts = <String, MachineAccessResult>{};
|
||||
final passwords = <String, String>{};
|
||||
final probes = <String>[];
|
||||
final signIns = <(String, String)>[];
|
||||
|
||||
@override
|
||||
MachineAccessResult? status(String id) => verdicts[id];
|
||||
|
||||
@override
|
||||
Future<MachineAccessResult> probe(SavedServer server) async {
|
||||
probes.add(server.id);
|
||||
return verdicts[server.id] ??
|
||||
const MachineAccessResult(MachineAccess.connected);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<String?> authenticate(SavedServer server, String password) async {
|
||||
signIns.add((server.id, password));
|
||||
if (passwords[server.id] != password) return 'Wrong password.';
|
||||
verdicts[server.id] = const MachineAccessResult(MachineAccess.connected);
|
||||
notifyListeners();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> revealSave(WidgetTester tester) async {
|
||||
await tester.scrollUntilVisible(
|
||||
find.text('Save server'),
|
||||
120,
|
||||
scrollable: find.byType(Scrollable).last,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> addServer(
|
||||
WidgetTester tester, {
|
||||
required String name,
|
||||
required String address,
|
||||
}) async {
|
||||
await tester.tap(find.text('Add server'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byKey(const Key('server-profile-name')), name);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('server-profile-addresses')),
|
||||
address,
|
||||
);
|
||||
await revealSave(tester);
|
||||
await tester.tap(find.text('Save server'));
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets('a new machine asks for its own password ($cupertino)', (
|
||||
tester,
|
||||
) async {
|
||||
final connections = ServerConnections(
|
||||
store: MemoryServerCatalogStore(
|
||||
catalog: ServerCatalog(
|
||||
servers: [
|
||||
SavedServer.validated(
|
||||
id: 'mac',
|
||||
name: 'Mac',
|
||||
endpoints: ['ws://10.0.0.75:8083/connect'],
|
||||
),
|
||||
],
|
||||
selectedId: 'mac',
|
||||
),
|
||||
),
|
||||
onSelected: (_) async {},
|
||||
);
|
||||
addTearDown(connections.dispose);
|
||||
await connections.load();
|
||||
final auth = FakeAuthenticator()
|
||||
..verdicts['mac'] = const MachineAccessResult(MachineAccess.connected);
|
||||
connections.authenticator = auth;
|
||||
final body = SingleChildScrollView(
|
||||
child: SavedServersSection(connections: connections),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: body)),
|
||||
)
|
||||
: MaterialApp(home: Scaffold(body: body)),
|
||||
);
|
||||
expect(find.text('Connected'), findsOneWidget);
|
||||
// The new machine is unknown to the authenticator until saved; a
|
||||
// password verdict arrives for whatever id the editor assigned.
|
||||
auth.verdicts.addAll({
|
||||
for (final id in ['pending']) id: const MachineAccessResult(
|
||||
MachineAccess.needsPassword,
|
||||
),
|
||||
});
|
||||
await tester.tap(find.text('Add server'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byKey(const Key('server-profile-name')), 'tank');
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('server-profile-addresses')),
|
||||
'ws://10.0.0.100:8082/connect',
|
||||
);
|
||||
// Whatever id the editor chose, that machine wants a password.
|
||||
connections.addListener(() {
|
||||
for (final server in connections.catalog.servers) {
|
||||
auth.verdicts.putIfAbsent(
|
||||
server.id,
|
||||
() => const MachineAccessResult(MachineAccess.needsPassword),
|
||||
);
|
||||
auth.passwords.putIfAbsent(server.id, () => 'tank-secret');
|
||||
}
|
||||
});
|
||||
await revealSave(tester);
|
||||
await tester.tap(find.text('Save server'));
|
||||
await tester.pumpAndSettle();
|
||||
final tank = connections.catalog.servers.firstWhere((s) => s.name == 'tank');
|
||||
expect(auth.probes, [tank.id]);
|
||||
// Saved, and the editor now asks this machine's password; the first
|
||||
// machine's sign-in is not reused.
|
||||
expect(find.byKey(const Key('server-profile-password')), findsOneWidget);
|
||||
expect(find.textContaining('asks for its own password'), findsOneWidget);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('server-profile-password')),
|
||||
'wrong',
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('server-profile-sign-in')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Wrong password.'), findsOneWidget);
|
||||
expect(find.byKey(const Key('server-profile-password')), findsOneWidget);
|
||||
await tester.enterText(
|
||||
find.byKey(const Key('server-profile-password')),
|
||||
'tank-secret',
|
||||
);
|
||||
await tester.tap(find.byKey(const Key('server-profile-sign-in')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(auth.signIns, [(tank.id, 'wrong'), (tank.id, 'tank-secret')]);
|
||||
// Back on the list: both machines connected, each on its own sign-in.
|
||||
expect(find.byKey(const Key('server-profile-password')), findsNothing);
|
||||
expect(find.text('Connected'), findsNWidgets(2));
|
||||
expect(find.text('Address: ws://10.0.0.100:8082/connect'), findsOneWidget);
|
||||
expect(connections.catalog.active?.id, 'mac');
|
||||
});
|
||||
}
|
||||
|
||||
testWidgets('an unreachable machine stays saved with the reason shown', (
|
||||
tester,
|
||||
) async {
|
||||
final connections = ServerConnections(
|
||||
store: MemoryServerCatalogStore(),
|
||||
onSelected: (_) async {},
|
||||
);
|
||||
addTearDown(connections.dispose);
|
||||
await connections.load();
|
||||
final auth = FakeAuthenticator();
|
||||
connections.authenticator = auth;
|
||||
connections.addListener(() {
|
||||
for (final server in connections.catalog.servers) {
|
||||
auth.verdicts.putIfAbsent(
|
||||
server.id,
|
||||
() => const MachineAccessResult(
|
||||
MachineAccess.unreachable,
|
||||
detail: 'The HTTPS certificate of 100.85.25.33:8443 does not '
|
||||
'cover an IP address.',
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: SavedServersSection(connections: connections),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await addServer(
|
||||
tester,
|
||||
name: 'Mac by IP',
|
||||
address: 'wss://100.85.25.33:8443/connect',
|
||||
);
|
||||
expect(find.textContaining('could not be reached'), findsOneWidget);
|
||||
expect(find.textContaining('does not cover an IP address'), findsOneWidget);
|
||||
expect(find.byKey(const Key('server-profile-password')), findsNothing);
|
||||
await tester.tap(find.byKey(const Key('server-sign-in-later')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(connections.catalog.servers.single.name, 'Mac by IP');
|
||||
expect(find.textContaining('Unreachable: The HTTPS certificate'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a saved machine that wants a password offers Sign in', (
|
||||
tester,
|
||||
) async {
|
||||
final tank = SavedServer.validated(
|
||||
id: 'tank',
|
||||
name: 'tank',
|
||||
endpoints: ['ws://10.0.0.100:8082/connect'],
|
||||
);
|
||||
final connections = ServerConnections(
|
||||
store: MemoryServerCatalogStore(
|
||||
catalog: ServerCatalog(servers: [tank], selectedId: 'tank'),
|
||||
),
|
||||
onSelected: (_) async {},
|
||||
);
|
||||
addTearDown(connections.dispose);
|
||||
await connections.load();
|
||||
final auth = FakeAuthenticator()
|
||||
..verdicts['tank'] = const MachineAccessResult(MachineAccess.needsPassword)
|
||||
..passwords['tank'] = 'tank-secret';
|
||||
connections.authenticator = auth;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(body: SavedServersSection(connections: connections)),
|
||||
),
|
||||
);
|
||||
expect(find.text('Sign in required'), findsOneWidget);
|
||||
await tester.tap(find.byKey(savedServerMenuKey('tank')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Sign in to tank'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byKey(const Key('machine-password')), 'tank-secret');
|
||||
await tester.tap(find.byKey(const Key('machine-sign-in')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(auth.signIns, [('tank', 'tank-secret')]);
|
||||
expect(find.text('Connected'), findsOneWidget);
|
||||
expect(find.text('Sign in required'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('editing a name alone does not re-ask the password', (
|
||||
tester,
|
||||
) async {
|
||||
final mac = SavedServer.validated(
|
||||
id: 'mac',
|
||||
name: 'Mac',
|
||||
endpoints: ['ws://10.0.0.75:8083/connect'],
|
||||
);
|
||||
final auth = FakeAuthenticator()
|
||||
..verdicts['mac'] = const MachineAccessResult(MachineAccess.needsPassword);
|
||||
SavedServer? saved;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: TextButton(
|
||||
onPressed: () => editSavedServer(
|
||||
context,
|
||||
server: mac,
|
||||
authenticator: auth,
|
||||
onSave: (value) async => saved = value,
|
||||
),
|
||||
child: const Text('Edit'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('Edit'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byKey(const Key('server-profile-name')), 'Studio');
|
||||
await revealSave(tester);
|
||||
await tester.tap(find.text('Save server'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(saved?.name, 'Studio');
|
||||
expect(auth.probes, isEmpty);
|
||||
expect(find.text('Edit'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -11,6 +11,16 @@ import 'saved_server_menu.dart';
|
||||
SavedServer profile(String id, List<String> urls) =>
|
||||
SavedServer.validated(id: id, name: id, endpoints: urls);
|
||||
|
||||
/// The editor's list builds lazily; scroll its Save button into view.
|
||||
Future<void> revealSave(WidgetTester tester) async {
|
||||
await tester.scrollUntilVisible(
|
||||
find.text('Save server'),
|
||||
120,
|
||||
scrollable: find.byType(Scrollable).last,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'browser Back aligns active identity with the actual page; failed switch restores selection',
|
||||
@@ -129,8 +139,7 @@ void main() {
|
||||
find.byKey(const Key('server-profile-addresses')),
|
||||
'wss://tail.example/connect\nws://192.168.1.2:8083/connect',
|
||||
);
|
||||
await tester.ensureVisible(find.text('Save server'));
|
||||
await tester.pumpAndSettle();
|
||||
await revealSave(tester);
|
||||
await tester.tap(find.text('Save server'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(connections.catalog.active?.name, 'Home');
|
||||
@@ -139,7 +148,7 @@ void main() {
|
||||
'ws://192.168.1.2:8083/connect',
|
||||
]);
|
||||
expect(
|
||||
find.text('Backup 1: ws://192.168.1.2:8083/connect'),
|
||||
find.text('Backup address: ws://192.168.1.2:8083/connect'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await openSavedServerMenu(tester);
|
||||
@@ -149,8 +158,7 @@ void main() {
|
||||
find.byKey(const Key('server-profile-name')),
|
||||
'My home',
|
||||
);
|
||||
await tester.ensureVisible(find.text('Save server'));
|
||||
await tester.pumpAndSettle();
|
||||
await revealSave(tester);
|
||||
await tester.tap(find.text('Save server'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(connections.catalog.active?.name, 'My home');
|
||||
@@ -183,8 +191,7 @@ void main() {
|
||||
find.byKey(const Key('server-profile-addresses')),
|
||||
'not-a-url',
|
||||
);
|
||||
await tester.ensureVisible(find.text('Save server'));
|
||||
await tester.pumpAndSettle();
|
||||
await revealSave(tester);
|
||||
await tester.tap(find.text('Save server'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const Key('server-profile-addresses')), findsOneWidget);
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/servers/server_catalog.dart';
|
||||
import 'package:pipelines_app/core/servers/server_catalog_store.dart';
|
||||
import 'package:pipelines_app/features/settings/server_connections.dart';
|
||||
|
||||
SavedServer profile(String id) => SavedServer.validated(
|
||||
id: id,
|
||||
name: id,
|
||||
endpoints: ['wss://$id.test/connect'],
|
||||
);
|
||||
|
||||
void main() {
|
||||
test('a native host hands the primary role to the next machine', () async {
|
||||
final store = MemoryServerCatalogStore(
|
||||
catalog: ServerCatalog(
|
||||
servers: [profile('mac'), profile('tank')],
|
||||
selectedId: 'mac',
|
||||
),
|
||||
);
|
||||
final activated = <String?>[];
|
||||
final connections = ServerConnections(
|
||||
store: store,
|
||||
onSelected: (server) async => activated.add(server?.id),
|
||||
replaceRemovedPrimary: true,
|
||||
);
|
||||
addTearDown(connections.dispose);
|
||||
await connections.load();
|
||||
expect(await connections.remove('mac'), isTrue);
|
||||
expect(connections.catalog.active?.id, 'tank');
|
||||
expect(store.catalog?.selectedId, 'tank');
|
||||
expect(activated, ['tank']);
|
||||
// Removing the last machine activates "nothing" so the root can recover.
|
||||
expect(await connections.remove('tank'), isTrue);
|
||||
expect(connections.catalog.servers, isEmpty);
|
||||
expect(activated, ['tank', null]);
|
||||
});
|
||||
|
||||
test('removing a non-primary machine keeps the primary', () async {
|
||||
final store = MemoryServerCatalogStore(
|
||||
catalog: ServerCatalog(
|
||||
servers: [profile('mac'), profile('tank')],
|
||||
selectedId: 'mac',
|
||||
),
|
||||
);
|
||||
final activated = <String?>[];
|
||||
final connections = ServerConnections(
|
||||
store: store,
|
||||
onSelected: (server) async => activated.add(server?.id),
|
||||
replaceRemovedPrimary: true,
|
||||
);
|
||||
addTearDown(connections.dispose);
|
||||
await connections.load();
|
||||
expect(await connections.remove('tank'), isTrue);
|
||||
expect(connections.catalog.active?.id, 'mac');
|
||||
expect(activated, isEmpty);
|
||||
});
|
||||
|
||||
test('browsers never switch machines when the primary is removed', () async {
|
||||
final store = MemoryServerCatalogStore(
|
||||
catalog: ServerCatalog(
|
||||
servers: [profile('mac'), profile('tank')],
|
||||
selectedId: 'mac',
|
||||
),
|
||||
);
|
||||
final activated = <String?>[];
|
||||
final connections = ServerConnections(
|
||||
store: store,
|
||||
onSelected: (server) async => activated.add(server?.id),
|
||||
);
|
||||
addTearDown(connections.dispose);
|
||||
await connections.load();
|
||||
expect(await connections.remove('mac'), isTrue);
|
||||
expect(connections.catalog.active, isNull);
|
||||
expect(connections.catalog.servers.map((s) => s.id), ['tank']);
|
||||
expect(activated, [null]);
|
||||
});
|
||||
}
|
||||
@@ -188,7 +188,7 @@ void main() {
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.text('Preferred: wss://work.test/connect'), findsOneWidget);
|
||||
expect(find.text('Address: wss://work.test/connect'), findsOneWidget);
|
||||
expect(find.byKey(savedServerMenuKey('Home')), findsOneWidget);
|
||||
expect(find.text('Add server'), findsOneWidget);
|
||||
// Tapping another server's row uses it.
|
||||
|
||||
Reference in New Issue
Block a user