Commit 78455c7c authored by Wèi Cōngruì's avatar Wèi Cōngruì Committed by Matt Holt

caddytls: set certmagic.Config.Email when parsing config file (#2432)

parent 01f2b858
......@@ -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]
......
......@@ -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"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment