Initialize Android physical interfaces and preserve macOS scoped routes. Add redacted diagnostics, default DNS, ordered auto-save, simplified controls, scanner rotation settings, and native regression coverage. Restore vendored build sources and document validation and stability checks.
152 lines
4.7 KiB
Dart
152 lines
4.7 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 supplies encrypted default DNS and protects proxy queries', () {
|
|
final p = ProxyProfile();
|
|
expect(p.runtime()['dns_protection'], true);
|
|
expect(p.validateConnection, throwsFormatException);
|
|
p.nodes = importProxyNodes('socks://127.0.0.1:1080').nodes;
|
|
p.selectedId = p.nodes.single.id;
|
|
p.proxyDnsServer = 'tls://resolver.example';
|
|
expect(p.validateConnection, returnsNormally);
|
|
p.proxyDnsServer = '';
|
|
expect(p.runtime()['proxy_dns_server'], ProxyProfile.defaultProxyDns);
|
|
expect(p.validateConnection, returnsNormally);
|
|
p.mode = 'direct';
|
|
expect(p.validateConnection, returnsNormally);
|
|
p.mode = 'global';
|
|
p.feature = 'mesh';
|
|
expect(p.validateConnection, returnsNormally);
|
|
});
|
|
|
|
test('proxy requires a selected node, while direct and mesh do not', () {
|
|
final p = ProxyProfile()..proxyDnsServer = 'tls://resolver.example';
|
|
for (final mode in ['rule', 'global', 'bypass_cn']) {
|
|
p.mode = mode;
|
|
expect(p.validateConnection, throwsFormatException);
|
|
}
|
|
p.nodes = importProxyNodes('socks://127.0.0.1:1080').nodes;
|
|
p.selectedId = 'deleted-node';
|
|
expect(p.validateConnection, throwsFormatException);
|
|
p.selectedId = p.nodes.single.id;
|
|
expect(p.validateConnection, returnsNormally);
|
|
p.nodes.clear();
|
|
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);
|
|
}
|
|
},
|
|
);
|
|
}
|