8000 Add SAML broker regression tests for incomplete subject confirmation by atiqur-rahman-pro · Pull Request #54075 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

Add SAML broker regression tests for incomplete subject confirmation - #54075

Merged
pedroigor merged 2 commits into
keycloak:mainfrom
atiqur-rahman-pro:fix/saml-broker-subject-confirmation-tests-54066
Oct 28, 2026
Merged

pedroigor merged 2 commits into
keycloak:mainfrom
atiqur-rahman-pro:fix/saml-broker-subject-confirmation-tests-54066

Conversation

@atiqur-rahman-pro
@atiqur-rahman-pro atiqur-rahman-pro commented Oct 17, 2026 •
Copy link
Copy Markdown
Contributor

Closes #54066

Adds broker-level regression tests for SAML assertions missing a Subject, Bearer SubjectConfirmation, SubjectConfirmationData, NotOnOrAfter, or Recipient.

A focused test helper intercepts the IdP response, modifies the assertion, and submits it to the broker endpoint. Each case verifies rejection with HTTP 400.

Validation

  • The five runtime integration tests passed before the latest no-response guard was added.
  • The final commit has not been rerun locally because Maven could not access the local .m2 repository; CI will validate it.
  • git diff --check passed.

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.

🟡 Changes recommended

The helper bypasses framework-managed certificates, causing HTTPS runs to fail before testing SAML validation.

1 open issue
What changed in this PR

Adds broker-level SAML regression coverage for #54066 in the new test suite.

Changes:

  • Introduces an HTTP helper that intercepts and modifies IdP assertions.
  • Adds five tests checking rejection of missing subject-confirmation elements or attributes.
File Description
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​broker/​saml/​SamlBrokerResponseTampering.java Drives login and mutates SAML responses.
tests/​base/​src/​test/​java/​org/​keycloak/​tests/​broker/​saml/​KcSamlBrokerTest.java Verifies malformed responses return HTTP 400 and “Invalid requester”.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 17, 2026 09:47
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.

🟢 Approval recommended

The focused test-only changes address the requested regression coverage, with no blocking issues identified.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@atiqur-rahman-pro
Copy link
Copy Markdown
Contributor Author

Hi @sguilhen, this PR adds broker-level regression tests for #54066.
All CI checks have passed successfully — looking forward to your feedback.

import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;
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.

nit: consider jsoup instead of javax.swing.text.html for form parsing

parseForms/attribute here use javax.swing.text.html.HTMLEditorKit.ParserCallback + ParserDelegator to scrape the auto-submit login/SAML forms. That's Swing's GUI HTML renderer, not a general-purpose HTML parser and using it here pulls java.desktop into a server test module for something it wasn't designed to do, and it's quirky/under-documented for edge cases.

The legacy suite already solves this exact problem SamlClient/ModifySamlResponseStepBuilder extracting an auto-submit SAMLResponse form) using jsoup, which is purpose-built for this. It's not currently a dependency of tests/base/tests/pom.xml, but adding it as a test-scope dependency and swapping the ParserDelegator callback for Jsoup.parse(html).select("form") would be a small, mechanical change that doesn't touch the HTTP-client or SAML-mutation logic, and keeps the new testsuite's SAML tooling aligned with the legacy convention it's replacing.

Copilot AI balanced review requested due to automatic review settings October 20, 2026 23:21
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.

🟢 Approval recommended

The focused, test-only changes cover the requested scenarios with no unresolved findings.

No open issues 🎉

Review effort: Balanced

@atiqur-rahman-pro
Copy link
Copy Markdown
Contributor Author

Hi @sguilhen , Thanks for the suggestion. I have replaced the Swing parser with jsoup and added it as a test dependency. All five SAML regression tests have completed successfully.

@sguilhen sguilhen 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.

Thanks one more time for the contribution, @atiqur-rahman-pro . LGTM!

Comment thread tests/base/pom.xml Outdated
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.23.1</version>
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.

What is the reasoning behind the new dependency? Also, it does not follow the same definition as other dependencies; managed dependency + version property.

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.

Same dependency exists in the legacy testsuite for SAML tests that need to manipulate the response

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.

Do you mean docs/documentation/tests/pom.xml. This is not the legacy test suite. AFAIK, versions are not explicitly set for individual dependencies either.

