Skip to content
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

Fix Flaky Tests: NameAndRoleClaimDelegates and RoleClaims #2873

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

kellyyangsong
Copy link
Contributor

See explanation here.

Fixes #2841

@kellyyangsong kellyyangsong requested a review from a team as a code owner October 3, 2024 22:55
Copy link
Collaborator

@jennyf19 jennyf19 left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up!

@@ -112,6 +112,10 @@ public bool MapInboundClaims
if (!_mapInboundClaims && value && _inboundClaimTypeMap.Count == 0)
_inboundClaimTypeMap = new Dictionary<string, string>(DefaultInboundClaimTypeMap);

// If the inbound claim type mapping is on and being turned off, make sure that the _inboundClaimTypeMap is empty.
if (_mapInboundClaims && !value && _inboundClaimTypeMap.Count > 0)
_inboundClaimTypeMap.Clear();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is logically what I believe should happen - but is there a reason why we didn't have this before?

Copy link
Contributor

Choose a reason for hiding this comment

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

Quick thought: _mapInboundClaims flag should be checked if it's true before map is used. If it's false, the map should never be used. So this should not be needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have the same behavior in JsonWebTokenHandler?

Copy link
Contributor

Choose a reason for hiding this comment

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

The test tests that the constructor of JwtSecurityTokenHandler sets up the map or not depending if the static flag DefaultMapInboundClaims was set or not; then it also checks if setting MapInboundClaims property initializes the map list.

Both MapInboundClaims and InboundClaimTypeMap are public. In our code we check the flag first before using the map. There are a couple of usage scenarios.

  1. MapInboundClaims is false and InboundClaimTypeMap is empty. Set flag to true. This will initialize the map to the default map values, which makes sense since we don't know if the map will be explicitly initialized, so we set it to default. The map can still be overwritten to non-default values.
  2. InboundClaimTypeMap is set to custom values. MapInboundClaims is set to true. This will not reset the map to default values because it already as values.
  3. InboundClaimTypeMap is set to custom values. MapInboundClaims is set to true, then set to false. With the previous code, the map will not be cleared and when the flag is set to true, custom values will remain. With updated code, the custom values will be cleared, and when the flag is set to true, map will be set to default values. This is the possible breaking change. Probably unlikely but still.

So I would only update the test to reset DefaultMapInboundClaims to true (default) and move it and add a collection attribute to it.

@jennyf19 jennyf19 added this to the 8.2.0 milestone Oct 4, 2024
Copy link
Contributor

@pmaytak pmaytak left a comment

Choose a reason for hiding this comment

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

This may be a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants