vault: testing mount/unmount

This commit is contained in:
Armon Dadgar 2015-03-11 18:29:49 -07:00
parent 586878ffe0
commit ada83992b1
2 changed files with 67 additions and 0 deletions

View File

@ -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
}
}

View File

@ -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)