From 557a45abfa1e94fd730a2d38b761364507dcd029 Mon Sep 17 00:00:00 2001 From: Mariano Cano Date: Tue, 26 Nov 2019 18:44:43 -0800 Subject: [PATCH] Update template tests. --- authority/ssh_test.go | 2 +- authority/testdata/templates/config.tpl | 11 ++++++++++- authority/testdata/templates/include.tpl | 6 +++++- templates/templates_test.go | 4 +++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/authority/ssh_test.go b/authority/ssh_test.go index c2f4ceb7..3ea4e98d 100644 --- a/authority/ssh_test.go +++ b/authority/ssh_test.go @@ -407,7 +407,7 @@ func TestAuthority_GetSSHConfig(t *testing.T) { } userOutputWithUserData := []templates.Output{ {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{ {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")}, diff --git a/authority/testdata/templates/config.tpl b/authority/testdata/templates/config.tpl index 96233680..63269a4c 100644 --- a/authority/testdata/templates/config.tpl +++ b/authority/testdata/templates/config.tpl @@ -1,3 +1,12 @@ Match exec "step ssh check-host %h" ForwardAgent yes - UserKnownHostsFile {{.User.StepPath}}/ssh/known_hosts \ No newline at end of file +{{- 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 + ProxyCommand step ssh proxycommand %r %h %p +{{- end }} diff --git a/authority/testdata/templates/include.tpl b/authority/testdata/templates/include.tpl index e7113727..5d21dd45 100644 --- a/authority/testdata/templates/include.tpl +++ b/authority/testdata/templates/include.tpl @@ -1,2 +1,6 @@ Host * - Include {{.User.StepPath}}/ssh/config \ No newline at end of file +{{- if or .User.GOOS "linux" | eq "windows" }} + Include {{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/config +{{- else }} + Include {{.User.StepPath}}/ssh/config +{{- end }} \ No newline at end of file diff --git a/templates/templates_test.go b/templates/templates_test.go index 537fab4c..c3d252ad 100644 --- a/templates/templates_test.go +++ b/templates/templates_test.go @@ -230,6 +230,8 @@ func TestTemplate_Render(t *testing.T) { }, "User": map[string]string{ "StepPath": "/tmp/.step", + "User": "john", + "GOOS": "linux", }, } @@ -271,7 +273,7 @@ func TestTemplate_Render(t *testing.T) { return } 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)) } }) }