mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-20 06:01:10 +02:00
vault: testing mount/unmount
This commit is contained in:
parent
586878ffe0
commit
ada83992b1
@ -202,6 +202,7 @@ func (c *Core) unmountPath(path string) error {
|
||||
if newTable.Entries[i].Path == path {
|
||||
newTable.Entries[i], newTable.Entries[n-1] = newTable.Entries[n-1], nil
|
||||
newTable.Entries = newTable.Entries[:n-1]
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,72 @@ func TestCore_DefaultMountTable(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCore_MountEntry(t *testing.T) {
|
||||
c, key := testUnsealedCore(t)
|
||||
me := &MountEntry{
|
||||
Path: "foo",
|
||||
Type: "generic",
|
||||
}
|
||||
err := c.mountEntry(me)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
match := c.router.MatchingMount("foo/bar")
|
||||
if match != "foo/" {
|
||||
t.Fatalf("missing mount")
|
||||
}
|
||||
|
||||
conf := &CoreConfig{physical: c.physical}
|
||||
c2, err := NewCore(conf)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
unseal, err := c2.Unseal(key)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if !unseal {
|
||||
t.Fatalf("should be unsealed")
|
||||
}
|
||||
|
||||
// Verify matching mount tables
|
||||
if !reflect.DeepEqual(c.mounts, c2.mounts) {
|
||||
t.Fatalf("mismatch: %v %v", c.mounts, c2.mounts)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCore_UnmountPath(t *testing.T) {
|
||||
c, key := testUnsealedCore(t)
|
||||
err := c.unmountPath("secret")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
|
||||
match := c.router.MatchingMount("secret/foo")
|
||||
if match != "" {
|
||||
t.Fatalf("backend present")
|
||||
}
|
||||
|
||||
conf := &CoreConfig{physical: c.physical}
|
||||
c2, err := NewCore(conf)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
unseal, err := c2.Unseal(key)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if !unseal {
|
||||
t.Fatalf("should be unsealed")
|
||||
}
|
||||
|
||||
// Verify matching mount tables
|
||||
if !reflect.DeepEqual(c.mounts, c2.mounts) {
|
||||
t.Fatalf("mismatch: %v %v", c.mounts, c2.mounts)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDefaultMountTable(t *testing.T) {
|
||||
table := defaultMountTable()
|
||||
verifyDefaultTable(t, table)
|
||||
|
Loading…
x
Reference in New Issue
Block a user