diff --git a/caddytls/setup.go b/caddytls/setup.go index ef65acb55..52c924f76 100644 --- a/caddytls/setup.go +++ b/caddytls/setup.go @@ -123,15 +123,16 @@ func setupTLS(c *caddy.Controller) error { // that value in the ACMEEmail field. config.ACMEEmail = args[0] + switch args[0] { // user can force-disable managed TLS this way - if args[0] == "off" { + case "off": config.Enabled = false return nil - } - // user might want a temporary, in-memory, self-signed cert - if args[0] == "self_signed" { + case "self_signed": config.SelfSigned = true + default: + config.Manager.Email = args[0] } case 2: certificateFile = args[0] diff --git a/caddytls/setup_test.go b/caddytls/setup_test.go index 067259656..cb97587fb 100644 --- a/caddytls/setup_test.go +++ b/caddytls/setup_test.go @@ -404,6 +404,26 @@ func TestSetupParseWithOneTLSProtocol(t *testing.T) { } } +func TestSetupParseWithEmail(t *testing.T) { + email := "user@example.com" + params := "tls " + email + cfg := &Config{Manager: &certmagic.Config{}} + RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg }) + c := caddy.NewTestController("", params) + + err := setupTLS(c) + if err != nil { + t.Errorf("Expected no errors, got: %v", err) + } + + if cfg.ACMEEmail != email { + t.Errorf("Expected cfg.ACMEEmail to be %#v, got %#v", email, cfg.ACMEEmail) + } + if cfg.Manager.Email != email { + t.Errorf("Expected cfg.Manager.Email to be %#v, got %#v", email, cfg.Manager.Email) + } +} + const ( certFile = "test_cert.pem" keyFile = "test_key.pem"