Skip to content

Migrate ssl package to new test framework#48407

Merged
vmuzikar merged 1 commit into
keycloak:mainfrom
michalvavrik:chore/issues/47812
May 11, 2026
Merged

Migrate ssl package to new test framework#48407
vmuzikar merged 1 commit into
keycloak:mainfrom
michalvavrik:chore/issues/47812

Conversation

@michalvavrik
Copy link
Copy Markdown
Member

@michalvavrik michalvavrik commented Apr 23, 2026

  • Closes: Migrate ssl package to new test framework #47812
  • As far as the email goes, I thought it would be better to avoid adding extra dependency (SubEthaSmtp) to the new test framework for the SMTPS feature that only tests added in this PR are using. So I turned around the paradigm (change truststore on the server side, not keystore on the mail server side). I believe all the original scenarios are tested, you can compare it yourself:
Old test method New test
test01VerifyEmailWithSslWrongCertificate EmailUntrustedCertTest#testVerifyEmailWithUntrustedCert
test02VerifyEmailWithSslWrongCertificateAndAnyHostnamePolicy EmailUntrustedCertAnyHostnameTest#testEmailSucceedsWithSslAndAnyHostnamePolicyDespiteEmptyTruststore due to #48407 (comment)
test03erifyEmailWithSslWrongHostname EmailTest#testVerifyEmailWithSslWrongHostname
test04VerifyEmailWithSslEnabled EmailTest#testVerifyEmailWithSslEnabled
test05VerifyEmailWithSslWrongHostnameButAnyHostnamePolicy EmailAnyHostnameTest#testVerifyEmailWithSslWrongHostnameSucceeds
test06VerifyEmailOpportunisticEncryptionWithAnyHostnamePolicy EmailPlainAuthTest#testVerifyEmailWithPlainSmtpAuth

Copy link
Copy Markdown

@keycloak-github-bot keycloak-github-bot Bot left a comment

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.authz.PolicyEvaluationTest#

Keycloak CI - Base IT (3)

org.opentest4j.AssertionFailedError: expected: <PERMIT> but was: <null>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
...
org.opentest4j.AssertionFailedError: expected: <PERMIT> but was: <null>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
...
org.opentest4j.AssertionFailedError: expected: <PERMIT> but was: <null>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
...

Report flaky test

@michalvavrik michalvavrik marked this pull request as draft April 23, 2026 14:52
@michalvavrik michalvavrik marked this pull request as ready for review April 23, 2026 16:59
Copy link
Copy Markdown

@keycloak-github-bot keycloak-github-bot Bot left a comment

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.authz.PolicyEvaluationTest#

Keycloak CI - Base IT (3)

org.opentest4j.AssertionFailedError: expected: <PERMIT> but was: <null>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
...
org.opentest4j.AssertionFailedError: expected: <PERMIT> but was: <null>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
...
org.opentest4j.AssertionFailedError: expected: <PERMIT> but was: <null>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
...

Report flaky test

@vmuzikar
Copy link
Copy Markdown
Contributor

vmuzikar commented May 6, 2026

@shawkins Could you please review and merge this?

@vmuzikar vmuzikar requested a review from shawkins May 6, 2026 16:23
@vmuzikar vmuzikar removed their request for review May 6, 2026 16:23
@vmuzikar
Copy link
Copy Markdown
Contributor

vmuzikar commented May 6, 2026

@michalvavrik Can you please rebase?

@michalvavrik michalvavrik force-pushed the chore/issues/47812 branch from 6158ce0 to 9c94801 Compare May 6, 2026 18:59
@michalvavrik
Copy link
Copy Markdown
Member Author

@michalvavrik Can you please rebase?

done

@shawkins
Copy link
Copy Markdown
Contributor

shawkins commented May 7, 2026

Will this need to align to #48785

@michalvavrik
Copy link
Copy Markdown
Member Author

Will this need to align to #48785

This PR has been opened for 2 weeks +, while #48785 has been opened for 5 hours and is still draft. Why don't they align with this PR?

@michalvavrik
Copy link
Copy Markdown
Member Author

