XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

LumaTunnel

【WinUI】LumaTunnel 是一个面向个人多设备的 Windows 代理系统。客户端在本机提供 HTTP/HTTPS CONNECT 与 SOCKS5 TCP 代理,并通过一个受信任 TLS 证书保护的 WSS 会话,将多个 TCP 流复用到自建 Windows Server 节点。

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Net;
using LumaTunnel.Client.Core.Routing;
using LumaTunnel.Shared.Models;

namespace LumaTunnel.Client.Core.Tests;

public sealed class RoutingServiceTests
{
    [Theory]
    [InlineData("localhost")]
    [InlineData("printer.local")]
    [InlineData("nas.lan")]
    [InlineData("192.168.1.10")]
    [InlineData("10.0.0.1")]
    public void PrivateAndLocalTargetsAreAlwaysDirect(string host)
    {
        var service = new RoutingService { Mode = ProxyMode.Global };
        Assert.Equal(RouteAction.Direct, service.Resolve(new ProxyTarget(host, 443)));
    }

    [Fact]
    public void FirstEnabledRuleByPriorityWins()
    {
        var service = new RoutingService();
        service.SetRules([
            new RoutingRule { Kind = RuleKind.DomainSuffix, Value = "example.com", Action = RouteAction.Tunnel, Priority = 20 },
            new RoutingRule { Kind = RuleKind.Domain, Value = "api.example.com", Action = RouteAction.Direct, Priority = 10 }
        ]);

        Assert.Equal(RouteAction.Direct, service.Resolve(new ProxyTarget("api.example.com", 443)));
        Assert.Equal(RouteAction.Tunnel, service.Resolve(new ProxyTarget("www.example.com", 443)));
    }

    [Fact]
    public void CidrRuleMatchesLiteralAddress()
    {
        var service = new RoutingService();
        service.SetRules([
            new RoutingRule { Kind = RuleKind.IpCidr, Value = "8.8.8.0/24", Action = RouteAction.Direct }
        ]);

        Assert.Equal(RouteAction.Direct, service.Resolve(new ProxyTarget("8.8.8.8", 53, IPAddress.Parse("8.8.8.8"))));
        Assert.Equal(RouteAction.Tunnel, service.Resolve(new ProxyTarget("1.1.1.1", 53, IPAddress.Parse("1.1.1.1"))));
    }

    [Fact]
    public void InvalidRuleIsRejectedDuringCompilation()
    {
        var service = new RoutingService();
        Assert.Throws<ArgumentException>(() => service.SetRules([
            new RoutingRule { Kind = RuleKind.IpCidr, Value = "not-cidr", Action = RouteAction.Direct }
        ]));
    }
}