mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-31 03:53:13 +08:00
Domains flag should accept simple wildcards (#1983)
This commit is contained in:
parent
cb88bdd068
commit
4c3583cd5a
3 changed files with 73 additions and 3 deletions
|
@ -294,8 +294,15 @@ func (args *FilterArgs) shouldRunDomain(d string) bool {
|
|||
if args.Domains == "" {
|
||||
return true
|
||||
}
|
||||
for _, dom := range strings.Split(args.Domains, ",") {
|
||||
if dom == d {
|
||||
return domainInList(d, strings.Split(args.Domains, ","))
|
||||
}
|
||||
|
||||
func domainInList(domain string, list []string) bool {
|
||||
for _, item := range list {
|
||||
if strings.HasPrefix(item, "*") && strings.HasSuffix(domain, item[1:]) {
|
||||
return true
|
||||
}
|
||||
if item == domain {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
63
commands/commands_test.go
Normal file
63
commands/commands_test.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package commands
|
||||
|
||||
import "testing"
|
||||
|
||||
func Test_domainInList(t *testing.T) {
|
||||
type args struct {
|
||||
domain string
|
||||
list []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "small",
|
||||
args: args{
|
||||
domain: "foo.com",
|
||||
list: []string{"foo.com"},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "big",
|
||||
args: args{
|
||||
domain: "foo.com",
|
||||
list: []string{"example.com", "foo.com", "baz.com"},
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "missing",
|
||||
args: args{
|
||||
domain: "foo.com",
|
||||
list: []string{"bar.com"},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "wildcard",
|
||||
args: args{
|
||||
domain: "*.10.in-addr.arpa",
|
||||
list: []string{"bar.com", "10.in-addr.arpa", "example.com"},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "wildcardmissing",
|
||||
args: args{
|
||||
domain: "*.10.in-addr.arpa",
|
||||
list: []string{"bar.com", "6.in-addr.arpa", "example.com"},
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := domainInList(tt.args.domain, tt.args.list); got != tt.want {
|
||||
t.Errorf("domainInList() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -85,7 +85,7 @@ and `domain.tld!external` you now require humans to remember that
|
|||
may have noticed this mistake, but will your coworkers? Will you in
|
||||
six months? You get the idea.
|
||||
|
||||
DNSControl command line flag `--domains` is an exact match. If you
|
||||
DNSControl command line flag `--domains` matches the full name (with the "!"). If you
|
||||
define domains `example.com!george` and `example.com!john` then:
|
||||
|
||||
* `--domains=example.com` will not match either domain.
|
||||
|
|
Loading…
Reference in a new issue