Fix VPN internet connectivity and simplify client setup
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.
This commit is contained in:
@@ -4,22 +4,42 @@ 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('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()
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshport_lab/features/runtime_diagnostics.dart';
|
||||
|
||||
void main() {
|
||||
test('diagnostics redact nested credentials and retain replaced secrets', () {
|
||||
final redactor = DiagnosticRedactor();
|
||||
redactor.remember({
|
||||
'network_secret': 'mesh-secret',
|
||||
'nodes': [
|
||||
{
|
||||
'options': {
|
||||
'username': 'proxy-user',
|
||||
'password': 'proxy-password',
|
||||
'uuid': '00000000-0000-0000-0000-000000000001',
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
redactor.remember({'password': 'replacement-password'});
|
||||
final text = redactor.sanitize(
|
||||
'mesh-secret proxy-user proxy-password replacement-password '
|
||||
'00000000-0000-0000-0000-000000000001 '
|
||||
'socks://other-user:other-pass@proxy.example:1080 '
|
||||
'https://example.test/sub?token=subscription-secret',
|
||||
);
|
||||
for (final secret in [
|
||||
'mesh-secret',
|
||||
'proxy-user',
|
||||
'proxy-password',
|
||||
'replacement-password',
|
||||
'00000000-0000-0000-0000-000000000001',
|
||||
'other-user',
|
||||
'other-pass',
|
||||
'subscription-secret',
|
||||
]) {
|
||||
expect(text, isNot(contains(secret)));
|
||||
}
|
||||
expect(text, contains('proxy.example:1080'));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshport_client_core/meshport_client_core.dart';
|
||||
import 'package:meshport_lab/features/lab_screen.dart';
|
||||
|
||||
void main() {
|
||||
test('sharing links show decoded Unicode names', () {
|
||||
for (final fragment in ['演示节点', '%E6%BC%94%E7%A4%BA%E8%8A%82%E7%82%B9']) {
|
||||
expect(
|
||||
importProxyNodes('socks5://127.0.0.1:1080#$fragment').nodes.single.name,
|
||||
'演示节点',
|
||||
);
|
||||
}
|
||||
});
|
||||
test('blank and legacy DNS use default while custom resolver survives', () {
|
||||
final p = ProxyProfile();
|
||||
p.addNodes(importProxyNodes('socks://127.0.0.1:1080').nodes);
|
||||
p.proxyDnsServer = ' ';
|
||||
expect(p.runtime()['proxy_dns_server'], ProxyProfile.defaultProxyDns);
|
||||
expect(p.runtime()['dns_protection'], true);
|
||||
expect(p.validateConnection, returnsNormally);
|
||||
final legacy = p.toJson();
|
||||
(legacy['runtime'] as Map)['proxy_dns_server'] = '';
|
||||
expect(
|
||||
ProxyProfile.fromJson(legacy).proxyDnsServer,
|
||||
ProxyProfile.defaultProxyDns,
|
||||
);
|
||||
p.proxyDnsServer = 'tls://resolver.example';
|
||||
expect(ProxyProfile.fromJson(p.toJson()).proxyDnsServer, p.proxyDnsServer);
|
||||
});
|
||||
|
||||
test('only initial single node is selected automatically', () {
|
||||
final p = ProxyProfile();
|
||||
p.addNodes(importProxyNodes('socks://127.0.0.1:1080').nodes);
|
||||
final selected = p.selectedId;
|
||||
expect(selected, p.nodes.single.id);
|
||||
p.addNodes(importProxyNodes('socks://127.0.0.1:1081').nodes);
|
||||
expect(p.selectedId, selected);
|
||||
final multiple = ProxyProfile();
|
||||
multiple.addNodes(
|
||||
importProxyNodes('socks://127.0.0.1:1080\nsocks://127.0.0.1:1081').nodes,
|
||||
);
|
||||
expect(multiple.selectedId, isNull);
|
||||
final subscription = ProxyProfile();
|
||||
replaceSubscription(
|
||||
subscription,
|
||||
's',
|
||||
importProxyNodes('socks://127.0.0.1:1080', source: 's'),
|
||||
DateTime.now(),
|
||||
);
|
||||
expect(subscription.selectedId, subscription.nodes.single.id);
|
||||
replaceSubscription(
|
||||
subscription,
|
||||
's',
|
||||
importProxyNodes('socks://127.0.0.1:1081', source: 's'),
|
||||
DateTime.now(),
|
||||
);
|
||||
expect(subscription.selectedId, isNull);
|
||||
});
|
||||
|
||||
const channel = MethodChannel('meshport/system_vpn');
|
||||
final binding = TestWidgetsFlutterBinding.ensureInitialized();
|
||||
tearDown(
|
||||
() =>
|
||||
binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, null),
|
||||
);
|
||||
|
||||
Future<void> openProxy(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(home: LabScreen(initializeNative: false)),
|
||||
);
|
||||
await tester.tap(find.text('代理').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('仅代理'), findsOneWidget);
|
||||
expect(find.text('网络入口'), findsNothing);
|
||||
expect(find.text('编辑 DNS'), findsNothing);
|
||||
}
|
||||
|
||||
Future<void> chooseMode(WidgetTester tester, String mode) async {
|
||||
final field = find.byWidgetPredicate(
|
||||
(w) =>
|
||||
w is DropdownButtonFormField<String> &&
|
||||
w.decoration.labelText == '上网模式',
|
||||
);
|
||||
await tester.ensureVisible(field);
|
||||
await tester.tap(field);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(mode).last);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'automatic saves serialize rapid edits and keep latest value',
|
||||
(tester) async {
|
||||
final first = Completer<void>();
|
||||
final saves = <Map<String, dynamic>>[];
|
||||
binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
||||
call,
|
||||
) async {
|
||||
if (call.method == 'save_proxy_profile') {
|
||||
saves.add(
|
||||
jsonDecode(call.arguments as String) as Map<String, dynamic>,
|
||||
);
|
||||
if (saves.length == 1) await first.future;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
await openProxy(tester);
|
||||
await chooseMode(tester, '直连');
|
||||
await chooseMode(tester, '全局代理');
|
||||
expect(saves.length, 1);
|
||||
first.complete();
|
||||
await tester.pumpAndSettle();
|
||||
expect(saves.length, 2);
|
||||
expect((saves.last['runtime'] as Map)['mode'], 'global');
|
||||
expect(find.text('正在自动保存…'), findsNothing);
|
||||
expect(find.text('重试保存'), findsNothing);
|
||||
},
|
||||
skip: !Platform.isMacOS,
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'failed automatic save offers retry and clears after success',
|
||||
(tester) async {
|
||||
var fail = true;
|
||||
binding.defaultBinaryMessenger.setMockMethodCallHandler(channel, (
|
||||
call,
|
||||
) async {
|
||||
if (call.method == 'save_proxy_profile' && fail) {
|
||||
throw PlatformException(code: 'KEYCHAIN_SAVE');
|
||||
}
|
||||
return null;
|
||||
});
|
||||
await openProxy(tester);
|
||||
await chooseMode(tester, '直连');
|
||||
expect(find.text('重试保存'), findsOneWidget);
|
||||
fail = false;
|
||||
await tester.ensureVisible(find.text('重试保存'));
|
||||
await tester.tap(find.text('重试保存'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('重试保存'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
skip: !Platform.isMacOS,
|
||||
);
|
||||
}
|
||||
@@ -3,6 +3,36 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meshport_lab/features/lab_screen.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('connection explains missing node and clears stale errors', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(home: LabScreen(initializeNative: false)),
|
||||
);
|
||||
await tester.tap(find.text('代理').last);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.ensureVisible(find.text('连接').last);
|
||||
await tester.tap(find.text('连接').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('请先添加代理节点'), findsOneWidget);
|
||||
|
||||
await tester.ensureVisible(find.text('诊断与日志'));
|
||||
await tester.tap(find.text('诊断与日志'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('[校验代理配置] 失败'), findsOneWidget);
|
||||
expect(find.textContaining('入口=unified_vpn'), findsOneWidget);
|
||||
await tester.pageBack();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.ensureVisible(find.text('全局代理').last);
|
||||
await tester.tap(find.text('全局代理').last);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('直连').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('请先添加代理节点'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('China bypass can be selected and switched to global', (
|
||||
tester,
|
||||
) async {
|
||||
@@ -14,7 +44,7 @@ void main() {
|
||||
final mode = find.byWidgetPredicate(
|
||||
(w) =>
|
||||
w is DropdownButtonFormField<String> &&
|
||||
w.decoration.labelText == '普通互联网流量模式',
|
||||
w.decoration.labelText == '上网模式',
|
||||
);
|
||||
await tester.ensureVisible(mode);
|
||||
await tester.tap(mode);
|
||||
@@ -52,7 +82,7 @@ void main() {
|
||||
);
|
||||
await tester.tap(find.text('代理').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('普通互联网流量模式'), findsOneWidget);
|
||||
expect(find.text('上网模式'), findsOneWidget);
|
||||
await tester.ensureVisible(find.text('导入与预览'));
|
||||
await tester.tap(find.text('导入与预览'));
|
||||
await tester.pumpAndSettle();
|
||||
@@ -67,6 +97,13 @@ void main() {
|
||||
await tester.tap(find.text('确认导入'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Preview'), findsOneWidget);
|
||||
expect(find.text('安全保存配置'), findsOneWidget);
|
||||
expect(find.byIcon(Icons.radio_button_checked), findsOneWidget);
|
||||
expect(find.text('网络入口'), findsNothing);
|
||||
expect(find.text('编辑 DNS'), findsNothing);
|
||||
await tester.ensureVisible(find.text('高级设置'));
|
||||
await tester.tap(find.text('高级设置'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('网络入口'), findsOneWidget);
|
||||
expect(find.text('编辑 DNS'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user