diff --git a/app/dispatcher/impl/sniffer_test.go b/app/dispatcher/impl/sniffer_test.go index ce252de4..9ae7eac8 100644 --- a/app/dispatcher/impl/sniffer_test.go +++ b/app/dispatcher/impl/sniffer_test.go @@ -3,6 +3,8 @@ package impl_test import ( "testing" + "v2ray.com/core/app/proxyman" + . "v2ray.com/core/app/dispatcher/impl" . "v2ray.com/ext/assert" ) @@ -184,3 +186,9 @@ func TestTLSHeaders(t *testing.T) { assert(err, Equals, test.err) } } + +func TestUnknownSniffer(t *testing.T) { + assert := With(t) + + assert(func() { NewSniffer([]proxyman.KnownProtocols{proxyman.KnownProtocols(-1)}) }, Panics) +} diff --git a/common/net/address_test.go b/common/net/address_test.go index 2e8715c3..9c2ab9c8 100644 --- a/common/net/address_test.go +++ b/common/net/address_test.go @@ -85,3 +85,19 @@ func TestParseIPv6Address(t *testing.T) { assert(ip, IsIPv4) assert(ip.String(), Equals, "123.151.71.143") } + +func TestInvalidAddressConvertion(t *testing.T) { + assert := With(t) + + assert(func() { ParseAddress("8.8.8.8").Domain() }, Panics) + assert(func() { ParseAddress("2001:4860:0:2001::68").Domain() }, Panics) + assert(func() { ParseAddress("v2ray.com").IP() }, Panics) +} + +func TestIPOrDomain(t *testing.T) { + assert := With(t) + + assert(NewIPOrDomain(ParseAddress("v2ray.com")).AsAddress(), Equals, ParseAddress("v2ray.com")) + assert(NewIPOrDomain(ParseAddress("8.8.8.8")).AsAddress(), Equals, ParseAddress("8.8.8.8")) + assert(NewIPOrDomain(ParseAddress("2001:4860:0:2001::68")).AsAddress(), Equals, ParseAddress("2001:4860:0:2001::68")) +}