2015-03-19 02:36:17 +00:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestCore_DefaultAuthTable(t *testing.T) {
|
|
|
|
c, key := TestCoreUnsealed(t)
|
|
|
|
verifyDefaultAuthTable(t, c.auth)
|
|
|
|
|
|
|
|
// Start a second core with same physical
|
|
|
|
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.auth, c2.auth) {
|
|
|
|
t.Fatalf("mismatch: %v %v", c.auth, c2.auth)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDefaultAuthTable(t *testing.T) {
|
|
|
|
table := defaultAuthTable()
|
|
|
|
verifyDefaultAuthTable(t, table)
|
|
|
|
}
|
|
|
|
|
2015-03-19 16:54:57 +00:00
|
|
|
func verifyDefaultAuthTable(t *testing.T, table *MountTable) {
|
2015-03-19 02:36:17 +00:00
|
|
|
if len(table.Entries) != 1 {
|
|
|
|
t.Fatalf("bad: %v", table.Entries)
|
|
|
|
}
|
|
|
|
for idx, entry := range table.Entries {
|
|
|
|
switch idx {
|
|
|
|
case 0:
|
2015-03-19 16:54:57 +00:00
|
|
|
if entry.Path != "token" {
|
2015-03-19 02:36:17 +00:00
|
|
|
t.Fatalf("bad: %v", entry)
|
|
|
|
}
|
|
|
|
if entry.Type != "token" {
|
|
|
|
t.Fatalf("bad: %v", entry)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if entry.Description == "" {
|
|
|
|
t.Fatalf("bad: %v", entry)
|
|
|
|
}
|
|
|
|
if entry.UUID == "" {
|
|
|
|
t.Fatalf("bad: %v", entry)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|