aboutsummaryrefslogtreecommitdiff
path: root/plugin/forward/setup_test.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2018-04-13 17:02:54 +0100
committerGravatar GitHub <noreply@github.com> 2018-04-13 17:02:54 +0100
commitcff0c9fb4c43eb084da2c9c318af8f83ecba3de7 (patch)
treea2726968ebc815033e795f72aff83159caf58ece /plugin/forward/setup_test.go
parent662edf6607f6e8fb3cb65d5853642cc82a75f4f2 (diff)
downloadcoredns-cff0c9fb4c43eb084da2c9c318af8f83ecba3de7.tar.gz
coredns-cff0c9fb4c43eb084da2c9c318af8f83ecba3de7.tar.zst
coredns-cff0c9fb4c43eb084da2c9c318af8f83ecba3de7.zip
plugin/forward: test TLS setup (#1677)
Diffstat (limited to 'plugin/forward/setup_test.go')
-rw-r--r--plugin/forward/setup_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/plugin/forward/setup_test.go b/plugin/forward/setup_test.go
index bf77bb932..d787a59d0 100644
--- a/plugin/forward/setup_test.go
+++ b/plugin/forward/setup_test.go
@@ -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)
+ }
+ }
+}