From 78455c7cb9c381058c844aa16db827d5154d82cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?W=C3=A8i=20C=C5=8Dngru=C3=AC?= Date: Fri, 18 Jan 2019 14:25:41 +0000 Subject: [PATCH] caddytls: set certmagic.Config.Email when parsing config file (#2432) --- caddytls/setup.go | 9 +++++---- caddytls/setup_test.go | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) 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"