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:
@@ -0,0 +1,104 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/servers/server_probe.dart';
|
||||
import 'package:pipelines_app/core/session/login_probe.dart';
|
||||
import 'package:pipelines_app/core/session/server_session.dart';
|
||||
import 'package:pipelines_app/core/session/server_session_io.dart' as io;
|
||||
|
||||
void main() {
|
||||
final login = Uri.parse('https://mac.tail1.ts.net:8443/login');
|
||||
|
||||
test('the login page, a redirect and other answers are told apart', () {
|
||||
expect(
|
||||
ServerSession.interpret(
|
||||
login,
|
||||
const LoginProbe(status: 200, loginPage: true),
|
||||
).state,
|
||||
SessionState.signedOut,
|
||||
);
|
||||
expect(
|
||||
ServerSession.interpret(login, const LoginProbe(status: 302)).state,
|
||||
SessionState.signedIn,
|
||||
);
|
||||
final other = ServerSession.interpret(
|
||||
login,
|
||||
const LoginProbe(status: 200, loginPage: false),
|
||||
);
|
||||
expect(other.state, SessionState.unreachable);
|
||||
expect(other.reason, contains('not with the Pipelines sign-in page'));
|
||||
expect(other.reason, contains('mac.tail1.ts.net:8443'));
|
||||
final missing = ServerSession.interpret(
|
||||
login,
|
||||
const LoginProbe(status: 404),
|
||||
);
|
||||
expect(missing.state, SessionState.unreachable);
|
||||
expect(missing.reason, contains('HTTP 404'));
|
||||
final failed = ServerSession.interpret(
|
||||
login,
|
||||
const LoginProbe(failure: 'Could not reach mac.tail1.ts.net:8443: down.'),
|
||||
);
|
||||
expect(failed.state, SessionState.unreachable);
|
||||
expect(failed.reason, 'Could not reach mac.tail1.ts.net:8443: down.');
|
||||
expect(
|
||||
LoginProbe.isPipelinesLogin(
|
||||
'<form method="post" action="/login"><input name="password"></form>',
|
||||
),
|
||||
isTrue,
|
||||
);
|
||||
expect(LoginProbe.isPipelinesLogin('<h1>Some other app</h1>'), isFalse);
|
||||
});
|
||||
|
||||
test('TLS against a Tailscale IP explains the name requirement', () {
|
||||
final byIp = io.describeFailure(
|
||||
Uri.parse('https://100.85.25.33:8443/login'),
|
||||
const HandshakeException('alert internal error'),
|
||||
);
|
||||
expect(byIp, contains('does not cover an IP address'));
|
||||
expect(byIp, contains('wss://<name>.ts.net:8443/connect'));
|
||||
final byName = io.describeFailure(
|
||||
login,
|
||||
const HandshakeException('certificate verify failed'),
|
||||
);
|
||||
expect(byName, contains('HTTPS connection to mac.tail1.ts.net:8443 failed'));
|
||||
expect(byName, contains('certificate verify failed'));
|
||||
expect(
|
||||
io.describeFailure(
|
||||
login,
|
||||
const SocketException('refused', osError: OSError('Connection refused', 61)),
|
||||
),
|
||||
'Could not reach mac.tail1.ts.net:8443: Connection refused.',
|
||||
);
|
||||
expect(
|
||||
io.describeFailure(login, TimeoutException('slow')),
|
||||
contains('no answer within 10 seconds'),
|
||||
);
|
||||
});
|
||||
|
||||
test('probing several addresses reports the first reason when all fail', () async {
|
||||
final result = await probeServerAddresses(
|
||||
[Uri.parse('wss://a.test/connect'), Uri.parse('ws://b.test/connect')],
|
||||
probe: (uri) async => ServerProbeResult(
|
||||
SessionState.unreachable,
|
||||
reason: 'no ${uri.host}',
|
||||
),
|
||||
isCurrent: () => true,
|
||||
);
|
||||
expect(result.state, SessionState.unreachable);
|
||||
expect(result.endpoint, Uri.parse('wss://a.test/connect'));
|
||||
expect(result.reason, 'no a.test');
|
||||
final reached = await probeServerAddresses(
|
||||
[Uri.parse('wss://a.test/connect'), Uri.parse('ws://b.test/connect')],
|
||||
probe: (uri) async => uri.host == 'b.test'
|
||||
? const ServerProbeResult(SessionState.signedOut)
|
||||
: const ServerProbeResult(SessionState.unreachable, reason: 'x'),
|
||||
isCurrent: () => true,
|
||||
);
|
||||
expect(reached.endpoint, Uri.parse('ws://b.test/connect'));
|
||||
expect(reached.state, SessionState.signedOut);
|
||||
expect(reached.reason, isNull);
|
||||
final plain = probeFromCheck((_) async => SessionState.signedIn);
|
||||
expect((await plain(login)).state, SessionState.signedIn);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user