Set TokenParent in the Index to be cached (#10833)

Co-authored-by: Calvin Leung Huang <cleung2010@gmail.com>
This commit is contained in:
Theron Voran 2021-02-03 18:30:41 -08:00 committed by GitHub
parent b1c4b86d7f
commit c62ce48b5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

3
changelog/10833.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
agent: Set TokenParent correctly in the Index to be cached.
```

View File

@ -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)

View File

@ -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{