mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-16 18:38:52 -07:00
ae8de95d89
Merge in DNS/adguard-home from 2234-move-to-internal to master Squashed commit of the following: commit d26a288cabeac86f9483fab307677b1027c78524 Author: Eugene Burkov <e.burkov@adguard.com> Date: Fri Oct 30 12:44:18 2020 +0300 * all: move internal Go packages to internal/ Closes #2234.
42 lines
1020 B
Go
42 lines
1020 B
Go
package dnsforward
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
|
"github.com/miekg/dns"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIPSET(t *testing.T) {
|
|
s := Server{}
|
|
s.conf.IPSETList = append(s.conf.IPSETList, "HOST.com/name")
|
|
s.conf.IPSETList = append(s.conf.IPSETList, "host2.com,host3.com/name23")
|
|
s.conf.IPSETList = append(s.conf.IPSETList, "host4.com/name4,name41")
|
|
c := ipsetCtx{}
|
|
c.init(s.conf.IPSETList)
|
|
|
|
assert.Equal(t, "name", c.ipsetList["host.com"][0])
|
|
assert.Equal(t, "name23", c.ipsetList["host2.com"][0])
|
|
assert.Equal(t, "name23", c.ipsetList["host3.com"][0])
|
|
assert.Equal(t, "name4", c.ipsetList["host4.com"][0])
|
|
assert.Equal(t, "name41", c.ipsetList["host4.com"][1])
|
|
|
|
_, ok := c.ipsetList["host0.com"]
|
|
assert.False(t, ok)
|
|
|
|
ctx := &dnsContext{
|
|
srv: &s,
|
|
}
|
|
ctx.proxyCtx = &proxy.DNSContext{}
|
|
ctx.proxyCtx.Req = &dns.Msg{
|
|
Question: []dns.Question{
|
|
{
|
|
Name: "host.com.",
|
|
Qtype: dns.TypeA,
|
|
},
|
|
},
|
|
}
|
|
assert.Equal(t, resultDone, c.process(ctx))
|
|
}
|