forked from coredns/coredns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtls_test.go
67 lines (58 loc) · 1.49 KB
/
tls_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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package test
import (
"crypto/tls"
"fmt"
"testing"
"github.com/miekg/dns"
)
func TestTLS(t *testing.T) {
tempCorefile := `%s {
tls ../plugin/tls/test_cert.pem ../plugin/tls/test_key.pem
whoami
}`
dot, doh := ":1053", ":8443"
m := new(dns.Msg)
m.SetQuestion("example.com.", dns.TypeA)
answerLength := 0
tests := []struct {
server string
tlsConfig *tls.Config
}{
{fmt.Sprintf("tls://.%s", dot),
&tls.Config{InsecureSkipVerify: true},
},
{fmt.Sprintf("tls://.%s", dot),
&tls.Config{InsecureSkipVerify: true, NextProtos: []string{"dot"}},
},
{fmt.Sprintf("tls://.%s https://.%s", dot, doh),
&tls.Config{InsecureSkipVerify: true},
},
{fmt.Sprintf("tls://.%s https://.%s", dot, doh),
&tls.Config{InsecureSkipVerify: true, NextProtos: []string{"dot"}},
},
}
for _, tc := range tests {
ex, _, _, err := CoreDNSServerAndPorts(fmt.Sprintf(tempCorefile, tc.server))
if err != nil {
t.Fatalf("Could not get CoreDNS serving instance: %s", err)
}
client := dns.Client{
Net: "tcp-tls",
TLSConfig: tc.tlsConfig,
}
r, _, err := client.Exchange(m, dot)
if err != nil {
t.Fatalf("Could not exchange msg: %s", err)
}
if n := len(r.Answer); n != answerLength {
t.Fatalf("Expected %v answers, got %v", answerLength, n)
}
if n := len(r.Extra); n != 2 {
t.Errorf("Expected 2 RRs in additional section, but got %d", n)
}
if r.Rcode != dns.RcodeSuccess {
t.Errorf("Expected success but got %d", r.Rcode)
}
ex.Stop()
}
}