aboutsummaryrefslogtreecommitdiff
path: root/plugin/pkg/doh/doh_test.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-07-07 08:22:07 +0100
committerGravatar GitHub <noreply@github.com> 2018-07-07 08:22:07 +0100
commit30a788fd3a3afe51945554d301386665eca705f2 (patch)
tree59c1b68cd159838ebb58747bc359add5a576dfca /plugin/pkg/doh/doh_test.go
parentbc5090123487653ce502d5801007d03dbb6a2ba7 (diff)
downloadcoredns-30a788fd3a3afe51945554d301386665eca705f2.tar.gz
coredns-30a788fd3a3afe51945554d301386665eca705f2.tar.zst
coredns-30a788fd3a3afe51945554d301386665eca705f2.zip
Doh: put in pkg/doh (#1946)
* DoH: put in pkg/doh Factor out the DoH stuff into its own package, add function to request a DoH response. This can be used by forward (and maybe proxy) to implement DoH client support. Signed-off-by: Miek Gieben <miek@miek.nl> * lint Signed-off-by: Miek Gieben <miek@miek.nl> * ... and make it compile Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/pkg/doh/doh_test.go')
-rw-r--r--plugin/pkg/doh/doh_test.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/plugin/pkg/doh/doh_test.go b/plugin/pkg/doh/doh_test.go
new file mode 100644
index 000000000..449166151
--- /dev/null
+++ b/plugin/pkg/doh/doh_test.go
@@ -0,0 +1,52 @@
+package doh
+
+import (
+ "net/http"
+ "testing"
+
+ "github.com/miekg/dns"
+)
+
+func TestPostRequest(t *testing.T) {
+ m := new(dns.Msg)
+ m.SetQuestion("example.org.", dns.TypeDNSKEY)
+
+ req, err := NewRequest(http.MethodPost, "https://example.org:443", m)
+ if err != nil {
+ t.Errorf("Failure to make request: %s", err)
+ }
+
+ m, err = RequestToMsg(req)
+ if err != nil {
+ t.Fatalf("Failure to get message from request: %s", err)
+ }
+
+ if x := m.Question[0].Name; x != "example.org." {
+ t.Errorf("Qname expected %s, got %s", "example.org.", x)
+ }
+ if x := m.Question[0].Qtype; x != dns.TypeDNSKEY {
+ t.Errorf("Qname expected %d, got %d", x, dns.TypeDNSKEY)
+ }
+}
+
+func TestGetRequest(t *testing.T) {
+ m := new(dns.Msg)
+ m.SetQuestion("example.org.", dns.TypeDNSKEY)
+
+ req, err := NewRequest(http.MethodGet, "https://example.org:443", m)
+ if err != nil {
+ t.Errorf("Failure to make request: %s", err)
+ }
+
+ m, err = RequestToMsg(req)
+ if err != nil {
+ t.Fatalf("Failure to get message from request: %s", err)
+ }
+
+ if x := m.Question[0].Name; x != "example.org." {
+ t.Errorf("Qname expected %s, got %s", "example.org.", x)
+ }
+ if x := m.Question[0].Qtype; x != dns.TypeDNSKEY {
+ t.Errorf("Qname expected %d, got %d", x, dns.TypeDNSKEY)
+ }
+}