Search in sources :

Example 1 with BrowserTabUtil

use of org.keycloak.testsuite.util.BrowserTabUtil in project keycloak by keycloak.

the class ResetPasswordTest method resetPasswordTwiceInNewTab.

private void resetPasswordTwiceInNewTab(UserRepresentation user, String clientId, boolean shouldLogOut, String redirectUri, String requiredUri) throws IOException {
    events.clear();
    updateForgottenPassword(user, clientId, redirectUri, requiredUri);
    if (shouldLogOut) {
        String sessionId = events.expectLogin().user(user.getId()).detail(Details.USERNAME, user.getUsername()).detail(Details.REDIRECT_URI, redirectUri).client(clientId).assertEvent().getSessionId();
        oauth.openLogout();
        events.expectLogout(sessionId).user(user.getId()).session(sessionId).assertEvent();
    }
    BrowserTabUtil util = BrowserTabUtil.getInstanceAndSetEnv(driver);
    assertThat(util.getCountOfTabs(), Matchers.equalTo(2));
    util.closeTab(1);
    assertThat(util.getCountOfTabs(), Matchers.equalTo(1));
    if (shouldLogOut) {
        final ClientRepresentation client = testRealm().clients().findByClientId(clientId).stream().findFirst().orElse(null);
        assertThat(client, Matchers.notNullValue());
        updateForgottenPassword(user, clientId, getValidRedirectUriWithRootUrl(client.getRootUrl(), client.getRedirectUris()));
    } else {
        doForgotPassword(user.getUsername());
    }
}
Also used : BrowserTabUtil(org.keycloak.testsuite.util.BrowserTabUtil) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation)

Example 2 with BrowserTabUtil

use of org.keycloak.testsuite.util.BrowserTabUtil in project keycloak by keycloak.

the class ResetPasswordTest method resetPasswordLinkNewTabAndProperRedirectAccount.

@Test
// TODO remove this (KEYCLOAK-16228)
@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true)
public void resetPasswordLinkNewTabAndProperRedirectAccount() throws IOException {
    final String REQUIRED_URI = OAuthClient.AUTH_SERVER_ROOT + "/realms/test/account/applications";
    final String REDIRECT_URI = getAccountRedirectUrl() + "?path=applications";
    final String CLIENT_ID = "account";
    final String ACCOUNT_MANAGEMENT_TITLE = getProjectName() + " Account Management";
    try (BrowserTabUtil tabUtil = BrowserTabUtil.getInstanceAndSetEnv(driver)) {
        assertThat(tabUtil.getCountOfTabs(), Matchers.is(1));
        driver.navigate().to(REQUIRED_URI);
        resetPasswordTwiceInNewTab(defaultUser, CLIENT_ID, false, REDIRECT_URI, REQUIRED_URI);
        assertThat(driver.getTitle(), Matchers.equalTo(ACCOUNT_MANAGEMENT_TITLE));
        oauth.openLogout();
        driver.navigate().to(REQUIRED_URI);
        resetPasswordTwiceInNewTab(defaultUser, CLIENT_ID, true, REDIRECT_URI, REQUIRED_URI);
        assertThat(driver.getTitle(), Matchers.equalTo(ACCOUNT_MANAGEMENT_TITLE));
    }
}
Also used : BrowserTabUtil(org.keycloak.testsuite.util.BrowserTabUtil) DisableFeature(org.keycloak.testsuite.arquillian.annotation.DisableFeature) AbstractKerberosTest(org.keycloak.testsuite.federation.kerberos.AbstractKerberosTest) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Example 3 with BrowserTabUtil

use of org.keycloak.testsuite.util.BrowserTabUtil in project keycloak by keycloak.

the class ResetPasswordTest method updateForgottenPassword.

private void updateForgottenPassword(UserRepresentation user, String clientId, String redirectUri, String requiredUri) throws IOException {
    final int emailCount = greenMail.getReceivedMessages().length;
    doForgotPassword(user.getUsername());
    assertEquals("You should receive an email shortly with further instructions.", loginPage.getSuccessMessage());
    events.expectRequiredAction(EventType.SEND_RESET_PASSWORD).user(user.getId()).client(clientId).detail(Details.REDIRECT_URI, redirectUri).detail(Details.USERNAME, user.getUsername()).detail(Details.EMAIL, user.getEmail()).session((String) null).assertEvent();
    assertEquals(emailCount + 1, greenMail.getReceivedMessages().length);
    final MimeMessage message = greenMail.getReceivedMessages()[emailCount];
    final String changePasswordUrl = MailUtils.getPasswordResetEmailLink(message);
    BrowserTabUtil util = BrowserTabUtil.getInstanceAndSetEnv(driver);
    util.newTab(changePasswordUrl.trim());
    changePasswordOnUpdatePage(driver);
    events.expectRequiredAction(EventType.UPDATE_PASSWORD).detail(Details.REDIRECT_URI, redirectUri).client(clientId).user(user.getId()).detail(Details.USERNAME, user.getUsername()).assertEvent();
    assertThat(driver.getCurrentUrl(), Matchers.containsString(requiredUri));
}
Also used : BrowserTabUtil(org.keycloak.testsuite.util.BrowserTabUtil) MimeMessage(javax.mail.internet.MimeMessage)

Example 4 with BrowserTabUtil

use of org.keycloak.testsuite.util.BrowserTabUtil in project keycloak by keycloak.

the class ResetPasswordTest method resetPasswordLinkNewTabAndProperRedirectClient.

