@marcel91200 / caddy Mirror · read-only / commits / 90f1f7bc
Fork 0

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: error for wrong arg count of admin opt (#3126) (#3131)

Francis Lavoie committed Mar 10, 2020 at 10:25 UTC 90f1f7bce75686d3a9864e1f36abf15930b3fc5f
2 files changed +71 -1
caddyconfig/httpcaddyfile/httptype_test.go
+68
@@ -79,3 +79,71 @@ func TestSpecificity(t *testing.T) {
79 }
80 }
81 }
82 +
83 +func TestGlobalOptions(t *testing.T) {
84 + for i, tc := range []struct {
85 + input string
86 + expectWarn bool
87 + expectError bool
88 + }{
89 + {
90 + input: `
91 + {
92 + email test@example.com
93 + }
94 + :80
95 + `,
96 + expectWarn: false,
97 + expectError: false,
98 + },
99 + {
100 + input: `
101 + {
102 + admin off
103 + }
104 + :80
105 + `,
106 + expectWarn: false,
107 + expectError: false,
108 + },
109 + {
110 + input: `
111 + {
112 + admin 127.0.0.1:2020
113 + }
114 + :80
115 + `,
116 + expectWarn: false,
117 + expectError: false,
118 + },
119 + {
120 + input: `
121 + {
122 + admin {
123 + disabled false
124 + }
125 + }
126 + :80
127 + `,
128 + expectWarn: false,
129 + expectError: true,
130 + },
131 + } {
132 +
133 + adapter := caddyfile.Adapter{
134 + ServerType: ServerType{},
135 + }
136 +
137 + _, warnings, err := adapter.Adapt([]byte(tc.input), nil)
138 +
139 + if len(warnings) > 0 != tc.expectWarn {
140 + t.Errorf("Test %d warning expectation failed Expected: %v, got %v", i, tc.expectWarn, warnings)
141 + continue
142 + }
143 +
144 + if err != nil != tc.expectError {
145 + t.Errorf("Test %d error expectation failed Expected: %v, got %s", i, tc.expectError, err)
146 + continue
147 + }
148 + }
149 +}
caddyconfig/httpcaddyfile/options.go
+3 -1
@@ -177,7 +177,9 @@ func parseOptSingleString(d *caddyfile.Dispenser) (string, error) {
177 func parseOptAdmin(d *caddyfile.Dispenser) (string, error) {
178 if d.Next() {
179 var listenAddress string
180 - d.AllArgs(&listenAddress)
180 + if !d.AllArgs(&listenAddress) {
181 + return "", d.ArgErr()
182 + }
183 if listenAddress == "" {
184 listenAddress = caddy.DefaultAdminListen
185 }