Skip to content

Commit

Permalink
Pull request 376: 412 Upstream validation
Browse files Browse the repository at this point in the history
Closes #411.

Squashed commit of the following:

commit cc58523
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Aug 16 20:09:30 2024 +0300

    upstream: fix tests

commit 18ed578
Merge: 9fdb436 48ef185
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Aug 16 19:58:42 2024 +0300

    Merge branch 'master' into 412-upstream-validation

commit 9fdb436
Author: sanyo <yeshengan.ysa@alibaba-inc.com>
Date:   Wed Aug 14 20:13:04 2024 +0800

    fix upstream doh hostname validate
  • Loading branch information
EugeneOne1 committed Aug 19, 2024
1 parent 48ef185 commit ae6b69c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion upstream/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func validateUpstreamURL(u *url.URL) (err error) {
return nil
}

err = netutil.ValidateHostname(host)
err = netutil.ValidateDomainName(host)
if err != nil {
return fmt.Errorf("invalid address %s: %w", host, err)
}
Expand Down
12 changes: 6 additions & 6 deletions upstream/upstream_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,14 @@ func TestAddressToUpstream_bads(t *testing.T) {
wantErrMsg: `invalid port : strconv.ParseUint: parsing "": invalid syntax`,
}, {
addr: ":53",
wantErrMsg: `invalid address : bad hostname "": hostname is empty`,
wantErrMsg: `invalid address : bad domain name "": domain name is empty`,
}, {
addr: "!!!",
wantErrMsg: `invalid address !!!: bad hostname "!!!": bad top-level domain name ` +
wantErrMsg: `invalid address !!!: bad domain name "!!!": bad top-level domain name ` +
`label "!!!": bad top-level domain name label rune '!'`,
}, {
addr: "123",
wantErrMsg: `invalid address 123: bad hostname "123": bad top-level domain name ` +
wantErrMsg: `invalid address 123: bad domain name "123": bad top-level domain name ` +
`label "123": all octets are numeric`,
}, {
addr: "tcp://12345.1.1.1:1234567",
Expand All @@ -340,14 +340,14 @@ func TestAddressToUpstream_bads(t *testing.T) {
wantErrMsg: `invalid port : strconv.ParseUint: parsing "": invalid syntax`,
}, {
addr: "tcp://:53",
wantErrMsg: `invalid address : bad hostname "": hostname is empty`,
wantErrMsg: `invalid address : bad domain name "": domain name is empty`,
}, {
addr: "tcp://!!!",
wantErrMsg: `invalid address !!!: bad hostname "!!!": bad top-level domain name ` +
wantErrMsg: `invalid address !!!: bad domain name "!!!": bad top-level domain name ` +
`label "!!!": bad top-level domain name label rune '!'`,
}, {
addr: "tcp://123",
wantErrMsg: `invalid address 123: bad hostname "123": bad top-level domain name ` +
wantErrMsg: `invalid address 123: bad domain name "123": bad top-level domain name ` +
`label "123": all octets are numeric`,
}}

Expand Down

0 comments on commit ae6b69c

Please sign in to comment.