Skip to content

fix: correct token expiration and JSON parsing bugs in XSUAA client - #5819

Open
o-liver wants to merge 2 commits into
masterfrom
fix/xsuaa-token-expiration-and-json-parsing
Open

fix: correct token expiration and JSON parsing bugs in XSUAA client#5819
o-liver wants to merge 2 commits into
masterfrom
fix/xsuaa-token-expiration-and-json-parsing

Conversation

@o-liver

@o-liver o-liver commented Jul 6, 2026

Copy link
Copy Markdown
Member

Description

Fixes two critical bugs in the XSUAA OAuth2 client that prevent proper token refreshing and error handling.

Bugs Fixed

  1. Token expiration logic (line 46): Removed secondsOfValidityLeft > 0 check that prevented expired tokens from being refreshed. When a token expires, secondsOfValidityLeft becomes negative, and the old condition secondsOfValidityLeft > 0 && secondsOfValidityLeft < oneHourInSeconds would never be true for expired tokens, causing them to never refresh.

  2. JSON parsing error check (line 98): Changed if err != nil to if parsingErr != nil. The original code checked the wrong variable, silently ignoring JSON unmarshal failures and only catching earlier HTTP errors.

Impact

These bugs could cause:

  • Bug 1: Authentication failures when tokens expire, requiring service restarts
  • Bug 2: Silent failures when XSUAA returns malformed JSON, making debugging difficult

Changes

- if len(x.CachedAuthToken.AccessToken) == 0 ||
-     (secondsOfValidityLeft > 0 && secondsOfValidityLeft < oneHourInSeconds) {
+ if len(x.CachedAuthToken.AccessToken) == 0 ||
+     secondsOfValidityLeft < oneHourInSeconds {

- if err != nil {
+ if parsingErr != nil {

Testing

Unit tests pass. The fixes ensure:

  • Expired tokens (negative secondsOfValidityLeft) trigger refresh
  • JSON parsing errors are properly caught and returned

Related

These fixes were discovered during migration of the ANS/XSUAA packages to the tekton-logging-shim: https://github.tools.sap/cloudci/tekton-logging-shim/pull/81

Co-Authored-By: Claude <noreply@anthropic.com>
@o-liver
o-liver requested a review from a team as a code owner July 6, 2026 14:08
@o-liver

o-liver commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

/go-it

@o-liver
o-liver enabled auto-merge (squash) July 6, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant