summaryrefslogtreecommitdiff
path: root/caddyconfig
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2020-03-10 10:25:26 -0400
committerGitHub <noreply@github.com>2020-03-10 08:25:26 -0600
commit90f1f7bce75686d3a9864e1f36abf15930b3fc5f (patch)
tree877f28d3044ac8afccbe9cdd97a68d9ea302db81 /caddyconfig
parent2762f8f058803e3bb1c55636df78b815b1d70439 (diff)
httpcaddyfile: error for wrong arg count of admin opt (#3126) (#3131)
Diffstat (limited to 'caddyconfig')
-rw-r--r--caddyconfig/httpcaddyfile/httptype_test.go68
-rw-r--r--caddyconfig/httpcaddyfile/options.go4
2 files changed, 71 insertions, 1 deletions
diff --git a/caddyconfig/httpcaddyfile/httptype_test.go b/caddyconfig/httpcaddyfile/httptype_test.go
index 3b69677..d612cd4 100644
--- a/caddyconfig/httpcaddyfile/httptype_test.go
+++ b/caddyconfig/httpcaddyfile/httptype_test.go
@@ -79,3 +79,71 @@ func TestSpecificity(t *testing.T) {
}
}
}
+
+func TestGlobalOptions(t *testing.T) {
+ for i, tc := range []struct {
+ input string
+ expectWarn bool
+ expectError bool
+ }{
+ {
+ input: `
+ {
+ email test@example.com
+ }
+ :80
+ `,
+ expectWarn: false,
+ expectError: false,
+ },
+ {
+ input: `
+ {
+ admin off
+ }
+ :80
+ `,
+ expectWarn: false,
+ expectError: false,
+ },
+ {
+ input: `
+ {
+ admin 127.0.0.1:2020
+ }
+ :80
+ `,
+ expectWarn: false,
+ expectError: false,
+ },
+ {
+ input: `
+ {
+ admin {
+ disabled false
+ }
+ }
+ :80
+ `,
+ 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
+ }
+ }
+}
diff --git a/caddyconfig/httpcaddyfile/options.go b/caddyconfig/httpcaddyfile/options.go
index f8c221c..7dc7bdb 100644
--- a/caddyconfig/httpcaddyfile/options.go
+++ b/caddyconfig/httpcaddyfile/options.go
@@ -177,7 +177,9 @@ func parseOptSingleString(d *caddyfile.Dispenser) (string, error) {
func parseOptAdmin(d *caddyfile.Dispenser) (string, error) {
if d.Next() {
var listenAddress string
- d.AllArgs(&listenAddress)
+ if !d.AllArgs(&listenAddress) {
+ return "", d.ArgErr()
+ }
if listenAddress == "" {
listenAddress = caddy.DefaultAdminListen
}