summaryrefslogtreecommitdiff
path: root/caddyconfig
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2020-05-15 17:57:16 -0400
committerGitHub <noreply@github.com>2020-05-15 15:57:16 -0600
commit21de227fe94508d0e259dfd803b482055b214640 (patch)
tree0313ac1501ce94f079ff7b4d6387dfbe17206a18 /caddyconfig
parent62c9f2cf3e86f8aaea7a1583f09adb6b8007cfe6 (diff)
httpcaddyfile: Be stricter about `log` syntax (#3419)
Diffstat (limited to 'caddyconfig')
-rw-r--r--caddyconfig/httpcaddyfile/builtins.go5
-rw-r--r--caddyconfig/httpcaddyfile/builtins_test.go62
2 files changed, 67 insertions, 0 deletions
diff --git a/caddyconfig/httpcaddyfile/builtins.go b/caddyconfig/httpcaddyfile/builtins.go
index 4cc453e..2bb9b90 100644
--- a/caddyconfig/httpcaddyfile/builtins.go
+++ b/caddyconfig/httpcaddyfile/builtins.go
@@ -469,6 +469,11 @@ func parseHandleErrors(h Helper) ([]ConfigValue, error) {
func parseLog(h Helper) ([]ConfigValue, error) {
var configValues []ConfigValue
for h.Next() {
+ // log does not currently support any arguments
+ if h.NextArg() {
+ return nil, h.ArgErr()
+ }
+
cl := new(caddy.CustomLog)
for h.NextBlock(0) {
diff --git a/caddyconfig/httpcaddyfile/builtins_test.go b/caddyconfig/httpcaddyfile/builtins_test.go
new file mode 100644
index 0000000..a255538
--- /dev/null
+++ b/caddyconfig/httpcaddyfile/builtins_test.go
@@ -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
+ }
+ }
+}