Files
pipelines/app/test/features/onboarding/discovery/discovered_server_test.dart
T
alan ad6cdab418 Listen on loopback and tailnet by default; make the plain-HTTP LAN opt-in
The web proxy binds the wildcard and drops connections that are not
loopback or Tailscale at both ends. A LAN listener is opt-in (web.lan) and
refuses sign-in and signed-in pages over plain HTTP unless
web.lan_plain_login is set. Existing installs keep their bind address with
a warning. Without the LAN the mDNS advert carries only the tailnet and
public routes (lan=0).
2026-11-10 01:02:02 +00:00

160 lines
4.9 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/onboarding/discovery/discovered_server.dart';
import 'package:pipelines_app/features/onboarding/discovery/server_discovery.dart';
void main() {
test('a proxied server becomes a ws endpoint that asks for a password', () {
final server = DiscoveredServer.fromRecord(
instance: 'Pipelines-box',
addresses: ['fe80::1', '192.168.1.20'],
port: 8083,
attributes: {
'v': 'v1.4.0',
'name': 'box',
'path': '/connect',
'tls': '0',
'auth': 'password',
},
)!;
expect(server.name, 'box');
expect(server.endpoint, Uri.parse('ws://192.168.1.20:8083/connect'));
expect(server.address, '192.168.1.20:8083');
expect(server.passwordRequired, isTrue);
expect(server.version, 'v1.4.0');
});
test('TLS, no auth, missing TXT and IPv6-only records', () {
final secure = DiscoveredServer.fromRecord(
instance: 'Pipelines-box',
addresses: ['2001:db8::5'],
port: 443,
attributes: {'tls': '1', 'auth': 'none'},
)!;
expect(secure.name, 'Pipelines-box');
expect(secure.endpoint, Uri.parse('wss://[2001:db8::5]:443/connect'));
expect(secure.passwordRequired, isFalse);
});
test('falls back to the SRV host name, and refuses nothing to dial', () {
final named = DiscoveredServer.fromRecord(
instance: 'Pipelines-box',
addresses: ['fe80::1', '127.0.0.1'],
hostname: 'box.local.',
port: 8083,
)!;
expect(named.endpoint, Uri.parse('ws://box.local:8083/connect'));
expect(
DiscoveredServer.fromRecord(
instance: 'x',
addresses: const [],
port: 8083,
),
isNull,
);
expect(
DiscoveredServer.fromRecord(
instance: 'x',
addresses: ['10.0.0.2'],
port: 0,
),
isNull,
);
});
test('web and native platforms provide discovery', () {
expect(platformServerDiscovery(web: true), isNotNull);
expect(platformServerDiscovery(web: false), isNotNull);
});
test('TXT ts/public list every route to the same machine', () {
final server = DiscoveredServer.fromRecord(
instance: 'Pipelines-box',
addresses: ['10.0.0.75'],
port: 8083,
attributes: {
'name': 'box',
'path': '/connect',
'tls': '0',
'auth': 'password',
'ts': '100.85.25.33, 10.0.0.9,100.70.1.1',
'public': 'https://box.tail1.ts.net:8443',
},
)!;
expect(server.endpoint, Uri.parse('ws://10.0.0.75:8083/connect'));
expect(server.addresses.map((a) => a.route), [
DiscoveredRoute.lan,
DiscoveredRoute.tailscale,
DiscoveredRoute.tailscale,
DiscoveredRoute.public,
]);
expect(server.endpoints.map((u) => u.toString()), [
'ws://10.0.0.75:8083/connect',
'ws://100.85.25.33:8083/connect',
'ws://100.70.1.1:8083/connect',
'wss://box.tail1.ts.net:8443/connect',
]);
expect(server.addresses.last.label, 'Tailscale name (HTTPS)');
expect(server.addresses[1].label, 'Tailscale IP');
final chosen = server.choosing([server.addresses.last, server.addresses[1]]);
expect(chosen.endpoint, Uri.parse('wss://box.tail1.ts.net:8443/connect'));
expect(chosen.secure, isTrue);
expect(chosen.endpoints, hasLength(2));
expect(chosen.name, 'box');
expect(chosen.passwordRequired, isTrue);
expect(server.choosing(const []), server);
final unsafe = DiscoveredServer.fromRecord(
instance: 'Pipelines-box',
addresses: ['10.0.0.75'],
port: 8083,
attributes: {
'ts': 'evil.example,10.0.0.9',
'public': 'javascript:alert(1)',
},
)!;
expect(unsafe.addresses, hasLength(1));
expect(
DiscoveredServer.publicEndpoint('https://user@box.ts.net/app?x=1'),
isNull,
);
expect(
DiscoveredServer.publicEndpoint('http://10.0.0.5:8083/'),
Uri.parse('ws://10.0.0.5:8083/connect'),
);
expect(DiscoveredServer.isTailscaleIPv4('100.127.0.1'), isTrue);
expect(DiscoveredServer.isTailscaleIPv4('100.128.0.1'), isFalse);
});
test('lan=0 drops the LAN route and dials the tailnet first', () {
final server = DiscoveredServer.fromRecord(
instance: 'Pipelines-box',
addresses: ['100.85.25.33'],
port: 8083,
attributes: {
'name': 'box',
'path': '/connect',
'tls': '0',
'auth': 'password',
'lan': '0',
'ts': '100.85.25.33',
'public': 'https://box.tail1.ts.net:8443',
},
)!;
expect(server.addresses.map((a) => a.route), [
DiscoveredRoute.tailscale,
DiscoveredRoute.public,
]);
expect(server.endpoint, Uri.parse('ws://100.85.25.33:8083/connect'));
expect(
DiscoveredServer.fromRecord(
instance: 'Pipelines-box',
addresses: ['100.85.25.33'],
port: 8083,
attributes: {'lan': '0'},
),
isNull,
);
});
}