plugin/proxy: max the number of upstreams (#1359)
* plugin/proxy: max the number of upstreams Put a max of 15 on the number of upstreams.
This commit is contained in:
parent
dd37627e8e
commit
a7590897fb
2 changed files with 17 additions and 1 deletions
|
@ -53,6 +53,10 @@ func NewStaticUpstreams(c *caddyfile.Dispenser) ([]Upstream, error) {
|
||||||
return upstreams, err
|
return upstreams, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(toHosts) > max {
|
||||||
|
return upstreams, fmt.Errorf("more than %d TOs configured: %d", max, len(toHosts))
|
||||||
|
}
|
||||||
|
|
||||||
for c.NextBlock() {
|
for c.NextBlock() {
|
||||||
if err := parseBlock(c, upstream); err != nil {
|
if err := parseBlock(c, upstream); err != nil {
|
||||||
return upstreams, err
|
return upstreams, err
|
||||||
|
@ -192,3 +196,5 @@ func (u *staticUpstream) IsAllowedDomain(name string) bool {
|
||||||
|
|
||||||
func (u *staticUpstream) Exchanger() Exchanger { return u.ex }
|
func (u *staticUpstream) Exchanger() Exchanger { return u.ex }
|
||||||
func (u *staticUpstream) From() string { return u.from }
|
func (u *staticUpstream) From() string { return u.from }
|
||||||
|
|
||||||
|
const max = 15
|
||||||
|
|
|
@ -259,7 +259,7 @@ proxy . FILE
|
||||||
proxy example.org 2.2.2.2:1234
|
proxy example.org 2.2.2.2:1234
|
||||||
`,
|
`,
|
||||||
`
|
`
|
||||||
junky resolve.conf
|
junky resolv.conf
|
||||||
`,
|
`,
|
||||||
false,
|
false,
|
||||||
[]string{"1.1.1.1:5000", "2.2.2.2:1234"},
|
[]string{"1.1.1.1:5000", "2.2.2.2:1234"},
|
||||||
|
@ -303,6 +303,16 @@ junky resolve.conf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMaxTo(t *testing.T) {
|
||||||
|
// Has 16 IP addresses.
|
||||||
|
config := `proxy . 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1 1.1.1.1`
|
||||||
|
c := caddy.NewTestController("dns", config)
|
||||||
|
_, err := NewStaticUpstreams(&c.Dispenser)
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Expected to many TOs configured, but nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getPEMFiles(t *testing.T) (rmFunc func(), cert, key, ca string) {
|
func getPEMFiles(t *testing.T) (rmFunc func(), cert, key, ca string) {
|
||||||
tempDir, rmFunc, err := test.WritePEMFiles("")
|
tempDir, rmFunc, err := test.WritePEMFiles("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue