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{