Moved ClientRedirectTest to new testsuite
This commit is contained in:
parent
6ec19d0b63
commit
19c29387fa
3 changed files with 68 additions and 79 deletions
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||
* and other contributors as indicated by the @author tags.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.keycloak.testsuite.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.testsuite.TestRealmKeycloakTest;
|
||||
import org.keycloak.testsuite.util.ClientBuilder;
|
||||
import org.keycloak.testsuite.util.RealmBuilder;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:thomas.darimont@gmail.com">Thomas Darimont</a>
|
||||
*/
|
||||
public class ClientRedirectTest extends TestRealmKeycloakTest {
|
||||
|
||||
@Override
|
||||
public void configureTestRealm(RealmRepresentation testRealm) {
|
||||
RealmBuilder.edit(testRealm)
|
||||
.client(ClientBuilder.create().clientId("launchpad-test").baseUrl("").rootUrl("http://example.org/launchpad"))
|
||||
.client(ClientBuilder.create().clientId("dummy-test").baseUrl("/base-path").rootUrl("http://example.org/dummy"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Integration test for {@link org.keycloak.services.resources.RealmsResource#getRedirect(String, String)}.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testClientRedirectEndpoint() throws Exception {
|
||||
oauth.doLogin("test-user@localhost", "password");
|
||||
|
||||
driver.get(getAuthServerRoot().toString() + "realms/test/clients/launchpad-test/redirect");
|
||||
assertEquals("http://example.org/launchpad", driver.getCurrentUrl());
|
||||
|
||||
driver.get(getAuthServerRoot().toString() + "realms/test/clients/dummy-test/redirect");
|
||||
assertEquals("http://example.org/dummy/base-path", driver.getCurrentUrl());
|
||||
|
||||
driver.get(getAuthServerRoot().toString() + "realms/test/clients/account/redirect");
|
||||
assertEquals(getAuthServerRoot().toString() + "realms/test/account", driver.getCurrentUrl());
|
||||
}
|
||||
}
|
|
@ -88,4 +88,14 @@ public class ClientBuilder {
|
|||
rep.setRedirectUris(Arrays.asList(redirectUris));
|
||||
return this;
|
||||
}
|
||||
|
||||
public ClientBuilder baseUrl(String baseUrl) {
|
||||
rep.setBaseUrl(baseUrl);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ClientBuilder rootUrl(String rootUrl) {
|
||||
rep.setRootUrl(rootUrl);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
package org.keycloak.testsuite;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.models.ClientModel;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.services.managers.RealmManager;
|
||||
import org.keycloak.testsuite.rule.KeycloakRule;
|
||||
import org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup;
|
||||
import org.keycloak.testsuite.rule.WebResource;
|
||||
import org.keycloak.testsuite.rule.WebRule;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:thomas.darimont@gmail.com">Thomas Darimont</a>
|
||||
*/
|
||||
public class ClientRedirectTest {
|
||||
|
||||
@ClassRule
|
||||
public static KeycloakRule keycloakRule = new KeycloakRule(new KeycloakSetup() {
|
||||
|
||||
@Override
|
||||
public void config(RealmManager manager, RealmModel adminstrationRealm, RealmModel appRealm) {
|
||||
|
||||
RealmModel testRealm = manager.getRealmByName("test");
|
||||
|
||||
ClientModel launchpadClient = testRealm.addClient("launchpad-test");
|
||||
launchpadClient.setBaseUrl("");
|
||||
launchpadClient.setRootUrl("http://example.org/launchpad");
|
||||
|
||||
ClientModel dummyClient = testRealm.addClient("dummy-test");
|
||||
dummyClient.setRootUrl("http://example.org/dummy");
|
||||
dummyClient.setBaseUrl("/base-path");
|
||||
}
|
||||
});
|
||||
|
||||
@Rule
|
||||
public WebRule webRule = new WebRule(this);
|
||||
|
||||
@WebResource
|
||||
protected OAuthClient oauth;
|
||||
|
||||
@WebResource
|
||||
protected WebDriver webDriver;
|
||||
|
||||
private static int getKeycloakPort() {
|
||||
|
||||
String keycloakPort = System.getProperty("keycloak.port", System.getenv("KEYCLOAK_DEV_PORT"));
|
||||
|
||||
try {
|
||||
return Integer.parseInt(keycloakPort);
|
||||
} catch (Exception ex) {
|
||||
return 8081;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Integration test for {@link org.keycloak.services.resources.RealmsResource#getRedirect(String, String)}.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testClientRedirectEndpoint() throws Exception {
|
||||
|
||||
oauth.doLogin("test-user@localhost", "password");
|
||||
|
||||
webDriver.get("http://localhost:" + getKeycloakPort() + "/auth/realms/test/clients/launchpad-test/redirect");
|
||||
assertEquals("http://example.org/launchpad", webDriver.getCurrentUrl());
|
||||
|
||||
webDriver.get("http://localhost:" + getKeycloakPort() + "/auth/realms/test/clients/dummy-test/redirect");
|
||||
assertEquals("http://example.org/dummy/base-path", webDriver.getCurrentUrl());
|
||||
|
||||
webDriver.get("http://localhost:" + getKeycloakPort() + "/auth/realms/test/clients/account/redirect");
|
||||
assertEquals("http://localhost:" + getKeycloakPort() + "/auth/realms/test/account", webDriver.getCurrentUrl());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue