Sam
8df0347891
All checks were successful
continuous-integration/drone/push Build is passing
also slight refactors :) closes #96 Co-authored-by: Sam Therapy <sam@samtherapy.net> Reviewed-on: #98 Reviewed-by: grumbulon <grumbulon@grumbulon.xyz>
117 lines
2.1 KiB
Go
117 lines
2.1 KiB
Go
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package query_test
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"git.froth.zone/sam/awl/query"
|
|
"git.froth.zone/sam/awl/util"
|
|
"github.com/miekg/dns"
|
|
"gotest.tools/v3/assert"
|
|
)
|
|
|
|
func TestResolve(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
opts := util.Options{
|
|
Logger: util.InitLogger(0),
|
|
Request: util.Request{
|
|
Server: "8.8.4.1",
|
|
Port: 1,
|
|
Type: dns.TypeA,
|
|
Name: "example.com.",
|
|
Timeout: time.Second / 2,
|
|
Retries: 0,
|
|
},
|
|
}
|
|
resolver, err := query.LoadResolver(opts)
|
|
assert.NilError(t, err)
|
|
|
|
msg := new(dns.Msg)
|
|
msg.SetQuestion(opts.Request.Name, opts.Request.Type)
|
|
|
|
_, err = resolver.LookUp(msg)
|
|
assert.ErrorContains(t, err, "timeout")
|
|
}
|
|
|
|
func TestTruncate(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
opts := util.Options{
|
|
Logger: util.InitLogger(0),
|
|
IPv4: true,
|
|
Request: util.Request{
|
|
Server: "madns.binarystar.systems",
|
|
Port: 5301,
|
|
Type: dns.TypeTXT,
|
|
Name: "limit.txt.example.",
|
|
},
|
|
}
|
|
resolver, err := query.LoadResolver(opts)
|
|
assert.NilError(t, err)
|
|
|
|
msg := new(dns.Msg)
|
|
msg.SetQuestion(opts.Request.Name, opts.Request.Type)
|
|
res, err := resolver.LookUp(msg)
|
|
|
|
assert.NilError(t, err)
|
|
assert.Assert(t, res != util.Response{})
|
|
}
|
|
|
|
func TestResolveAgain(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
opt util.Options
|
|
}{
|
|
{
|
|
util.Options{
|
|
Logger: util.InitLogger(0),
|
|
TCP: true,
|
|
|
|
Request: util.Request{
|
|
Server: "8.8.4.4",
|
|
Port: 53,
|
|
Type: dns.TypeA,
|
|
Name: "example.com.",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
util.Options{
|
|
Logger: util.InitLogger(0),
|
|
Request: util.Request{
|
|
Server: "8.8.4.4",
|
|
Port: 53,
|
|
Type: dns.TypeAAAA,
|
|
Name: "example.com.",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
util.Options{
|
|
Logger: util.InitLogger(0),
|
|
TLS: true,
|
|
Request: util.Request{
|
|
Server: "dns.google",
|
|
Port: 853,
|
|
Type: dns.TypeAAAA,
|
|
Name: "example.com.",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
test := test
|
|
|
|
t.Run("", func(t *testing.T) {
|
|
t.Parallel()
|
|
res, err := query.CreateQuery(test.opt)
|
|
assert.NilError(t, err)
|
|
assert.Assert(t, res != util.Response{})
|
|
})
|
|
}
|
|
}
|