29 lines
1.3 KiB
C#
29 lines
1.3 KiB
C#
using MoShiro.Protocol;
|
|
|
|
namespace MoShiro.Protocol.Tests;
|
|
|
|
public sealed class TargetHostTests
|
|
{
|
|
[Theory]
|
|
[InlineData("http_request", "https://Example.com/health?x=1", "https://example.com/health?x=1")]
|
|
[InlineData("http_request", "http://192.0.2.1:8080", "http://192.0.2.1:8080/")]
|
|
[InlineData("tcp_connect", "Example.com:443", "example.com:443")]
|
|
[InlineData("tcp_connect", "192.0.2.1", "192.0.2.1")]
|
|
[InlineData("tcp_connect", "[2001:db8::1]:443", "[2001:db8::1]:443")]
|
|
[InlineData("icmp_ping", "2001:db8::1", "2001:db8::1")]
|
|
public void Normalize_AcceptsTheTargetFormOfTheKind(string kind, string target, string expected) =>
|
|
Assert.Equal(expected, TargetHost.Normalize(kind, target));
|
|
|
|
[Theory]
|
|
[InlineData("http_request", "example.com")] // http 必须是 URL
|
|
[InlineData("http_request", "ftp://example.com/")]
|
|
[InlineData("http_request", "https://user:pw@example.com/")]
|
|
[InlineData("tcp_connect", "https://example.com/")] // 其余 Kind 不能是 URL
|
|
[InlineData("tcp_connect", "example.com:0")]
|
|
[InlineData("tcp_connect", "exa mple.com")]
|
|
[InlineData("tcp_connect", "-bad.example.com")]
|
|
[InlineData("tcp_connect", "")]
|
|
public void Normalize_RejectsTheWrongFormForTheKind(string kind, string target) =>
|
|
Assert.Null(TargetHost.Normalize(kind, target));
|
|
}
|