mirror of
https://github.com/coredns/coredns.git
synced 2025-12-23 10:35:23 -05:00
plugin/dns64 : add support for DNS requests over IPv4 network (#4809)
This commit is contained in:
@@ -21,6 +21,58 @@ func To6(prefix, address string) (net.IP, error) {
|
||||
return to6(pref, addr)
|
||||
}
|
||||
|
||||
func TestRequestShouldIntercept(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
allowIpv4 bool
|
||||
remoteIP string
|
||||
msg *dns.Msg
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "should intercept request from IPv6 network - AAAA - IN",
|
||||
allowIpv4: true,
|
||||
remoteIP: "::1",
|
||||
msg: new(dns.Msg).SetQuestion("example.com", dns.TypeAAAA),
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "should intercept request from IPv4 network - AAAA - IN",
|
||||
allowIpv4: true,
|
||||
remoteIP: "127.0.0.1",
|
||||
msg: new(dns.Msg).SetQuestion("example.com", dns.TypeAAAA),
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "should not intercept request from IPv4 network - AAAA - IN",
|
||||
allowIpv4: false,
|
||||
remoteIP: "127.0.0.1",
|
||||
msg: new(dns.Msg).SetQuestion("example.com", dns.TypeAAAA),
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "should not intercept request from IPv6 network - A - IN",
|
||||
allowIpv4: false,
|
||||
remoteIP: "::1",
|
||||
msg: new(dns.Msg).SetQuestion("example.com", dns.TypeA),
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
h := DNS64{AllowIPv4: tc.allowIpv4}
|
||||
rec := dnstest.NewRecorder(&test.ResponseWriter{RemoteIP: tc.remoteIP})
|
||||
r := request.Request{W: rec, Req: tc.msg}
|
||||
|
||||
actual := h.requestShouldIntercept(&r)
|
||||
|
||||
if actual != tc.want {
|
||||
t.Fatalf("Expected %v, but got %v", tc.want, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestTo6(t *testing.T) {
|
||||
|
||||
v6, err := To6("64:ff9b::/96", "64.64.64.64")
|
||||
|
||||
Reference in New Issue
Block a user