AFAICT it will still work, there will just be some merge conflicts.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Migrates the legacy Arquillian-based ssl tests to the new test framework, moving coverage for SMTP(S) truststore/hostname verification and ssl-required behavior into tests/base and wiring the new package into the JUnit suite.

Changes:

  • Removed legacy Arquillian SSL tests and suite entries (testsuite/.../ssl, base-suite, fips-suite).
  • Added new org.keycloak.tests.ssl test package (email over SMTPS + hostname policy scenarios, and ssl-required HTTP/TLS behavior).
  • Added SSL test resources (SMTP server cert PEM) and registered the new test package in Base2TestSuite.

Reviewed changes

Copilot reviewed 13 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
testsuite/integration-arquillian/tests/base/testsuites/fips-suite Removes legacy TrustStoreEmailTest from FIPS suite list.
testsuite/integration-arquillian/tests/base/testsuites/base-suite Removes legacy ssl group from Arquillian base suite.
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/ssl/TrustStoreEmailTest.java Deletes legacy Arquillian truststore email tests.
testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/ssl/TLSTest.java Deletes legacy Arquillian TLS/ssl-required test.
tests/base/src/test/resources/org/keycloak/tests/ssl/smtp-server.pem Adds SMTP server certificate intended for truststore-paths PEM loading.
tests/base/src/test/java/org/keycloak/tests/suites/Base2TestSuite.java Adds org.keycloak.tests.ssl to the new test suite package list.
tests/base/src/test/java/org/keycloak/tests/ssl/AbstractSslEmailTest.java Introduces shared SMTPS+verify-email test base using GreenMail + shared keystore config.
tests/base/src/test/java/org/keycloak/tests/ssl/TrustStoreEmailTest.java New SMTPS verify-email success + wrong-hostname failure tests.
tests/base/src/test/java/org/keycloak/tests/ssl/TrustStoreEmailAnyHostnameTest.java New hostname-policy-ANY test where hostname mismatch should succeed.
tests/base/src/test/java/org/keycloak/tests/ssl/TrustStoreEmailUntrustedCertTest.java New untrusted-certificate (empty truststore) failure test.
tests/base/src/test/java/org/keycloak/tests/ssl/TrustStoreEmailUntrustedCertAnyHostnameTest.java New “untrusted cert + ANY hostname policy” failure test (currently mixes STARTTLS/SMTPS).
tests/base/src/test/java/org/keycloak/tests/ssl/TrustStoreEmailPlainAuthTest.java New plain SMTP auth verify-email flow test.
tests/base/src/test/java/org/keycloak/tests/ssl/TlsSslRequiredTest.java New ssl-required behavior test for HTTP allowed/rejected depending on realm setting.

