plugin/forward: test TLS setup (#1677)
This commit is contained in:
parent
662edf6607
commit
cff0c9fb4c
2 changed files with 38 additions and 1 deletions
|
@ -114,7 +114,7 @@ func parseForward(c *caddy.Controller) (*Forward, error) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is more of a bug in // dnsutil.ParseHostPortOrFile that defaults to
|
// This is more of a bug in dnsutil.ParseHostPortOrFile that defaults to
|
||||||
// 53 because it doesn't know about the tls:// // and friends (that should be fixed). Hence
|
// 53 because it doesn't know about the tls:// // and friends (that should be fixed). Hence
|
||||||
// Fix the port number here, back to what the user intended.
|
// Fix the port number here, back to what the user intended.
|
||||||
if p == "53" {
|
if p == "53" {
|
||||||
|
|
|
@ -68,3 +68,40 @@ func TestSetup(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetupTLS(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
input string
|
||||||
|
shouldErr bool
|
||||||
|
expectedServerName string
|
||||||
|
expectedErr string
|
||||||
|
}{
|
||||||
|
// positive
|
||||||
|
{`forward . 127.0.0.1 {
|
||||||
|
tls_servername dns
|
||||||
|
}`, false, "dns", ""},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, test := range tests {
|
||||||
|
c := caddy.NewTestController("dns", test.input)
|
||||||
|
f, err := parseForward(c)
|
||||||
|
|
||||||
|
if test.shouldErr && err == nil {
|
||||||
|
t.Errorf("Test %d: expected error but found %s for input %s", i, err, test.input)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if !test.shouldErr {
|
||||||
|
t.Errorf("Test %d: expected no error but found one for input %s, got: %v", i, test.input, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(err.Error(), test.expectedErr) {
|
||||||
|
t.Errorf("Test %d: expected error to contain: %v, found error: %v, input: %s", i, test.expectedErr, err, test.input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !test.shouldErr && test.expectedServerName != f.tlsConfig.ServerName {
|
||||||
|
t.Errorf("Test %d: expected: %q, actual: %q", i, test.expectedServerName, f.tlsConfig.ServerName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue