feat: support custom bypass rules and mesh routing policies
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
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() {
|
||||
testWidgets('bypass mode edits custom rules and retains preset fallback', (
|
||||
tester,
|
||||
) async {
|
||||
final profile = ProxyProfile()
|
||||
..feature = 'proxy'
|
||||
..mode = 'bypass_cn'
|
||||
..defaultAction = 'reject';
|
||||
var saved = false;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) {
|
||||
return TextButton(
|
||||
onPressed: () => Navigator.push<void>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) =>
|
||||
RulesPage(profile: profile, changed: () => saved = true),
|
||||
),
|
||||
),
|
||||
child: const Text('open'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('open'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('自定义规则和规则集优先'), findsOneWidget);
|
||||
expect(find.text('当前模式暂停普通规则'), findsNothing);
|
||||
expect(find.text('固定默认出口'), findsNothing);
|
||||
expect(find.textContaining('预设默认出口:所选代理'), findsOneWidget);
|
||||
await tester.tap(find.text('添加规则'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byType(TextField), 'example.com');
|
||||
await tester.tap(find.text('保存规则'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('保存草稿'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(saved, true);
|
||||
expect(profile.rules.single, {
|
||||
'type': 'domain_suffix',
|
||||
'value': 'example.com',
|
||||
'action': 'proxy',
|
||||
});
|
||||
// Keep the custom-mode fallback draft; the engine owns bypass mode's proxy fallback.
|
||||
expect(profile.defaultAction, 'reject');
|
||||
expect(profile.mode, 'bypass_cn');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import 'package:flutter/material.dart';
|
||||
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() {
|
||||
testWidgets('IPv4 subnet rule offers all four policies and saves mesh', (
|
||||
tester,
|
||||
) async {
|
||||
Map<String, dynamic>? saved;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (context) {
|
||||
return TextButton(
|
||||
onPressed: () async {
|
||||
saved = await Navigator.push<Map<String, dynamic>>(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const RuleEditor()),
|
||||
);
|
||||
},
|
||||
child: const Text('open'),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('open'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byType(DropdownButtonFormField<String>).first);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('IP CIDR').last);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byType(TextField), '192.168.50.0/24');
|
||||
await tester.tap(find.byType(DropdownButtonFormField<String>).last);
|
||||
await tester.pumpAndSettle();
|
||||
for (final label in ['代理', '直连', '组网', '拒绝']) {
|
||||
expect(find.text(label), findsWidgets);
|
||||
}
|
||||
await tester.tap(find.text('组网').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.textContaining('不会自动发布远端网段'), findsOneWidget);
|
||||
await tester.tap(find.text('保存规则'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(saved, {
|
||||
'type': 'ip_cidr',
|
||||
'value': '192.168.50.0/24',
|
||||
'action': 'mesh',
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('mesh rule refuses unsupported IPv6 subnet', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: RuleEditor(
|
||||
rule: {'type': 'ip_cidr', 'value': 'fd00::/64', 'action': 'mesh'},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('保存规则'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('组网目前仅支持 IPv4 网段'), findsOneWidget);
|
||||
});
|
||||
|
||||
test('mesh policies and legacy reject survive profile persistence', () {
|
||||
final profile = ProxyProfile()
|
||||
..feature = 'combined'
|
||||
..mode = 'bypass_cn'
|
||||
..defaultAction = 'mesh'
|
||||
..rules = [
|
||||
{'type': 'ip_cidr', 'value': '192.168.50.0/24', 'action': 'mesh'},
|
||||
{'type': 'domain', 'value': 'blocked.test', 'action': 'reject'},
|
||||
]
|
||||
..ruleSets = [
|
||||
{
|
||||
'tag': 'group-sites',
|
||||
'enabled': true,
|
||||
'action': 'mesh',
|
||||
'rules': [
|
||||
{
|
||||
'domain': ['mesh.test'],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
final restored = ProxyProfile.fromJson(profile.toJson());
|
||||
expect(restored.runtime()['rules'], profile.rules);
|
||||
expect(restored.runtime()['rule_sets'], profile.ruleSets);
|
||||
expect(restored.defaultAction, 'mesh');
|
||||
expect(routingPolicyLabel('reject'), '拒绝');
|
||||
expect(routingPolicyLabel('mesh'), '组网');
|
||||
});
|
||||
}
|
||||
@@ -31,6 +31,18 @@ void main() {
|
||||
await tester.tap(find.text(label).last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.takeException(), isNull, reason: label);
|
||||
if (label == '代理') {
|
||||
await tester.ensureVisible(find.text('高级设置'));
|
||||
await tester.tap(find.text('高级设置'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.ensureVisible(find.text('DNS 设置'));
|
||||
expect(
|
||||
tester.takeException(),
|
||||
isNull,
|
||||
reason: 'expanded advanced settings',
|
||||
);
|
||||
expect(find.textContaining('代理 DNS:'), findsOneWidget);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user