-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Failing tests:
Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerTests.ExpirationAndIssuedWhenMinOrMaxValue
Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerTests_Handler.ExpirationAndIssuedWhenMinOrMaxValue
Some unit tests in Identity are failing if local timezone on developer's machine is to the east of UTC, due to DateTime.MaxValue is locale-specific. For example, if my local machine is at UTC+4, the exp
value written to generated JWT is 253402286400
(which stands for 9999-12-31T20:00:00.0000000Z
), while expected value was 253402300800
(standing for 9999-12-31T23:59:59.9999999Z
). If I set local time zone for UTC or any "UTC-minus-N" timezone, the value written to JWT is expected and same for any such time zone.
Need to add explicit DateTimeKind UTC and immediate conversion to UTC when parsing, since the actual time value (9999T23:59:59+00
) is unrepresentable in local timezone.
Expected Behavior
No response
Steps To Reproduce
Run tests with local time zone "UTC plus N", for example UTC+4
Exceptions (if any)
Test JwtBearerTests_Handler.ExpirationAndIssuedWhenMinOrMaxValue
error:
Message:
System.FormatException : The DateTime represented by the string '9999-12-31T20:00:00+00:00' is out of range.
Stack Trace:
DateTimeParse.Parse(ReadOnlySpan`1 s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
DateTime.Parse(String s, IFormatProvider provider)
JwtBearerTests_Handler.ExpirationAndIssuedWhenMinOrMaxValue() line 947
Test JwtBearerTests.ExpirationAndIssuedWhenMinOrMaxValue
error:
Message:
System.FormatException : The DateTime represented by the string '9999-12-31T20:00:00+00:00' is out of range.
Stack Trace:
DateTimeParse.Parse(ReadOnlySpan`1 s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
DateTime.Parse(String s, IFormatProvider provider)
JwtBearerTests.ExpirationAndIssuedWhenMinOrMaxValue() line 1003
.NET Version
No response
Anything else?
No response