8000 Migrate url package to new test framework by michalvavrik · Pull Request #48212 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,28 @@ public void testServerFailsToStartWithoutHostnameSpecified(LaunchResult result)
public void testServerStartsDevtWithoutHostnameSpecified(LaunchResult result) {
((CLIResult) result).assertStartedDevMode();
}

@Test
@Launch({"start", "--db=dev-file", "--http-enabled=true", "--hostname=htt://localtest.me"})
public void testInvalidHostnameUrl(LaunchResult result) {
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.

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

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.

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.

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.

We don't see many specific downsides of the current Quarkus testsuite.

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.

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.

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?

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.

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?

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.

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.

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

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.

Moved to #48399

assertThat(result.getErrorOutput(), containsString("Provided hostname is neither a plain hostname nor a valid URL"));
}

@Test
@Launch({"start", "--db=dev-file", "--http-enabled=true", "--hostname=localtest.me", "--hostname-admin=htt://admin.localtest.me"})
public void testInvalidAdminUrl(LaunchResult result) {
assertThat(result.getErrorOutput(), containsString("Provided hostname-admin is not a valid URL"));
}

@Test
@Launch({"start", "--db=dev-file", "--http-enabled=true", "--hostname-backchannel-dynamic=true", "--hostname-strict=false"})
public void testBackchannelDynamicRequiresHostname(LaunchResult result) {
assertThat(result.getErrorOutput(), containsString("hostname-backchannel-dynamic must be set to false when no hostname is provided"));
}

@Test
@Launch({"start", "--db=dev-file", "--http-enabled=true", "--hostname=localtest.me", "--hostname-backchannel-dynamic=true"})
public void testBackchannelDynamicRequiresFullHostnameUrl(LaunchResult result) {
assertThat(result.getErrorOutput(), containsString("hostname-backchannel-dynamic must be set to false if hostname is not provided as full URL"));
}
}
8000
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"org.keycloak.tests.session",
"org.keycloak.tests.tracing",
"org.keycloak.tests.transactions",
"org.keycloak.tests.url",
"org.keycloak.tests.vault",
"org.keycloak.tests.welcomepage",
"org.keycloak.tests.workflow"
Expand Down
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 + "\""));
}
}
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"
));
}
}
}
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"
));
}
}
}
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);
}
}
}
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);
}
}
}
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
));
}
}
}
Loading
Loading
0