fix(https): add default endpoint (#152)
continuous-integration/drone/push Build is passing Details

say you do -H @dns.froth.zone/sodd
It should send a request to dns.froth.zone/sodd
but if you do -H @dns.froth.zone
it should send a request to dns.froth.zone/dns-query

This does that

Reviewed-on: #152
Reviewed-by: grumbulon <grumbulon@grumbulon.xyz>
This commit is contained in:
Sam Therapy 2022-11-07 15:07:44 +00:00
parent 2836633c62
commit feef2cddaf
Signed by: Froth Git
GPG Key ID: 5D8CD75CC6B79913
4 changed files with 42 additions and 5 deletions

View File

@ -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

View File

@ -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"}

View File

@ -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:

View File

@ -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"},
}