69 lines
2.0 KiB
Dart
69 lines
2.0 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);
|
|
});
|
|
}
|