Comment thread tests/base/src/test/resources/org/keycloak/tests/ssl/smtp-server.pem Outdated
Comment on lines +120 to +130
static class StarttlsEmailRealmConfig implements RealmConfig {
@Override
public RealmBuilder configure(RealmBuilder realm) {
realm.verifyEmail(true);
realm.build().setSmtpServer(starttlsSmtpConfig());
return realm;
}

private static Map<String, String> starttlsSmtpConfig() {
return Map.of("from", FROM, "host", HOST, "port", PORT_SSL, "starttls", "true");
}
Copy link
Copy Markdown
Member Author

@michalvavrik michalvavrik May 7, 2026

Choose a reason for hiding this comment

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

StarttlsEmailRealmConfig sets starttls=true while also using PORT_SSL (SMTPS port) and the test starts an SMTPS server via AbstractSslEmailTest.createSmtpsServer(). This mixes STARTTLS and SMTPS and will cause the email send to fail for the wrong reason (protocol mismatch), so the test does not actually validate the “untrusted cert even with ANY hostname policy” scenario.
Align the realm SMTP configuration with the server you start (e.g., use ssl=true + PORT_SSL for SMTPS, or start an SMTP server configured for STARTTLS on the non-SSL port).

The original test also used starttls=true, it started with SMTP, then upgraded. The DefaultEmailSenderProvider.setupTruststore() sets mail.smtp.ssl.trust=* when hostname policy is ANY, which tells JavaMail to trust all server certificates regardless of the truststore. So yes, with STARTTLS capable mail server (like SubEthaSMTP used by the original test) it failed. But it is not very useful because it just verifies Jakarta Mail implementation that behaves differently for STARTTLS and differently for SSL=TRUE. What use is it if untrusted certificate is rejected for STARTTLS=TRUE but allowed for SSL=TRUE? IMO that is useless assertion. Either it is a bug in Keycloak, or we should assert success with the SSL=TRUE, so I reworked this test after Copilet comment to show "pass scenario" instead.

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.

props.setProperty("mail.smtp.ssl.trust", "*");

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 15 changed files in this pull request and generated 2 comments.

Comment thread tests/base/src/test/java/org/keycloak/tests/ssl/TrustStoreEmailPlainAuthTest.java Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

shawkins
shawkins previously approved these changes May 7, 2026
Copy link
Copy Markdown
Contributor

@shawkins shawkins left a comment

Choose a reason for hiding this comment

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

I think what you did with the mail sever makes sense. As long as the cert ends up untrusted, we get the same assertion.

test06VerifyEmailOpportunisticEncryptionWithAnyHostnamePolicy

That seems like an odd name for the legacy test as it implies encryption was still being used. I agree with your new naming testVerifyEmailWithPlainSmtpAuth.

On the naming of the test classes in general, it would probably read better to drop the TrustStore prefix - in particular testVerifyEmailWithPlainSmtpAuth would pass without a truststore set. But this isn't a blocker for me.

* Closes: keycloak#47812

Signed-off-by: Michal Vavřík <michal.vavrik@aol.com>
@michalvavrik
Copy link
Copy Markdown
Member Author

On the naming of the test classes in general, it would probably read better to drop the TrustStore prefix - in particular testVerifyEmailWithPlainSmtpAuth would pass without a truststore set. But this isn't a blocker for me.

I've dropped the TrustStore prefix, I agree it reads better.

Copy link
Copy Markdown

@keycloak-github-bot keycloak-github-bot Bot left a comment

Choose a reason for hiding this comment

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

Unreported flaky test detected, please review

@keycloak-github-bot
Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.adapter.servlet.SAMLServletAdapterTest#salesPostSigEmailTest

Keycloak CI - Adapter IT Strict Cookies

org.opentest4j.AssertionFailedError: expected: <true> but was: <false>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertTrue.failNotTrue(AssertTrue.java:63)
	at org.junit.jupiter.api.AssertTrue.assertTrue(AssertTrue.java:36)
...

Report flaky test

org.keycloak.testsuite.adapter.servlet.SAMLServletAdapterTest#testReloginWithInvalidAuthSessionCookie

Keycloak CI - Adapter IT Strict Cookies

org.awaitility.core.ConditionTimeoutException: Assertion condition defined as a Lambda expression in org.keycloak.testsuite.util.URLAssert URL expected to begin with: https://localhost:8543/auth/realms/demo/login-action ; actual URL: https://localhost:8643/sales-post-sig-email/ ==> expected: <true> but was: <false> within 10 seconds.
	at org.awaitility.core.ConditionAwaiter.await(ConditionAwaiter.java:167)
	at org.awaitility.core.AssertionCondition.await(AssertionCondition.java:119)
	at org.awaitility.core.AssertionCondition.await(AssertionCondition.java:31)
	at org.awaitility.core.ConditionFactory.until(ConditionFactory.java:1160)
...

Report flaky test

Copy link
Copy Markdown
Contributor

@shawkins shawkins left a comment

Choose a reason for hiding this comment

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

LGTM

@michalvavrik
Copy link
Copy Markdown
Member Author

maybe let's merge it to avoid conflicts with the other PR from Stian @vmuzikar ?

@vmuzikar
Copy link
Copy Markdown
Contributor

Merging based on @shawkins' review.

@vmuzikar vmuzikar merged commit b360264 into keycloak:main May 11, 2026
86 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.

Migrate ssl package to new test framework

4 participants