From c62ce48b5b21ebbab27509dcbca2397b4f6c306b Mon Sep 17 00:00:00 2001 From: Theron Voran Date: Wed, 3 Feb 2021 18:30:41 -0800 Subject: [PATCH] Set TokenParent in the Index to be cached (#10833) Co-authored-by: Calvin Leung Huang --- changelog/10833.txt | 3 +++ command/agent/cache/lease_cache.go | 2 +- command/agent/cache/lease_cache_test.go | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 changelog/10833.txt diff --git a/changelog/10833.txt b/changelog/10833.txt new file mode 100644 index 000000000..588c782cd --- /dev/null +++ b/changelog/10833.txt @@ -0,0 +1,3 @@ +```release-note:bug +agent: Set TokenParent correctly in the Index to be cached. +``` diff --git a/command/agent/cache/lease_cache.go b/command/agent/cache/lease_cache.go index cbaa6cc15..7d3867520 100644 --- a/command/agent/cache/lease_cache.go +++ b/command/agent/cache/lease_cache.go @@ -353,7 +353,7 @@ func (c *LeaseCache) Send(ctx context.Context, req *SendRequest) (*SendResponse, c.logger.Debug("setting parent context", "method", req.Request.Method, "path", req.Request.URL.Path) parentCtx = entry.RenewCtxInfo.Ctx - entry.TokenParent = req.Token + index.TokenParent = req.Token } renewCtxInfo = c.createCtxInfo(parentCtx) diff --git a/command/agent/cache/lease_cache_test.go b/command/agent/cache/lease_cache_test.go index 3b31385d0..ba6dafa8b 100644 --- a/command/agent/cache/lease_cache_test.go +++ b/command/agent/cache/lease_cache_test.go @@ -162,6 +162,18 @@ func TestLeaseCache_SendCacheable(t *testing.T) { t.Fatalf("expected getting proxied response: got %v", diff) } + // Check TokenParent + cachedItem, err := lc.db.Get(cachememdb.IndexNameToken, "testtoken") + if err != nil { + t.Fatal(err) + } + if cachedItem == nil { + t.Fatalf("expected token entry from cache") + } + if cachedItem.TokenParent != "autoauthtoken" { + t.Fatalf("unexpected value for tokenparent: %s", cachedItem.TokenParent) + } + // Modify the request a little bit to ensure the second response is // returned to the lease cache. sendReq = &SendRequest{