Skip to content

fix: ImpersonatedCredentials does not use Calendar for expiration#1908

Merged
lqiu96 merged 6 commits intomainfrom
transient-fix
Mar 26, 2026
Merged

fix: ImpersonatedCredentials does not use Calendar for expiration#1908
lqiu96 merged 6 commits intomainfrom
transient-fix

Conversation

@lqiu96
Copy link
Copy Markdown
Member

@lqiu96 lqiu96 commented Mar 24, 2026

See b/423905355 for more information.

Previously seen issues where calendar (marked transient) results in NPE when serializing a credential

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Mar 24, 2026
@lqiu96 lqiu96 requested a review from diegomarquezp March 25, 2026 18:57
@lqiu96 lqiu96 marked this pull request as ready for review March 25, 2026 18:58
@lqiu96 lqiu96 requested review from a team as code owners March 25, 2026 18:58
Comment on lines -656 to -664
@Test
void refreshAccessToken_GMT_dateParsedCorrectly() throws IOException, IllegalStateException {
Calendar c = Calendar.getInstance();
c.add(Calendar.SECOND, VALID_LIFETIME);

mockTransportFactory.getTransport().setTargetPrincipal(IMPERSONATED_CLIENT_EMAIL);
mockTransportFactory.getTransport().setAccessToken(ACCESS_TOKEN);
mockTransportFactory.getTransport().setExpireTime(getFormattedTime(c.getTime()));
mockTransportFactory.getTransport().addStatusCodeAndMessage(HttpStatusCodes.STATUS_CODE_OK, "");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed old tests that reference the obsolete api (setting custom calendar)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq: Are there still use cases where calendar may be used without serializing and deserializing the credentials?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not as far as I know. A code search through the repo shows that it's really only used for computing the expire time with the correct timezone offset.

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Copy link
Copy Markdown
Contributor

@diegomarquezp diegomarquezp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, added a couple of questions.

expirationInstant =
Instant.from(
DateTimeFormatter.ISO_INSTANT
.withZone(calendar.getTimeZone().toZoneId())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC the only effect of the calendar parameter is to change the formatter's timezone. Does that affect the effective expiration instant in the end, or is it just format?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not affect the effective expire time. The expireTime represents a moment in time, however, it may be a moment of time represented in a different time zone. This change is to ensure that we do not assume that it is always in Zulu time (e.g. account for offsets like +02:00)

Comment on lines -656 to -664
@Test
void refreshAccessToken_GMT_dateParsedCorrectly() throws IOException, IllegalStateException {
Calendar c = Calendar.getInstance();
c.add(Calendar.SECOND, VALID_LIFETIME);

mockTransportFactory.getTransport().setTargetPrincipal(IMPERSONATED_CLIENT_EMAIL);
mockTransportFactory.getTransport().setAccessToken(ACCESS_TOKEN);
mockTransportFactory.getTransport().setExpireTime(getFormattedTime(c.getTime()));
mockTransportFactory.getTransport().addStatusCodeAndMessage(HttpStatusCodes.STATUS_CODE_OK, "");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qq: Are there still use cases where calendar may be used without serializing and deserializing the credentials?

@lqiu96 lqiu96 merged commit 0f92593 into main Mar 26, 2026
39 of 41 checks passed
@lqiu96 lqiu96 deleted the transient-fix branch March 26, 2026 19:02
lqiu96 added a commit to googleapis/google-cloud-java that referenced this pull request Apr 1, 2026
)

* chore: Add ObsoleteApi annotation

* chore: Add tests for serializing ImpersonatedCredentials

* chore: Restore old code

* chore: Update error message

* chore: Fix failing test issue

* chore: Remove old tests referecing obsolete api functionality

Original-PR: googleapis/google-auth-library-java#1908
lqiu96 added a commit to googleapis/google-cloud-java that referenced this pull request Apr 1, 2026
)

* chore: Add ObsoleteApi annotation

* chore: Add tests for serializing ImpersonatedCredentials

* chore: Restore old code

* chore: Update error message

* chore: Fix failing test issue

* chore: Remove old tests referecing obsolete api functionality

Original-PR: googleapis/google-auth-library-java#1908
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants