Update template tests.

This commit is contained in:
Mariano Cano 2019-11-26 18:44:43 -08:00
parent 0528971693
commit 5d35586402
4 changed files with 19 additions and 4 deletions

View file

@ -407,7 +407,7 @@ func TestAuthority_GetSSHConfig(t *testing.T) {
} }
userOutputWithUserData := []templates.Output{ userOutputWithUserData := []templates.Output{
{Name: "include.tpl", Type: templates.File, Comment: "#", Path: "ssh/include", Content: []byte("Host *\n\tInclude /home/user/.step/ssh/config")}, {Name: "include.tpl", Type: templates.File, Comment: "#", Path: "ssh/include", Content: []byte("Host *\n\tInclude /home/user/.step/ssh/config")},
{Name: "config.tpl", Type: templates.File, Comment: "#", Path: "ssh/config", Content: []byte("Match exec \"step ssh check-host %h\"\n\tForwardAgent yes\n\tUserKnownHostsFile /home/user/.step/ssh/known_hosts")}, {Name: "config.tpl", Type: templates.File, Comment: "#", Path: "ssh/config", Content: []byte("Match exec \"step ssh check-host %h\"\n\tForwardAgent yes\n\tUserKnownHostsFile /home/user/.step/ssh/known_hosts\n\tProxyCommand step ssh proxycommand %r %h %p\n")},
} }
hostOutputWithUserData := []templates.Output{ hostOutputWithUserData := []templates.Output{
{Name: "sshd_config.tpl", Type: templates.File, Comment: "#", Path: "/etc/ssh/sshd_config", Content: []byte("TrustedUserCAKeys /etc/ssh/ca.pub\nHostCertificate /etc/ssh/ssh_host_ecdsa_key-cert.pub\nHostKey /etc/ssh/ssh_host_ecdsa_key")}, {Name: "sshd_config.tpl", Type: templates.File, Comment: "#", Path: "/etc/ssh/sshd_config", Content: []byte("TrustedUserCAKeys /etc/ssh/ca.pub\nHostCertificate /etc/ssh/ssh_host_ecdsa_key-cert.pub\nHostKey /etc/ssh/ssh_host_ecdsa_key")},

View file

@ -1,3 +1,12 @@
Match exec "step ssh check-host %h" Match exec "step ssh check-host %h"
ForwardAgent yes ForwardAgent yes
{{- if .User.User }}
User {{.User.User}}
{{- end }}
{{- if or .User.GOOS "none" | eq "windows" }}
UserKnownHostsFile {{.User.StepPath}}\ssh\known_hosts
ProxyCommand C:\Windows\System32\cmd.exe /c step ssh proxycommand %r %h %p
{{- else }}
UserKnownHostsFile {{.User.StepPath}}/ssh/known_hosts UserKnownHostsFile {{.User.StepPath}}/ssh/known_hosts
ProxyCommand step ssh proxycommand %r %h %p
{{- end }}

View file

@ -1,2 +1,6 @@
Host * Host *
{{- if or .User.GOOS "linux" | eq "windows" }}
Include {{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/config
{{- else }}
Include {{.User.StepPath}}/ssh/config Include {{.User.StepPath}}/ssh/config
{{- end }}

View file

@ -230,6 +230,8 @@ func TestTemplate_Render(t *testing.T) {
}, },
"User": map[string]string{ "User": map[string]string{
"StepPath": "/tmp/.step", "StepPath": "/tmp/.step",
"User": "john",
"GOOS": "linux",
}, },
} }
@ -271,7 +273,7 @@ func TestTemplate_Render(t *testing.T) {
return return
} }
if !reflect.DeepEqual(got, tt.want) { if !reflect.DeepEqual(got, tt.want) {
t.Errorf("Template.Render() = %v, want %v", got, tt.want) t.Errorf("Template.Render() = %v, want %v", string(got), string(tt.want))
} }
}) })
} }