mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 03:58:01 +00:00
Validate HCL for SSHHelper too
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user