aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Marius Kimmina <38843153+mariuskimmina@users.noreply.github.com> 2022-07-15 17:00:42 +0200
committerGravatar GitHub <noreply@github.com> 2022-07-15 17:00:42 +0200
commit9ea4c09485fd85cda29ab4255080508af821ae10 (patch)
tree5cf04960f59d601c8520f9abd77355df06a6c077 /test
parentddee42c974d89d9beb4ebf7b82019624fbf0c456 (diff)
downloadcoredns-9ea4c09485fd85cda29ab4255080508af821ae10.tar.gz
coredns-9ea4c09485fd85cda29ab4255080508af821ae10.tar.zst
coredns-9ea4c09485fd85cda29ab4255080508af821ae10.zip
Add test for DNS over TLS (#5511)
Diffstat (limited to 'test')
-rw-r--r--test/tls_test.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/tls_test.go b/test/tls_test.go
new file mode 100644
index 000000000..f302d5105
--- /dev/null
+++ b/test/tls_test.go
@@ -0,0 +1,46 @@
+package test
+
+import (
+ "crypto/tls"
+ "testing"
+
+ "github.com/miekg/dns"
+)
+
+func TestDNSoverTLS(t *testing.T) {
+ corefile := `tls://.:1053 {
+ tls ../plugin/tls/test_cert.pem ../plugin/tls/test_key.pem
+ whoami
+ }`
+ qname := "example.com."
+ qtype := dns.TypeA
+ answerLength := 0
+
+ ex, _, tcp, err := CoreDNSServerAndPorts(corefile)
+ if err != nil {
+ t.Fatalf("Could not get CoreDNS serving instance: %s", err)
+ }
+ defer ex.Stop()
+
+ m := new(dns.Msg)
+ m.SetQuestion(qname, qtype)
+ client := dns.Client{
+ Net: "tcp-tls",
+ TLSConfig: &tls.Config{InsecureSkipVerify: true},
+ }
+ r, _, err := client.Exchange(m, tcp)
+
+ 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)
+ }
+}