2019-10-15 04:55:31 +00:00
|
|
|
package misc
|
2019-06-19 13:40:57 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/go-hclog"
|
|
|
|
"github.com/hashicorp/vault/api"
|
|
|
|
vaulthttp "github.com/hashicorp/vault/http"
|
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
|
|
|
"github.com/hashicorp/vault/vault"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Tests the regression in
|
|
|
|
// https://github.com/hashicorp/vault/pull/6920
|
|
|
|
func TestRecoverFromPanic(t *testing.T) {
|
|
|
|
logger := hclog.New(nil)
|
|
|
|
coreConfig := &vault.CoreConfig{
|
|
|
|
LogicalBackends: map[string]logical.Factory{
|
|
|
|
"noop": vault.NoopBackendFactory,
|
|
|
|
},
|
|
|
|
EnableRaw: true,
|
|
|
|
Logger: logger,
|
|
|
|
}
|
|
|
|
cluster := vault.NewTestCluster(t, coreConfig, &vault.TestClusterOptions{
|
|
|
|
HandlerFunc: vaulthttp.Handler,
|
|
|
|
})
|
|
|
|
cluster.Start()
|
|
|
|
defer cluster.Cleanup()
|
|
|
|
|
|
|
|
core := cluster.Cores[0]
|
|
|
|
vault.TestWaitActive(t, core.Core)
|
|
|
|
client := core.Client
|
|
|
|
|
2022-04-07 19:12:58 +00:00
|
|
|
err := client.Sys().Mount("noop", &api.MountInput{
|
2019-06-19 13:40:57 +00:00
|
|
|
Type: "noop",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-04-07 19:12:58 +00:00
|
|
|
_, err = client.Logical().Read("noop/panic")
|
2019-06-19 13:40:57 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatal("expected error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// This will deadlock the test if we hit the condition
|
|
|
|
cluster.EnsureCoresSealed(t)
|
|
|
|
}
|