awl/query/HTTPS_test.go
Sam Therapy 92812c337f
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Another day's work
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2022-07-21 19:06:46 -05:00

88 lines
2.5 KiB
Go

// SPDX-License-Identifier: BSD-3-Clause
package query_test
import (
"fmt"
"strings"
"testing"
"git.froth.zone/sam/awl/cli"
"git.froth.zone/sam/awl/internal/helpers"
"git.froth.zone/sam/awl/query"
"git.froth.zone/sam/awl/util"
"github.com/miekg/dns"
"gotest.tools/v3/assert"
)
func TestResolveHTTPS(t *testing.T) {
t.Parallel()
var err error
opts := cli.Options{
HTTPS: true,
Logger: util.InitLogger(0),
}
testCase := helpers.Request{Server: "dns9.quad9.net/dns-query", Type: dns.TypeA, Name: "git.froth.zone"}
resolver, err := query.LoadResolver(testCase.Server, opts)
assert.NilError(t, err)
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.Type)
// msg = msg.SetQuestion(testCase.Name, testCase.Type)
res, err := resolver.LookUp(msg)
assert.NilError(t, err)
assert.Assert(t, res != helpers.Response{})
}
func Test2ResolveHTTPS(t *testing.T) {
t.Parallel()
opts := cli.Options{
HTTPS: true,
Logger: util.InitLogger(0),
}
var err error
testCase := helpers.Request{Server: "dns9.quad9.net/dns-query", Type: dns.TypeA, Name: "git.froth.zone"}
resolver, err := query.LoadResolver(testCase.Server, opts)
assert.NilError(t, err)
msg := new(dns.Msg)
msg.SetQuestion(testCase.Name, testCase.Type)
// msg = msg.SetQuestion(testCase.Name, testCase.Type)
res, err := resolver.LookUp(msg)
assert.ErrorContains(t, err, "fully qualified")
assert.Equal(t, res, helpers.Response{})
}
func Test3ResolveHTTPS(t *testing.T) {
t.Parallel()
opts := cli.Options{
HTTPS: true,
Logger: util.InitLogger(0),
}
var err error
testCase := helpers.Request{Server: "dns9..quad9.net/dns-query", Type: 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)
}
resolver, err := query.LoadResolver(testCase.Server, opts)
assert.NilError(t, err)
msg := new(dns.Msg)
msg.SetQuestion(testCase.Name, testCase.Type)
// msg = msg.SetQuestion(testCase.Name, testCase.Type)
res, err := resolver.LookUp(msg)
assert.ErrorContains(t, err, "request error")
assert.Equal(t, res, helpers.Response{})
}