aboutsummaryrefslogtreecommitdiff
path: root/plugin/pkg/doh/doh_test.go
blob: 4491661514b541298c9fd3229db9c54f3b4fd6dc (plain) (blame)
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
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)
	}
}