Pull request 2361: imp-test-file-names
Merge in DNS/adguard-home from imp-test-file-names to master Squashed commit of the following: commit a0827efdf633fba012c5eb0e0f69eaabf7629724 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 10 21:41:46 2025 +0300 all: imp tests commit 21fc274d9276ce0442572261ea39a1c018490870 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 10 19:40:40 2025 +0300 all: imp test file names
This commit is contained in:
@@ -1,14 +1,15 @@
|
|||||||
package aghalg
|
package aghalg_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/internal/aghalg"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewSortedMap(t *testing.T) {
|
func TestNewSortedMap(t *testing.T) {
|
||||||
var m SortedMap[string, int]
|
var m aghalg.SortedMap[string, int]
|
||||||
|
|
||||||
letters := []string{}
|
letters := []string{}
|
||||||
for i := range 10 {
|
for i := range 10 {
|
||||||
@@ -17,7 +18,7 @@ func TestNewSortedMap(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
t.Run("create_and_fill", func(t *testing.T) {
|
t.Run("create_and_fill", func(t *testing.T) {
|
||||||
m = NewSortedMap[string, int](strings.Compare)
|
m = aghalg.NewSortedMap[string, int](strings.Compare)
|
||||||
|
|
||||||
nums := []int{}
|
nums := []int{}
|
||||||
for i, r := range letters {
|
for i, r := range letters {
|
||||||
@@ -68,7 +69,7 @@ func TestNewSortedMap_nil(t *testing.T) {
|
|||||||
val = "val"
|
val = "val"
|
||||||
)
|
)
|
||||||
|
|
||||||
var m SortedMap[string, string]
|
var m aghalg.SortedMap[string, string]
|
||||||
|
|
||||||
assert.Panics(t, func() {
|
assert.Panics(t, func() {
|
||||||
m.Set(key, val)
|
m.Set(key, val)
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package aghnet
|
package aghnet_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,13 +30,13 @@ func TestGenerateHostName(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
hostname := GenerateHostname(tc.ip)
|
hostname := aghnet.GenerateHostname(tc.ip)
|
||||||
assert.Equal(t, tc.want, hostname)
|
assert.Equal(t, tc.want, hostname)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("invalid", func(t *testing.T) {
|
t.Run("invalid", func(t *testing.T) {
|
||||||
assert.Panics(t, func() { GenerateHostname(netip.Addr{}) })
|
assert.Panics(t, func() { aghnet.GenerateHostname(netip.Addr{}) })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,24 @@
|
|||||||
package aghnet
|
package aghnet_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||||
"github.com/AdguardTeam/golibs/errors"
|
"github.com/AdguardTeam/golibs/errors"
|
||||||
"github.com/AdguardTeam/golibs/testutil"
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
// fakeIface is a stub implementation of aghnet.NetIface to simplify testing.
|
// fakeIface is a stub implementation of [aghnet.NetIface] interface to simplify
|
||||||
|
// testing.
|
||||||
type fakeIface struct {
|
type fakeIface struct {
|
||||||
err error
|
err error
|
||||||
addrs []net.Addr
|
addrs []net.Addr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Addrs implements the NetIface interface for *fakeIface.
|
// Addrs implements the [aghnet.NetIface] interface for *fakeIface.
|
||||||
func (iface *fakeIface) Addrs() (addrs []net.Addr, err error) {
|
func (iface *fakeIface) Addrs() (addrs []net.Addr, err error) {
|
||||||
if iface.err != nil {
|
if iface.err != nil {
|
||||||
return nil, iface.err
|
return nil, iface.err
|
||||||
@@ -25,6 +27,9 @@ func (iface *fakeIface) Addrs() (addrs []net.Addr, err error) {
|
|||||||
return iface.addrs, nil
|
return iface.addrs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// type check
|
||||||
|
var _ aghnet.NetIface = (*fakeIface)(nil)
|
||||||
|
|
||||||
func TestIfaceIPAddrs(t *testing.T) {
|
func TestIfaceIPAddrs(t *testing.T) {
|
||||||
const errTest errors.Error = "test error"
|
const errTest errors.Error = "test error"
|
||||||
|
|
||||||
@@ -35,76 +40,76 @@ func TestIfaceIPAddrs(t *testing.T) {
|
|||||||
addr6 := &net.IPNet{IP: ip6}
|
addr6 := &net.IPNet{IP: ip6}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
iface NetIface
|
iface aghnet.NetIface
|
||||||
name string
|
name string
|
||||||
wantErrMsg string
|
wantErrMsg string
|
||||||
want []net.IP
|
want []net.IP
|
||||||
ipv IPVersion
|
ipv aghnet.IPVersion
|
||||||
}{{
|
}{{
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr4}, err: nil},
|
iface: &fakeIface{addrs: []net.Addr{addr4}, err: nil},
|
||||||
name: "ipv4_success",
|
name: "ipv4_success",
|
||||||
wantErrMsg: "",
|
wantErrMsg: "",
|
||||||
want: []net.IP{ip4},
|
want: []net.IP{ip4},
|
||||||
ipv: IPVersion4,
|
ipv: aghnet.IPVersion4,
|
||||||
}, {
|
}, {
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr6, addr4}, err: nil},
|
iface: &fakeIface{addrs: []net.Addr{addr6, addr4}, err: nil},
|
||||||
name: "ipv4_success_with_ipv6",
|
name: "ipv4_success_with_ipv6",
|
||||||
wantErrMsg: "",
|
wantErrMsg: "",
|
||||||
want: []net.IP{ip4},
|
want: []net.IP{ip4},
|
||||||
ipv: IPVersion4,
|
ipv: aghnet.IPVersion4,
|
||||||
}, {
|
}, {
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr4}, err: errTest},
|
iface: &fakeIface{addrs: []net.Addr{addr4}, err: errTest},
|
||||||
name: "ipv4_error",
|
name: "ipv4_error",
|
||||||
wantErrMsg: errTest.Error(),
|
wantErrMsg: errTest.Error(),
|
||||||
want: nil,
|
want: nil,
|
||||||
ipv: IPVersion4,
|
ipv: aghnet.IPVersion4,
|
||||||
}, {
|
}, {
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr6}, err: nil},
|
iface: &fakeIface{addrs: []net.Addr{addr6}, err: nil},
|
||||||
name: "ipv6_success",
|
name: "ipv6_success",
|
||||||
wantErrMsg: "",
|
wantErrMsg: "",
|
||||||
want: []net.IP{ip6},
|
want: []net.IP{ip6},
|
||||||
ipv: IPVersion6,
|
ipv: aghnet.IPVersion6,
|
||||||
}, {
|
}, {
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr6, addr4}, err: nil},
|
iface: &fakeIface{addrs: []net.Addr{addr6, addr4}, err: nil},
|
||||||
name: "ipv6_success_with_ipv4",
|
name: "ipv6_success_with_ipv4",
|
||||||
wantErrMsg: "",
|
wantErrMsg: "",
|
||||||
want: []net.IP{ip6},
|
want: []net.IP{ip6},
|
||||||
ipv: IPVersion6,
|
ipv: aghnet.IPVersion6,
|
||||||
}, {
|
}, {
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr6}, err: errTest},
|
iface: &fakeIface{addrs: []net.Addr{addr6}, err: errTest},
|
||||||
name: "ipv6_error",
|
name: "ipv6_error",
|
||||||
wantErrMsg: errTest.Error(),
|
wantErrMsg: errTest.Error(),
|
||||||
want: nil,
|
want: nil,
|
||||||
ipv: IPVersion6,
|
ipv: aghnet.IPVersion6,
|
||||||
}, {
|
}, {
|
||||||
iface: &fakeIface{addrs: nil, err: nil},
|
iface: &fakeIface{addrs: nil, err: nil},
|
||||||
name: "bad_proto",
|
name: "bad_proto",
|
||||||
wantErrMsg: "invalid ip version 10",
|
wantErrMsg: "invalid ip version 10",
|
||||||
want: nil,
|
want: nil,
|
||||||
ipv: IPVersion6 + IPVersion4,
|
ipv: aghnet.IPVersion6 + aghnet.IPVersion4,
|
||||||
}, {
|
}, {
|
||||||
iface: &fakeIface{addrs: []net.Addr{&net.IPAddr{IP: ip4}}, err: nil},
|
iface: &fakeIface{addrs: []net.Addr{&net.IPAddr{IP: ip4}}, err: nil},
|
||||||
name: "ipaddr_v4",
|
name: "ipaddr_v4",
|
||||||
wantErrMsg: "",
|
wantErrMsg: "",
|
||||||
want: []net.IP{ip4},
|
want: []net.IP{ip4},
|
||||||
ipv: IPVersion4,
|
ipv: aghnet.IPVersion4,
|
||||||
}, {
|
}, {
|
||||||
iface: &fakeIface{addrs: []net.Addr{&net.IPAddr{IP: ip6, Zone: ""}}, err: nil},
|
iface: &fakeIface{addrs: []net.Addr{&net.IPAddr{IP: ip6, Zone: ""}}, err: nil},
|
||||||
name: "ipaddr_v6",
|
name: "ipaddr_v6",
|
||||||
wantErrMsg: "",
|
wantErrMsg: "",
|
||||||
want: []net.IP{ip6},
|
want: []net.IP{ip6},
|
||||||
ipv: IPVersion6,
|
ipv: aghnet.IPVersion6,
|
||||||
}, {
|
}, {
|
||||||
iface: &fakeIface{addrs: []net.Addr{&net.UnixAddr{}}, err: nil},
|
iface: &fakeIface{addrs: []net.Addr{&net.UnixAddr{}}, err: nil},
|
||||||
name: "non-ipv4",
|
name: "non-ipv4",
|
||||||
wantErrMsg: "",
|
wantErrMsg: "",
|
||||||
want: nil,
|
want: nil,
|
||||||
ipv: IPVersion4,
|
ipv: aghnet.IPVersion4,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
got, err := IfaceIPAddrs(tc.iface, tc.ipv)
|
got, err := aghnet.IfaceIPAddrs(tc.iface, tc.ipv)
|
||||||
testutil.AssertErrorMsg(t, tc.wantErrMsg, err)
|
testutil.AssertErrorMsg(t, tc.wantErrMsg, err)
|
||||||
|
|
||||||
assert.Equal(t, tc.want, got)
|
assert.Equal(t, tc.want, got)
|
||||||
@@ -118,7 +123,10 @@ type waitingFakeIface struct {
|
|||||||
n int
|
n int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Addrs implements the NetIface interface for *waitingFakeIface.
|
// type check
|
||||||
|
var _ aghnet.NetIface = (*waitingFakeIface)(nil)
|
||||||
|
|
||||||
|
// Addrs implements the [aghnet.NetIface] interface for *waitingFakeIface.
|
||||||
func (iface *waitingFakeIface) Addrs() (addrs []net.Addr, err error) {
|
func (iface *waitingFakeIface) Addrs() (addrs []net.Addr, err error) {
|
||||||
if iface.err != nil {
|
if iface.err != nil {
|
||||||
return nil, iface.err
|
return nil, iface.err
|
||||||
@@ -143,76 +151,76 @@ func TestIfaceDNSIPAddrs(t *testing.T) {
|
|||||||
addr6 := &net.IPNet{IP: ip6}
|
addr6 := &net.IPNet{IP: ip6}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
iface NetIface
|
iface aghnet.NetIface
|
||||||
wantErr error
|
wantErr error
|
||||||
name string
|
name string
|
||||||
want []net.IP
|
want []net.IP
|
||||||
ipv IPVersion
|
ipv aghnet.IPVersion
|
||||||
}{{
|
}{{
|
||||||
name: "ipv4_success",
|
name: "ipv4_success",
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr4}, err: nil},
|
iface: &fakeIface{addrs: []net.Addr{addr4}, err: nil},
|
||||||
ipv: IPVersion4,
|
ipv: aghnet.IPVersion4,
|
||||||
want: []net.IP{ip4, ip4},
|
want: []net.IP{ip4, ip4},
|
||||||
wantErr: nil,
|
wantErr: nil,
|
||||||
}, {
|
}, {
|
||||||
name: "ipv4_success_with_ipv6",
|
name: "ipv4_success_with_ipv6",
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr6, addr4}, err: nil},
|
iface: &fakeIface{addrs: []net.Addr{addr6, addr4}, err: nil},
|
||||||
ipv: IPVersion4,
|
ipv: aghnet.IPVersion4,
|
||||||
want: []net.IP{ip4, ip4},
|
want: []net.IP{ip4, ip4},
|
||||||
wantErr: nil,
|
wantErr: nil,
|
||||||
}, {
|
}, {
|
||||||
name: "ipv4_error",
|
name: "ipv4_error",
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr4}, err: errTest},
|
iface: &fakeIface{addrs: []net.Addr{addr4}, err: errTest},
|
||||||
ipv: IPVersion4,
|
ipv: aghnet.IPVersion4,
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: errTest,
|
wantErr: errTest,
|
||||||
}, {
|
}, {
|
||||||
name: "ipv4_wait",
|
name: "ipv4_wait",
|
||||||
iface: &waitingFakeIface{addrs: []net.Addr{addr4}, err: nil, n: 1},
|
iface: &waitingFakeIface{addrs: []net.Addr{addr4}, err: nil, n: 1},
|
||||||
ipv: IPVersion4,
|
ipv: aghnet.IPVersion4,
|
||||||
want: []net.IP{ip4, ip4},
|
want: []net.IP{ip4, ip4},
|
||||||
wantErr: nil,
|
wantErr: nil,
|
||||||
}, {
|
}, {
|
||||||
name: "ipv6_success",
|
name: "ipv6_success",
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr6}, err: nil},
|
iface: &fakeIface{addrs: []net.Addr{addr6}, err: nil},
|
||||||
ipv: IPVersion6,
|
ipv: aghnet.IPVersion6,
|
||||||
want: []net.IP{ip6, ip6},
|
want: []net.IP{ip6, ip6},
|
||||||
wantErr: nil,
|
wantErr: nil,
|
||||||
}, {
|
}, {
|
||||||
name: "ipv6_success_with_ipv4",
|
name: "ipv6_success_with_ipv4",
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr6, addr4}, err: nil},
|
iface: &fakeIface{addrs: []net.Addr{addr6, addr4}, err: nil},
|
||||||
ipv: IPVersion6,
|
ipv: aghnet.IPVersion6,
|
||||||
want: []net.IP{ip6, ip6},
|
want: []net.IP{ip6, ip6},
|
||||||
wantErr: nil,
|
wantErr: nil,
|
||||||
}, {
|
}, {
|
||||||
name: "ipv6_error",
|
name: "ipv6_error",
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr6}, err: errTest},
|
iface: &fakeIface{addrs: []net.Addr{addr6}, err: errTest},
|
||||||
ipv: IPVersion6,
|
ipv: aghnet.IPVersion6,
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: errTest,
|
wantErr: errTest,
|
||||||
}, {
|
}, {
|
||||||
name: "ipv6_wait",
|
name: "ipv6_wait",
|
||||||
iface: &waitingFakeIface{addrs: []net.Addr{addr6}, err: nil, n: 1},
|
iface: &waitingFakeIface{addrs: []net.Addr{addr6}, err: nil, n: 1},
|
||||||
ipv: IPVersion6,
|
ipv: aghnet.IPVersion6,
|
||||||
want: []net.IP{ip6, ip6},
|
want: []net.IP{ip6, ip6},
|
||||||
wantErr: nil,
|
wantErr: nil,
|
||||||
}, {
|
}, {
|
||||||
name: "empty",
|
name: "empty",
|
||||||
iface: &fakeIface{addrs: nil, err: nil},
|
iface: &fakeIface{addrs: nil, err: nil},
|
||||||
ipv: IPVersion4,
|
ipv: aghnet.IPVersion4,
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: nil,
|
wantErr: nil,
|
||||||
}, {
|
}, {
|
||||||
name: "many",
|
name: "many",
|
||||||
iface: &fakeIface{addrs: []net.Addr{addr4, addr4}},
|
iface: &fakeIface{addrs: []net.Addr{addr4, addr4}},
|
||||||
ipv: IPVersion4,
|
ipv: aghnet.IPVersion4,
|
||||||
want: []net.IP{ip4, ip4},
|
want: []net.IP{ip4, ip4},
|
||||||
wantErr: nil,
|
wantErr: nil,
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
got, err := IfaceDNSIPAddrs(tc.iface, tc.ipv, 2, 0)
|
got, err := aghnet.IfaceDNSIPAddrs(tc.iface, tc.ipv, 2, 0)
|
||||||
require.ErrorIs(t, err, tc.wantErr)
|
require.ErrorIs(t, err, tc.wantErr)
|
||||||
|
|
||||||
assert.Equal(t, tc.want, got)
|
assert.Equal(t, tc.want, got)
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package aghnet
|
package aghnet_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||||
"github.com/AdguardTeam/golibs/netutil"
|
"github.com/AdguardTeam/golibs/netutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@@ -18,7 +19,7 @@ func TestIPMut(t *testing.T) {
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
t.Run("nil_no_mut", func(t *testing.T) {
|
t.Run("nil_no_mut", func(t *testing.T) {
|
||||||
ipmut := NewIPMut(nil)
|
ipmut := aghnet.NewIPMut(nil)
|
||||||
|
|
||||||
ips := netutil.CloneIPs(testIPs)
|
ips := netutil.CloneIPs(testIPs)
|
||||||
for i := range ips {
|
for i := range ips {
|
||||||
@@ -28,7 +29,7 @@ func TestIPMut(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("not_nil_mut", func(t *testing.T) {
|
t.Run("not_nil_mut", func(t *testing.T) {
|
||||||
ipmut := NewIPMut(func(ip net.IP) {
|
ipmut := aghnet.NewIPMut(func(ip net.IP) {
|
||||||
for i := range ip {
|
for i := range ip {
|
||||||
ip[i] = 0
|
ip[i] = 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//go:build darwin
|
||||||
|
|
||||||
package aghnet
|
package aghnet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
package filtering
|
package filtering_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/golibs/netutil"
|
"github.com/AdguardTeam/golibs/netutil"
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@@ -50,8 +51,17 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
|||||||
|1.2.3.5.in-addr.arpa^$dnsrewrite=NOERROR;PTR;new-ptr-with-dot.
|
|1.2.3.5.in-addr.arpa^$dnsrewrite=NOERROR;PTR;new-ptr-with-dot.
|
||||||
`
|
`
|
||||||
|
|
||||||
f, _ := newForTest(t, nil, []Filter{{ID: 0, Data: []byte(text)}})
|
conf := &filtering.Config{
|
||||||
setts := &Settings{
|
SafeBrowsingCacheSize: 10000,
|
||||||
|
ParentalCacheSize: 10000,
|
||||||
|
SafeSearchCacheSize: 1000,
|
||||||
|
CacheTime: 30,
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := filtering.New(conf, []filtering.Filter{{ID: 0, Data: []byte(text)}})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
setts := &filtering.Settings{
|
||||||
FilteringEnabled: true,
|
FilteringEnabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +127,8 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
|||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
host := path.Base(tc.name)
|
host := path.Base(tc.name)
|
||||||
|
|
||||||
res, err := f.CheckHostRules(host, tc.dtyp, setts)
|
var res filtering.Result
|
||||||
|
res, err = f.CheckHostRules(host, tc.dtyp, setts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
dnsrr := res.DNSRewriteResult
|
dnsrr := res.DNSRewriteResult
|
||||||
@@ -141,7 +152,8 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
|||||||
dtyp := dns.TypeA
|
dtyp := dns.TypeA
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
res, err := f.CheckHostRules(host, dtyp, setts)
|
var res filtering.Result
|
||||||
|
res, err = f.CheckHostRules(host, dtyp, setts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "new-cname", res.CanonName)
|
assert.Equal(t, "new-cname", res.CanonName)
|
||||||
@@ -151,7 +163,8 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
|||||||
dtyp := dns.TypeA
|
dtyp := dns.TypeA
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
res, err := f.CheckHostRules(host, dtyp, setts)
|
var res filtering.Result
|
||||||
|
res, err = f.CheckHostRules(host, dtyp, setts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, "new-cname-2", res.CanonName)
|
assert.Equal(t, "new-cname-2", res.CanonName)
|
||||||
@@ -162,7 +175,8 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
|||||||
dtyp := dns.TypeA
|
dtyp := dns.TypeA
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
res, err := f.CheckHostRules(host, dtyp, setts)
|
var res filtering.Result
|
||||||
|
res, err = f.CheckHostRules(host, dtyp, setts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.Empty(t, res.CanonName)
|
assert.Empty(t, res.CanonName)
|
||||||
@@ -173,7 +187,8 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
|||||||
dtyp := dns.TypePTR
|
dtyp := dns.TypePTR
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
res, err := f.CheckHostRules(host, dtyp, setts)
|
var res filtering.Result
|
||||||
|
res, err = f.CheckHostRules(host, dtyp, setts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res.DNSRewriteResult)
|
require.NotNil(t, res.DNSRewriteResult)
|
||||||
|
|
||||||
@@ -193,7 +208,8 @@ func TestDNSFilter_CheckHostRules_dnsrewrite(t *testing.T) {
|
|||||||
dtyp := dns.TypePTR
|
dtyp := dns.TypePTR
|
||||||
host := path.Base(t.Name())
|
host := path.Base(t.Name())
|
||||||
|
|
||||||
res, err := f.CheckHostRules(host, dtyp, setts)
|
var res filtering.Result
|
||||||
|
res, err = f.CheckHostRules(host, dtyp, setts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res.DNSRewriteResult)
|
require.NotNil(t, res.DNSRewriteResult)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package filtering
|
package filtering_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
||||||
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
||||||
"github.com/AdguardTeam/AdGuardHome/internal/filtering/rulelist"
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering/rulelist"
|
||||||
"github.com/AdguardTeam/golibs/testutil"
|
"github.com/AdguardTeam/golibs/testutil"
|
||||||
"github.com/AdguardTeam/urlfilter/rules"
|
"github.com/AdguardTeam/urlfilter/rules"
|
||||||
@@ -50,27 +51,27 @@ func TestDNSFilter_CheckHost_hostsContainer(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
testutil.CleanupAndRequireSuccess(t, hc.Close)
|
testutil.CleanupAndRequireSuccess(t, hc.Close)
|
||||||
|
|
||||||
conf := &Config{
|
conf := &filtering.Config{
|
||||||
EtcHosts: hc,
|
EtcHosts: hc,
|
||||||
}
|
}
|
||||||
f, err := New(conf, nil)
|
f, err := filtering.New(conf, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
setts := &Settings{
|
setts := &filtering.Settings{
|
||||||
FilteringEnabled: true,
|
FilteringEnabled: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
host string
|
host string
|
||||||
wantRules []*ResultRule
|
wantRules []*filtering.ResultRule
|
||||||
wantResps []rules.RRValue
|
wantResps []rules.RRValue
|
||||||
dtyp uint16
|
dtyp uint16
|
||||||
}{{
|
}{{
|
||||||
name: "v4",
|
name: "v4",
|
||||||
host: "v4.host.example",
|
host: "v4.host.example",
|
||||||
dtyp: dns.TypeA,
|
dtyp: dns.TypeA,
|
||||||
wantRules: []*ResultRule{{
|
wantRules: []*filtering.ResultRule{{
|
||||||
Text: "1.2.3.4 v4.host.example",
|
Text: "1.2.3.4 v4.host.example",
|
||||||
FilterListID: rulelist.URLFilterIDEtcHosts,
|
FilterListID: rulelist.URLFilterIDEtcHosts,
|
||||||
}},
|
}},
|
||||||
@@ -79,7 +80,7 @@ func TestDNSFilter_CheckHost_hostsContainer(t *testing.T) {
|
|||||||
name: "v6",
|
name: "v6",
|
||||||
host: "v6.host.example",
|
host: "v6.host.example",
|
||||||
dtyp: dns.TypeAAAA,
|
dtyp: dns.TypeAAAA,
|
||||||
wantRules: []*ResultRule{{
|
wantRules: []*filtering.ResultRule{{
|
||||||
Text: "::1 v6.host.example",
|
Text: "::1 v6.host.example",
|
||||||
FilterListID: rulelist.URLFilterIDEtcHosts,
|
FilterListID: rulelist.URLFilterIDEtcHosts,
|
||||||
}},
|
}},
|
||||||
@@ -88,7 +89,7 @@ func TestDNSFilter_CheckHost_hostsContainer(t *testing.T) {
|
|||||||
name: "mapped",
|
name: "mapped",
|
||||||
host: "mapped.host.example",
|
host: "mapped.host.example",
|
||||||
dtyp: dns.TypeAAAA,
|
dtyp: dns.TypeAAAA,
|
||||||
wantRules: []*ResultRule{{
|
wantRules: []*filtering.ResultRule{{
|
||||||
Text: "::ffff:1.2.3.4 mapped.host.example",
|
Text: "::ffff:1.2.3.4 mapped.host.example",
|
||||||
FilterListID: rulelist.URLFilterIDEtcHosts,
|
FilterListID: rulelist.URLFilterIDEtcHosts,
|
||||||
}},
|
}},
|
||||||
@@ -97,7 +98,7 @@ func TestDNSFilter_CheckHost_hostsContainer(t *testing.T) {
|
|||||||
name: "ptr",
|
name: "ptr",
|
||||||
host: "4.3.2.1.in-addr.arpa",
|
host: "4.3.2.1.in-addr.arpa",
|
||||||
dtyp: dns.TypePTR,
|
dtyp: dns.TypePTR,
|
||||||
wantRules: []*ResultRule{{
|
wantRules: []*filtering.ResultRule{{
|
||||||
Text: "1.2.3.4 v4.host.example",
|
Text: "1.2.3.4 v4.host.example",
|
||||||
FilterListID: rulelist.URLFilterIDEtcHosts,
|
FilterListID: rulelist.URLFilterIDEtcHosts,
|
||||||
}},
|
}},
|
||||||
@@ -106,7 +107,7 @@ func TestDNSFilter_CheckHost_hostsContainer(t *testing.T) {
|
|||||||
name: "ptr-mapped",
|
name: "ptr-mapped",
|
||||||
host: "4.0.3.0.2.0.1.0.f.f.f.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa",
|
host: "4.0.3.0.2.0.1.0.f.f.f.f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa",
|
||||||
dtyp: dns.TypePTR,
|
dtyp: dns.TypePTR,
|
||||||
wantRules: []*ResultRule{{
|
wantRules: []*filtering.ResultRule{{
|
||||||
Text: "::ffff:1.2.3.4 mapped.host.example",
|
Text: "::ffff:1.2.3.4 mapped.host.example",
|
||||||
FilterListID: rulelist.URLFilterIDEtcHosts,
|
FilterListID: rulelist.URLFilterIDEtcHosts,
|
||||||
}},
|
}},
|
||||||
@@ -133,7 +134,7 @@ func TestDNSFilter_CheckHost_hostsContainer(t *testing.T) {
|
|||||||
name: "v4_mismatch",
|
name: "v4_mismatch",
|
||||||
host: "v4.host.example",
|
host: "v4.host.example",
|
||||||
dtyp: dns.TypeAAAA,
|
dtyp: dns.TypeAAAA,
|
||||||
wantRules: []*ResultRule{{
|
wantRules: []*filtering.ResultRule{{
|
||||||
Text: fmt.Sprintf("%s v4.host.example", addrv4),
|
Text: fmt.Sprintf("%s v4.host.example", addrv4),
|
||||||
FilterListID: rulelist.URLFilterIDEtcHosts,
|
FilterListID: rulelist.URLFilterIDEtcHosts,
|
||||||
}},
|
}},
|
||||||
@@ -142,7 +143,7 @@ func TestDNSFilter_CheckHost_hostsContainer(t *testing.T) {
|
|||||||
name: "v6_mismatch",
|
name: "v6_mismatch",
|
||||||
host: "v6.host.example",
|
host: "v6.host.example",
|
||||||
dtyp: dns.TypeA,
|
dtyp: dns.TypeA,
|
||||||
wantRules: []*ResultRule{{
|
wantRules: []*filtering.ResultRule{{
|
||||||
Text: fmt.Sprintf("%s v6.host.example", addrv6),
|
Text: fmt.Sprintf("%s v6.host.example", addrv6),
|
||||||
FilterListID: rulelist.URLFilterIDEtcHosts,
|
FilterListID: rulelist.URLFilterIDEtcHosts,
|
||||||
}},
|
}},
|
||||||
@@ -163,7 +164,7 @@ func TestDNSFilter_CheckHost_hostsContainer(t *testing.T) {
|
|||||||
name: "v4_dup",
|
name: "v4_dup",
|
||||||
host: "v4.host.with-dup",
|
host: "v4.host.with-dup",
|
||||||
dtyp: dns.TypeA,
|
dtyp: dns.TypeA,
|
||||||
wantRules: []*ResultRule{{
|
wantRules: []*filtering.ResultRule{{
|
||||||
Text: "4.3.2.1 v4.host.with-dup",
|
Text: "4.3.2.1 v4.host.with-dup",
|
||||||
FilterListID: rulelist.URLFilterIDEtcHosts,
|
FilterListID: rulelist.URLFilterIDEtcHosts,
|
||||||
}},
|
}},
|
||||||
@@ -172,7 +173,7 @@ func TestDNSFilter_CheckHost_hostsContainer(t *testing.T) {
|
|||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
var res Result
|
var res filtering.Result
|
||||||
res, err = f.CheckHost(tc.host, tc.dtyp, setts)
|
res, err = f.CheckHost(tc.host, tc.dtyp, setts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user