forked from TrueCloudLab/certificates
Add test case for error executing template.
This commit is contained in:
parent
e3ae751b57
commit
ff32746312
2 changed files with 19 additions and 1 deletions
|
@ -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: "#"},
|
{Name: "config.tpl", Type: templates.File, TemplatePath: "./testdata/templates/config.tpl", Path: "ssh/config", Comment: "#"},
|
||||||
},
|
},
|
||||||
Host: []templates.Template{
|
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{}{
|
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 {
|
type fields struct {
|
||||||
templates *templates.Templates
|
templates *templates.Templates
|
||||||
userSigner ssh.Signer
|
userSigner ssh.Signer
|
||||||
|
@ -456,6 +471,8 @@ func TestAuthority_GetSSHConfig(t *testing.T) {
|
||||||
{"userError", fields{tmplConfigErr, userSigner, hostSigner}, args{"user", nil}, nil, true},
|
{"userError", fields{tmplConfigErr, userSigner, hostSigner}, args{"user", nil}, nil, true},
|
||||||
{"hostError", fields{tmplConfigErr, userSigner, hostSigner}, args{"host", map[string]string{"Function": "foo"}}, 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},
|
{"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 {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
1
authority/testdata/templates/fail.tpl
vendored
Normal file
1
authority/testdata/templates/fail.tpl
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{{ fail "This template will fail" }}
|
Loading…
Add table
Reference in a new issue