From 9832d1538b1b4405d65734171942ec445c4eff6b Mon Sep 17 00:00:00 2001 From: Mariano Cano Date: Mon, 15 Jun 2020 17:25:47 -0700 Subject: [PATCH] Avoid nil pointer panic on step ssh config with no templates. --- authority/ssh.go | 4 ++++ authority/ssh_test.go | 1 + 2 files changed, 5 insertions(+) diff --git a/authority/ssh.go b/authority/ssh.go index b38cfca9..b80797d0 100644 --- a/authority/ssh.go +++ b/authority/ssh.go @@ -125,6 +125,10 @@ func (a *Authority) GetSSHConfig(ctx context.Context, typ string, data map[strin return nil, errs.NotFound("getSSHConfig: ssh is not configured") } + if a.config.Templates == nil { + return nil, errs.NotFound("getSSHConfig: ssh templates are not configured") + } + var ts []templates.Template switch typ { case provisioner.SSHUserCert: diff --git a/authority/ssh_test.go b/authority/ssh_test.go index 0fae9cef..626c0da6 100644 --- a/authority/ssh_test.go +++ b/authority/ssh_test.go @@ -455,6 +455,7 @@ func TestAuthority_GetSSHConfig(t *testing.T) { {"badType", fields{tmplConfig, userSigner, hostSigner}, args{"bad", 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}, + {"noTemplates", fields{nil, userSigner, hostSigner}, args{"user", nil}, nil, true}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {