import 'dart:convert'; import 'package:flutter_test/flutter_test.dart'; import 'package:meshport_client_core/meshport_client_core.dart'; void main() { test( 'full JSON extracts nodes without importing route/DNS and deduplicates', () { final value = jsonEncode({ 'inbounds': [ {'type': 'tun'}, ], 'route': {'final': 'bad'}, 'dns': {'servers': []}, 'outbounds': [ {'type': 'direct', 'tag': 'D'}, { 'type': 'socks', 'tag': 'A', 'server': '127.0.0.1', 'server_port': 1080, }, { 'type': 'socks', 'tag': 'B', 'server': '127.0.0.1', 'server_port': 1080, }, ], }); final preview = importProxyNodes(value); expect(preview.nodes.length, 1); expect(preview.unsupported, 1); expect(preview.nodes.single.options.containsKey('route'), false); }, ); test('URI/Base64 supports credentials and TLS without logging inputs', () { final input = 'vless://00000000-0000-0000-0000-000000000001@example.test:443?security=tls&sni=example.test&type=ws&path=%2Fmesh#Node'; final node = importProxyNodes( base64.encode(utf8.encode(input)), ).nodes.single; expect(node.options['type'], 'vless'); expect(node.options['tls']['enabled'], true); expect(node.options['transport']['path'], '/mesh'); final ss = importProxyNodes( 'ss://${base64.encode(utf8.encode('aes-128-gcm:test-only'))}@example.test:8388#SS', ).nodes.single; expect(ss.options['method'], 'aes-128-gcm'); expect(ss.options['password'], 'test-only'); }); test( 'rejects invalid credential fields, oversize input and injected dialer', () { for (final raw in [ '{"type":"socks","server":"a.test","server_port":0}', '{"type":"vless","server":"a.test","server_port":443,"uuid":"invalid"}', '{"type":"socks","server":"a.test","server_port":1080,"detour":"meshport"}', ]) { expect(() => importProxyNodes(raw), throwsFormatException); } expect( () => importProxyNodes('x' * (1024 * 1024 + 1)), throwsFormatException, ); }, ); test( 'profile round trip preserves subscription provenance and selection', () { final p = ProxyProfile(); p.nodes = importProxyNodes( 'socks5://user:test-only@example.test:1080#Node', source: 'source-1', ).nodes; p.selectedId = p.nodes.single.id; p.mode = 'global'; p.subscriptions = [ { 'id': 'source-1', 'name': 'Source', 'url': 'https://example.test/sub?token=test-only', }, ]; final loaded = ProxyProfile.fromJson( jsonDecode(jsonEncode(p.toJson())) as Map, ); expect(loaded.selectedId, p.selectedId); expect(loaded.nodes.single.source, 'source-1'); expect(loaded.runtime()['proxy']['password'], 'test-only'); expect(loaded.mode, 'global'); }, ); test('subscription requires HTTPS without auth URL', () async { await expectLater( fetchSubscription('http://example.test/sub', source: 's'), throwsFormatException, ); await expectLater( fetchSubscription('https://user:password@example.test/sub', source: 's'), throwsFormatException, ); }); }