From 58154df8119e4328a40fe4824b1077774ab3fa95 Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 10 May 2018 18:22:04 -0400 Subject: [PATCH] Fix two failing tests due to the fact that the expiration manager now needs to be running to properly revoke tests. --- vault/token_store_test.go | 54 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/vault/token_store_test.go b/vault/token_store_test.go index d6eff4ea1..26eca23d5 100644 --- a/vault/token_store_test.go +++ b/vault/token_store_test.go @@ -379,8 +379,26 @@ func TestTokenStore_HandleRequest_ListAccessors(t *testing.T) { } func TestTokenStore_HandleRequest_RevokeAccessor(t *testing.T) { - _, ts, _, root := TestCoreWithTokenStore(t) + exp := mockExpiration(t) + ts := exp.tokenStore + + rootToken, err := ts.rootToken(context.Background()) + root := rootToken.ID + testMakeToken(t, ts, root, "tokenid", "", []string{"foo"}) + + auth := &logical.Auth{ + ClientToken: "tokenid", + LeaseOptions: logical.LeaseOptions{ + TTL: time.Hour, + Renewable: true, + }, + } + err = exp.RegisterAuth("auth/token/create", auth) + if err != nil { + t.Fatalf("err: %v", err) + } + out, err := ts.Lookup(context.Background(), "tokenid") if err != nil { t.Fatalf("err: %s", err) @@ -1367,10 +1385,40 @@ func TestTokenStore_HandleRequest_CreateToken_TTL(t *testing.T) { } func TestTokenStore_HandleRequest_Revoke(t *testing.T) { - _, ts, _, root := TestCoreWithTokenStore(t) + exp := mockExpiration(t) + ts := exp.tokenStore + + rootToken, err := ts.rootToken(context.Background()) + root := rootToken.ID + testMakeToken(t, ts, root, "child", "", []string{"root", "foo"}) + + auth := &logical.Auth{ + ClientToken: "child", + LeaseOptions: logical.LeaseOptions{ + TTL: time.Hour, + Renewable: true, + }, + } + err = exp.RegisterAuth("auth/token/create", auth) + if err != nil { + t.Fatalf("err: %v", err) + } + testMakeToken(t, ts, "child", "sub-child", "", []string{"foo"}) + auth = &logical.Auth{ + ClientToken: "sub-child", + LeaseOptions: logical.LeaseOptions{ + TTL: time.Hour, + Renewable: true, + }, + } + err = exp.RegisterAuth("auth/token/create", auth) + if err != nil { + t.Fatalf("err: %v", err) + } + req := logical.TestRequest(t, logical.UpdateOperation, "revoke") req.Data = map[string]interface{}{ "token": "child", @@ -1390,7 +1438,7 @@ func TestTokenStore_HandleRequest_Revoke(t *testing.T) { t.Fatalf("err: %v", err) } if out != nil { - t.Fatalf("bad: %v", out) + t.Fatalf("bad: %#v", out) } // Sub-child should not exist