mirror of
https://github.com/caddyserver/caddy.git
synced 2025-05-24 02:02:26 -04:00
parent
3e2b1d145a
commit
f3721c103c
@ -66,6 +66,12 @@ func setupTLS(c *caddy.Controller) error {
|
|||||||
for c.NextBlock() {
|
for c.NextBlock() {
|
||||||
hadBlock = true
|
hadBlock = true
|
||||||
switch c.Val() {
|
switch c.Val() {
|
||||||
|
case "ca":
|
||||||
|
arg := c.RemainingArgs()
|
||||||
|
if len(arg) != 1 {
|
||||||
|
return c.ArgErr()
|
||||||
|
}
|
||||||
|
config.CAUrl = arg[0]
|
||||||
case "key_type":
|
case "key_type":
|
||||||
arg := c.RemainingArgs()
|
arg := c.RemainingArgs()
|
||||||
value, ok := supportedKeyTypes[strings.ToUpper(arg[0])]
|
value, ok := supportedKeyTypes[strings.ToUpper(arg[0])]
|
||||||
|
@ -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) {
|
func TestSetupParseWithKeyType(t *testing.T) {
|
||||||
params := `tls {
|
params := `tls {
|
||||||
key_type p384
|
key_type p384
|
||||||
|
Loading…
x
Reference in New Issue
Block a user