Fix incorrect expiry check in ConfigureCrmServerSideSync.ps1 - #816
Open
Anwarul Haq (Anwarluck) wants to merge 1 commit into
Open
Conversation
endDateTime comes back from the Graph API response as a string, while currentDateTime is a DateTime object. Comparing them with -lt coerces the DateTime to a string and does a lexicographic comparison instead of an actual date comparison, so expired certificates can be missed (or valid ones flagged as expired) depending on how the two string representations happen to sort. Cast endDateTime to DateTime before comparing. Fixes microsoft#797
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #797
endDateTimeon the service principal credential comes back from the Graph API response as a string (e.g.2024-05-01T00:00:00Z), but$currentDateTimeis aDateTimeobject fromGet-Date. When you compare a string to a DateTime with-lt, PowerShell converts the right-hand side to match the type of the left-hand side, so this ends up doing a lexicographic string comparison instead of an actual date comparison. Depending on the string formats involved, that can miss certificates that are genuinely expired, or flag ones that aren't.The fix casts
endDateTimeto[DateTime]before the comparison, same as$certificateInfo.NotAftera few lines above it, which is already a proper DateTime and compares correctly.Left the
Write-Outputline below it using the raw string value on purpose — that's just for the log message and reads better as the original ISO timestamp.