1
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-16 21:56:40 -05:00

httpcaddyfile: Be stricter about log syntax (#3419)

This commit is contained in:
Francis Lavoie 2020-05-15 17:57:16 -04:00 committed by GitHub
parent 62c9f2cf3e
commit 21de227fe9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 0 deletions

View file

@ -469,6 +469,11 @@ func parseHandleErrors(h Helper) ([]ConfigValue, error) {
func parseLog(h Helper) ([]ConfigValue, error) { func parseLog(h Helper) ([]ConfigValue, error) {
var configValues []ConfigValue var configValues []ConfigValue
for h.Next() { for h.Next() {
// log does not currently support any arguments
if h.NextArg() {
return nil, h.ArgErr()
}
cl := new(caddy.CustomLog) cl := new(caddy.CustomLog)
for h.NextBlock(0) { for h.NextBlock(0) {

View file

@ -0,0 +1,62 @@
package httpcaddyfile
import (
"testing"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
_ "github.com/caddyserver/caddy/v2/modules/logging"
)
func TestLogDirectiveSyntax(t *testing.T) {
for i, tc := range []struct {
input string
expectWarn bool
expectError bool
}{
{
input: `:8080 {
log
}
`,
expectWarn: false,
expectError: false,
},
{
input: `:8080 {
log {
output file foo.log
}
}
`,
expectWarn: false,
expectError: false,
},
{
input: `:8080 {
log /foo {
output file foo.log
}
}
`,
expectWarn: false,
expectError: true,
},
} {
adapter := caddyfile.Adapter{
ServerType: ServerType{},
}
_, warnings, err := adapter.Adapt([]byte(tc.input), nil)
if len(warnings) > 0 != tc.expectWarn {
t.Errorf("Test %d warning expectation failed Expected: %v, got %v", i, tc.expectWarn, warnings)
continue
}
if err != nil != tc.expectError {
t.Errorf("Test %d error expectation failed Expected: %v, got %s", i, tc.expectError, err)
continue
}
}
}