8000 Create more validation tests for PUT/PATCH logic by mabartos · Pull Request #47282 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Create more validation tests for PUT/PATCH logic - #47282

Merged
vmuzikar merged 5 commits into
keycloak:mainfrom
mabartos:KC-47058
Mar 27, 2026
Merged

vmuzikar merged 5 commits into
keycloak:mainfrom
mabartos:KC-47058

Conversation

@mabartos
@mabartos mabartos commented Mar 19, 2026 •
Copy link
Copy Markdown
Member
  • Closes Create more validation tests for PUT/PATCH logic #47058
  • Number of tests increased from 19 to 99 🚀
  • There are many common tests that run automatically with POST/PUT/PATCH (bigger coverage)
  • Tests run with OIDC and SAML (bigger coverage)
  • Improving the error message for invalid type of field with PATCH
  • When the clientId is specified in the PATCH payload, it needs to be aligned with the path client ID
  • Added more tests for client-secret-based validations
  • Covering more corner cases

Based on my analysis, we should cover all validation rules for now.

@vmuzikar @edewit Could you please check it? Thanks!

@mabartos mabartos self-assigned this Mar 19, 2026
@mabartos
mabartos requested review from edewit and vmuzikar March 19, 2026 08:19
@mabartos mabartos added the team/admin-api-wg Admin API v2 Working Group label Mar 19, 2026
@mabartos
mabartos marked this pull request as ready for review March 19, 2026 08:19
@mabartos
mabartos requested review from a team as code owners March 19, 2026 08:19
@mabartos
mabartos requested a review from Copilot March 19, 2026 08:45
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR significantly expands validation test coverage for PUT/PATCH operations in the Keycloak Client Admin API v2. The test count increases from 19 to 99 tests by systematically testing validation rules across POST, PUT, and PATCH HTTP methods, with both OIDC and SAML client protocols. Additionally, the implementation improves error messages for PATCH operations when type mismatches occur and adds validation for clientId consistency in PATCH requests.

Changes:

  • Refactored monolithic validation test class into a composable hierarchy: AbstractClientValidationTest (base with common tests), PostClientValidationTest, PutClientValidationTest (extends abstract), and PatchClientValidationTest (extends PUT)
  • Enhanced DefaultClientService.patchClient() with improved error handling for invalid field types and clientId validation
  • Centralized setAuthHeader() method in AbstractClientApiV2Test to reduce code duplication across multiple test classes

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
AbstractClientValidationTest.java New abstract base class containing 14+ common validation test methods covering clientId, protocol, URL, collection element, and unknown field validations
PostClientValidationTest.java New concrete test class implementing POST method tests with UUID validation
PutClientValidationTest.java New concrete test class implementing PUT method tests including secret authentication validation
PatchClientValidationTest.java New concrete test class extending PUT tests, adding PATCH-specific tests and disabling inappropriate inherited tests
DefaultClientService.java Enhanced patchClient() with JsonMappingException handling for better error messages and clientId validation in PATCH payloads
AbstractClientApiV2Test.java Centralized setAuthHeader() method for test infrastructure reuse
ClientApiV2Test.java, ClientPoliciesV2Test.java, AdminEventV2Test.java Refactored to use centralized setAuthHeader() from parent class

You can also share your feedback on Copilot code review. Take the survey.

@mabartos
Copy link
Copy Markdown
Member Author

@vmuzikar Could you please check it? Thanks!

@vmuzikar vmuzikar left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mabartos Thank you for the PR!

@vmuzikar
Copy link
Copy Markdown
Contributor

This conflicts/overlaps with #47375. CC @edewit

@vmuzikar
Copy link
Copy Markdown
Contributor

@Pepo48 @shawkins @michalvavrik Can you please review as well?

@@ -263,6 +269,12 @@ public void deleteClient(RealmModel realm, String clientId) throws ServiceExcept
fireAdminEvent(OperationType.DELETE, client);
}

protected void assertSameClientIds(String pathId, String payloadId) {
if (!Objects.equals(pathId, payloadId)) {
@michalvavrik michalvavrik Mar 26, 2026 •
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If someone left the client id out of the patch, here payloadId would be "null" string. Maybe you could improve it to say something like "clientId cannot be removed via PATCH"?

@mabartos mabartos Mar 26, 2026 •
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Maybe also related to the required clientId? #47282 (comment)

As that might be done in a follow-up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@michalvavrik michalvavrik left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I didn't find a test that tries to change protocol from OIDC to SAML. I hope I didn't miss something, can you double-check, please?

@michalvavrik
Copy link
Copy Markdown
Member

Sorry, I didn't read existing comments first, it was already noted here #47282 so forget about it.

@mabartos
mabartos commented Mar 26, 2026 •
Copy link
Copy Markdown
Member Author

I didn't find a test that tries to change protocol from OIDC to SAML. I hope I didn't miss something, can you double-check, please?

@michalvavrik It's similar to this, and should be already fixed: #47282 (comment). I'll verify if we have it verified on the PUT as well.

@mabartos
mabartos marked this pull request as draft March 26, 2026 15:18
Closes keycloak#47058

Signed-off-by: Martin Bartoš <mabartos@redhat.com>
Signed-off-by: Martin Bartoš <mabartos@redhat.com>
Signed-off-by: Martin Bartoš <mabartos@redhat.com>
Signed-off-by: Martin Bartoš <mabartos@redhat.com>
Signed-off-by: Martin Bartoš <mabartos@redhat.com>
@mabartos
mabartos marked this pull request as ready for review March 27, 2026 12:48
@mabartos
Copy link
Copy Markdown
Member Author

@vmuzikar Can you review it again? Thanks!

@vmuzikar vmuzikar left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks for the updates.

@vmuzikar
vmuzikar merged commit a69f08f into keycloak:main Mar 27, 2026
85 checks passed
sashyo pushed a commit to tide-foundation/keycloak-IGA that referenced this pull request Jul 20, 2026
* Create more validation tests for PUT/PATCH logic

Closes keycloak#47058

Signed-off-by: Martin Bartoš <mabartos@redhat.com>

* Test for trying to change the protocol for existing client

Signed-off-by: Martin Bartoš <mabartos@redhat.com>

* PATCH tests do not extend PUT tests

Signed-off-by: Martin Bartoš <mabartos@redhat.com>

* Introduce the ProtocolUnmofidiedValidator

Signed-off-by: Martin Bartoš <mabartos@redhat.com>

* Accomodate changes for the protocol unmodified validator

Signed-off-by: Martin Bartoš <mabartos@redhat.com>

---------

Signed-off-by: Martin Bartoš <mabartos@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team/admin-api-wg Admin API v2 Working Group team/cloud-native

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create more validation tests for PUT/PATCH logic

6 participants

0