Add test case for error executing template.

This commit is contained in:
Mariano Cano 2020-06-16 18:21:44 -07:00
parent e3ae751b57
commit ff32746312
2 changed files with 19 additions and 1 deletions

View file

@ -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) {

1
authority/testdata/templates/fail.tpl vendored Normal file
View file

@ -0,0 +1 @@
{{ fail "This template will fail" }}