middleware/proxy: fix except keyword (#505)

Fix the except keyword usage - the config would allow it, but it was
not enforced in the code.
Turns out that **FROM** was also not enforced, fix both, by (basically)
copying the code from Caddy.

Update the README and tests.

Locally test as well, shows that this works:

~~~
.:1053 {
    proxy miek.nl 8.8.8.8:53 {
        except a.miek.nl
    }
    proxy a.miek.nl 8.8.4.4:53

    errors stdout
    log stdout
}
~~~

And gives the desired results, not having a proxy line for `a.miek.nl`
results in a SERVFAIL (as expected).

Fixes #502
This commit is contained in:
Miek Gieben
2017-02-07 18:01:16 +00:00
committed by GitHub
parent e8ebcd3cfd
commit dbe1b2510d
5 changed files with 43 additions and 16 deletions

View File

@@ -13,7 +13,7 @@ import (
func TestHealthCheck(t *testing.T) {
upstream := &staticUpstream{
from: "",
from: ".",
Hosts: testPool(),
Policy: &Random{},
Spray: nil,
@@ -31,7 +31,7 @@ func TestHealthCheck(t *testing.T) {
func TestSelect(t *testing.T) {
upstream := &staticUpstream{
from: "",
from: ".",
Hosts: testPool()[:3],
Policy: &Random{},
FailTimeout: 10 * time.Second,
@@ -59,10 +59,10 @@ func TestRegisterPolicy(t *testing.T) {
}
func TestAllowedPaths(t *testing.T) {
func TestAllowedDomain(t *testing.T) {
upstream := &staticUpstream{
from: "miek.nl.",
IgnoredSubDomains: []string{"download.", "static."}, // closing dot mandatory
IgnoredSubDomains: []string{"download.miek.nl.", "static.miek.nl."}, // closing dot mandatory
}
tests := []struct {
name string
@@ -75,7 +75,7 @@ func TestAllowedPaths(t *testing.T) {
}
for i, test := range tests {
isAllowed := upstream.IsAllowedPath(test.name)
isAllowed := upstream.IsAllowedDomain(test.name)
if test.expected != isAllowed {
t.Errorf("Test %d: expected %v found %v for %s", i+1, test.expected, isAllowed, test.name)
}