Skip to content

#62774 Fix JWT Bearer unit tests failing if local timezone is UTC+N #62775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 31, 2025

Conversation

navferty
Copy link
Contributor

Tests were failing if local timezone is to the east of UTC, due to DateTime.MaxValue is locale-specific. Add explicit DateTimeKind UTC and immediate conversion to UTC when parsing, since this time is unrepresentable in local timezone

Fixes #62774

…TC+N

Tests were failing if local timezone is to the east of UTC, due to DateTime.MaxValue is locale-specific. Add explicit DateTimeKind UTC and immediate conversion to UTC when parsing, since this time is unrepresentable in local timezone
@Copilot Copilot AI review requested due to automatic review settings July 17, 2025 13:58
@navferty navferty requested a review from halter73 as a code owner July 17, 2025 13:58
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jul 17, 2025
@github-actions github-actions bot added the area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer label Jul 17, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes JWT Bearer unit tests that were failing when run in timezones east of UTC (UTC+N). The issue occurred because DateTime.MaxValue is locale-specific, causing test failures in certain timezone configurations.

Key changes:

  • Explicitly set DateTimeKind.Utc when creating JWT tokens with DateTime.MaxValue expiration
  • Simplified DateTime parsing to directly convert to UTC using DateTimeStyles.AdjustToUniversal

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Security/Authentication/test/JwtBearerTests_Handler.cs Updated JWT token creation and DateTime parsing to use explicit UTC handling
src/Security/Authentication/test/JwtBearerTests.cs Applied identical fixes for JWT token creation and DateTime parsing consistency

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

Thanks!

@halter73 halter73 enabled auto-merge (squash) July 31, 2025 01:42
@halter73
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@halter73 halter73 merged commit 7296d4d into dotnet:main Jul 31, 2025
32 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-rc1 milestone Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Some Jwt Bearer unit tests are failing in specific local time zones
2 participants