If we really need to add this dependency, we should probably talk first with @lhanusov.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification, @pedroigor. I meant tests/base, where SamlBrokerResponseTampering uses jsoup to parse the IdP auto-submit form. I mentioned the legacy suite only as a precedent for parsing and modifying SAML responses, not as the target module.

I understand that adding jsoup to the new test suite needs discussion. @lhanusov, could you advise whether this dependency is acceptable here? If not, I can keep the existing parser approach.

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.

@pedroigor No, I meant the Arquillian testsuite. jsoup is used there in SamlClient and ModifySamlResponseStepBuilder, which is the exact "intercept the auto-submit form and rewrite SAMLResponse" pattern this PR reproduces, plus LoginBuilder, OtpLoginBuilder, UpdateProfileBuilder, RequiredConsentBuilder and a few tests. It doesn't show up in a pom grep because legacy never declares it, it comes in transitively via arquillian-browser-screenshooter

That said, your concern is fair: tests/base has no jsoup today (I checked with dependency:tree), so this is a genuinely new declared dependency rather than an inherited one, and that is worth @lhanusov's input.

One alternative if we would rather not add it: tests/base already pulls org.htmlunit:htmlunit + neko-htmlunit transitively through keycloak-test-framework-ui, so the form parsing could be done with that instead. It is the same trade legacy made though, depending on something undeclared.

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.

@sguilhen @atiqur-rahman-pro Sorry, I missed it. I'll check with Lukas.

Copilot AI balanced review requested due to automatic review settings October 22, 2026 14:40
@atiqur-rahman-pro
atiqur-rahman-pro force-pushed the fix/saml-broker-subject-confirmation-tests-54066 branch from 7a3e03f to 60b8c58 Compare October 22, 2026 14:40
@atiqur-rahman-pro
Copy link
Copy Markdown
Contributor Author

Thanks, @sguilhen, for clarifying the use case. The helper uses jsoup to parse the IdP auto-submit form and modify the SAML response, consistent with the legacy test suite.

@pedroigor, I’ve updated the dependency to follow Keycloak’s conventions: its version is defined as a root POM property and managed through dependencyManagement, while tests/base/pom.xml keeps it test-scoped.

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.

🟢 Approval recommended

No blocking issues were identified in the focused test changes, and the PR reports all five regression tests passing.

No open issues 🎉

Review effort: Balanced

@lhanusov lhanusov 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.

@sguilhen @atiqur-rahman-pro @pedroigor I suggest to extend the new framework’s SamlClient (class) with the response-processing capabilities needed here, following the legacy processSamlResponse(...).transformDocument(...) pattern. This helper introduces a separate login/form/redirect driver for five assertion mutations, which is not optimal. Jsoup is reasonable for HTML parsing, but the reusable flow handling should live in the SAML test utilities.

Missing pieces for SamlClientBuilder, SamlClient are in Arquillian -> https://github.com/keycloak/keycloak/blob/main/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/SamlClient.java

@lhanusov
Copy link
Copy Markdown
Contributor

@pskopek may I ask you for your suggestion as well? thanks :+1

@sguilhen
Copy link
Copy Markdown
Contributor

@sguilhen @atiqur-rahman-pro @pedroigor I suggest to extend the new framework’s SamlClient (class) with the response-processing capabilities needed here, following the legacy processSamlResponse(...).transformDocument(...) pattern. This helper introduces a separate login/form/redirect driver for five assertion mutations, which is not optimal. Jsoup is reasonable for HTML parsing, but the reusable flow handling should live in the SAML test utilities.

Missing pieces for SamlClientBuilder, SamlClient are in Arquillian -> https://github.com/keycloak/keycloak/blob/main/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/util/SamlClient.java

Thanks for the input, @lhanusov

@atiqur-rahman-pro
Copy link
Copy Markdown
Contributor Author

Thanks for the review and suggestion @lhanusov! I'll wait to see if @pskopek has any additional thoughts on the design.

@pskopek
pskopek commented Oct 27, 2026
Copy link
Copy Markdown
Contributor

@pskopek may I ask you for your suggestion as well? thanks :+1

