Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions test/extended/util/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,10 @@ func (c *CLI) TeardownProject() {
err := dynamicClient.Resource(resource.Resource).Namespace(resource.Namespace).Delete(context.Background(), resource.Name, metav1.DeleteOptions{})
framework.Logf("Deleted %v, err: %v", resource, err)
}
// Clear the slice so resources from this test do not accumulate and get
// redundantly re-attempted for deletion in subsequent tests that share the
// same CLI instance
c.resourcesToDelete = nil
}

// Verbose turns on printing verbose messages when executing OpenShift commands
Expand Down Expand Up @@ -1195,18 +1199,25 @@ func (c *CLI) GetClientConfigForUser(username string) *rest.Config {
}

privToken, pubToken := GenerateOAuthTokenPair()
token, err := oauthClient.OauthV1().OAuthAccessTokens().Create(ctx, &oauthv1.OAuthAccessToken{
_, err = oauthClient.OauthV1().OAuthAccessTokens().Create(ctx, &oauthv1.OAuthAccessToken{
ObjectMeta: metav1.ObjectMeta{Name: pubToken},
ClientName: oauthClientName,
UserName: username,
UserUID: string(user.UID),
Scopes: []string{"user:full"},
RedirectURI: "https://localhost:8443/oauth/token/implicit",
ExpiresIn: 86400, // 24 h TTL; auto-expires without explicit deletion
}, metav1.CreateOptions{})
if err != nil {
FatalErr(err)
}
c.AddResourceToDelete(oauthv1.GroupVersion.WithResource("oauthaccesstokens"), token)
// The token is intentionally not added to resourcesToDelete.
// TeardownProject runs as an AfterEach, which fires before the framework's
// DeferCleanup (namespace deletion). Deleting the token there invalidates
// the bearer token in any DeferCleanup that still needs to authenticate as
// this user. The User deletion (registered above) makes the token
// effectively unusable for auth anyway, and ExpiresIn ensures it is
// eventually cleaned up by the OAuth token controller.

userClientConfig := rest.AnonymousClientConfig(turnOffRateLimiting(rest.CopyConfig(c.AdminConfig())))
userClientConfig.BearerToken = privToken
Expand Down