forked from folbricht/routedns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdotclient_test.go
38 lines (32 loc) · 1.13 KB
/
dotclient_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package rdns
import (
"testing"
"github.com/miekg/dns"
"github.com/stretchr/testify/require"
)
func TestDoTClientSimple(t *testing.T) {
d, _ := NewDoTClient("test-dot", "dns.google:853", DoTClientOptions{})
q := new(dns.Msg)
q.SetQuestion("cloudflare.com.", dns.TypeA)
r, err := d.Resolve(q, ClientInfo{})
require.NoError(t, err)
require.NotEmpty(t, r.Answer)
}
func TestDoTClientCA(t *testing.T) {
// Create client cert options with a CA. TODO: Should read the cert dynamically
// to avoid failure when this expires or changes.
tlsConfig, err := TLSClientConfig("testdata/DigiCertECCSecureServerCA.pem", "", "")
require.NoError(t, err)
// DoT client with valid CA
d, _ := NewDoTClient("test-dot", "1.1.1.1:853", DoTClientOptions{TLSConfig: tlsConfig})
q := new(dns.Msg)
q.SetQuestion("cloudflare.com.", dns.TypeA)
r, err := d.Resolve(q, ClientInfo{})
require.NoError(t, err)
require.NotEmpty(t, r.Answer)
// DoT client with invalid CA
d, _ = NewDoTClient("test-dot", "dns.google:853", DoTClientOptions{TLSConfig: tlsConfig})
q.SetQuestion("cloudflare.com.", dns.TypeA)
_, err = d.Resolve(q, ClientInfo{})
require.Error(t, err)
}