@Test
public void resetPasswordLinkNewTabAndProperRedirectClient() throws IOException {
    final String REDIRECT_URI = getAuthServerRoot() + "realms/master/app/auth";
    final String CLIENT_ID = "test-app";
    try (BrowserTabUtil tabUtil = BrowserTabUtil.getInstanceAndSetEnv(driver);
        ClientAttributeUpdater cau = ClientAttributeUpdater.forClient(getAdminClient(), TEST_REALM_NAME, CLIENT_ID).filterRedirectUris(uri -> uri.contains(REDIRECT_URI)).update()) {
        assertThat(tabUtil.getCountOfTabs(), Matchers.is(1));
        loginPage.open();
        resetPasswordTwiceInNewTab(defaultUser, CLIENT_ID, false, REDIRECT_URI);
        assertThat(driver.getCurrentUrl(), Matchers.containsString(REDIRECT_URI));
        oauth.openLogout();
        loginPage.open();
        resetPasswordTwiceInNewTab(defaultUser, CLIENT_ID, true, REDIRECT_URI);
        assertThat(driver.getCurrentUrl(), Matchers.containsString(REDIRECT_URI));
    }
}
Also used : BrowserTabUtil(org.keycloak.testsuite.util.BrowserTabUtil) ClientAttributeUpdater(org.keycloak.testsuite.updaters.ClientAttributeUpdater) RedirectUtils(org.keycloak.protocol.oidc.utils.RedirectUtils) ClientAttributeUpdater(org.keycloak.testsuite.updaters.ClientAttributeUpdater) URL(java.net.URL) AssertEvents(org.keycloak.testsuite.AssertEvents) MessagingException(javax.mail.MessagingException) WebElement(org.openqa.selenium.WebElement) Page(org.jboss.arquillian.graphene.page.Page) AbstractKerberosTest(org.keycloak.testsuite.federation.kerberos.AbstractKerberosTest) OAuthClient(org.keycloak.testsuite.util.OAuthClient) LoginPasswordUpdatePage(org.keycloak.testsuite.pages.LoginPasswordUpdatePage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) SystemClientUtil(org.keycloak.models.utils.SystemClientUtil) Collection(java.util.Collection) InfoPage(org.keycloak.testsuite.pages.InfoPage) DisableFeature(org.keycloak.testsuite.arquillian.annotation.DisableFeature) RealmRepresentation(org.keycloak.representations.idm.RealmRepresentation) LoginPasswordResetPage(org.keycloak.testsuite.pages.LoginPasswordResetPage) EventRepresentation(org.keycloak.representations.idm.EventRepresentation) ClientRepresentation(org.keycloak.representations.idm.ClientRepresentation) ServiceAccountConstants(org.keycloak.common.constants.ServiceAccountConstants) Details(org.keycloak.events.Details) LoginPage(org.keycloak.testsuite.pages.LoginPage) ResetCredentialsActionToken(org.keycloak.authentication.actiontoken.resetcred.ResetCredentialsActionToken) BrowserTabUtil(org.keycloak.testsuite.util.BrowserTabUtil) Profile(org.keycloak.common.Profile) AuthServerContainerExclude(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude) SecondBrowser(org.keycloak.testsuite.util.SecondBrowser) GreenMailRule(org.keycloak.testsuite.util.GreenMailRule) WebDriver(org.openqa.selenium.WebDriver) Constants(org.keycloak.models.Constants) HashMap(java.util.HashMap) RealmBuilder(org.keycloak.testsuite.util.RealmBuilder) Drone(org.jboss.arquillian.drone.api.annotation.Drone) AuthenticationExecutionModel(org.keycloak.models.AuthenticationExecutionModel) UserBuilder(org.keycloak.testsuite.util.UserBuilder) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UserResource(org.keycloak.admin.client.resource.UserResource) AuthServer(org.keycloak.testsuite.arquillian.annotation.AuthServerContainerExclude.AuthServer) MailUtils(org.keycloak.testsuite.util.MailUtils) ApiUtil(org.keycloak.testsuite.admin.ApiUtil) WaitUtils(org.keycloak.testsuite.util.WaitUtils) AppPage(org.keycloak.testsuite.pages.AppPage) Errors(org.keycloak.events.Errors) UserRepresentation(org.keycloak.representations.idm.UserRepresentation) MalformedURLException(java.net.MalformedURLException) By(org.openqa.selenium.By) Matchers(org.hamcrest.Matchers) EventType(org.keycloak.events.EventType) VerifyEmailPage(org.keycloak.testsuite.pages.VerifyEmailPage) IOException(java.io.IOException) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest) MimeMessage(javax.mail.internet.MimeMessage) RequestType(org.keycloak.testsuite.pages.AppPage.RequestType) ErrorPage(org.keycloak.testsuite.pages.ErrorPage) Closeable(java.io.Closeable) org.junit(org.junit) Assert(org.junit.Assert) Collections(java.util.Collections) UserActionTokenBuilder(org.keycloak.testsuite.util.UserActionTokenBuilder) AbstractKerberosTest(org.keycloak.testsuite.federation.kerberos.AbstractKerberosTest) AbstractTestRealmKeycloakTest(org.keycloak.testsuite.AbstractTestRealmKeycloakTest)

Aggregations

BrowserTabUtil (org.keycloak.testsuite.util.BrowserTabUtil)3 MimeMessage (javax.mail.internet.MimeMessage)2 ClientRepresentation (org.keycloak.representations.idm.ClientRepresentation)2 AbstractTestRealmKeycloakTest (org.keycloak.testsuite.AbstractTestRealmKeycloakTest)2 DisableFeature (org.keycloak.testsuite.arquillian.annotation.DisableFeature)2 AbstractKerberosTest (org.keycloak.testsuite.federation.kerberos.AbstractKerberosTest)2 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MessagingException (javax.mail.MessagingException)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers (org.hamcrest.Matchers)1 Drone (org.jboss.arquillian.drone.api.annotation.Drone)1 Page (org.jboss.arquillian.graphene.page.Page)1