Repository navigation
Migrate url package to new test framework #48212
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
tests/base/src/test/java/org/keycloak/tests/url/HostnameV2Assertions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package org.keycloak.tests.url; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import org.keycloak.http.simple.SimpleHttp; | ||
| import org.keycloak.protocol.oidc.representations.OIDCConfigurationRepresentation; | ||
| import org.keycloak.testframework.oauth.OAuthClient; | ||
| import org.keycloak.testframework.server.KeycloakUrls; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
||
| final class HostnameV2Assertions { | ||
|
|
||
| static final String REALM_FRONTEND_NAME = "frontendUrlRealm"; | ||
| static final String REALM_FRONTEND_URL = "https://realmFrontend.localtest.me:445"; | ||
|
|
||
| private HostnameV2Assertions() { | ||
| } | ||
|
|
||
| static void assertFrontendAndBackendUrls(OAuthClient oAuthClient, String realm, | ||
| String expectedFrontendUrl, String expectedBackendUrl) { | ||
| final OIDCConfigurationRepresentation config = oAuthClient.realm(realm).doWellKnownRequest(); | ||
| final String realmPath = "/realms/" + realm; | ||
|
|
||
| assertThat("issuer for realm " + realm, config.getIssuer(), is(expectedFrontendUrl + realmPath)); | ||
| assertThat("authorization endpoint for realm " + realm, | ||
| config.getAuthorizationEndpoint(), is(expectedFrontendUrl + realmPath + "/protocol/openid-connect/auth")); | ||
| assert 8BD0 That("token endpoint for realm " + realm, | ||
| config.getTokenEndpoint(), is(expectedBackendUrl + realmPath + "/protocol/openid-connect/token")); | ||
| assertThat("userinfo endpoint for realm " + realm, | ||
| config.getUserinfoEndpoint(), is(expectedBackendUrl + realmPath + "/protocol/openid-connect/userinfo")); | ||
| } | ||
|
|
||
| static void assertAdminUrls(SimpleHttp simpleHttp, KeycloakUrls keycloakUrls, String realm, | ||
| String expectedFrontendUrl, String expectedAdminUrl) throws IOException { | ||
| final String adminConsoleUrl = keycloakUrls.getBase() + "/admin/" + realm + "/console"; | ||
| final String adminIndexPage = simpleHttp.doGet(adminConsoleUrl).asString(); | ||
|
|
||
| assertThat("authServerUrl in admin console for realm " + realm, | ||
| adminIndexPage, containsString("\"authServerUrl\": \"" + expectedFrontendUrl + "\"")); | ||
| assertThat("authUrl in admin console for realm " + realm, | ||
| adminIndexPage, containsString("\"authUrl\": \"" + expectedAdminUrl + "\"")); | ||
| } | ||
| } |
54 changes: 54 additions & 0 deletions
54
tests/base/src/test/java/org/keycloak/tests/url/HostnameV2BackchannelDynamicTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package org.keycloak.tests.url; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| import org.keycloak.http.simple.SimpleHttp; | ||
| import org.keycloak.testframework.annotations.InjectKeycloakUrls; | ||
| import org.keycloak.testframework.annotations.InjectSimpleHttp; | ||
| import org.keycloak.testframework.annotations.KeycloakIntegrationTest; | ||
| import org.keycloak.testframework.oauth.OAuthClient; | ||
| import org.keycloak.testframework.oauth.annotations.InjectOAuthClient; | ||
| import org.keycloak.testframework.server.KeycloakServerConfig; | ||
| import org.keycloak.testframework.server.KeycloakServerConfigBuilder; | ||
| import org.keycloak.testframework.server.KeycloakUrls; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.keycloak.tests.url.HostnameV2Assertions.assertAdminUrls; | ||
| import static org.keycloak.tests.url.HostnameV2Assertions.assertFrontendAndBackendUrls; | ||
|
|
||
| @KeycloakIntegrationTest(config = HostnameV2BackchannelDynamicTest.ServerConfig.class) | ||
| class HostnameV2BackchannelDynamicTest { | ||
|
|
||
| private static final String FIXED_URL = "https://localtest.me:444"; | ||
|
|
||
| @InjectKeycloakUrls | ||
| KeycloakUrls keycloakUrls; | ||
|
|
||
| @InjectOAuthClient | ||
| OAuthClient oAuthClient; | ||
|
|
||
| @InjectSimpleHttp | ||
| SimpleHttp simpleHttp; | ||
|
|
||
| @Test | ||
| void testFrontendAndBackendUrls() { | ||
| assertFrontendAndBackendUrls(oAuthClient, "master", FIXED_URL, keycloakUrls.getBase()); | ||
| } | ||
|
|
||
| @Test | ||
| void testAdminUrls() throws IOException { | ||
| assertAdminUrls(simpleHttp, keycloakUrls, "master", FIXED_URL, FIXED_URL); | ||
| } | ||
|
|
||
| static class ServerConfig implements KeycloakServerConfig { | ||
| @Override | ||
| public KeycloakServerConfigBuilder configure(KeycloakServerConfigBuilder config) { | ||
| return config.options(Map.of( | ||
| "hostname", FIXED_URL, | ||
| "hostname-backchannel-dynamic", "true" | ||
| )); | ||
| } | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
tests/base/src/test/java/org/keycloak/tests/url/HostnameV2DefaultPortTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package org.keycloak.tests.url; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| import org.keycloak.http.simple.SimpleHttp; | ||
| import org.keycloak.testframework.annotations.InjectKeycloakUrls; | ||
| import org.keycloak.testframework.annotations.InjectSimpleHttp; | ||
| import org.keycloak.testframework.annotations.KeycloakIntegrationTest; | ||
| import org.keycloak.testframework.oauth.OAuthClient; | ||
| import org.keycloak.testframework.oauth.annotations.InjectOAuthClient; | ||
| import org.keycloak.testframework.server.KeycloakServerConfig; | ||
| import org.keycloak.testframework.server.KeycloakServerConfigBuilder; | ||
| import org.keycloak.testframework.server.KeycloakUrls; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.keycloak.tests.url.HostnameV2Assertions.assertAdminUrls; | ||
| import static org.keycloak.tests.url.HostnameV2Assertions.assertFrontendAndBackendUrls; | ||
|
|
||
| @KeycloakIntegrationTest(config = HostnameV2DefaultPortTest.ServerConfig.class) | ||
| class HostnameV2DefaultPortTest { | ||
|
|
||
| private static final String EXPECTED_FRONTEND_URL = "https://localtest.me"; | ||
| private static final String EXPECTED_ADMIN_URL = "https://admin.localtest.me"; | ||
|
|
||
| @InjectKeycloakUrls | ||
| KeycloakUrls keycloakUrls; | ||
|
|
||
| @InjectOAuthClient | ||
| OAuthClient oAuthClient; | ||
|
|
||
| @InjectSimpleHttp | ||
| SimpleHttp simpleHttp; | ||
|
|
||
| @Test | ||
| void testFrontendAndBackendUrls() { | ||
| assertFrontendAndBackendUrls(oAuthClient, "master", EXPECTED_FRONTEND_URL, EXPECTED_FRONTEND_URL); | ||
| } | ||
|
|
||
| @Test | ||
| void testAdminUrls() throws IOException { | ||
| assertAdminUrls(simpleHttp, keycloakUrls, "master", EXPECTED_FRONTEND_URL, EXPECTED_ADMIN_URL); | ||
| } | ||
|
|
||
| static class ServerConfig implements KeycloakServerConfig { | ||
| @Override | ||
| public KeycloakServerConfigBuilder configure(KeycloakServerConfigBuilder config) { | ||
| return config.options(Map.of( | ||
| "hostname", "https://localtest.me:443", | ||
| "hostname-admin", "https://admin.localtest.me:443" | ||
| )); | ||
| } | ||
| } | ||
| } |
80 changes: 80 additions & 0 deletions
80
tests/base/src/test/java/org/keycloak/tests/url/HostnameV2FixedHostnameTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| package org.keycloak.tests.url; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import org.keycloak.http.simple.SimpleHttp; | ||
| import org.keycloak.testframework.annotations.InjectKeycloakUrls; | ||
| import org.keycloak.testframework.annotations.InjectRealm; | ||
| import org.keycloak.testframework.annotations.InjectSimpleHttp; | ||
| import org.keycloak.testframework.annotations.KeycloakIntegrationTest; | ||
| import org.keycloak.testframework.oauth.OAuthClient; | ||
| import org.keycloak.testframework.oauth.annotations.InjectOAuthClient; | ||
| import org.keycloak.testframework.realm.ManagedRealm; | ||
| import org.keycloak.testframework.realm.RealmBuilder; | ||
| import org.keycloak.testframework.realm.RealmConfig; | ||
| import org.keycloak.testframework.server.KeycloakServerConfig; | ||
| import org.keycloak.testframework.server.KeycloakServerConfigBuilder; | ||
| import org.keycloak.testframework.server.KeycloakUrls; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.keycloak.tests.url.HostnameV2Assertions.REALM_FRONTEND_NAME; | ||
| import static org.keycloak.tests.url.HostnameV2Assertions.REALM_FRONTEND_URL; | ||
| import static org.keycloak.tests.url.HostnameV2Assertions.assertAdminUrls; | ||
| import static org.keycloak.tests.url.HostnameV2Assertions.assertFrontendAndBackendUrls; | ||
|
|
||
| @KeycloakIntegrationTest(config = HostnameV2FixedHostnameTest.ServerConfig.class) | ||
| class HostnameV2FixedHostnameTest { | ||
|
|
||
| private static final String HOSTNAME = "localtest.me"; | ||
| private static final String EXPECTED_URL = "http://" + HOSTNAME + ":8080"; | ||
|
|
||
| @InjectKeycloakUrls | ||
| KeycloakUrls keycloakUrls; | ||
|
|
||
| @InjectOAuthClient | ||
| OAuthClient oAuthClient; | ||
|
|
||
| @InjectSimpleHttp | ||
| SimpleHttp simpleHttp; | ||
|
|
||
| @InjectRealm(config = FrontendUrlRealmConfig.class) | ||
| ManagedRealm frontendUrlRealm; | ||
|
|
||
| @Test | ||
| void testMasterRealmFrontendAndBackendUrls() { | ||
| assertFrontendAndBackendUrls(oAuthClient, "master", EXPECTED_URL, EXPECTED_URL); | ||
| } | ||
|
|
||
| @Test | ||
| void testMasterRealmAdminUrls() throws IOException { | ||
| assertAdminUrls(simpleHttp, keycloakUrls, "master", EXPECTED_URL, EXPECTED_URL); | ||
| } | ||
|
|
||
| @Test | ||
| void testCustomRealmFrontendAndBackendUrls() { | ||
| final String realmName = frontendUrlRealm.getName(); | ||
| assertFrontendAndBackendUrls(oAuthClient, realmName, REALM_FRONTEND_URL, REALM_FRONTEND_URL); | ||
| } | ||
|
|
||
| @Test | ||
| void testCustomRealmAdminUrls() throws IOException { | ||
| final String realmName = frontendUrlRealm.getName(); | ||
| assertAdminUrls(simpleHttp, keycloakUrls, realmName, REALM_FRONTEND_URL, REALM_FRONTEND_URL); | ||
| } | ||
|
|
||
| static class ServerConfig implements KeycloakServerConfig { | ||
| @Override | ||
| public KeycloakServerConfigBuilder configure(KeycloakServerConfigBuilder config) { | ||
| return config.option("hostname", HOSTNAME); | ||
| } | ||
| } | ||
|
|
||
| static class FrontendUrlRealmConfig implements RealmConfig { | ||
| @Override | ||
| public RealmBuilder configure(RealmBuilder realm) { | ||
| realm.attribute("frontendUrl", REALM_FRONTEND_URL); | ||
| return realm.name(REALM_FRONTEND_NAME); | ||
| } | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
tests/base/src/test/java/org/keycloak/tests/url/HostnameV2FixedUrlTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package org.keycloak.tests.url; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import org.keycloak.http.simple.SimpleHttp; | ||
| import org.keycloak.testframework.annotations.InjectKeycloakUrls; | ||
| import org.keycloak.testframework.annotations.InjectSimpleHttp; | ||
| import org.keycloak.testframework.annotations.KeycloakIntegrationTest; | ||
| import org.keycloak.testframework.oauth.OAuthClient; | ||
| import org.keycloak.testframework.oauth.annotations.InjectOAuthClient; | ||
| import org.keycloak.testframework.server.KeycloakServerConfig; | ||
| import org.keycloak.testframework.server.KeycloakServerConfigBuilder; | ||
| import org.keycloak.testframework.server.KeycloakUrls; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.keycloak.tests.url.HostnameV2Assertions.assertAdminUrls; | ||
| import static org.keycloak.tests.url.HostnameV2Assertions.assertFrontendAndBackendUrls; | ||
|
|
||
| @KeycloakIntegrationTest(config = HostnameV2FixedUrlTest.ServerConfig.class) | ||
| class HostnameV2FixedUrlTest { | ||
|
|
||
| private static final String FIXED_URL = "https://localtest.me:444"; | ||
|
|
||
| @InjectKeycloakUrls | ||
| KeycloakUrls keycloakUrls; | ||
|
|
||
| @InjectOAuthClient | ||
| OAuthClient oAuthClient; | ||
|
|
||
| @InjectSimpleHttp | ||
| SimpleHttp simpleHttp; | ||
|
|
||
| @Test | ||
| void testFrontendAndBackendUrls() { | ||
| assertFrontendAndBackendUrls(oAuthClient, "master", FIXED_URL, FIXED_URL); | ||
| } | ||
|
|
||
| @Test | ||
| void testAdminUrls() throws IOException { | ||
| assertAdminUrls(simpleHttp, keycloakUrls, "master", FIXED_URL, FIXED_URL); | ||
| } | ||
|
|
||
| static class ServerConfig implements KeycloakServerConfig { | ||
| @Override | ||
| public KeycloakServerConfigBuilder configure(KeycloakServerConfigBuilder config) { | ||
| return config.option("hostname", FIXED_URL); | ||
| } | ||
| } | ||
| } |
55 changes: 55 additions & 0 deletions
55
tests/base/src/test/java/org/keycloak/tests/url/HostnameV2FrontendAndAdminTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package org.keycloak.tests.url; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| import org.keycloak.http.simple.SimpleHttp; | ||
| import org.keycloak.testframework.annotations.InjectKeycloakUrls; | ||
| import org.keycloak.testframework.annotations.InjectSimpleHttp; | ||
| import org.keycloak.testframework.annotations.KeycloakIntegrationTest; | ||
| import org.keycloak.testframework.oauth.OAuthClient; | ||
| import org.keycloak.testframework.oauth.annotations.InjectOAuthClient; | ||
| import org.keycloak.testframework.server.KeycloakServerConfig; | ||
| import org.keycloak.testframework.server.KeycloakServerConfigBuilder; | ||
| import org.keycloak.testframework.server.KeycloakUrls; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.keycloak.tests.url.HostnameV2Assertions.assertAdminUrls; | ||
| import static org.keycloak.tests.url.HostnameV2Assertions.assertFrontendAndBackendUrls; | ||
|
|
||
| @KeycloakIntegrationTest(config = HostnameV2FrontendAndAdminTest.ServerConfig.class) | ||
| class HostnameV2FrontendAndAdminTest { | ||
|
|
||
| private static final String FIXED_FRONTEND_URL = "http://localtest.me:444"; | ||
| private static final String FIXED_ADMIN_URL = "https://admin.localtest.me:445"; | ||
|
|
||
| @InjectKeycloakUrls | ||
| KeycloakUrls keycloakUrls; | ||
|
|
||
| @InjectOAuthClient | ||
| OAuthClient oAuthClient; | ||
|
|
||
| @InjectSimpleHttp | ||
| SimpleHttp simpleHttp; | ||
|
|
||
| @Test | ||
| void testFrontendAndBackendUrls() { | ||
| assertFrontendAndBackendUrls(oAuthClient, "master", FIXED_FRONTEND_URL, FIXED_FRONTEND_URL); | ||
| } | ||
|
|
||
| @Test | ||
| void testAdminUrls() throws IOException { | ||
| assertAdminUrls(simpleHttp, keycloakUrls, "master", FIXED_FRONTEND_URL, FIXED_ADMIN_URL); | ||
| } | ||
|
|
||
| static class ServerConfig implements KeycloakServerConfig { | ||
| @Override | ||
| public KeycloakServerConfigBuilder configure(KeycloakServerConfigBuilder config) { | ||
| return config.options(Map.of( | ||
| "hostname", FIXED_FRONTEND_URL, | ||
| "hostname-admin", FIXED_ADMIN_URL | ||
| )); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@vmuzikar and others - just a general question on the role of the quarkus integration tests moving forward. Do we even want to keep most of what exists separate from the new test suite? I'd be fine with removing most of our quarkus integration tests in favor of Picocli test cases and the new test suite. Maybe start with converting enough such that we only need a single CI test run, instead of the two we currently have.
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.
Potentially yes, but not sure it's worth the effort to rewrite it to the new testsuite. We don't see many specific downsides of the current Quarkus testsuite.
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.
We've had to optimize things several times, and introduce a split into two test runs. If we keep adding to it, we'll need to add a third. Seems better to work towards shifting to unit tests and the general test suite so that we can be less on the hook for optimization / splitting test runs.
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.
So rather than a question whether we should migrate to the new test framework, it's a question whether we should migrate some of the Quarkus integration tests to unit tests?
There was a problem hiding th 8000 is comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's down to the individual test.
We absolutely need coverage of our scripts - but we have removed command / option specific logic (dealing with --optimized, help, etc.) from kc.sh and kc.bat, so I think we can streamline what we're covering. I'd at least say anything that is marked as DryRun which is not specifically for exercising a script should just be a unit test.
If a test is actually starting the server and is something that is expressable in the new test framework, I would be in favor of migrating it or identifying why it can't.
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.
@shawkins Can you please create a discussion with the proposal for migrating the Quarkus tests? This is not the correct place to discuss it as it will probably require more thought.
It'd be good to have a summarization of the specific proposal and the expected benefits.
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.
Moved to #48399