From d76834f843f3f6c97303b9281aae4aa0704ad95c Mon Sep 17 00:00:00 2001 From: Dimitry Kolyshev Date: Mon, 26 Dec 2022 22:44:19 +0700 Subject: [PATCH] filtering: imp code --- internal/filtering/filtering_test.go | 79 ++++++++++++++-------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/internal/filtering/filtering_test.go b/internal/filtering/filtering_test.go index 05869765..6e0ea4dd 100644 --- a/internal/filtering/filtering_test.go +++ b/internal/filtering/filtering_test.go @@ -417,274 +417,275 @@ func TestMatching(t *testing.T) { host string wantReason Reason wantIsFiltered bool - wantDNSType uint16 + qtype uint16 }{{ name: "sanity", rules: "||doubleclick.net^", host: "www.doubleclick.net", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "sanity", rules: "||doubleclick.net^", host: "nodoubleclick.net", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "sanity", rules: "||doubleclick.net^", host: "doubleclick.net.ru", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "sanity", rules: "||doubleclick.net^", host: sbBlocked, wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "blocking", rules: blockingRules, host: "example.org", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "blocking", rules: blockingRules, host: "test.example.org", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "blocking", rules: blockingRules, host: "test.test.example.org", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "blocking", rules: blockingRules, host: "testexample.org", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "blocking", rules: blockingRules, host: "onemoreexample.org", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "allowlist", rules: allowlistRules, host: "example.org", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "allowlist", rules: allowlistRules, host: "test.example.org", wantIsFiltered: false, wantReason: NotFilteredAllowList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "allowlist", rules: allowlistRules, host: "test.test.example.org", wantIsFiltered: false, wantReason: NotFilteredAllowList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "allowlist", rules: allowlistRules, host: "testexample.org", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "allowlist", rules: allowlistRules, host: "onemoreexample.org", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "important", rules: importantRules, host: "example.org", wantIsFiltered: false, wantReason: NotFilteredAllowList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "important", rules: importantRules, host: "test.example.org", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "important", rules: importantRules, host: "test.test.example.org", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "important", rules: importantRules, host: "testexample.org", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "important", rules: importantRules, host: "onemoreexample.org", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "regex", rules: regexRules, host: "example.org", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "regex", rules: regexRules, host: "test.example.org", wantIsFiltered: false, wantReason: NotFilteredAllowList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "regex", rules: regexRules, host: "test.test.example.org", wantIsFiltered: false, wantReason: NotFilteredAllowList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "regex", rules: regexRules, host: "testexample.org", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "regex", rules: regexRules, host: "onemoreexample.org", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "mask", rules: maskRules, host: "test.example.org", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "mask", rules: maskRules, host: "test2.example.org", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "mask", rules: maskRules, host: "example.com", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "mask", rules: maskRules, host: "exampleeee.com", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "mask", rules: maskRules, host: "onemoreexamsite.com", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "mask", rules: maskRules, host: "example.org", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "mask", rules: maskRules, host: "testexample.org", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "mask", rules: maskRules, host: "example.co.uk", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "dnstype", rules: dnstypeRules, host: "onemoreexample.org", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "dnstype", rules: dnstypeRules, host: "example.org", wantIsFiltered: false, wantReason: NotFilteredNotFound, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "dnstype", rules: dnstypeRules, host: "example.org", wantIsFiltered: true, wantReason: FilteredBlockList, - wantDNSType: dns.TypeAAAA, + qtype: dns.TypeAAAA, }, { name: "dnstype", rules: dnstypeRules, host: "test.example.org", wantIsFiltered: false, wantReason: NotFilteredAllowList, - wantDNSType: dns.TypeA, + qtype: dns.TypeA, }, { name: "dnstype", rules: dnstypeRules, host: "test.example.org", wantIsFiltered: false, wantReason: NotFilteredAllowList, - wantDNSType: dns.TypeAAAA, + qtype: dns.TypeAAAA, }} + for _, tc := range testCases { t.Run(fmt.Sprintf("%s-%s", tc.name, tc.host), func(t *testing.T) { filters := []Filter{{ID: 0, Data: []byte(tc.rules)}} d, setts := newForTest(t, nil, filters) t.Cleanup(d.Close) - res, err := d.CheckHost(tc.host, tc.wantDNSType, setts) + res, err := d.CheckHost(tc.host, tc.qtype, setts) require.NoError(t, err) assert.Equalf(t, tc.wantIsFiltered, res.IsFiltered, "Hostname %s has wrong result (%v must be %v)", tc.host, res.IsFiltered, tc.wantIsFiltered)