Migration of OAuthDanceClientSessionExtensionTest

This commit is contained in:
Bruno Oliveira 2016-05-05 15:29:51 -03:00
parent 49dc5363bb
commit 2a60f65229
No known key found for this signature in database
GPG key ID: 6119F27084DC9914

View file

@ -17,40 +17,44 @@
package org.keycloak.testsuite.oauth; package org.keycloak.testsuite.oauth;
import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.keycloak.OAuth2Constants; import org.keycloak.OAuth2Constants;
import org.keycloak.events.Details; import org.keycloak.events.Details;
import org.keycloak.events.Event; import org.keycloak.representations.idm.EventRepresentation;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.testsuite.AbstractKeycloakTest;
import org.keycloak.testsuite.AssertEvents; import org.keycloak.testsuite.AssertEvents;
import org.keycloak.testsuite.OAuthClient; import org.keycloak.testsuite.util.OAuthClient;
import org.keycloak.testsuite.rule.KeycloakRule;
import org.keycloak.testsuite.rule.WebResource; import java.util.List;
import org.keycloak.testsuite.rule.WebRule;
import static org.keycloak.testsuite.admin.AbstractAdminTest.loadJson;
/** /**
* @author Sebastian Rose, AOE on 02.06.15. * @author Sebastian Rose, AOE on 02.06.15.
*/ */
public class OAuthDanceClientSessionExtensionTest { public class OAuthDanceClientSessionExtensionTest extends AbstractKeycloakTest {
@ClassRule
public static KeycloakRule keycloakRule = new KeycloakRule();
@Rule @Rule
public WebRule webRule = new WebRule(this); public AssertEvents events = new AssertEvents(this);
@WebResource @Override
protected OAuthClient oauth; public void beforeAbstractKeycloakTest() throws Exception {
super.beforeAbstractKeycloakTest();
}
@Rule @Override
public AssertEvents events = new AssertEvents(keycloakRule); public void addTestRealms(List<RealmRepresentation> testRealms) {
RealmRepresentation realmRepresentation = loadJson(getClass().getResourceAsStream("/testrealm.json"), RealmRepresentation.class);
testRealms.add(realmRepresentation);
}
@Test @Test
public void doOauthDanceWithClientSessionStateAndHost() throws Exception { public void doOauthDanceWithClientSessionStateAndHost() throws Exception {
oauth.doLogin("test-user@localhost", "password"); oauth.doLogin("test-user@localhost", "password");
Event loginEvent = events.expectLogin().assertEvent(); EventRepresentation loginEvent = events.expectLogin().assertEvent();
String sessionId = loginEvent.getSessionId(); String sessionId = loginEvent.getSessionId();
String codeId = loginEvent.getDetails().get(Details.CODE_ID); String codeId = loginEvent.getDetails().get(Details.CODE_ID);
@ -61,27 +65,27 @@ public class OAuthDanceClientSessionExtensionTest {
String clientSessionHost = "test-client-host"; String clientSessionHost = "test-client-host";
OAuthClient.AccessTokenResponse tokenResponse = oauth.clientSessionState(clientSessionState) OAuthClient.AccessTokenResponse tokenResponse = oauth.clientSessionState(clientSessionState)
.clientSessionHost(clientSessionHost) .clientSessionHost(clientSessionHost)
.doAccessTokenRequest(code, "password"); .doAccessTokenRequest(code, "password");
String refreshTokenString = tokenResponse.getRefreshToken(); String refreshTokenString = tokenResponse.getRefreshToken();
Event tokenEvent = events.expectCodeToToken(codeId, sessionId) EventRepresentation tokenEvent = events.expectCodeToToken(codeId, sessionId)
.detail(Details.CLIENT_SESSION_STATE, clientSessionState) .detail(Details.CLIENT_SESSION_STATE, clientSessionState)
.detail(Details.CLIENT_SESSION_HOST, clientSessionHost) .detail(Details.CLIENT_SESSION_HOST, clientSessionHost)
.assertEvent(); .assertEvent();
String updatedClientSessionState = "5678"; String updatedClientSessionState = "5678";
oauth.clientSessionState(updatedClientSessionState) oauth.clientSessionState(updatedClientSessionState)
.clientSessionHost(clientSessionHost) .clientSessionHost(clientSessionHost)
.doRefreshTokenRequest(refreshTokenString, "password"); .doRefreshTokenRequest(refreshTokenString, "password");
events.expectRefresh(tokenEvent.getDetails().get(Details.REFRESH_TOKEN_ID), sessionId) events.expectRefresh(tokenEvent.getDetails().get(Details.REFRESH_TOKEN_ID), sessionId)
.detail(Details.CLIENT_SESSION_STATE, updatedClientSessionState) .detail(Details.CLIENT_SESSION_STATE, updatedClientSessionState)
.detail(Details.CLIENT_SESSION_HOST, clientSessionHost) .detail(Details.CLIENT_SESSION_HOST, clientSessionHost)
.assertEvent(); .assertEvent();
} }