242 lines
23 KiB
C#
242 lines
23 KiB
C#
|
|
using System.Text.Json;
|
||
|
|
using System.Text.Json.Nodes;
|
||
|
|
|
||
|
|
namespace UCVL.VPNPlus;
|
||
|
|
|
||
|
|
internal static class PrivateAuxiliaryRoutingSelfTest
|
||
|
|
{
|
||
|
|
internal static async Task<int> RunAsync()
|
||
|
|
{
|
||
|
|
var checks = new Dictionary<string, bool>();
|
||
|
|
var now = DateTimeOffset.UtcNow;
|
||
|
|
PrivateAuxiliaryNode Node(string slug = "jinan-private", string address = "192.168.50.111", int contract = 1,
|
||
|
|
DateTimeOffset? expiry = null, string status = "candidate") => new() {
|
||
|
|
Slug = slug, Name = "优创未来·济南办", Region = "济南", ProbeIpv4 = address, TlsLeafSha256 = new string('a', 64),
|
||
|
|
Contract = contract, ExpiresAt = expiry ?? now.AddMinutes(3), Status = status };
|
||
|
|
Profile ProfileOf(List<PrivateAuxiliaryNode>? nodes = null, string identity = "employee", string status = "active",
|
||
|
|
List<NodeInfo>? publicNodes = null, long used = 0, long limit = 0, DateTimeOffset? expiry = null) => new() {
|
||
|
|
IdentityType = identity, Nodes = publicNodes ?? [new() { Slug = "public", Name = "公共节点" }],
|
||
|
|
PrivateAuxiliaryNodes = nodes ?? [Node()],
|
||
|
|
Subscription = new() { Status = status, UsedBytes = used, TrafficLimitBytes = limit, ExpiresAt = expiry } };
|
||
|
|
bool Reject(Action action) { try { action(); return false; } catch (InvalidOperationException) { return true; } }
|
||
|
|
var profile = ProfileOf();
|
||
|
|
var grants = PrivateAuxiliaryRouting.Eligible(profile, now);
|
||
|
|
checks["valid_separate_grant"] = grants.Count == 1;
|
||
|
|
checks["phone_grant_eligible"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(address: "192.168.50.170")]), now).Count == 1;
|
||
|
|
checks["phone_tailnet_grant_eligible"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(address: "100.64.0.4")]), now).Count == 1;
|
||
|
|
checks["not_in_public_list"] = profile.Nodes.All(n => n.Slug != grants[0].Slug);
|
||
|
|
checks["legacy_profile_has_no_auxiliary"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([]), now).Count == 0;
|
||
|
|
checks["external_account_denied"] = PrivateAuxiliaryRouting.Eligible(ProfileOf(identity: "external"), now).Count == 0;
|
||
|
|
checks["suspended_subscription_denied"] = PrivateAuxiliaryRouting.Eligible(ProfileOf(status: "suspended"), now).Count == 0;
|
||
|
|
checks["expired_subscription_denied"] = PrivateAuxiliaryRouting.Eligible(ProfileOf(expiry: now), now).Count == 0;
|
||
|
|
checks["exhausted_subscription_denied"] = PrivateAuxiliaryRouting.Eligible(ProfileOf(used: 10, limit: 10), now).Count == 0;
|
||
|
|
checks["expired_grant_denied"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(expiry: now)]), now).Count == 0;
|
||
|
|
checks["offline_grant_denied"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(status: "offline")]), now).Count == 0;
|
||
|
|
checks["unknown_contract_denied"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(contract: 2)]), now).Count == 0;
|
||
|
|
checks["different_ip_not_probed"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(address: "172.16.0.1")]), now).Count == 0;
|
||
|
|
checks["hostname_not_resolved"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(address: "localhost")]), now).Count == 0;
|
||
|
|
checks["public_or_metadata_ip_denied"] = new[] { "8.8.8.8", "169.254.169.254", "127.0.0.1", "100.64.0.1" }
|
||
|
|
.All(ip => PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(address: ip)]), now).Count == 0);
|
||
|
|
checks["duplicates_denied"] = PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(), Node()]), now).Count == 0;
|
||
|
|
checks["public_private_slug_collision_denied"] = PrivateAuxiliaryRouting.Eligible(ProfileOf(publicNodes: [new() { Slug = "jinan-private" }]), now).Count == 0;
|
||
|
|
checks["malformed_slug_denied"] = new[] { "auto", "../config", "", "https://bad" }
|
||
|
|
.All(slug => PrivateAuxiliaryRouting.Eligible(ProfileOf([Node(slug: slug)]), now).Count == 0);
|
||
|
|
var auto = ConnectionSelection.Create(false, null, ["public", "jinan-private"]);
|
||
|
|
var manualPrivate = ConnectionSelection.Create(true, "jinan-private", ["public", "jinan-private"]);
|
||
|
|
var manualPublic = ConnectionSelection.Create(true, "public", ["public", "jinan-private"]);
|
||
|
|
var probes = 0;
|
||
|
|
Task<bool> Yes(PrivateAuxiliaryNode n, CancellationToken t) { probes++; return Task.FromResult(true); }
|
||
|
|
Task<bool> No(PrivateAuxiliaryNode n, CancellationToken t) { probes++; return Task.FromResult(false); }
|
||
|
|
var empty = new HashSet<string>(StringComparer.Ordinal);
|
||
|
|
var slow = Node("slow", "192.168.50.111");
|
||
|
|
var fast = Node("fast", "100.64.0.4");
|
||
|
|
var dead = Node("dead", "192.168.50.170");
|
||
|
|
var measured = 0;
|
||
|
|
Task<long?> Measure(PrivateAuxiliaryNode n, CancellationToken t) {
|
||
|
|
measured++; return Task.FromResult<long?>(n.Slug == "fast" ? 12 : n.Slug == "slow" ? 90 : null);
|
||
|
|
}
|
||
|
|
var ranking = await PrivateAuxiliaryRouting.RankByLatencyAsync([slow, dead, fast], empty, Measure, default);
|
||
|
|
checks["local_ranking_fast_first_unreachable_excluded"] = ranking.Select(n => n.Slug).SequenceEqual(["fast", "slow"]) && measured == 3;
|
||
|
|
checks["local_cooldown_excluded_from_measurement"] = (await PrivateAuxiliaryRouting.RankByLatencyAsync(
|
||
|
|
[slow, fast], new HashSet<string> { "fast" }, Measure, default)).Single() == slow;
|
||
|
|
var rankedAuto = ConnectionSelection.Create(false, null, ["slow", "fast", "dead"]);
|
||
|
|
checks["initial_connect_uses_lowest_latency"] = await PrivateAuxiliaryRouting.SelectByLatencyAsync(
|
||
|
|
rankedAuto, [slow, dead, fast], empty, false, Measure, default) == fast;
|
||
|
|
measured = 0;
|
||
|
|
checks["latency_does_not_replace_running_session"] = await PrivateAuxiliaryRouting.SelectByLatencyAsync(
|
||
|
|
rankedAuto, [slow, fast], empty, true, Measure, default) is null && measured == 0;
|
||
|
|
var fixedSlow = ConnectionSelection.Create(true, "slow", ["slow", "fast"]);
|
||
|
|
checks["manual_choice_not_overridden_by_faster_node"] = await PrivateAuxiliaryRouting.SelectByLatencyAsync(
|
||
|
|
fixedSlow, [slow, fast], empty, false, Measure, default) == slow && measured == 1;
|
||
|
|
var unknown = Node("unknown", "100.84.199.105");
|
||
|
|
measured = 0;
|
||
|
|
checks["ranking_never_probes_unregistered_ip"] = (await PrivateAuxiliaryRouting.RankByLatencyAsync(
|
||
|
|
[unknown], empty, Measure, default)).Count == 0 && measured == 0;
|
||
|
|
Task<long?> Tie(PrivateAuxiliaryNode n, CancellationToken t) => Task.FromResult<long?>(20);
|
||
|
|
checks["equal_latency_keeps_stable_order"] = (await PrivateAuxiliaryRouting.RankByLatencyAsync(
|
||
|
|
[slow, fast], empty, Tie, default)).SequenceEqual([slow, fast]);
|
||
|
|
var domain = new PrivateAuxiliaryNode { Slug = "same-site", Name = "济南(博翠明湖)", Status = "candidate",
|
||
|
|
Contract = 1, ExpiresAt = now.AddMinutes(3), TlsLeafSha256 = new string('a', 64),
|
||
|
|
ProbeIpv4 = "192.0.2.1", ConnectAddress = "vpn.toplc.cn", ProbePort = 11080 };
|
||
|
|
Task<long?> PublicFast(PrivateAuxiliaryNode n, CancellationToken t) => Task.FromResult<long?>(n == domain ? 1 : 90);
|
||
|
|
checks["internal_priority_even_when_domain_ping_is_faster"] = (await PrivateAuxiliaryRouting.RankByLatencyAsync(
|
||
|
|
[domain, slow], empty, PublicFast, default)).SequenceEqual([slow, domain]);
|
||
|
|
var oneSite = new PrivateAuxiliaryNode { Slug = "same-site", Name = domain.Name, Status = "candidate",
|
||
|
|
Contract = 1, ExpiresAt = now.AddMinutes(3), TlsLeafSha256 = new string('a', 64),
|
||
|
|
ProbeIpv4 = "100.64.0.4", ConnectionEndpoints = [
|
||
|
|
new() { Address = "100.64.0.4", ProbeIpv4 = "100.64.0.4", Port = 18081 },
|
||
|
|
new() { Address = "vpn.toplc.cn", ProbeIpv4 = "192.0.2.1", Port = 11080 }] };
|
||
|
|
Task<long?> Both(PrivateAuxiliaryNode n, CancellationToken t) => Task.FromResult<long?>(n.ProbePort == 11080 ? 1 : 90);
|
||
|
|
var fixedSite = ConnectionSelection.Create(true, "same-site", ["same-site"]);
|
||
|
|
var sameSiteRanking = await PrivateAuxiliaryRouting.RankForSelectionAsync(fixedSite, [oneSite], empty, false, Both, default);
|
||
|
|
checks["two_transports_still_one_authorized_node"] = sameSiteRanking.Count == 2
|
||
|
|
&& sameSiteRanking.All(n => n.Slug == "same-site") && sameSiteRanking[0].ProbeIpv4 == "100.64.0.4";
|
||
|
|
checks["manual_can_fallback_transport_not_node"] = ConnectionAttemptPlanner.CreateRanked(fixedSite, sameSiteRanking, 3)
|
||
|
|
.All(a => a.IsPrivate && a.Slug == "same-site");
|
||
|
|
var renewal = PrivateAuxiliaryRouting.ForRenewal(oneSite, domain);
|
||
|
|
checks["renewal_keeps_working_domain_not_preferred_tailnet"] = renewal.EndpointHost == "vpn.toplc.cn"
|
||
|
|
&& renewal.ProbePort == 11080 && renewal.ExpiresAt == oneSite.ExpiresAt;
|
||
|
|
checks["renewal_keeps_working_internal_endpoint"] = PrivateAuxiliaryRouting.ForRenewal(oneSite, sameSiteRanking[0]).ProbeIpv4 == "100.64.0.4";
|
||
|
|
checks["renewal_revoked_transport_rejected"] = Reject(() => PrivateAuxiliaryRouting.ForRenewal(oneSite, Node()));
|
||
|
|
checks["renewal_legacy_endpoint_preserved"] = PrivateAuxiliaryRouting.ForRenewal(grants[0], grants[0]) == grants[0];
|
||
|
|
Task<long?> OnlyDomain(PrivateAuxiliaryNode n, CancellationToken t) => Task.FromResult<long?>(n.ProbePort == 11080 ? 30 : null);
|
||
|
|
checks["failed_internal_selects_same_site_domain"] = (await PrivateAuxiliaryRouting.RankForSelectionAsync(
|
||
|
|
fixedSite, [oneSite], empty, false, OnlyDomain, default)).Single().EndpointHost == "vpn.toplc.cn";
|
||
|
|
var domainConfig = Config(mutate: r => {
|
||
|
|
r["outbounds"]![0]!["settings"]!["servers"]![0]!["address"] = "vpn.toplc.cn";
|
||
|
|
r["outbounds"]![0]!["settings"]!["servers"]![0]!["port"] = 11080;
|
||
|
|
});
|
||
|
|
// The fixture config helper is defined below; domain validation is checked there.
|
||
|
|
try {
|
||
|
|
await PrivateAuxiliaryRouting.SelectByLatencyAsync(ConnectionSelection.Create(true, "dead", ["dead"]),
|
||
|
|
[dead], empty, false, Measure, default);
|
||
|
|
checks["manual_unreachable_latency_reports_failure"] = false;
|
||
|
|
} catch (InvalidOperationException) { checks["manual_unreachable_latency_reports_failure"] = true; }
|
||
|
|
var preferred = await PrivateAuxiliaryRouting.SelectAsync(auto, grants, empty, false, Yes, default);
|
||
|
|
checks["ping_once_selects_private"] = preferred == grants[0] && probes == 1;
|
||
|
|
var plans = ConnectionAttemptPlanner.Create(auto, preferred, 3);
|
||
|
|
checks["private_is_first_then_public_auto"] = plans.Count == 4 && plans[0].IsPrivate && plans.Skip(1).All(p => p.Slug == "auto" && !p.IsPrivate);
|
||
|
|
checks["public_retry_budget_not_consumed_by_private"] = ConnectionAttemptPlanner.Create(auto, preferred, 20).Count == 9;
|
||
|
|
checks["private_only_does_not_fabricate_public_nodes"] = ConnectionAttemptPlanner.Create(auto, preferred, 0).Count == 1;
|
||
|
|
preferred = await PrivateAuxiliaryRouting.SelectAsync(auto, grants, empty, false, No, default);
|
||
|
|
checks["unreachable_skips_private"] = preferred is null && ConnectionAttemptPlanner.Create(auto, preferred, 2).All(p => !p.IsPrivate);
|
||
|
|
probes = 0;
|
||
|
|
preferred = await PrivateAuxiliaryRouting.SelectAsync(auto, grants, new HashSet<string> { "jinan-private" }, false, Yes, default);
|
||
|
|
checks["cooldown_skips_ping_and_private"] = preferred is null && probes == 0;
|
||
|
|
preferred = await PrivateAuxiliaryRouting.SelectAsync(auto, grants, empty, true, Yes, default);
|
||
|
|
checks["running_session_not_moved_by_ping"] = preferred is null && probes == 0;
|
||
|
|
preferred = await PrivateAuxiliaryRouting.SelectAsync(manualPublic, grants, empty, false, Yes, default);
|
||
|
|
checks["manual_public_not_overridden"] = preferred is null && probes == 0;
|
||
|
|
preferred = await PrivateAuxiliaryRouting.SelectAsync(manualPrivate, grants, empty, false, Yes, default);
|
||
|
|
checks["manual_private_has_no_public_fallback"] = ConnectionAttemptPlanner.Create(manualPrivate, preferred, 3).Count == 1;
|
||
|
|
try { await PrivateAuxiliaryRouting.SelectAsync(manualPrivate, grants, empty, false, No, default); checks["manual_unreachable_reports_failure"] = false; }
|
||
|
|
catch (InvalidOperationException) { checks["manual_unreachable_reports_failure"] = true; }
|
||
|
|
using (var cts = new CancellationTokenSource())
|
||
|
|
{
|
||
|
|
cts.Cancel(); probes = 0;
|
||
|
|
try { await PrivateAuxiliaryRouting.SelectAsync(auto, grants, empty, false, Yes, cts.Token); checks["cancel_before_probe"] = false; }
|
||
|
|
catch (OperationCanceledException) { checks["cancel_before_probe"] = probes == 0; }
|
||
|
|
}
|
||
|
|
using (var cts = new CancellationTokenSource())
|
||
|
|
{
|
||
|
|
Task<bool> Cancel(PrivateAuxiliaryNode n, CancellationToken t) { cts.Cancel(); return Task.FromResult(true); }
|
||
|
|
try { await PrivateAuxiliaryRouting.SelectAsync(auto, grants, empty, false, Cancel, cts.Token); checks["cancel_after_ping_never_connects"] = false; }
|
||
|
|
catch (OperationCanceledException) { checks["cancel_after_ping_never_connects"] = true; }
|
||
|
|
}
|
||
|
|
ConfigResponse Config(string scope = "private_auxiliary", int contract = 3, string slug = "jinan-private",
|
||
|
|
string route = "smart", GatewayInfo? gateway = null, Action<JsonNode>? mutate = null, DateTimeOffset? expiry = null) {
|
||
|
|
var root = JsonNode.Parse("""
|
||
|
|
{"inbounds":[],"outbounds":[{"tag":"proxy","protocol":"socks","settings":{"servers":[{"address":"192.168.50.111","port":18081,"users":[{"user":"device-fixture","pass":"synthetic-fixture-not-a-real-device-credential"}]}]},"streamSettings":{"security":"tls","network":"tcp","tlsSettings":{"serverName":"zero3-test","pinnedPeerCertSha256":"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}}},{"tag":"direct","protocol":"freedom"}],"routing":{"rules":[]}}
|
||
|
|
""")!;
|
||
|
|
mutate?.Invoke(root);
|
||
|
|
return new() { ConnectionScope = scope, ConfigContract = contract, Node = new() { Slug = slug },
|
||
|
|
RouteMode = route, Gateway = gateway, ConfigExpiresAt = expiry ?? now.AddMinutes(2), Config = JsonSerializer.SerializeToElement(root) };
|
||
|
|
}
|
||
|
|
checks["compatible_private_config_accepted"] = !Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(), "smart"));
|
||
|
|
var sameSlugDomain = new PrivateAuxiliaryNode { Slug = "jinan-private", Status = "candidate", Contract = 1,
|
||
|
|
ExpiresAt = now.AddMinutes(3), TlsLeafSha256 = new string('a', 64), ProbeIpv4 = "192.0.2.1",
|
||
|
|
ConnectAddress = "vpn.toplc.cn", ProbePort = 11080 };
|
||
|
|
checks["authorized_domain_mapping_config_accepted"] = !Reject(() => PrivateAuxiliaryRouting.ValidateConfig(sameSlugDomain, domainConfig, "smart"));
|
||
|
|
checks["domain_runtime_keeps_real_hostname"] = PrivateAuxiliaryRuntime.Address(domainConfig.GetRuntimeConfigJson()) == "vpn.toplc.cn";
|
||
|
|
foreach (var address in new[] { "192.168.50.170", "100.64.0.4" }) {
|
||
|
|
var phoneGrant = Node(address: address);
|
||
|
|
var phoneConfig = Config(mutate: r => r["outbounds"]![0]!["settings"]!["servers"]![0]!["address"] = address);
|
||
|
|
checks[$"registered_endpoint_config_{address}"] = !Reject(() => PrivateAuxiliaryRouting.ValidateConfig(phoneGrant, phoneConfig, "smart"));
|
||
|
|
var json = phoneConfig.GetRuntimeConfigJson();
|
||
|
|
checks[$"runtime_actual_endpoint_{address}"] = PrivateAuxiliaryRuntime.Address(json) == address
|
||
|
|
&& !Reject(() => PrivateAuxiliaryRuntime.ValidateLifetime(json));
|
||
|
|
checks[$"endpoint_substitution_rejected_{address}"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(phoneGrant, Config(), "smart"));
|
||
|
|
}
|
||
|
|
checks["public_config_not_private"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(scope: ""), "smart"));
|
||
|
|
checks["wrong_contract_rejected"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(contract: 2), "smart"));
|
||
|
|
checks["node_substitution_rejected"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(slug: "public"), "smart"));
|
||
|
|
checks["route_substitution_rejected"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(route: "direct"), "smart"));
|
||
|
|
checks["public_gateway_override_rejected"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(gateway: new() { Host = "example.invalid" }), "smart"));
|
||
|
|
checks["ping_ip_not_arbitrary_endpoint"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(mutate: r => r["outbounds"]![0]!["settings"]!["servers"]![0]!["address"] = "172.16.0.112"), "smart"));
|
||
|
|
checks["unencrypted_proxy_rejected"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(mutate: r => r["outbounds"]![0]!["streamSettings"]!["security"] = "none"), "smart"));
|
||
|
|
checks["missing_device_credential_rejected"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(mutate: r => r["outbounds"]![0]!["settings"]!["servers"]![0]!["users"] = new JsonArray()), "smart"));
|
||
|
|
checks["trial_shared_credential_not_production"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(mutate: r => r["outbounds"]![0]!["settings"]!["servers"]![0]!["users"]![0]!["user"] = "zero3-test"), "smart"));
|
||
|
|
checks["different_certificate_rejected"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(mutate: r => r["outbounds"]![0]!["streamSettings"]!["tlsSettings"]!["pinnedPeerCertSha256"] = new string('b', 64)), "smart"));
|
||
|
|
checks["insecure_tls_rejected"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(mutate: r => r["outbounds"]![0]!["streamSettings"]!["tlsSettings"]!["allowInsecure"] = true), "smart"));
|
||
|
|
checks["expired_config_rejected"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(expiry: now.AddMinutes(-1)), "smart"));
|
||
|
|
checks["config_cannot_extend_grant"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(expiry: now.AddHours(1)), "smart"));
|
||
|
|
checks["direct_mode_not_private"] = Reject(() => PrivateAuxiliaryRouting.ValidateConfig(grants[0], Config(route: "direct"), "direct"));
|
||
|
|
var privateJson = Config().GetRuntimeConfigJson();
|
||
|
|
var privateRuntime = JsonNode.Parse(TunConfigBuilder.Build(privateJson, "Ethernet-fixture", false))!;
|
||
|
|
checks["actual_socks_endpoint_discovered"] = TunConfigBuilder.GetProxyServerHosts(privateJson).SequenceEqual(["192.168.50.111"]);
|
||
|
|
checks["private_preserves_lan_or_tailscale_socket_route"] = privateRuntime["outbounds"]![0]!["streamSettings"]!["sockopt"]!["interface"] is null;
|
||
|
|
checks["direct_traffic_keeps_physical_interface"] = privateRuntime["outbounds"]![1]!["streamSettings"]!["sockopt"]!["interface"]!.GetValue<string>() == "Ethernet-fixture";
|
||
|
|
checks["private_dns_is_https_inside_proxy"] = privateRuntime["dns"]!["servers"]!.AsArray().All(n => n!.GetValue<string>().StartsWith("https://", StringComparison.Ordinal))
|
||
|
|
&& privateRuntime["routing"]!["rules"]![0]!["outboundTag"]!.GetValue<string>() == "proxy";
|
||
|
|
checks["private_udp_blocked_after_dns_interception"] = privateRuntime["routing"]!["rules"]![1]!["outboundTag"]!.GetValue<string>() == "ucvl-dns-out"
|
||
|
|
&& privateRuntime["routing"]!["rules"]![2]!["outboundTag"]!.GetValue<string>() == "ucvl-private-udp-block";
|
||
|
|
checks["runtime_metadata_not_sent_to_xray"] = privateRuntime[PrivateAuxiliaryRuntime.Marker] is null;
|
||
|
|
checks["public_dns_and_interface_baseline"] = TunConfigBuilder.SelfTest();
|
||
|
|
checks["rebind_rejects_expired_config"] = Reject(() => PrivateAuxiliaryRuntime.ValidateLifetime(Config(expiry: now.AddMinutes(-1)).GetRuntimeConfigJson()));
|
||
|
|
checks["lease_renewal_keeps_same_connection"] = PrivateAuxiliaryRuntime.SameConnection(privateJson, Config(expiry: now.AddMinutes(2.5)).GetRuntimeConfigJson());
|
||
|
|
checks["credential_rotation_not_silent_renewal"] = !PrivateAuxiliaryRuntime.SameConnection(privateJson,
|
||
|
|
Config(mutate: r => r["outbounds"]![0]!["settings"]!["servers"]![0]!["users"]![0]!["pass"] = "another-synthetic-device-credential-only").GetRuntimeConfigJson());
|
||
|
|
var nic = new HashSet<int> { 12, 34 };
|
||
|
|
checks["lan_route_preserved"] = PrivateAuxiliaryRuntime.HasPreservedRoute([new("172.16.0.0", "255.255.255.0", "0.0.0.0", 12)], nic);
|
||
|
|
checks["phone_ethernet_route_preserved"] = PrivateAuxiliaryRuntime.HasPreservedRoute(
|
||
|
|
[new("192.168.8.0", "255.255.255.0", "0.0.0.0", 12)], nic, "192.168.50.170");
|
||
|
|
checks["phone_tailnet_route_preserved"] = PrivateAuxiliaryRuntime.HasPreservedRoute(
|
||
|
|
[new("100.64.0.4", "255.255.255.255", "0.0.0.0", 34)], nic, "100.64.0.4");
|
||
|
|
checks["old_zero3_route_cannot_stand_in_for_phone"] = !PrivateAuxiliaryRuntime.HasPreservedRoute(
|
||
|
|
[new("172.16.0.0", "255.255.255.0", "0.0.0.0", 12)], nic, "192.168.50.170");
|
||
|
|
checks["phone_tailnet_default_route_not_accepted"] = !PrivateAuxiliaryRuntime.HasPreservedRoute(
|
||
|
|
[new("0.0.0.0", "0.0.0.0", "192.168.50.1", 12)], nic, "100.64.0.4");
|
||
|
|
checks["tailscale_subnet_route_preserved"] = PrivateAuxiliaryRuntime.HasPreservedRoute([new("172.16.0.0", "255.255.0.0", "0.0.0.0", 34)], nic);
|
||
|
|
checks["tailscale_host_route_preserved"] = PrivateAuxiliaryRuntime.HasPreservedRoute([new("192.168.50.111", "255.255.255.255", "100.100.100.100", 34)], nic);
|
||
|
|
checks["default_route_not_manufactured_as_site"] = !PrivateAuxiliaryRuntime.HasPreservedRoute([new("0.0.0.0", "0.0.0.0", "172.16.0.1", 12)], nic);
|
||
|
|
checks["tun_or_down_interface_excluded"] = !PrivateAuxiliaryRuntime.HasPreservedRoute([new("172.16.0.0", "255.255.0.0", "0.0.0.0", 99)], nic);
|
||
|
|
checks["other_lan_not_matched"] = !PrivateAuxiliaryRuntime.HasPreservedRoute([new("172.17.0.0", "255.255.0.0", "0.0.0.0", 12)], nic);
|
||
|
|
checks["invalid_mask_rejected"] = !PrivateAuxiliaryRuntime.HasPreservedRoute([new("172.16.0.0", "255.0.255.0", "0.0.0.0", 12)], nic);
|
||
|
|
using (var form = new MainForm(preview: true, uiOnly: true))
|
||
|
|
foreach (var item in form.CheckPrivateAuxiliaryUi(profile)) checks[item.Key] = item.Value;
|
||
|
|
var passed = checks.Values.All(v => v);
|
||
|
|
File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "private-auxiliary-self-test.json"),
|
||
|
|
JsonSerializer.Serialize(new { passed, network_modified = false, probes_are_synthetic = true,
|
||
|
|
board_protocol_integration_tested = false, published = false, checks }, new JsonSerializerOptions { WriteIndented = true }));
|
||
|
|
return passed ? 0 : 19;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
internal sealed partial class MainForm
|
||
|
|
{
|
||
|
|
internal Dictionary<string, bool> CheckPrivateAuxiliaryUi(Profile profile)
|
||
|
|
{
|
||
|
|
UpdateSelectionNodes(profile, false);
|
||
|
|
var result = new Dictionary<string, bool> {
|
||
|
|
["ui_defaults_auto_with_private_and_public"] = !ManualSelection && _availableNodeCount == 2 && _publicNodeCount == 1,
|
||
|
|
["ui_private_label_not_public_core"] = _manualNodeCombo.Items[0]?.ToString()?.Contains("私有辅助") == true };
|
||
|
|
_connectionModeCombo.SelectedIndex = 1; _manualNodeCombo.SelectedIndex = 0;
|
||
|
|
UpdateSelectionNodes(profile, true);
|
||
|
|
result["ui_private_manual_choice_preserved"] = _manualNodeCombo.SelectedItem is PrivateAuxiliaryNode;
|
||
|
|
UpdateSelectionNodes(new Profile { Nodes = profile.Nodes }, true);
|
||
|
|
result["ui_removed_private_grant_not_replaced_by_public"] = ManualSelection && _manualNodeCombo.SelectedItem is null;
|
||
|
|
result["ui_legacy_profile_public_unchanged"] = _publicNodeCount == 1 && _availableNodeCount == 1 && _privateAuxiliaryNodes.Count == 0;
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
}
|