@lhanusov this is a good suggestion.
@atiqur-rahman-pro I recommend to implement needed mutations using SamlClient Lukas suggested.

@atiqur-rahman-pro
Copy link
Copy Markdown
Contributor Author

Thank you so much @pskopek and @lhanusov for the confirmation! I will refactor the PR to extend the new test framework's SamlClient with processSamlResponse / transformDocument and update the regression tests accordingly.

Copilot AI balanced review requested due to automatic review settings October 27, 2026 15:50
@atiqur-rahman-pro
atiqur-rahman-pro force-pushed the fix/saml-broker-subject-confirmation-tests-54066 branch from 5c6185e to 3f69a5c Compare October 27, 2026 15:57
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.

Copilot AI balanced review requested due to automatic review settings October 27, 2026 16:07
@atiqur-rahman-pro
atiqur-rahman-pro force-pushed the fix/saml-broker-subject-confirmation-tests-54066 branch 2 times, most recently from e0967ee to ce189fb Compare October 27, 2026 16:17
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.

Comment on lines +57 to +69
private void assertInvalidSamlResponse(Consumer<Document> mutator) throws Exception {
new SamlClientBuilder(certificates)
.navigateTo(oauth.loginForm().param("kc_idp_hint", IDP_SAML_ALIAS).build())
.processSamlResponse(SamlClient.Binding.POST)
.targetAttributeSamlRequest()
.build()
.login().user(getUserLogin(), getUserPassword()).build()
.processSamlResponse(SamlClient.Binding.POST)
.transformDocument(mutator)
.build()
.execute(response -> {
String body = "";
try {
Copilot AI balanced review requested due to automatic review settings October 27, 2026 16:25
@atiqur-rahman-pro
atiqur-rahman-pro force-pushed the fix/saml-broker-subject-confirmation-tests-54066 branch from ce189fb to f038807 Compare October 27, 2026 16:26
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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

15 open issues

Review effort: Lite

Comment on lines +57 to +69
private void assertInvalidSamlResponse(Consumer<Document> mutator) throws Exception {
new SamlClientBuilder(certificates)
.navigateTo(oauth.loginForm().param("kc_idp_hint", IDP_SAML_ALIAS).build())
.processSamlResponse(SamlClient.Binding.POST)
.targetAttributeSamlRequest()
.build()
.login().user(getUserLogin(), getUserPassword()).build()
.processSamlResponse(SamlClient.Binding.POST)
.transformDocument(mutator)
.build()
.execute(response -> assertEquals(400, response.getStatusLine().getStatusCode(),
"Malformed broker SAML response should be rejected"));
}
Copilot AI balanced review requested due to automatic review settings October 27, 2026 16:42
Add a test framework SAML client pipeline for mutating broker responses and cover missing or incomplete bearer subject confirmations. Configure managed certificates for HTTPS tests and parse auto-submit forms with jsoup.

Closes keycloak#54066

Signed-off-by: Atiqur Rahman <rahman.atiqur.pro@gmail.com>
@atiqur-rahman-pro
atiqur-rahman-pro force-pushed the fix/saml-broker-subject-confirmation-tests-54066 branch from f038807 to c086558 Compare October 27, 2026 16: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.

🟢 Approval recommended

No blocking issues were identified in the focused test infrastructure and regression coverage; final runtime validation remains for CI.

3 open issues
12 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 27, 2026 16:53
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.

10BC8

🟢 Approval recommended

No blocking issues were identified in the test-only changes, though CI validation of the final no-response guard remains pending.

2 open issues
1 resolved since last review

Review effort: Balanced

@atiqur-rahman-pro
Copy link
Copy Markdown
Contributor Author

Hi @pedroigor, @lhanusov I’ve refactored the tests to use SamlClientBuilder and aligned the flow with the new test framework. Could you please review the latest changes when you have a chance?

@pedroigor pedroigor 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.

@pedroigor
pedroigor dismissed lhanusov’s stale review October 28, 2026 13:26

Comments addressed as now we have the SamlClient updated and based on the existing capabilities from the old test suite.

@pedroigor
pedroigor merged commit 951c285 into keycloak:main Oct 28, 2026
101 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add regression tests for missing/incomplete Bearer SubjectConfirmationData in SAML broker login

6 participants

0