From b90c84a2c609c0b7be8ea1a6a9d1e9fc62ddfb8a Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Mon, 5 Jun 2017 11:37:16 -0400 Subject: [PATCH] Add unsalted test to app-id --- builtin/credential/app-id/backend.go | 7 ++--- builtin/credential/app-id/backend_test.go | 37 ++++++++++++++++++++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/builtin/credential/app-id/backend.go b/builtin/credential/app-id/backend.go index aabd5724f..eba7d136c 100644 --- a/builtin/credential/app-id/backend.go +++ b/builtin/credential/app-id/backend.go @@ -13,10 +13,10 @@ func Factory(conf *logical.BackendConfig) (logical.Backend, error) { if err != nil { 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 b.MapAppId = &framework.PolicyMap{ PathMap: framework.PathMap{ @@ -75,11 +75,10 @@ func Backend(conf *logical.BackendConfig) (*framework.Backend, error) { } b.view = conf.StorageView - b.MapAppId.SaltFunc = b.Salt b.MapUserId.SaltFunc = b.Salt - return b.Backend, nil + return b, nil } type backend struct { diff --git a/builtin/credential/app-id/backend_test.go b/builtin/credential/app-id/backend_test.go index 52d4433e4..e795a816a 100644 --- a/builtin/credential/app-id/backend_test.go +++ b/builtin/credential/app-id/backend_test.go @@ -9,8 +9,19 @@ import ( ) 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{ - Factory: Factory, + Factory: factory, Steps: []logicaltest.TestStep{ testAccStepMapAppId(t), testAccStepMapUserId(t), @@ -21,6 +32,30 @@ func TestBackend_basic(t *testing.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) {