fix(https): add default endpoint
Signed-off-by: Sam Therapy <sam@samtherapy.net>
This commit is contained in:
parent
2836633c62
commit
e343955ca4
4 changed files with 42 additions and 5 deletions
|
@ -26,10 +26,10 @@ func ParseCLI(args []string, version string) (*util.Options, error) {
|
|||
Usage: awl name [@server] [record]
|
||||
<name> domain, IP address, phone number
|
||||
<record> defaults to A
|
||||
|
||||
|
||||
Arguments may be in any order, including flags.
|
||||
Dig-like +[no]commands are also supported, see dig(1) or dig -h
|
||||
|
||||
|
||||
Options:`)
|
||||
flagSet.PrintDefaults()
|
||||
}
|
||||
|
@ -174,6 +174,10 @@ func ParseCLI(args []string, version string) (*util.Options, error) {
|
|||
ZFlag: uint16(mbz & 0x7FFF),
|
||||
Padding: *padding,
|
||||
},
|
||||
HTTPSOptions: util.HTTPSOptions{
|
||||
Endpoint: "/dns-query",
|
||||
Get: false,
|
||||
},
|
||||
}
|
||||
|
||||
// TODO: DRY
|
||||
|
|
|
@ -149,6 +149,28 @@ func TestRetries(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestSetHTTPS(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
args := [][]string{
|
||||
{"awl", "-H", "@dns.froth.zone/dns-query"},
|
||||
{"awl", "+https", "@dns.froth.zone"},
|
||||
}
|
||||
for _, test := range args {
|
||||
test := test
|
||||
|
||||
t.Run(test[1], func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
opt, err := cli.ParseCLI(test, "TEST")
|
||||
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, opt.Request.Server, "dns.froth.zone")
|
||||
assert.Equal(t, opt.HTTPSOptions.Endpoint, "/dns-query")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func FuzzFlags(f *testing.F) {
|
||||
testcases := []string{"git.froth.zone", "", "!12345", "google.com.edu.org.fr"}
|
||||
|
||||
|
|
15
cmd/misc.go
15
cmd/misc.go
|
@ -50,7 +50,18 @@ func ParseMiscArgs(args []string, opts *util.Options) error {
|
|||
case strings.HasPrefix(arg, "udp://"):
|
||||
opts.Request.Server = strings.TrimPrefix(arg, "udp://")
|
||||
default:
|
||||
opts.Request.Server = arg
|
||||
// Allow HTTPS queries to have a fallback default
|
||||
if opts.HTTPS {
|
||||
server, endpoint, isSplit := strings.Cut(arg, "/")
|
||||
if isSplit {
|
||||
opts.HTTPSOptions.Endpoint = "/" + endpoint
|
||||
opts.Request.Server = server
|
||||
} else {
|
||||
opts.Request.Server = server
|
||||
}
|
||||
} else {
|
||||
opts.Request.Server = arg
|
||||
}
|
||||
}
|
||||
|
||||
// Dig-style +queries
|
||||
|
@ -114,7 +125,7 @@ func ParseMiscArgs(args []string, opts *util.Options) error {
|
|||
case opts.TLS:
|
||||
opts.Request.Server = "dns.google"
|
||||
case opts.HTTPS:
|
||||
opts.Request.Server = "https://dns.cloudflare.com/dns-query"
|
||||
opts.Request.Server = "https://dns.cloudflare.com"
|
||||
case opts.QUIC:
|
||||
opts.Request.Server = "dns.adguard.com"
|
||||
default:
|
||||
|
|
|
@ -88,7 +88,7 @@ func TestDefaultServer(t *testing.T) {
|
|||
}{
|
||||
{"DNSCrypt", "sdns://AQMAAAAAAAAAETk0LjE0MC4xNC4xNDo1NDQzINErR_JS3PLCu_iZEIbq95zkSV2LFsigxDIuUso_OQhzIjIuZG5zY3J5cHQuZGVmYXVsdC5uczEuYWRndWFyZC5jb20"},
|
||||
{"TLS", "dns.google"},
|
||||
{"HTTPS", "https://dns.cloudflare.com/dns-query"},
|
||||
{"HTTPS", "https://dns.cloudflare.com"},
|
||||
{"QUIC", "dns.adguard.com"},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue