From ff32746312a1de5212168178189e87af7f73dd22 Mon Sep 17 00:00:00 2001 From: Mariano Cano Date: Tue, 16 Jun 2020 18:21:44 -0700 Subject: [PATCH] Add test case for error executing template. --- authority/ssh_test.go | 19 ++++++++++++++++++- authority/testdata/templates/fail.tpl | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 authority/testdata/templates/fail.tpl diff --git a/authority/ssh_test.go b/authority/ssh_test.go index a07ed0db..ba381786 100644 --- a/authority/ssh_test.go +++ b/authority/ssh_test.go @@ -398,7 +398,14 @@ func TestAuthority_GetSSHConfig(t *testing.T) { {Name: "config.tpl", Type: templates.File, TemplatePath: "./testdata/templates/config.tpl", Path: "ssh/config", Comment: "#"}, }, Host: []templates.Template{ - {Name: "sshd_config.tpl", Type: templates.File, TemplatePath: "./testdata/templates/sshd_config.tpl", Path: "/etc/ssh/sshd_config", Comment: "#"}, + { + Name: "sshd_config.tpl", + Type: templates.File, + TemplatePath: "./testdata/templates/sshd_config.tpl", + Path: "/etc/ssh/sshd_config", + Comment: "#", + RequiredData: []string{"Certificate", "Key"}, + }, }, }, Data: map[string]interface{}{ @@ -429,6 +436,14 @@ func TestAuthority_GetSSHConfig(t *testing.T) { }, } + tmplConfigFail := &templates.Templates{ + SSH: &templates.SSHTemplates{ + User: []templates.Template{ + {Name: "fail.tpl", Type: templates.File, TemplatePath: "./testdata/templates/fail.tpl", Path: "ssh/fail", Comment: "#"}, + }, + }, + } + type fields struct { templates *templates.Templates userSigner ssh.Signer @@ -456,6 +471,8 @@ func TestAuthority_GetSSHConfig(t *testing.T) { {"userError", fields{tmplConfigErr, userSigner, hostSigner}, args{"user", nil}, nil, true}, {"hostError", fields{tmplConfigErr, userSigner, hostSigner}, args{"host", map[string]string{"Function": "foo"}}, nil, true}, {"noTemplates", fields{nil, userSigner, hostSigner}, args{"user", nil}, nil, true}, + {"missingData", fields{tmplConfigWithUserData, userSigner, hostSigner}, args{"host", map[string]string{"Certificate": "ssh_host_ecdsa_key-cert.pub"}}, nil, true}, + {"failError", fields{tmplConfigFail, userSigner, hostSigner}, args{"user", nil}, nil, true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/authority/testdata/templates/fail.tpl b/authority/testdata/templates/fail.tpl new file mode 100644 index 00000000..1823f491 --- /dev/null +++ b/authority/testdata/templates/fail.tpl @@ -0,0 +1 @@ +{{ fail "This template will fail" }} \ No newline at end of file