mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-07 04:55:00 +03:00
ff9fd7b988
The AnyTLS URI scheme makes the port optional and defaults it to 443, and two of its three examples leave it out. The naive+https:// and naive+quic:// link format does the same: the port is omitted when it is 443, and none of its examples carries one. System.Uri answers -1 for an unregistered scheme with no port, so these links were imported with Port = -1 and the profile failed IsValid(). Apply the same default Hysteria2Fmt already uses (#10026). An explicit ":0" is still kept as 0. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.9 KiB
C#
45 lines
1.9 KiB
C#
namespace ServiceLib.Tests.Fmt;
|
|
|
|
public class NaiveFmtTests
|
|
{
|
|
// "port can be omitted if it's 443" -- https://gist.github.com/DuckSoft/ca03913b0a26fc77a1da4d01cc6ab2f1
|
|
// The first two cases are examples given there; none of its examples carries a port.
|
|
[Test]
|
|
[Arguments("naive+https://what:happened@test.someone.cf?padding=false#Naive!", false)]
|
|
[Arguments("naive+quic://manhole:114514@quic.test.me", true)]
|
|
[Arguments("naive+https://what:happened@test.someone.cf/", false)]
|
|
[Arguments("naive+https://what:happened@test.someone.cf:/", false)]
|
|
public async Task ResolveConfig_WithoutPort_ShouldDefaultTo443(string shareUri, bool quic)
|
|
{
|
|
var resolved = FmtHandler.ResolveConfig(shareUri, out var msg);
|
|
|
|
await resolved.Should().NotBeNull().Because($"uri: {shareUri}, msg: {msg}");
|
|
await resolved!.ConfigType.Should().BeEqualTo(EConfigType.Naive);
|
|
await resolved.Port.Should().BeEqualTo(443);
|
|
await (resolved.GetProtocolExtra().NaiveQuic == true).Should().BeEqualTo(quic);
|
|
await resolved.IsValid().Should().BeTrue();
|
|
}
|
|
|
|
[Test]
|
|
public async Task ResolveConfig_WithExplicitPort_ShouldKeepIt()
|
|
{
|
|
var resolved = FmtHandler.ResolveConfig("naive+https://what:happened@test.someone.cf:8443", out _);
|
|
|
|
await resolved.Should().NotBeNull();
|
|
await resolved!.Address.Should().BeEqualTo("test.someone.cf");
|
|
await resolved.Port.Should().BeEqualTo(8443);
|
|
await resolved.Username.Should().BeEqualTo("what");
|
|
await resolved.Password.Should().BeEqualTo("happened");
|
|
}
|
|
|
|
[Test]
|
|
public async Task ResolveConfig_WithExplicitZeroPort_ShouldNotApplyTheDefault()
|
|
{
|
|
var resolved = FmtHandler.ResolveConfig("naive+https://what:happened@test.someone.cf:0", out _);
|
|
|
|
await resolved.Should().NotBeNull();
|
|
await resolved!.Port.Should().BeEqualTo(0);
|
|
await resolved.IsValid().Should().BeFalse();
|
|
}
|
|
}
|