فهرست منبع

Update template tests.

Mariano Cano 7 سال پیش
والد
کامیت
557a45abfa
4فایلهای تغییر یافته به همراه19 افزوده شده و 4 حذف شده
  1. 1 1
      authority/ssh_test.go
  2. 10 1
      authority/testdata/templates/config.tpl
  3. 5 1
      authority/testdata/templates/include.tpl
  4. 3 1
      templates/templates_test.go

+ 1 - 1
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")},

+ 10 - 1
authority/testdata/templates/config.tpl

@@ -1,3 +1,12 @@
 Match exec "step ssh check-host %h"
 	ForwardAgent yes
-	UserKnownHostsFile {{.User.StepPath}}/ssh/known_hosts
+{{- 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 }}

+ 5 - 1
authority/testdata/templates/include.tpl

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

+ 3 - 1
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))
 			}
 		})
 	}