Additional test for logout when using multiple tabs (#21518)

Closes #21451
This commit is contained in:
Pedro Igor 2023-07-11 06:22:20 -03:00 committed by GitHub
parent 47eeece827
commit 57423bca2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,9 +29,11 @@ import org.jboss.arquillian.graphene.page.Page;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.keycloak.OAuth2Constants;
import org.keycloak.models.Constants;
import org.keycloak.models.UserModel;
import org.keycloak.models.utils.KeycloakModelUtils;
import org.keycloak.representations.AccessToken;
import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.representations.idm.UserRepresentation;
@ -54,6 +56,7 @@ import org.keycloak.testsuite.pages.VerifyEmailPage;
import org.keycloak.testsuite.util.BrowserTabUtil;
import org.keycloak.testsuite.util.ClientBuilder;
import org.keycloak.testsuite.util.GreenMailRule;
import org.keycloak.testsuite.util.OAuthClient;
import org.keycloak.testsuite.util.UserBuilder;
import org.openqa.selenium.NoSuchElementException;
@ -163,6 +166,42 @@ public class MultipleTabsLoginTest extends AbstractTestRealmKeycloakTest {
appPage.assertCurrent();
}
@Test
public void testLoginAfterLogoutFromDifferentTab() {
try (BrowserTabUtil util = BrowserTabUtil.getInstanceAndSetEnv(driver)) {
// login in the first tab
oauth.openLoginForm();
loginPage.login("login-test", "password");
updatePasswordPage.assertCurrent();
String tab1WindowHandle = util.getActualWindowHandle();
updatePasswordPage.changePassword("password", "password");
updateProfilePage.prepareUpdate().firstName("John").lastName("Doe3")
.email("john@doe3.com").submit();
appPage.assertCurrent();
String code = oauth.getCurrentQuery().get(OAuth2Constants.CODE);
OAuthClient.AccessTokenResponse tokenResponse = oauth.doAccessTokenRequest(code, "password");
AccessToken accessToken = oauth.verifyToken(tokenResponse.getAccessToken());
// seamless login in the second tab, user already authenticated
util.newTab(oauth.getLoginFormUrl());
oauth.openLoginForm();
appPage.assertCurrent();
events.clear();
// logout in the second tab
oauth.idTokenHint(tokenResponse.getIdToken()).openLogout();
events.expectLogout(accessToken.getSessionState()).user(userId).session(accessToken.getSessionState()).assertEvent();
// re-login in the second tab
oauth.openLoginForm();
loginPage.login("login-test", "password");
appPage.assertCurrent();
// seamless authentication in the first tab
util.switchToTab(tab1WindowHandle);
oauth.openLoginForm();
appPage.assertCurrent();
}
}
@Test
public void multipleTabsLoginAndPassiveCheck() throws MalformedURLException {
try (BrowserTabUtil util = BrowserTabUtil.getInstanceAndSetEnv(driver)) {