Add proxy routing and sing-box support

This commit is contained in:
Fabian Freund
2026-05-22 18:16:31 +02:00
parent 51289f1266
commit a5974617aa
262 changed files with 32003 additions and 3962 deletions
@@ -0,0 +1,54 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:weblibre/features/proxy/domain/services/dns_config_resolver.dart';
import 'package:weblibre/features/user/data/models/proxy_dns_override.dart';
void main() {
test('mirrors browser DoH through running profiles automatically', () {
final config = buildDnsConfig(
overridesByProfileId: const {'profile-1': null},
runningProfileIds: const {'profile-1'},
browserDohUrl: 'https://dns.example/dns-query',
);
expect(config, isNotNull);
expect(config!.finalServerTag, 'browser-doh');
expect(config.servers, hasLength(2));
expect(config.servers.first.detourTag, isNull);
expect(config.servers.last.tag, 'browser-doh-profile-1');
expect(config.servers.last.detourTag, 'out-singbox_profile-1');
expect(config.servers.last.matchInbounds, ['in-singbox_profile-1']);
});
test('profile override replaces automatic browser DoH mirror', () {
final config = buildDnsConfig(
overridesByProfileId: {
'profile-1': ProxyDnsOverride(remoteServerAddress: '10.0.0.53'),
},
runningProfileIds: const {'profile-1'},
browserDohUrl: 'https://dns.example/dns-query',
);
expect(config, isNotNull);
expect(config!.servers.map((s) => s.tag), [
'browser-doh',
'override-profile-1',
]);
expect(config.servers.last.address, '10.0.0.53');
expect(config.servers.last.detourTag, 'out-singbox_profile-1');
expect(config.servers.last.matchInbounds, ['in-singbox_profile-1']);
});
test('returns null when there is no browser DoH or override', () {
final config = buildDnsConfig(
overridesByProfileId: const {'profile-1': null},
runningProfileIds: const {'profile-1'},
browserDohUrl: null,
);
expect(config, isNull);
});
test('auto domain strategy emits sing-box as-is strategy', () {
expect(ProxyDnsDomainStrategy.auto.singboxValue, isEmpty);
});
}
@@ -0,0 +1,25 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:weblibre/features/proxy/domain/services/dns_config_resolver.dart';
/// The Dart and Kotlin sides of the sing-box config builder must produce the
/// same `out-`/`in-` tags. These cases mirror `SingboxTagFormatTest.kt` —
/// both must update together if this format ever changes.
void main() {
group('singbox tag format', () {
test('outboundTag is prefixed and sanitized', () {
expect(singboxOutboundTag('singbox:foo-bar'), 'out-singbox_foo-bar');
});
test('inboundTag is prefixed and sanitized', () {
expect(singboxInboundTag('singbox:foo-bar'), 'in-singbox_foo-bar');
});
test('sanitizeTag preserves alphanumeric, dots, dashes, underscores', () {
expect(singboxSanitizeTag('Abc_123.x-Y'), 'Abc_123.x-Y');
});
test('sanitizeTag replaces spaces, slashes, colons', () {
expect(singboxSanitizeTag('a:b c/d\\e'), 'a_b_c_d_e');
});
});
}