mirror of
https://github.com/tinyauthapp/tinyauth.git
synced 2026-08-27 15:53:32 +08:00
fix: allow for undescores and leading hyphens in domain validator (#1088)
This commit is contained in:
@@ -50,6 +50,16 @@ func TestDomainValidator_SafeHostname(t *testing.T) {
|
||||
input: "https://example.com",
|
||||
expected: "example.com",
|
||||
},
|
||||
{
|
||||
description: "Domain with underscores should pass",
|
||||
input: "https://my_domain.com",
|
||||
expected: "my_domain.com",
|
||||
},
|
||||
{
|
||||
description: "Domain with leading hyphen should pass",
|
||||
input: "https://-my-domain.com",
|
||||
expected: "-my-domain.com",
|
||||
},
|
||||
{
|
||||
description: "Domain without scheme should parse if scheme is disabled",
|
||||
input: "example.com",
|
||||
@@ -108,7 +118,7 @@ func TestDomainValidator_SafeHostname(t *testing.T) {
|
||||
},
|
||||
{
|
||||
description: "Invalid IDNA domain should fail",
|
||||
input: "ab--cd.example.com",
|
||||
input: "xn--r-kva.example.com",
|
||||
errorFunc: func(t *testing.T, e error) {
|
||||
assert.ErrorContains(t, e, "invalid label")
|
||||
},
|
||||
@@ -196,7 +206,7 @@ func TestDomainValidator_Validate(t *testing.T) {
|
||||
},
|
||||
{
|
||||
description: "Failure to format expected domain should fail",
|
||||
expected: "ab--cd.example.com",
|
||||
expected: "xn--r-kva.example.com",
|
||||
actual: "example.com",
|
||||
errorFunc: func(t *testing.T, e error) {
|
||||
assert.ErrorContains(t, e, "idna: invalid label")
|
||||
@@ -205,7 +215,7 @@ func TestDomainValidator_Validate(t *testing.T) {
|
||||
{
|
||||
description: "Failure to format check domain should fail",
|
||||
expected: "example.com",
|
||||
actual: "ab--cd.example.com",
|
||||
actual: "xn--r-kva.example.com",
|
||||
errorFunc: func(t *testing.T, e error) {
|
||||
assert.ErrorContains(t, e, "idna: invalid label")
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user