IP Whitelists for Frontend (with Docker- & Kubernetes-Provider Support)
This commit is contained in:
parent
55f610422a
commit
5f0b215e90
16 changed files with 731 additions and 14 deletions
|
@ -14,6 +14,8 @@ import (
|
|||
"github.com/containous/traefik/testhelpers"
|
||||
"github.com/containous/traefik/types"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/vulcand/oxy/roundrobin"
|
||||
)
|
||||
|
||||
|
@ -242,6 +244,57 @@ func TestServerParseHealthCheckOptions(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNewServerWithWhitelistSourceRange(t *testing.T) {
|
||||
cases := []struct {
|
||||
desc string
|
||||
whitelistStrings []string
|
||||
middlewareConfigured bool
|
||||
errMessage string
|
||||
}{
|
||||
{
|
||||
desc: "no whitelists configued",
|
||||
whitelistStrings: nil,
|
||||
middlewareConfigured: false,
|
||||
errMessage: "",
|
||||
}, {
|
||||
desc: "whitelists configued",
|
||||
whitelistStrings: []string{
|
||||
"1.2.3.4/24",
|
||||
"fe80::/16",
|
||||
},
|
||||
middlewareConfigured: true,
|
||||
errMessage: "",
|
||||
}, {
|
||||
desc: "invalid whitelists configued",
|
||||
whitelistStrings: []string{
|
||||
"foo",
|
||||
},
|
||||
middlewareConfigured: false,
|
||||
errMessage: "parsing CIDR whitelist <nil>: invalid CIDR address: foo",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
tc := tc
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
middleware, err := configureIPWhitelistMiddleware(tc.whitelistStrings)
|
||||
|
||||
if tc.errMessage != "" {
|
||||
require.EqualError(t, err, tc.errMessage)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
|
||||
if tc.middlewareConfigured {
|
||||
require.NotNil(t, middleware, "not expected middleware to be configured")
|
||||
} else {
|
||||
require.Nil(t, middleware, "expected middleware to be configured")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestServerLoadConfigEmptyBasicAuth(t *testing.T) {
|
||||
globalConfig := GlobalConfiguration{
|
||||
EntryPoints: EntryPoints{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue