Skip to content

Commit

Permalink
dnsforward: imp tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Apr 24, 2024
1 parent 3c42fca commit b71304a
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions internal/dnsforward/beforerequest_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,19 @@ func TestServer_HandleBefore_tls(t *testing.T) {
wantRCode: dns.RcodeRefused,
}}

localRR := newRR(t, testFQDN, dns.TypeA, 3600, net.IP{1, 2, 3, 4})
localAns := []dns.RR{&dns.A{
Hdr: dns.RR_Header{
Name: testFQDN,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: 3600,
Rdlength: 4,
},
A: net.IP{1, 2, 3, 4},
}}
localUpsHdlr := dns.HandlerFunc(func(w dns.ResponseWriter, req *dns.Msg) {
resp := (&dns.Msg{}).SetReply(req)
resp.Answer = []dns.RR{localRR}
resp.Answer = localAns

require.NoError(t, w.WriteMsg(resp))
})
Expand Down Expand Up @@ -147,7 +156,7 @@ func TestServer_HandleBefore_tls(t *testing.T) {

assert.Equal(t, tc.wantRCode, reply.Rcode)
if tc.wantRCode == dns.RcodeSuccess {
assert.NotEmpty(t, reply.Answer)
assert.Equal(t, localAns, reply.Answer)
} else {
assert.Empty(t, reply.Answer)
}
Expand Down Expand Up @@ -223,10 +232,19 @@ func TestServer_HandleBefore_udp(t *testing.T) {
wantTimeout: true,
}}

localRR := newRR(t, testFQDN, dns.TypeA, 3600, net.IP{1, 2, 3, 4})
localAns := []dns.RR{&dns.A{
Hdr: dns.RR_Header{
Name: testFQDN,
Rrtype: dns.TypeA,
Class: dns.ClassINET,
Ttl: 3600,
Rdlength: 4,
},
A: net.IP{1, 2, 3, 4},
}}
localUpsHdlr := dns.HandlerFunc(func(w dns.ResponseWriter, req *dns.Msg) {
resp := (&dns.Msg{}).SetReply(req)
resp.Answer = []dns.RR{localRR}
resp.Answer = localAns

require.NoError(t, w.WriteMsg(resp))
})
Expand Down Expand Up @@ -278,7 +296,7 @@ func TestServer_HandleBefore_udp(t *testing.T) {
require.NotNil(t, reply)

assert.Equal(t, dns.RcodeSuccess, reply.Rcode)
assert.NotEmpty(t, reply.Answer)
assert.Equal(t, localAns, reply.Answer)
}
})
}
Expand Down

0 comments on commit b71304a

Please sign in to comment.