Pull request: filtering: fix legacy rewrite domain case

Updates #3351.

Squashed commit of the following:

commit cc1c72cc13026ed703bb140e55dc3eb886846e48
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Jul 13 17:23:33 2021 +0300

    filtering: fix legacy rewrite domain case
This commit is contained in:
Ainar Garipov 2021-07-13 19:45:25 +03:00
parent ff4905b2a2
commit 167447547a
3 changed files with 19 additions and 2 deletions

View File

@ -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]).
@ -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

View File

@ -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

View File

@ -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()
@ -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 {
@ -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)
}
@ -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))