Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
httpcaddyfile: Be stricter about `log` syntax (#3419)
Francis Lavoie committed
May 15, 2020 at 17:57 UTC
21de227fe94508d0e259dfd803b482055b214640
2 files changed
+67
caddyconfig/httpcaddyfile/builtins.go
+5
@@ -469,6 +469,11 @@ func parseHandleErrors(h Helper) ([]ConfigValue, error) {
469
func parseLog(h Helper) ([]ConfigValue, error) {
470
var configValues []ConfigValue
471
for h.Next() {
472
+ // log does not currently support any arguments
473
+ if h.NextArg() {
474
+ return nil, h.ArgErr()
475
+ }
476
+
477
cl := new(caddy.CustomLog)
478
479
for h.NextBlock(0) {
caddyconfig/httpcaddyfile/builtins_test.go
new
+62
@@ -0,0 +1,62 @@
1
+package httpcaddyfile
2
+
3
+import (
4
+ "testing"
5
+
6
+ "github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
7
+ _ "github.com/caddyserver/caddy/v2/modules/logging"
8
+)
9
+
10
+func TestLogDirectiveSyntax(t *testing.T) {
11
+ for i, tc := range []struct {
12
+ input string
13
+ expectWarn bool
14
+ expectError bool
15
+ }{
16
+ {
17
+ input: `:8080 {
18
+ log
19
+ }
20
+ `,
21
+ expectWarn: false,
22
+ expectError: false,
23
+ },
24
+ {
25
+ input: `:8080 {
26
+ log {
27
+ output file foo.log
28
+ }
29
+ }
30
+ `,
31
+ expectWarn: false,
32
+ expectError: false,
33
+ },
34
+ {
35
+ input: `:8080 {
36
+ log /foo {
37
+ output file foo.log
38
+ }
39
+ }
40
+ `,
41
+ expectWarn: false,
42
+ expectError: true,
43
+ },
44
+ } {
45
+
46
+ adapter := caddyfile.Adapter{
47
+ ServerType: ServerType{},
48
+ }
49
+
50
+ _, warnings, err := adapter.Adapt([]byte(tc.input), nil)
51
+
52
+ if len(warnings) > 0 != tc.expectWarn {
53
+ t.Errorf("Test %d warning expectation failed Expected: %v, got %v", i, tc.expectWarn, warnings)
54
+ continue
55
+ }
56
+
57
+ if err != nil != tc.expectError {
58
+ t.Errorf("Test %d error expectation failed Expected: %v, got %s", i, tc.expectError, err)
59
+ continue
60
+ }
61
+ }
62
+}