Skip to content

fix: ImpersonatedCredentials does not use Calendar for expiration#1908

Open
lqiu96 wants to merge 6 commits intomainfrom
transient-fix
Open

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

Conversation

@lqiu96
Copy link
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
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
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?

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

Copy link
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
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?

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
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?

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