Add unsalted test to app-id

This commit is contained in:
Jeff Mitchell 2017-06-05 11:37:16 -04:00
parent 0a8991813b
commit b90c84a2c6
2 changed files with 39 additions and 5 deletions

View File

@ -13,10 +13,10 @@ func Factory(conf *logical.BackendConfig) (logical.Backend, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return b.Setup(conf) return b.Backend.Setup(conf)
} }
func Backend(conf *logical.BackendConfig) (*framework.Backend, error) { func Backend(conf *logical.BackendConfig) (backend, error) {
var b backend var b backend
b.MapAppId = &framework.PolicyMap{ b.MapAppId = &framework.PolicyMap{
PathMap: framework.PathMap{ PathMap: framework.PathMap{
@ -75,11 +75,10 @@ func Backend(conf *logical.BackendConfig) (*framework.Backend, error) {
} }
b.view = conf.StorageView b.view = conf.StorageView
b.MapAppId.SaltFunc = b.Salt b.MapAppId.SaltFunc = b.Salt
b.MapUserId.SaltFunc = b.Salt b.MapUserId.SaltFunc = b.Salt
return b.Backend, nil return b, nil
} }
type backend struct { type backend struct {

View File

@ -9,8 +9,19 @@ import (
) )
func TestBackend_basic(t *testing.T) { func TestBackend_basic(t *testing.T) {
var b backend
var err error
var storage logical.Storage
factory := func(conf *logical.BackendConfig) (logical.Backend, error) {
b, err = Backend(conf)
if err != nil {
t.Fatal(err)
}
storage = conf.StorageView
return b.Setup(conf)
}
logicaltest.Test(t, logicaltest.TestCase{ logicaltest.Test(t, logicaltest.TestCase{
Factory: Factory, Factory: factory,
Steps: []logicaltest.TestStep{ Steps: []logicaltest.TestStep{
testAccStepMapAppId(t), testAccStepMapAppId(t),
testAccStepMapUserId(t), testAccStepMapUserId(t),
@ -21,6 +32,30 @@ func TestBackend_basic(t *testing.T) {
testAccLoginDeleted(t), testAccLoginDeleted(t),
}, },
}) })
req := &logical.Request{
Path: "map/app-id",
Operation: logical.ListOperation,
Storage: storage,
}
resp, err := b.HandleRequest(req)
if err != nil {
t.Fatal(err)
}
if resp == nil {
t.Fatal("nil response")
}
keys := resp.Data["keys"].([]string)
if len(keys) != 1 {
t.Fatalf("expected 1 key, got %d", len(keys))
}
salt, err := b.Salt()
if err != nil {
t.Fatal(err)
}
if keys[0] != salt.SaltID("foo") {
t.Fatal("value was improperly salted")
}
} }
func TestBackend_cidr(t *testing.T) { func TestBackend_cidr(t *testing.T) {