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 15, 2024
1 parent 6ee6cc9 commit f1e4b72
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/dnsforward/dnsforward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,7 @@ func TestServer_HandleBefore(t *testing.T) {
allowedClients []string
disallowedClients []string
blockedHosts []string
wantRCode int
}{{
want: assert.NotEmpty,
clientSrvName: tlsServerName,
Expand All @@ -1676,6 +1677,7 @@ func TestServer_HandleBefore(t *testing.T) {
allowedClients: []string{},
disallowedClients: []string{},
blockedHosts: []string{},
wantRCode: dns.RcodeSuccess,
}, {
want: assert.NotEmpty,
clientSrvName: clientID + "." + tlsServerName,
Expand All @@ -1684,6 +1686,7 @@ func TestServer_HandleBefore(t *testing.T) {
allowedClients: []string{clientID},
disallowedClients: []string{},
blockedHosts: []string{},
wantRCode: dns.RcodeSuccess,
}, {
want: assert.Empty,
clientSrvName: "client-2." + tlsServerName,
Expand All @@ -1692,6 +1695,7 @@ func TestServer_HandleBefore(t *testing.T) {
allowedClients: []string{clientID},
disallowedClients: []string{},
blockedHosts: []string{},
wantRCode: dns.RcodeRefused,
}, {
want: assert.NotEmpty,
clientSrvName: tlsServerName,
Expand All @@ -1700,6 +1704,7 @@ func TestServer_HandleBefore(t *testing.T) {
allowedClients: []string{},
disallowedClients: []string{clientID},
blockedHosts: []string{},
wantRCode: dns.RcodeSuccess,
}, {
want: assert.Empty,
clientSrvName: clientID + "." + tlsServerName,
Expand All @@ -1708,6 +1713,7 @@ func TestServer_HandleBefore(t *testing.T) {
allowedClients: []string{},
disallowedClients: []string{clientID},
blockedHosts: []string{},
wantRCode: dns.RcodeRefused,
}, {
want: assert.NotEmpty,
clientSrvName: tlsServerName,
Expand All @@ -1716,6 +1722,7 @@ func TestServer_HandleBefore(t *testing.T) {
allowedClients: []string{},
disallowedClients: []string{},
blockedHosts: []string{blockedHost},
wantRCode: dns.RcodeSuccess,
}, {
want: assert.Empty,
clientSrvName: tlsServerName,
Expand All @@ -1724,10 +1731,13 @@ func TestServer_HandleBefore(t *testing.T) {
allowedClients: []string{},
disallowedClients: []string{},
blockedHosts: []string{blockedHost},
wantRCode: dns.RcodeRefused,
}}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

s, _ := createTestTLS(t, TLSConfig{
TLSListenAddrs: []*net.TCPAddr{{}},
ServerName: tlsServerName,
Expand All @@ -1738,7 +1748,7 @@ func TestServer_HandleBefore(t *testing.T) {
s.conf.BlockedHosts = tc.blockedHosts

err := s.Prepare(&s.conf)
require.NoErrorf(t, err, "failed to prepare server: %s", err)
require.NoError(t, err)

startDeferStop(t, s)

Expand All @@ -1758,6 +1768,7 @@ func TestServer_HandleBefore(t *testing.T) {
reply, _, err := client.Exchange(req, addr)
require.NoErrorf(t, err, "couldn't talk to server %s: %s", addr, err)
tc.want(t, reply.Answer)
assert.Equal(t, tc.wantRCode, reply.Rcode)
})
}
}

0 comments on commit f1e4b72

Please sign in to comment.