Files
MeshPort/apps/meshport_lab/test/advanced_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

132 lines
3.8 KiB
Dart

import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshport_client_core/meshport_client_core.dart';
import 'package:meshport_lab/features/configuration_pages.dart';
void main() {
test(
'client protects DNS and requires explicit resolver before connecting',
() {
final p = ProxyProfile();
expect(p.runtime()['dns_protection'], true);
expect(p.validateConnection, throwsStateError);
p.proxyDnsServer = 'tls://resolver.example';
expect(p.validateConnection, returnsNormally);
p.proxyDnsServer = '';
p.mode = 'direct';
expect(p.validateConnection, returnsNormally);
p.mode = 'global';
p.feature = 'mesh';
expect(p.validateConnection, returnsNormally);
},
);
test('China bypass mode persists without rewriting custom rules', () {
final p = ProxyProfile()
..mode = 'bypass_cn'
..defaultAction = 'reject';
p.rules = [
{'type': 'ip_cidr', 'value': '0.0.0.0/0', 'action': 'reject'},
];
final restored = ProxyProfile.fromJson(jsonDecode(jsonEncode(p.toJson())));
expect(restored.mode, 'bypass_cn');
expect(restored.modeLabel, '绕过中国大陆');
expect(restored.rules, p.rules);
restored.mode = 'global';
expect(restored.runtime()['mode'], 'global');
expect(restored.rules, p.rules);
});
test('subscription merge preserves manual node and stable selection', () {
final p = ProxyProfile();
p.nodes = importProxyNodes(
'socks://127.0.0.1:1001\nsocks://127.0.0.1:1002',
source: 's',
).nodes;
final stable = p.nodes.first.id;
p.selectedId = stable;
final manual = importProxyNodes('socks://127.0.0.1:1003').nodes.single;
p.nodes.add(manual);
p.subscriptions = [
{'id': 's', 'auto_update': true, 'interval_minutes': 60},
];
final now = DateTime.utc(2026, 10, 11);
replaceSubscription(
p,
's',
importProxyNodes(
'socks://127.0.0.1:1001\nsocks://127.0.0.1:1004',
source: 's',
),
now,
);
expect(p.nodes.any((n) => identical(n, manual)), true);
expect(p.selectedId, stable);
expect(
subscriptionDue(
p.subscriptions.single,
now.add(const Duration(minutes: 59)),
),
false,
);
expect(
subscriptionDue(
p.subscriptions.single,
now.add(const Duration(hours: 1)),
),
true,
);
replaceSubscription(
p,
's',
importProxyNodes('socks://127.0.0.1:1005', source: 's'),
now,
);
expect(p.selectedId, isNull);
});
test(
'encrypted DNS and rulesets persist without leaking selected node into runtime storage',
() {
final p = ProxyProfile()
..directDnsServer = 'https://dns.example/dns-query'
..proxyDnsServer = 'tls://dns.example'
..proxyEnabled = true;
p.ruleSets = [
{
'tag': 'sites',
'enabled': true,
'rules': [
{
'domain_suffix': ['example.test'],
},
],
'action': 'direct',
},
];
final restored = ProxyProfile.fromJson(
jsonDecode(jsonEncode(p.toJson())),
);
expect(restored.runtime()['direct_dns_server'], p.directDnsServer);
expect(restored.ruleSets, p.ruleSets);
expect(restored.proxyEnabled, true);
for (final value in [
'https://dns.example/dns-query',
'tls://dns.example:853',
'tls://dns.example',
'1.1.1.1',
]) {
expect(validResolver(value), true);
}
for (final value in [
'http://dns.example',
'tls://dns.example/path',
'https://u:p@dns.example',
'https://dns.example:0',
'https://dns.example?x=1',
]) {
expect(validResolver(value), false);
}
},
);
}