mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-28 04:45:56 +03:00
caddytls: set certmagic.Config.Email when parsing config file (#2432)
This commit is contained in:
parent
01f2b85826
commit
78455c7cb9
2 changed files with 25 additions and 4 deletions
|
@ -123,15 +123,16 @@ func setupTLS(c *caddy.Controller) error {
|
||||||
// that value in the ACMEEmail field.
|
// that value in the ACMEEmail field.
|
||||||
config.ACMEEmail = args[0]
|
config.ACMEEmail = args[0]
|
||||||
|
|
||||||
|
switch args[0] {
|
||||||
// user can force-disable managed TLS this way
|
// user can force-disable managed TLS this way
|
||||||
if args[0] == "off" {
|
case "off":
|
||||||
config.Enabled = false
|
config.Enabled = false
|
||||||
return nil
|
return nil
|
||||||
}
|
|
||||||
|
|
||||||
// user might want a temporary, in-memory, self-signed cert
|
// user might want a temporary, in-memory, self-signed cert
|
||||||
if args[0] == "self_signed" {
|
case "self_signed":
|
||||||
config.SelfSigned = true
|
config.SelfSigned = true
|
||||||
|
default:
|
||||||
|
config.Manager.Email = args[0]
|
||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
certificateFile = args[0]
|
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 (
|
const (
|
||||||
certFile = "test_cert.pem"
|
certFile = "test_cert.pem"
|
||||||
keyFile = "test_key.pem"
|
keyFile = "test_key.pem"
|
||||||
|
|
Loading…
Reference in a new issue