Skip to content

Commit

Permalink
Move singleton mount fetching function to mount.go and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferai committed May 5, 2017
1 parent a6f29c6 commit 250b232
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 12 deletions.
12 changes: 6 additions & 6 deletions vault/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestCore_EnableCredential(t *testing.T) {
Path: "foo",
Type: "noop",
}
err := c.enableCredential(me)
err := c.enableCredential(me, false)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand Down Expand Up @@ -179,13 +179,13 @@ func TestCore_EnableCredential_twice_409(t *testing.T) {
Path: "foo",
Type: "noop",
}
err := c.enableCredential(me)
err := c.enableCredential(me, false)
if err != nil {
t.Fatalf("err: %v", err)
}

// 2nd should be a 409 error
err2 := c.enableCredential(me)
err2 := c.enableCredential(me, false)
switch err2.(type) {
case logical.HTTPCodedError:
if err2.(logical.HTTPCodedError).Code() != 409 {
Expand All @@ -203,7 +203,7 @@ func TestCore_EnableCredential_Token(t *testing.T) {
Path: "foo",
Type: "token",
}
err := c.enableCredential(me)
err := c.enableCredential(me, false)
if err.Error() != "token credential backend cannot be instantiated" {
t.Fatalf("err: %v", err)
}
Expand All @@ -225,7 +225,7 @@ func TestCore_DisableCredential(t *testing.T) {
Path: "foo",
Type: "noop",
}
err = c.enableCredential(me)
err = c.enableCredential(me, false)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand Down Expand Up @@ -286,7 +286,7 @@ func TestCore_DisableCredential_Cleanup(t *testing.T) {
Path: "foo",
Type: "noop",
}
err := c.enableCredential(me)
err := c.enableCredential(me, false)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion vault/expiration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ func TestExpiration_RevokeForce(t *testing.T) {
Type: "badrenew",
}

err := core.mount(me)
err := core.mount(me, false)
if err != nil {
t.Fatal(err)
}
Expand Down
24 changes: 24 additions & 0 deletions vault/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/hashicorp/go-uuid"
"github.com/hashicorp/vault/helper/jsonutil"
"github.com/hashicorp/vault/helper/strutil"
"github.com/hashicorp/vault/logical"
)

Expand Down Expand Up @@ -792,3 +793,26 @@ func requiredMountTable() *MountTable {
table.Entries = append(table.Entries, sysMount)
return table
}

func (c *Core) singletonMountTables() (mounts, auth *MountTable) {
mounts = &MountTable{}
auth = &MountTable{}

c.mountsLock.RLock()
for _, entry := range c.mounts.Entries {
if strutil.StrListContains(singletonMounts, entry.Type) {
mounts.Entries = append(mounts.Entries, entry)
}
}
c.mountsLock.RUnlock()

c.authLock.RLock()
for _, entry := range c.auth.Entries {
if strutil.StrListContains(singletonMounts, entry.Type) {
auth.Entries = append(auth.Entries, entry)
}
}
c.authLock.RUnlock()

return
}
34 changes: 30 additions & 4 deletions vault/mount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestCore_Mount(t *testing.T) {
Path: "foo",
Type: "generic",
}
err := c.mount(me)
err := c.mount(me, false)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand Down Expand Up @@ -226,7 +226,7 @@ func TestCore_Unmount_Cleanup(t *testing.T) {
Path: "test/",
Type: "noop",
}
if err := c.mount(me); err != nil {
if err := c.mount(me, false); err != nil {
t.Fatalf("err: %v", err)
}

Expand Down Expand Up @@ -346,7 +346,7 @@ func TestCore_Remount_Cleanup(t *testing.T) {
Path: "test/",
Type: "noop",
}
if err := c.mount(me); err != nil {
if err := c.mount(me, false); err != nil {
t.Fatalf("err: %v", err)
}

Expand Down Expand Up @@ -458,7 +458,7 @@ func TestCore_MountTable_UpgradeToTyped(t *testing.T) {
Path: "foo",
Type: "noop",
}
err = c.enableCredential(me)
err = c.enableCredential(me, false)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand Down Expand Up @@ -628,3 +628,29 @@ func verifyDefaultTable(t *testing.T, table *MountTable) {
}
}
}

func TestSingletonMountTableFunc(t *testing.T) {
c, _, _ := TestCoreUnsealed(t)

mounts, auth := c.singletonMountTables()

if len(mounts.Entries) != 2 {
t.Fatal("length of mounts is wrong")
}
for _, entry := range mounts.Entries {
switch entry.Type {
case "system":
case "cubbyhole":
default:
t.Fatalf("unknown type %s", entry.Type)
}
}

if len(auth.Entries) != 1 {
t.Fatal("length of auth is wrong")
}

if auth.Entries[0].Type != "token" {
t.Fatal("unexpected entry type for auth")
}
}
2 changes: 1 addition & 1 deletion vault/request_handling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestRequestHandling_Wrapping(t *testing.T) {
UUID: meUUID,
Path: "wraptest",
Type: "generic",
})
}, false)
if err != nil {
t.Fatalf("err: %v", err)
}
Expand Down

0 comments on commit 250b232

Please sign in to comment.