Allow Træfik to know if a Host rule is malformed
This commit is contained in:
parent
b98f5ed8b1
commit
913d8737cc
4 changed files with 55 additions and 16 deletions
|
@ -54,24 +54,38 @@ func TestParseDomains(t *testing.T) {
|
|||
rules := &Rules{}
|
||||
|
||||
tests := []struct {
|
||||
expression string
|
||||
domain []string
|
||||
description string
|
||||
expression string
|
||||
domain []string
|
||||
errorExpected bool
|
||||
}{
|
||||
{
|
||||
expression: "Host:foo.bar,test.bar",
|
||||
domain: []string{"foo.bar", "test.bar"},
|
||||
description: "Many host rules",
|
||||
expression: "Host:foo.bar,test.bar",
|
||||
domain: []string{"foo.bar", "test.bar"},
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
expression: "Path:/test",
|
||||
domain: []string{},
|
||||
description: "No host rule",
|
||||
expression: "Path:/test",
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
expression: "Host:foo.bar;Path:/test",
|
||||
domain: []string{"foo.bar"},
|
||||
description: "Host rule and another rule",
|
||||
expression: "Host:foo.bar;Path:/test",
|
||||
domain: []string{"foo.bar"},
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
expression: "Host: Foo.Bar ;Path:/test",
|
||||
domain: []string{"foo.bar"},
|
||||
description: "Host rule to trim and another rule",
|
||||
expression: "Host: Foo.Bar ;Path:/test",
|
||||
domain: []string{"foo.bar"},
|
||||
errorExpected: false,
|
||||
},
|
||||
{
|
||||
description: "Host rule with no domain",
|
||||
expression: "Host: ;Path:/test",
|
||||
errorExpected: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -81,7 +95,12 @@ func TestParseDomains(t *testing.T) {
|
|||
t.Parallel()
|
||||
|
||||
domains, err := rules.ParseDomains(test.expression)
|
||||
require.NoError(t, err, "%s: Error while parsing domain.", test.expression)
|
||||
|
||||
if test.errorExpected {
|
||||
require.Errorf(t, err, "unable to parse correctly the domains in the Host rule from %q", test.expression)
|
||||
} else {
|
||||
require.NoError(t, err, "%s: Error while parsing domain.", test.expression)
|
||||
}
|
||||
|
||||
assert.EqualValues(t, test.domain, domains, "%s: Error parsing domains from expression.", test.expression)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue