Invalidate _cachedId in all property setters that affect Id computation#240
Merged
Invalidate _cachedId in all property setters that affect Id computation#240
Conversation
…omprehensive unit tests Co-authored-by: jmprieur <13203188+jmprieur@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Invalidate cachedId in all relevant property setters
Invalidate _cachedId in all property setters that affect Id computation
Feb 3, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request ensures that the cached Id for CredentialDescription remains consistent when any property that participates in the Id computation is modified, and adds regression tests around that behavior. It closes a bug where _cachedId could become stale when certain properties were updated after first access.
Changes:
- Updated multiple
CredentialDescriptionproperties (KeyVaultUrl,KeyVaultCertificateName,Base64EncodedValue,CertificateDiskPath,CertificateStorePath,CertificateThumbprint,CertificateDistinguishedName,ManagedIdentityClientId,SignedAssertionFileDiskPath,CustomSignedAssertionProviderName,CustomSignedAssertionProviderData) to use backing fields and clear_cachedIdin their setters. - Left existing invalidation behavior for
Certificate,ClientSecret, andCachedValueintact while aligning patterns with the new properties. - Added 14 xUnit tests in
CredentialDescriptionIdTestto confirm that updating each relevant property causes theIdto change or otherwise reflect the new state.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Microsoft.Identity.Abstractions/ApplicationOptions/CredentialDescription.cs | Adds backing fields and cache invalidation to all properties whose values are used in CredentialDescription.Id, ensuring IDs are recomputed after mutations. |
| test/Microsoft.Identity.Abstractions.Tests/CredentialDescriptionIdTest.cs | Adds targeted unit tests for each property affecting Id, though the certificate-based test currently does not truly validate cache invalidation due to using two identical certificates. |
…ify cache invalidation Co-authored-by: jmprieur <13203188+jmprieur@users.noreply.github.com>
Contributor
Author
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Contributor
Author
bgavrilMS
approved these changes
Feb 3, 2026
jmprieur
approved these changes
Feb 3, 2026
saurabhsathe-ms
approved these changes
Feb 3, 2026
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.
Invalidate _cachedId in all property setters that affect Id computation
Analysis
Based on the
Idproperty getter, the following properties are used in computing the cached ID based on theSourceType:Certificate(already invalidates)CachedValue(already invalidates)ClientSecret(already invalidates)KeyVaultUrl(added invalidation)KeyVaultCertificateName(added invalidation)Base64EncodedValue(added invalidation)CertificateDiskPath(added invalidation)CertificateStorePath(added invalidation)CertificateThumbprint(added invalidation)CertificateDistinguishedName(added invalidation)ManagedIdentityClientId(added invalidation)SignedAssertionFileDiskPath(added invalidation)CustomSignedAssertionProviderName(added invalidation)CustomSignedAssertionProviderData(added invalidation)Changes Made
_cachedId = nullto all relevant property setters (10 properties updated)Summary
This PR fixes a bug where the cached
Idvalue could become stale if certain properties were modified after theIdwas first computed. All property setters that contribute to theIdcomputation now properly invalidate the cache by setting_cachedId = null. Comprehensive unit tests have been added to verify the fix.The
CachedId_InvalidatedWhen_Certificate_Changestest has been updated to properly verify cache invalidation by changing from a certificate to null, which produces different IDs and confirms the cache is recomputed.Fixes: Issue about _cachedId invalidation in CredentialDescription
Related PR: #238
Discussion: #238 (comment)
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.