mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-31 00:06:04 +08:00
caddyfile: Reject directives in the place of site addresses (#6104)
Co-authored-by: Francis Lavoie <lavofr@gmail.com>
This commit is contained in:
@ -496,6 +496,7 @@ func TestUriReplace(t *testing.T) {
|
||||
|
||||
tester.AssertGetResponse("http://localhost:9080/endpoint?test={%20content%20}", 200, "test=%7B%20content%20%7D")
|
||||
}
|
||||
|
||||
func TestHandleErrorSimpleCodes(t *testing.T) {
|
||||
tester := caddytest.NewTester(t)
|
||||
tester.InitServer(`{
|
||||
@ -584,3 +585,30 @@ func TestHandleErrorRangeAndCodes(t *testing.T) {
|
||||
tester.AssertGetResponse("http://localhost:9080/threehundred", 301, "Error code is equal to 500 or in the [300..399] range")
|
||||
tester.AssertGetResponse("http://localhost:9080/private", 410, "Error in the [400 .. 499] range")
|
||||
}
|
||||
|
||||
func TestInvalidSiteAddressesAsDirectives(t *testing.T) {
|
||||
type testCase struct {
|
||||
config, expectedError string
|
||||
}
|
||||
|
||||
failureCases := []testCase{
|
||||
{
|
||||
config: `
|
||||
handle {
|
||||
file_server
|
||||
}`,
|
||||
expectedError: `Caddyfile:2: parsed 'handle' as a site address, but it is a known directive; directives must appear in a site block`,
|
||||
},
|
||||
{
|
||||
config: `
|
||||
reverse_proxy localhost:9000 localhost:9001 {
|
||||
file_server
|
||||
}`,
|
||||
expectedError: `Caddyfile:2: parsed 'reverse_proxy' as a site address, but it is a known directive; directives must appear in a site block`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, failureCase := range failureCases {
|
||||
caddytest.AssertLoadError(t, failureCase.config, "caddyfile", failureCase.expectedError)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user