-
Notifications
You must be signed in to change notification settings - Fork 6k
getClaimAsBoolean() should not be falsy #10151
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the submission @ahmedmq! One minor comment is below, and you can squash your changes and force push to the same branch.
oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/ClaimAccessor.java
Outdated
Show resolved
Hide resolved
@sjohnr - Not sure what has gone wrong, it ran all tests successfully before pushing |
@ahmedmq, you'll need to rebase on
|
@ahmedmq, are you able to rebase on |
Closes spring-projectsgh-10148 Remove comment as per PR review
@sjohnr - I am not sure of the expected behaviour when the claimValue is null. For e.g in the test case
Since in the above the claimValue is null, what should the boolean converter return? Should it return false by default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahmedmq, thanks for updating the PR. The implementation of the converter looks correct with your changes applied based on #10148. Meaning, it would now return an IllegalArgumentException
, so I would expect the test you mentioned to need to change. This change will break passivity, and so will go in the 5.6 release.
Also, please see below feedback inline.
@@ -135,4 +136,13 @@ public void getClaimWhenValueIsNotConvertedThenThrowClassCastException() { | |||
assertThatObject(this.claimAccessor.getClaim(claimName)).isNotInstanceOf(Boolean.class); | |||
} | |||
|
|||
// gh-10148 | |||
@Test | |||
public void getClaimAsBooleanThrowsIllegalArgumentForNonBooleanType() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to include When
for the condition set up by the test, e.g. getClaimAsBooleanWhenNonBooleanTypeThenThrowsIllegalArgumentException
.
} | ||
Object claimValue = getClaims().get(claim); | ||
Boolean convertedValue = ClaimConversionService.getSharedInstance().convert(claimValue, Boolean.class); | ||
Assert.isTrue(convertedValue != null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use Assert.isNotNull
here? Looks like other checks in this class don't do that, however, which is fine for now.
@ahmedmq did you have a chance to review the above feedback? |
Hi @sjohnr, I can work on this PR? Actually, I was just about to finish it. |
Closing in favor of #10356. |
Closes #10148