-
Notifications
You must be signed in to change notification settings - Fork 8.1k
added better validation and more validation tests #46277
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| import org.keycloak.services.resources.admin.ClientResource; | ||
| import org.keycloak.services.resources.admin.ClientsResource; | ||
| import org.keycloak.services.resources.admin.RealmAdminResource; | ||
| import org.keycloak.validation.ValidationUtil; | ||
| import org.keycloak.validation.jakarta.HibernateValidatorProvider; | ||
| import org.keycloak.validation.jakarta.JakartaValidatorProvider; | ||
|
|
||
|
|
@@ -98,6 +99,12 @@ public CreateOrUpdateResult createOrUpdate(RealmModel realm, BaseClientRepresent | |
| clientResource = clientsResource.getClient(model.getId()); | ||
|
|
||
| mapper.toModel(client, model); | ||
|
|
||
| // Validate the fully populated model (createClientModel only validates the basic model) | ||
| ValidationUtil.validateClient(session, model, true, r -> { | ||
| session.getTransactionManager().setRollbackOnly(); | ||
| throw new ServiceException(r.getAllErrorsAsString(), Response.Status.BAD_REQUEST); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the v1, we use localized errors, but I think it does not have to be here for now as we don't have propagated the Auth context in the service. So, +1 to keep this instead of the localized messages for now. |
||
| }); | ||
| } | ||
|
|
||
| handleRoles(client.getRoles()); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned, we lack of the validation for the update. Thus, we're missing some test cases for update. Bonus: It'd be good to abstract/generalize a little bit these test cases to avoid the duplication. |
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.
It is needed also for the update... See here: https://github.com/keycloak/keycloak/blob/main/services/src/main/java/org/keycloak/services/resources/admin/ClientResource.java#L162
Would it be possible to move this validation at the end of the method, where you set the third boolean param to mark if it's create or update op?
Uh oh!
There was an error while loading. Please reload this page.
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.
but the code you show there is executed already form DefaultClientService
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.
@edewit Ahh, sorry, you're right. So, please prepare the missing tests for the update. Thanks!