mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Fix panic when Vault enters recovery mode, added test (#20418)
* Fix panic when Vault enters recovery mode, added test * Added changelog
This commit is contained in:
@@ -286,6 +286,13 @@ func TestServer(t *testing.T) {
|
||||
0,
|
||||
[]string{"-test-verify-only"},
|
||||
},
|
||||
{
|
||||
"recovery_mode",
|
||||
testBaseHCL(t, "") + inmemHCL,
|
||||
"",
|
||||
0,
|
||||
[]string{"-test-verify-only", "-recovery"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
@@ -295,26 +302,21 @@ func TestServer(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ui, cmd := testServerCommand(t)
|
||||
f, err := ioutil.TempFile("", "")
|
||||
if err != nil {
|
||||
t.Fatalf("error creating temp dir: %v", err)
|
||||
}
|
||||
f.WriteString(tc.contents)
|
||||
f.Close()
|
||||
defer os.Remove(f.Name())
|
||||
|
||||
f, err := os.CreateTemp(t.TempDir(), "")
|
||||
require.NoErrorf(t, err, "error creating temp dir: %v", err)
|
||||
|
||||
_, err = f.WriteString(tc.contents)
|
||||
require.NoErrorf(t, err, "cannot write temp file contents")
|
||||
|
||||
err = f.Close()
|
||||
require.NoErrorf(t, err, "unable to close temp file")
|
||||
|
||||
args := append(tc.args, "-config", f.Name())
|
||||
|
||||
code := cmd.Run(args)
|
||||
output := ui.ErrorWriter.String() + ui.OutputWriter.String()
|
||||
|
||||
if code != tc.code {
|
||||
t.Errorf("expected %d to be %d: %s", code, tc.code, output)
|
||||
}
|
||||
|
||||
if !strings.Contains(output, tc.exp) {
|
||||
t.Fatalf("expected %q to contain %q", output, tc.exp)
|
||||
}
|
||||
require.Equal(t, tc.code, code, "expected %d to be %d: %s", code, tc.code, output)
|
||||
require.Contains(t, output, tc.exp, "expected %q to contain %q", output, tc.exp)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user