KEYCLOAK-4366

This commit is contained in:
mhajas 2017-02-27 09:52:57 +01:00
parent b30b96b9a1
commit 36fc643bfb
3 changed files with 169 additions and 17 deletions

View file

@ -43,12 +43,18 @@
<button onclick="createBearerRequest()">Create Bearer Request</button>
<button onclick="output(showTime())">Show current time</button>
<button onclick="cert()">Cert request</button>
<input id="timeSkewInput"/>
<button onclick="addToTimeSkew()">timeSkew offset</button>
<button onclick="refreshTimeSkew()">refresh timeSkew</button>
<button onclick="sendBearerToKeycloak()">Bearer to keycloak</button>
<button onclick="createUser()">Create user</button>
<button onclick="reentrancyCallback()">Reentrancy callback</button>
<button onclick='initWithDifferentRealmName(getInput())'>Init with different realm name</button>
<button onclick='keycloakInit(null, {refreshToken: getInput2()})'>Init with refresh token</button>
<button onclick='keycloakInit(null, {token: getInput(), refreshToken: getInput2()})'>Init with both tokens</button>
<button onclick='keycloakInit(null, {token: getInput(), refreshToken: getInput2(), timeSkew: parseInt(getInput3())})'>Init with TimeSkew</button>
<input id="inputField" value="input"/>
<input id="inputField2" value="input2"/>
<input id="inputField3" value="input3"/>
<select id="flowSelect">
@ -78,6 +84,15 @@ TimeSkew:
<script>
function getInput() {
return document.getElementById("inputField").value;
}
function getInput2() {
return document.getElementById("inputField2").value;
}
function getInput3() {
return document.getElementById("inputField3").value;
}
function loadProfile() {
keycloak.loadUserProfile().success(function (profile) {
output(profile);
@ -150,8 +165,7 @@ TimeSkew:
}
function addToTimeSkew() {
var offset = document.getElementById("timeSkewInput").value;
keycloak.timeSkew += parseInt(offset);
keycloak.timeSkew += parseInt(getInput());
document.getElementById("timeSkew").innerHTML = keycloak.timeSkew;
}
@ -284,10 +298,28 @@ TimeSkew:
);
}
function initWithDifferentRealmName(realmName) {
var url = 'http://localhost:8180/auth';
if (window.location.href.indexOf("8643") > -1) {
url = url.replace("8180","8543");
url = url.replace("http","https");
}
keycloakInit({
url: url,
realm: realmName,
clientId: 'js-console'
});
}
var keycloak;
function keycloakInit() {
keycloak = Keycloak();
function keycloakInit(configuration, initOptions) {
if (!configuration)
keycloak = Keycloak();
else
keycloak = Keycloak(configuration);
keycloak.onAuthSuccess = function () {
event('Auth Success');
@ -314,11 +346,14 @@ TimeSkew:
event('Access token expired.');
};
var initOptions = {
onLoad: document.getElementById("onLoad").value,
flow: document.getElementById("flowSelect").value,
responseMode: document.getElementById("responseModeSelect").value
};
if (!initOptions) {
var initOptions = {
onLoad: document.getElementById("onLoad").value,
flow: document.getElementById("flowSelect").value,
responseMode: document.getElementById("responseModeSelect").value
};
}
keycloak.init(initOptions).success(function (authenticated) {
output('Init Success (' + (authenticated ? 'Authenticated' : 'Not Authenticated') + ')');
}).error(function () {

View file

@ -48,6 +48,14 @@ public class JSConsoleTestApp extends AbstractPageWithInjectedUrl {
@FindBy(xpath = "//button[text() = 'Init']")
private WebElement initButton;
@FindBy(xpath = "//button[text() = 'Init with both tokens']")
private WebElement initWithBothTokens;
@FindBy(xpath = "//button[text() = 'Init with refresh token']")
private WebElement initWithRefreshToken;
@FindBy(xpath = "//button[text() = 'Init with TimeSkew']")
private WebElement initWithTimeSkew;
@FindBy(xpath = "//button[text() = 'Init with different realm name']")
private WebElement initWithDifferentRealmName;
@FindBy(xpath = "//button[text() = 'Login']")
private WebElement logInButton;
@FindBy(xpath = "//button[text() = 'Logout']")
@ -88,8 +96,12 @@ public class JSConsoleTestApp extends AbstractPageWithInjectedUrl {
@FindBy(id = "timeSkew")
private WebElement timeSkewValue;
@FindBy(id = "timeSkewInput")
private WebElement timeSkewInput;
@FindBy(id = "inputField")
private WebElement generalInput;
@FindBy(id = "inputField2")
private WebElement generalInput2;
@FindBy(id = "inputField3")
private WebElement generalInput3;
@FindBy(xpath = "//button[text() = 'timeSkew offset']")
private WebElement timeSkewButton;
@ -143,6 +155,22 @@ public class JSConsoleTestApp extends AbstractPageWithInjectedUrl {
initButton.click();
}
public void initWithBothTokens() {
initWithBothTokens.click();
}
public void initWithRefreshToken() {
initWithRefreshToken.click();
}
public void initWithTimeSkew() {
initWithTimeSkew.click();
}
public void initWithDifferentRealmName() {
initWithDifferentRealmName.click();
}
public void createBearerRequest() {
createBearerRequest.click();
}
@ -175,9 +203,27 @@ public class JSConsoleTestApp extends AbstractPageWithInjectedUrl {
return timeSkewValue;
}
public void setTimeSkewOffset(int value) {
timeSkewInput.clear();
timeSkewInput.sendKeys(Integer.toString(value));
public void setInput(String value) {
generalInput.clear();
generalInput.sendKeys(value);
}
public void setInput2(String value) {
generalInput2.clear();
generalInput2.sendKeys(value);
}
public void setInput3(String value) {
generalInput3.clear();
generalInput3.sendKeys(value);
}
public void setInput(int value) {
setInput(Integer.toString(value));
}
public void setTimeSkew(int value) {
setInput(value);
timeSkewButton.click();
}

View file

@ -21,6 +21,7 @@ import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.graphene.page.Page;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.keycloak.OAuth2Constants;
import org.keycloak.admin.client.resource.ClientResource;
import org.keycloak.admin.client.resource.UsersResource;
import org.keycloak.representations.idm.ClientRepresentation;
@ -34,6 +35,7 @@ import org.keycloak.testsuite.auth.page.account.Applications;
import org.keycloak.testsuite.auth.page.login.OAuthGrant;
import org.keycloak.testsuite.console.page.events.Config;
import org.keycloak.testsuite.console.page.events.LoginEvents;
import org.keycloak.testsuite.util.RealmBuilder;
import org.openqa.selenium.By;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
@ -379,12 +381,12 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
public void testUpdateToken() {
logInAndInit("standard");
jsConsoleTestAppPage.setTimeSkewOffset(-33);
jsConsoleTestAppPage.setTimeSkew(-33);
setTimeOffset(33);
jsConsoleTestAppPage.refreshTokenIfUnder5s();
jsConsoleTestAppPage.setTimeSkewOffset(-34);
jsConsoleTestAppPage.setTimeSkew(-34);
setTimeOffset(67);
jsConsoleTestAppPage.refreshTokenIfUnder5s();
@ -454,6 +456,75 @@ public abstract class AbstractJSConsoleExampleAdapterTest extends AbstractExampl
.contains("location: " + authServerContextRootPage.toString() + "/auth/admin/realms/" + EXAMPLE + "/users/" + users.get(0).getId());
}
@Test
public void spaceInRealmNameTest() {
String SPACE_REALM_NAME = "Example realm";
adminClient.realm(EXAMPLE).update(RealmBuilder.edit(adminClient.realm(EXAMPLE).toRepresentation()).name(SPACE_REALM_NAME).build());
jsConsoleTestAppPage.navigateTo();
jsConsoleTestAppPage.setInput(SPACE_REALM_NAME);
jsConsoleTestAppPage.initWithDifferentRealmName();
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Init Success (Not Authenticated)");
jsConsoleTestAppPage.logIn();
waitUntilElement(By.xpath("//body")).is().present();
testRealmLoginPage.form().login("user", "password");
jsConsoleTestAppPage.setInput(SPACE_REALM_NAME);
jsConsoleTestAppPage.initWithDifferentRealmName();
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Init Success (Authenticated)");
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().contains("Auth Success");
}
@Test
public void initializeWithTokenTest() {
oauth.realm(EXAMPLE);
oauth.clientId("js-console");
oauth.redirectUri(appServerContextRootPage + "/js-console");
oauth.doLogin("user", "password");
String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
String token = oauth.doAccessTokenRequest(code, "password").getAccessToken();
String refreshToken = oauth.doRefreshTokenRequest(token, "password").getRefreshToken();
jsConsoleTestAppPage.navigateTo();
jsConsoleTestAppPage.setInput(token);
jsConsoleTestAppPage.setInput2(refreshToken);
jsConsoleTestAppPage.initWithBothTokens();
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Init Success (Authenticated)");
jsConsoleTestAppPage.refreshToken();
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().contains("Auth Refresh Success");
}
@Test
public void initializeWithTimeSkew() {
setTimeOffset(600);
oauth.realm(EXAMPLE);
oauth.clientId("js-console");
oauth.redirectUri(appServerContextRootPage + "/js-console");
oauth.doLogin("user", "password");
String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
String token = oauth.doAccessTokenRequest(code, "password").getAccessToken();
String refreshToken = oauth.doRefreshTokenRequest(token, "password").getRefreshToken();
jsConsoleTestAppPage.navigateTo();
jsConsoleTestAppPage.setInput(token);
jsConsoleTestAppPage.setInput2(refreshToken);
jsConsoleTestAppPage.setInput3("-600");
jsConsoleTestAppPage.initWithTimeSkew();
waitUntilElement(jsConsoleTestAppPage.getOutputElement()).text().contains("Init Success (Authenticated)");
jsConsoleTestAppPage.refreshToken();
waitUntilElement(jsConsoleTestAppPage.getEventsElement()).text().contains("Auth Refresh Success");
setTimeOffset(0);
}
@Test
public void reentrancyCallbackTest() {
logInAndInit("standard");