// 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/structs" "git.froth.zone/sam/awl/query" "git.froth.zone/sam/awl/util" "github.com/miekg/dns" "github.com/stretchr/testify/assert" ) func TestResolveHTTPS(t *testing.T) { t.Parallel() var err error opts := cli.Options{ HTTPS: true, Logger: util.InitLogger(0), } testCase := structs.Request{Server: "dns9.quad9.net/dns-query", Type: dns.TypeA, Name: "git.froth.zone"} resolver, err := query.LoadResolver(testCase.Server, opts) assert.Nil(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.Nil(t, err) assert.NotNil(t, res) } func Test2ResolveHTTPS(t *testing.T) { t.Parallel() opts := cli.Options{ HTTPS: true, Logger: util.InitLogger(0), } var err error testCase := structs.Request{Server: "dns9.quad9.net/dns-query", Type: dns.TypeA, Name: "git.froth.zone"} resolver, err := query.LoadResolver(testCase.Server, opts) assert.Nil(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.Error(t, err) assert.Equal(t, res, structs.Response{}) } func Test3ResolveHTTPS(t *testing.T) { t.Parallel() opts := cli.Options{ HTTPS: true, Logger: util.InitLogger(0), } var err error testCase := structs.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.Nil(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.Error(t, err) assert.Equal(t, res, structs.Response{}) }