Add validation for wildcard server names
This commit is contained in:
parent
cdd6437380
commit
d74ea25df8
3 changed files with 35 additions and 1 deletions
|
|
@ -1448,3 +1448,24 @@ func TestModSecurityForLocation(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildServerName(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
title string
|
||||
hostname string
|
||||
expected string
|
||||
}{
|
||||
{"simple domain", "foo.bar", "foo.bar"},
|
||||
{"simple www domain", "www.foo.bar", "www.foo.bar"},
|
||||
{"wildcard domain", "*.foo.bar", "~^(?<subdomain>[\\w-]+)\\.foo\\.bar$"},
|
||||
{"wildcard two levels domain", "*.sub.foo.bar", "~^(?<subdomain>[\\w-]+)\\.sub\\.foo\\.bar$"},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
result := buildServerName(testCase.hostname)
|
||||
if result != testCase.expected {
|
||||
t.Errorf("%v: expected '%v' but returned '%v'", testCase.title, testCase.expected, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue