mirror of
https://github.com/coredns/coredns.git
synced 2026-06-01 23:00:23 -04:00
fix: reject invalid any and local config (#8133)
Signed-off-by: immanuwell <pchpr.00@list.ru>
This commit is contained in:
committed by
GitHub
parent
ce0e5a6f39
commit
4c07a287da
@@ -9,6 +9,14 @@ import (
|
||||
func init() { plugin.Register("any", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
c.Next() // 'any'
|
||||
if c.NextArg() {
|
||||
return plugin.Error("any", c.ArgErr())
|
||||
}
|
||||
if c.NextBlock() {
|
||||
return plugin.Error("any", c.Errf("unknown property '%s'", c.Val()))
|
||||
}
|
||||
|
||||
a := Any{}
|
||||
|
||||
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||
|
||||
@@ -19,3 +19,17 @@ func TestSetup(t *testing.T) {
|
||||
t.Error("Expected plugin to be added to config")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetupRejectsArgs(t *testing.T) {
|
||||
c := caddy.NewTestController("dns", `any example.org`)
|
||||
if err := setup(c); err == nil {
|
||||
t.Fatal("expected error for unexpected argument, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetupRejectsBlockOptions(t *testing.T) {
|
||||
c := caddy.NewTestController("dns", `any { foo }`)
|
||||
if err := setup(c); err == nil {
|
||||
t.Fatal("expected error for unexpected block option, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,14 @@ import (
|
||||
func init() { plugin.Register("local", setup) }
|
||||
|
||||
func setup(c *caddy.Controller) error {
|
||||
c.Next() // 'local'
|
||||
if c.NextArg() {
|
||||
return plugin.Error("local", c.ArgErr())
|
||||
}
|
||||
if c.NextBlock() {
|
||||
return plugin.Error("local", c.Errf("unknown property '%s'", c.Val()))
|
||||
}
|
||||
|
||||
l := Local{}
|
||||
|
||||
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||
|
||||
34
plugin/local/setup_test.go
Normal file
34
plugin/local/setup_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package local
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/coredns/caddy"
|
||||
"github.com/coredns/coredns/core/dnsserver"
|
||||
)
|
||||
|
||||
func TestSetup(t *testing.T) {
|
||||
c := caddy.NewTestController("dns", `local`)
|
||||
if err := setup(c); err != nil {
|
||||
t.Fatalf("expected no errors, but got: %v", err)
|
||||
}
|
||||
|
||||
cfg := dnsserver.GetConfig(c)
|
||||
if len(cfg.Plugin) == 0 {
|
||||
t.Fatal("expected plugin to be added to config")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetupRejectsArgs(t *testing.T) {
|
||||
c := caddy.NewTestController("dns", `local example.org`)
|
||||
if err := setup(c); err == nil {
|
||||
t.Fatal("expected error for unexpected argument, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetupRejectsBlockOptions(t *testing.T) {
|
||||
c := caddy.NewTestController("dns", `local { foo }`)
|
||||
if err := setup(c); err == nil {
|
||||
t.Fatal("expected error for unexpected block option, got nil")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user