1package token
2
3import (
4	"testing"
5
6	"github.com/hashicorp/go-hclog"
7	"github.com/hashicorp/vault/api"
8	vaulthttp "github.com/hashicorp/vault/http"
9	"github.com/hashicorp/vault/sdk/logical"
10	"github.com/hashicorp/vault/vault"
11)
12
13// Tests the regression in
14// https://github.com/hashicorp/vault/pull/6920
15func TestRecoverFromPanic(t *testing.T) {
16	logger := hclog.New(nil)
17
18	coreConfig := &vault.CoreConfig{
19		LogicalBackends: map[string]logical.Factory{
20			"noop": vault.NoopBackendFactory,
21		},
22		EnableRaw: true,
23		Logger:    logger,
24	}
25	cluster := vault.NewTestCluster(t, coreConfig, &vault.TestClusterOptions{
26		HandlerFunc: vaulthttp.Handler,
27	})
28	cluster.Start()
29	defer cluster.Cleanup()
30
31	core := cluster.Cores[0]
32	vault.TestWaitActive(t, core.Core)
33	client := core.Client
34
35	err := client.Sys().Mount("noop", &api.MountInput{
36		Type: "noop",
37	})
38	if err != nil {
39		t.Fatal(err)
40	}
41
42	_, err = client.Logical().Read("noop/panic")
43	if err == nil {
44		t.Fatal("expected error")
45	}
46
47	// This will deadlock the test if we hit the condition
48	cluster.EnsureCoresSealed(t)
49}
50