tls: add optional 'ca' tls directive, closes #1689 (#1699)

This commit is contained in:
Jason Hutchinson 2017-06-24 13:10:44 -05:00 committed by Matt Holt
parent 3e2b1d145a
commit f3721c103c
2 changed files with 46 additions and 0 deletions

View file

@ -66,6 +66,12 @@ func setupTLS(c *caddy.Controller) error {
for c.NextBlock() {
hadBlock = true
switch c.Val() {
case "ca":
arg := c.RemainingArgs()
if len(arg) != 1 {
return c.ArgErr()
}
config.CAUrl = arg[0]
case "key_type":
arg := c.RemainingArgs()
value, ok := supportedKeyTypes[strings.ToUpper(arg[0])]

View file

@ -277,6 +277,46 @@ func TestSetupParseWithClientAuth(t *testing.T) {
}
}
func TestSetupParseWithCAUrl(t *testing.T) {
testURL := "https://acme-staging.api.letsencrypt.org/directory"
for caseNumber, caseData := range []struct {
params string
expectedErr bool
expectedCAUrl string
}{
// Test working case
{`tls {
ca ` + testURL + `
}`, false, testURL},
// Test too few args
{`tls {
ca
}`, true, ""},
// Test too many args
{`tls {
ca 1 2
}`, true, ""},
} {
cfg := new(Config)
RegisterConfigGetter("", func(c *caddy.Controller) *Config { return cfg })
c := caddy.NewTestController("", caseData.params)
err := setupTLS(c)
if caseData.expectedErr {
if err == nil {
t.Errorf("In case %d: Expected an error, got: %v", caseNumber, err)
}
continue
}
if err != nil {
t.Errorf("In case %d: Expected no errors, got: %v", caseNumber, err)
}
if cfg.CAUrl != caseData.expectedCAUrl {
t.Errorf("Expected '%v' as CAUrl, got %#v", caseData.expectedCAUrl, cfg.CAUrl)
}
}
}
func TestSetupParseWithKeyType(t *testing.T) {
params := `tls {
key_type p384