Files
MeshPort/apps/meshport_lab/test/proxy_profile_test.dart
T
shenleiandClaude Haiku 5.5 2f185f914d Snapshot uncommitted work: proxy UI, sing-box integration, socks bridge
- Lab app: proxy panel, node editor, configuration and detail pages,
  responsive layout, and related tests
- Add meshport-socks crate and sing-box bridge scripts/docs
- Add singbox_flutter binding and meshport_client_core package
- FFI, VPN helper (unified mac path), and Android/macOS runner updates
- Docs for architecture, client runtime, UI design, and validation
- UI design output artifacts under outputs/ui

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
2026-10-12 10:06:15 +09:00

105 lines
3.4 KiB
Dart

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<String, dynamic>,
);
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,
);
});
}