Validate HCL for SSHHelper too

This commit is contained in:
Seth Vargo
2016-03-10 16:47:46 -05:00
parent 780c58d10f
commit d88b83d212
2 changed files with 111 additions and 22 deletions

View File

@@ -2,6 +2,7 @@ package api
import (
"fmt"
"strings"
"testing"
)
@@ -28,3 +29,41 @@ func TestSSH_CreateTLSClient(t *testing.T) {
panic(fmt.Sprintf("error creating client with TLS transport"))
}
}
func TestParseSSHHelperConfig(t *testing.T) {
config, err := ParseSSHHelperConfig(`
vault_addr = "1.2.3.4"
`)
if err != nil {
t.Fatal(err)
}
if config.SSHMountPoint != SSHHelperDefaultMountPoint {
t.Errorf("expected %q to be %q", config.SSHMountPoint, SSHHelperDefaultMountPoint)
}
}
func TestParseSSHHelperConfig_missingVaultAddr(t *testing.T) {
_, err := ParseSSHHelperConfig("")
if err == nil {
t.Fatal("expected error")
}
if !strings.Contains(err.Error(), "ssh_helper: missing config 'vault_addr'") {
t.Errorf("bad error: %s", err)
}
}
func TestParseSSHHelperConfig_badKeys(t *testing.T) {
_, err := ParseSSHHelperConfig(`
vault_addr = "1.2.3.4"
nope = "bad"
`)
if err == nil {
t.Fatal("expected error")
}
if !strings.Contains(err.Error(), "ssh_helper: invalid key 'nope' on line 3") {
t.Errorf("bad error: %s", err)
}
}