mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 19:47:54 +00:00
Bugfix: When walking a given CA path, the walk gives both files and directories to the function. However, both were being passed in to be read as certificates, with the result that "." (the given directory for the CA path) would cause an error. This fixes that problem by simply checking whether the given path in the walk is a directory or a file. Feature enhancement: VAULT_CACERT, VAULT_CAPATH, and VAULT_INSECURE now perform as expected.
67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
package command
|
|
|
|
import (
|
|
"flag"
|
|
"os"
|
|
"reflect"
|
|
"sort"
|
|
"testing"
|
|
)
|
|
|
|
func TestFlagSet(t *testing.T) {
|
|
cases := []struct {
|
|
Flags FlagSetFlags
|
|
Expected []string
|
|
}{
|
|
{
|
|
FlagSetNone,
|
|
[]string{},
|
|
},
|
|
{
|
|
FlagSetServer,
|
|
[]string{"address", "ca-cert", "ca-path", "insecure"},
|
|
},
|
|
}
|
|
|
|
for i, tc := range cases {
|
|
var m Meta
|
|
fs := m.FlagSet("foo", tc.Flags)
|
|
|
|
actual := make([]string, 0, 0)
|
|
fs.VisitAll(func(f *flag.Flag) {
|
|
actual = append(actual, f.Name)
|
|
})
|
|
sort.Strings(actual)
|
|
sort.Strings(tc.Expected)
|
|
|
|
if !reflect.DeepEqual(actual, tc.Expected) {
|
|
t.Fatalf("%d: flags: %#v\n\nExpected: %#v\nGot: %#v",
|
|
i, tc.Flags, tc.Expected, actual)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEnvSettings(t *testing.T) {
|
|
os.Setenv("VAULT_CACERT", "/path/to/fake/cert.crt")
|
|
os.Setenv("VAULT_CAPATH", "/path/to/fake/certs")
|
|
os.Setenv("VAULT_INSECURE", "true")
|
|
defer os.Setenv("VAULT_CACERT", "")
|
|
defer os.Setenv("VAULT_CAPATH", "")
|
|
defer os.Setenv("VAULT_INSECURE", "")
|
|
var m Meta
|
|
|
|
// Err is ignored as it is expected that the test settings
|
|
// will cause errors; just check the flag settings
|
|
m.Client()
|
|
|
|
if m.flagCACert != "/path/to/fake/cert.crt" {
|
|
t.Fatalf("bad: %s", m.flagAddress)
|
|
}
|
|
if m.flagCAPath != "/path/to/fake/certs" {
|
|
t.Fatalf("bad: %s", m.flagAddress)
|
|
}
|
|
if m.flagInsecure != true {
|
|
t.Fatalf("bad: %s", m.flagAddress)
|
|
}
|
|
}
|