import 'package:flutter_test/flutter_test.dart'; import 'package:remotedesk_android/edge_client.dart'; import 'package:remotedesk_android/models.dart'; void main() { test('host settings round-trip with relay configuration', () { const host = RemoteHost( id: 'host-1', name: 'Workstation', address: 'linux.example.test:39500', user: 'alice', certificateSha256: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', connectionMode: ConnectionMode.automatic, edgeApiUrl: 'https://edge.example.test/', agentPublicKey: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA', ); final decoded = RemoteHost.decodeList(RemoteHost.encodeList([host])).single; expect(decoded.toJson(), host.toJson()); }); test('legacy relay setting migrates to explicit relay mode', () { final host = RemoteHost.fromJson({ 'id': 'legacy', 'name': 'Legacy', 'address': 'linux.example.test:39500', 'user': 'alice', 'certificate_sha256': 'aa' * 32, 'use_relay': true, }); expect(host.connectionMode, ConnectionMode.relay); }); test('agent addresses are normalized to pinned WSS', () { expect( normalizeAgentUri('linux.example.test'), Uri.parse('wss://linux.example.test:39500/'), ); expect( () => normalizeAgentUri('ws://linux.example.test:39500'), throwsFormatException, ); }); test('Windows Agent addresses use plain transport on port 39501', () { expect( normalizeWindowsAgentUri('windows.example.test'), Uri.parse('tcp://windows.example.test:39501'), ); expect( normalizeWindowsAgentUri('[2001:db8::1]:40000'), Uri.parse('tcp://[2001:db8::1]:40000'), ); expect( () => normalizeWindowsAgentUri('https://windows.example.test'), throwsFormatException, ); }); test('Windows hosts round-trip without TLS fields', () { const host = RemoteHost( id: 'windows-1', name: 'Windows workstation', address: '192.0.2.20:39501', user: '', certificateSha256: '', platform: HostPlatform.windows, ); final decoded = RemoteHost.decodeList(RemoteHost.encodeList([host])).single; expect(decoded.platform, HostPlatform.windows); expect(decoded.certificateSha256, isEmpty); }); test('fingerprints and Edge origins are strict', () { expect(isValidFingerprint('ab:' * 31 + 'ab'), isTrue); expect(isValidFingerprint('ab' * 31), isFalse); expect( normalizeEdgeApiUri('https://edge.example.test/'), Uri.parse('https://edge.example.test/'), ); expect( () => normalizeEdgeApiUri('http://edge.example.test/'), throwsFormatException, ); }); }