mirror of
https://github.com/tinyauthapp/tinyauth.git
synced 2026-08-22 04:43:31 +08:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47b5866153 |
@@ -119,7 +119,15 @@ func (v *DomainValidator) getHostname(hostname string) (string, error) {
|
||||
if net.ParseIP(hostname) != nil {
|
||||
return "", fmt.Errorf("ip addresses are not supported")
|
||||
}
|
||||
hostname, err := idna.Lookup.ToASCII(hostname)
|
||||
i := idna.New(
|
||||
idna.MapForLookup(),
|
||||
idna.Transitional(false),
|
||||
idna.BidiRule(),
|
||||
idna.StrictDomainName(false),
|
||||
idna.CheckHyphens(false),
|
||||
idna.CheckJoiners(false),
|
||||
)
|
||||
hostname, err := i.ToASCII(hostname)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to convert hostname to ascii: %w", err)
|
||||
}
|
||||
|
||||
@@ -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