Skip to content

Commit

Permalink
filtering: fix legacy rewrite domain case
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Jul 13, 2021
1 parent ff4905b commit cc1c72c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ released by then.

### Fixed

- Domain name letter case mismatches in DNS rewrites ([#3351]).
- Conflicts between IPv4 and IPv6 DNS rewrites ([#3343]).
- Letter case mismatches in `CNAME` filtering ([#3335]).
- Occasional breakages on network errors with DNS-over-HTTP upstreams ([#3217]).
Expand Down Expand Up @@ -105,6 +106,7 @@ released by then.
[#3257]: https://github.com/AdguardTeam/AdGuardHome/issues/3257
[#3335]: https://github.com/AdguardTeam/AdGuardHome/issues/3335
[#3343]: https://github.com/AdguardTeam/AdGuardHome/issues/3343
[#3351]: https://github.com/AdguardTeam/AdGuardHome/issues/3351



Expand Down
5 changes: 5 additions & 0 deletions internal/filtering/rewrites.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func (a rewritesSorted) Less(i, j int) bool {

// prepare prepares the a new or decoded entry.
func (r *RewriteEntry) prepare() {
// TODO(a.garipov): Write a case-agnostic version of strings.HasSuffix
// and use it in matchDomainWildcard instead of using strings.ToLower
// everywhere.
r.Domain = strings.ToLower(r.Domain)

switch r.Answer {
case "AAAA":
r.IP = nil
Expand Down
14 changes: 12 additions & 2 deletions internal/filtering/rewrites_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func TestRewrites(t *testing.T) {
}, {
Domain: "*.hostboth.com",
Answer: "1234::5678",
}, {
Domain: "BIGHOST.COM",
Answer: "1.2.3.7",
}}
d.prepareRewrites()

Expand Down Expand Up @@ -126,6 +129,12 @@ func TestRewrites(t *testing.T) {
wantCName: "",
wantVals: []net.IP{net.ParseIP("1234::5678")},
dtyp: dns.TypeAAAA,
}, {
name: "issue3351",
host: "bighost.com",
wantCName: "",
wantVals: []net.IP{{1, 2, 3, 7}},
dtyp: dns.TypeA,
}}

for _, tc := range testCases {
Expand All @@ -139,7 +148,8 @@ func TestRewrites(t *testing.T) {
return
}

require.Equal(t, Rewritten, r.Reason)
require.Equalf(t, Rewritten, r.Reason, "got %s", r.Reason)

if tc.wantCName != "" {
assert.Equal(t, tc.wantCName, r.CanonName)
}
Expand Down Expand Up @@ -319,7 +329,7 @@ func TestRewritesExceptionIP(t *testing.T) {
return
}

assert.Equal(t, Rewritten, r.Reason)
assert.Equalf(t, Rewritten, r.Reason, "got %s", r.Reason)

require.Len(t, r.IPList, len(tc.want))

Expand Down

0 comments on commit cc1c72c

Please sign in to comment.