66 lines
1.9 KiB
Go
66 lines
1.9 KiB
Go
package query
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.froth.zone/sam/awl/util"
|
|
"github.com/miekg/dns"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestResolveHTTPS(t *testing.T) {
|
|
var err error
|
|
testCase := util.Answers{Server: "dns9.quad9.net/dns-query", Request: dns.TypeA, Name: "git.froth.zone"}
|
|
if !strings.HasPrefix(testCase.Server, "https://") {
|
|
testCase.Server = "https://" + testCase.Server
|
|
}
|
|
// if the domain is not canonical, make it canonical
|
|
if !strings.HasSuffix(testCase.Name, ".") {
|
|
testCase.Name = fmt.Sprintf("%s.", testCase.Name)
|
|
}
|
|
|
|
msg := new(dns.Msg)
|
|
msg.SetQuestion(testCase.Name, testCase.Request)
|
|
msg = msg.SetQuestion(testCase.Name, testCase.Request)
|
|
var in *dns.Msg
|
|
in, testCase.RTT, err = ResolveHTTPS(msg, testCase.Server)
|
|
assert.Nil(t, err)
|
|
assert.NotNil(t, in)
|
|
|
|
}
|
|
|
|
func Test2ResolveHTTPS(t *testing.T) {
|
|
var err error
|
|
testCase := util.Answers{Server: "dns9.quad9.net/dns-query", Request: dns.TypeA, Name: "git.froth.zone"}
|
|
|
|
msg := new(dns.Msg)
|
|
msg.SetQuestion(testCase.Name, testCase.Request)
|
|
msg = msg.SetQuestion(testCase.Name, testCase.Request)
|
|
var in *dns.Msg
|
|
in, testCase.RTT, err = ResolveHTTPS(msg, testCase.Server)
|
|
assert.NotNil(t, err)
|
|
assert.Nil(t, in)
|
|
|
|
}
|
|
func Test3ResolveHTTPS(t *testing.T) {
|
|
var err error
|
|
testCase := util.Answers{Server: "dns9..quad9.net/dns-query", Request: dns.TypeA, Name: "git.froth.zone."}
|
|
if !strings.HasPrefix(testCase.Server, "https://") {
|
|
testCase.Server = "https://" + testCase.Server
|
|
}
|
|
// if the domain is not canonical, make it canonical
|
|
if !strings.HasSuffix(testCase.Name, ".") {
|
|
testCase.Name = fmt.Sprintf("%s.", testCase.Name)
|
|
}
|
|
msg := new(dns.Msg)
|
|
msg.SetQuestion(testCase.Name, testCase.Request)
|
|
msg = msg.SetQuestion(testCase.Name, testCase.Request)
|
|
var in *dns.Msg
|
|
in, testCase.RTT, err = ResolveHTTPS(msg, testCase.Server)
|
|
assert.NotNil(t, err)
|
|
assert.Nil(t, in)
|
|
|
|
}
|