mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-28 18:08:51 +03:00
filtering: rewrite tests
This commit is contained in:
parent
d76834f843
commit
8e058b8042
1 changed files with 91 additions and 0 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering/rewrite"
|
||||||
"github.com/AdguardTeam/golibs/cache"
|
"github.com/AdguardTeam/golibs/cache"
|
||||||
"github.com/AdguardTeam/golibs/log"
|
"github.com/AdguardTeam/golibs/log"
|
||||||
"github.com/AdguardTeam/golibs/testutil"
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
|
@ -694,6 +695,96 @@ func TestMatching(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRewrites(t *testing.T) {
|
||||||
|
rewrites := []*rewrite.Item{{
|
||||||
|
Domain: "example.org",
|
||||||
|
Answer: "1.1.1.1",
|
||||||
|
}, {
|
||||||
|
Domain: "example-v6.org",
|
||||||
|
Answer: "1:2:3::4",
|
||||||
|
}, {
|
||||||
|
Domain: "cname.org",
|
||||||
|
Answer: "cname-res.org",
|
||||||
|
}}
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
host string
|
||||||
|
wantReason Reason
|
||||||
|
wantIsFiltered bool
|
||||||
|
qtype uint16
|
||||||
|
}{{
|
||||||
|
name: "not_found_a",
|
||||||
|
host: "not-example.org",
|
||||||
|
wantIsFiltered: false,
|
||||||
|
wantReason: NotFilteredNotFound,
|
||||||
|
qtype: dns.TypeA,
|
||||||
|
}, {
|
||||||
|
name: "not_found_aaaa",
|
||||||
|
host: "not-example.org",
|
||||||
|
wantIsFiltered: false,
|
||||||
|
wantReason: NotFilteredNotFound,
|
||||||
|
qtype: dns.TypeAAAA,
|
||||||
|
}, {
|
||||||
|
name: "not_found_txt",
|
||||||
|
host: "not-example.org",
|
||||||
|
wantIsFiltered: false,
|
||||||
|
wantReason: NotFilteredNotFound,
|
||||||
|
qtype: dns.TypeTXT,
|
||||||
|
}, {
|
||||||
|
name: "found_a",
|
||||||
|
host: "example.org",
|
||||||
|
wantIsFiltered: false,
|
||||||
|
wantReason: Rewritten,
|
||||||
|
qtype: dns.TypeA,
|
||||||
|
}, {
|
||||||
|
name: "found_aaaa",
|
||||||
|
host: "example-v6.org",
|
||||||
|
wantIsFiltered: false,
|
||||||
|
wantReason: Rewritten,
|
||||||
|
qtype: dns.TypeAAAA,
|
||||||
|
}, {
|
||||||
|
name: "found_txt",
|
||||||
|
host: "example.org",
|
||||||
|
wantIsFiltered: false,
|
||||||
|
wantReason: NotFilteredNotFound,
|
||||||
|
qtype: dns.TypeTXT,
|
||||||
|
}, {
|
||||||
|
name: "cname_a",
|
||||||
|
host: "cname.org",
|
||||||
|
wantIsFiltered: false,
|
||||||
|
wantReason: Rewritten,
|
||||||
|
qtype: dns.TypeA,
|
||||||
|
}, {
|
||||||
|
name: "cname_aaaa",
|
||||||
|
host: "cname.org",
|
||||||
|
wantIsFiltered: false,
|
||||||
|
wantReason: Rewritten,
|
||||||
|
qtype: dns.TypeAAAA,
|
||||||
|
}, {
|
||||||
|
name: "cname_txt",
|
||||||
|
host: "cname.org",
|
||||||
|
wantIsFiltered: false,
|
||||||
|
wantReason: NotFilteredNotFound,
|
||||||
|
qtype: dns.TypeTXT,
|
||||||
|
}}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
d, setts := newForTest(t, &Config{
|
||||||
|
Rewrites: rewrites,
|
||||||
|
}, nil)
|
||||||
|
t.Cleanup(d.Close)
|
||||||
|
|
||||||
|
res, err := d.CheckHost(tc.host, tc.qtype, setts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, tc.wantIsFiltered, res.IsFiltered)
|
||||||
|
assert.Equal(t, tc.wantReason, res.Reason)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestWhitelist(t *testing.T) {
|
func TestWhitelist(t *testing.T) {
|
||||||
rules := `||host1^
|
rules := `||host1^
|
||||||
||host2^
|
||host2^
|
||||||
|
|
Loading…
Reference in a new issue