RequiredActionEmailVerificationTest - old account console dependencies removed. (#19843)

Closes #19668
This commit is contained in:
Lukas Hanusovsky 2023-04-25 08:19:43 +02:00 committed by GitHub
parent 3026d8fad2
commit 30d976d64c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -40,9 +40,7 @@ import org.keycloak.testsuite.AssertEvents;
import org.keycloak.testsuite.AbstractTestRealmKeycloakTest;
import org.keycloak.testsuite.admin.ApiUtil;
import org.keycloak.testsuite.arquillian.AuthServerTestEnricher;
import org.keycloak.testsuite.arquillian.annotation.DisableFeature;
import org.keycloak.testsuite.arquillian.annotation.EnableFeature;
import org.keycloak.testsuite.auth.page.AuthRealm;
import org.keycloak.testsuite.cluster.AuthenticationSessionFailoverClusterTest;
import org.keycloak.testsuite.pages.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType;
@ -55,15 +53,18 @@ import org.keycloak.testsuite.pages.VerifyEmailPage;
import org.keycloak.testsuite.updaters.UserAttributeUpdater;
import org.keycloak.testsuite.util.GreenMailRule;
import org.keycloak.testsuite.util.InfinispanTestTimeServiceRule;
import org.keycloak.testsuite.util.MailUtils;
import org.keycloak.testsuite.util.SecondBrowser;
import org.keycloak.testsuite.util.UserActionTokenBuilder;
import org.keycloak.testsuite.util.UserBuilder;
import org.keycloak.testsuite.util.AccountHelper;
import org.keycloak.testsuite.util.TestAppHelper;
import org.keycloak.testsuite.util.UserActionTokenBuilder;
import org.keycloak.testsuite.util.MailUtils;
import java.io.Closeable;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@ -80,12 +81,10 @@ import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
/**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/
@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true) // TODO remove this (KEYCLOAK-16228)
public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeycloakTest {
@Rule
@ -359,10 +358,7 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
driver.navigate().to(verificationUrl1.trim());
appPage.assertCurrent();
accountPage.setAuthRealm(AuthRealm.TEST);
accountPage.navigateTo();
accountPage.logOut();
AccountHelper.logout(testRealm(), "test-user@localhost");
MimeMessage message2 = greenMail.getReceivedMessages()[1];
@ -616,7 +612,7 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
// https://issues.jboss.org/browse/KEYCLOAK-5861
@Test
public void verifyEmailNewBrowserSessionWithClientRedirect() throws IOException, MessagingException {
public void verifyEmailNewBrowserSessionWithClientRedirect() throws URISyntaxException, IOException, MessagingException {
try (Closeable u = new UserAttributeUpdater(testRealm().users().get(testUserId))
.setEmailVerified(false)
.update()) {
@ -636,14 +632,10 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
infoPage.assertCurrent();
assertEquals("Your account has been updated.", infoPage.getInfo());
// Now log into account page
accountPage.setAuthRealm(testRealm().toRepresentation().getRealm());
accountPage.navigateTo();
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
accountPage.assertCurrent();
// Now login to app
TestAppHelper testAppHelper = new TestAppHelper(oauth, loginPage, appPage);
testAppHelper.login("test-user@localhost", "password");
appPage.assertCurrent();
}
}
@ -686,9 +678,8 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
.setEmailVerified(false)
.setRequiredActions(RequiredAction.VERIFY_EMAIL)
.update()) {
accountPage.setAuthRealm(testRealm().toRepresentation().getRealm());
accountPage.navigateTo();
loginPage.open();
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
@ -701,7 +692,7 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
driver.navigate().to(verificationUrl.trim());
accountPage.assertCurrent();
appPage.assertCurrent();
}
}
@ -722,9 +713,7 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
driver.navigate().to(verificationUrl);
accountPage.setAuthRealm(testRealm().toRepresentation().getRealm());
accountPage.navigateTo();
loginPage.open();
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
@ -749,59 +738,52 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
driver.navigate().to(verificationUrl);
accountPage.setAuthRealm(testRealm().toRepresentation().getRealm());
accountPage.navigateTo();
loginPage.open();
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
accountPage.assertCurrent();
appPage.assertCurrent();
}
}
@Test
public void verifyEmailDuringAuthFlowAfterLogout() throws IOException, MessagingException {
public void verifyEmailDuringAuthFlowAfterLogout() throws URISyntaxException, IOException, MessagingException {
try (Closeable u = new UserAttributeUpdater(testRealm().users().get(testUserId))
.setEmailVerified(true)
.update()) {
accountPage.setAuthRealm(testRealm().toRepresentation().getRealm());
accountPage.navigateTo();
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
TestAppHelper testAppHelper = new TestAppHelper(oauth, loginPage, appPage);
testAppHelper.login("test-user@localhost", "password");
appPage.assertCurrent();
accountPage.assertCurrent();
accountPage.logOut();
loginPage.assertCurrent();
testAppHelper.logout();
appPage.assertCurrent();
verifyEmailDuringAuthFlow();
}
}
@Test
public void verifyEmailDuringAuthFlowAfterRefresh() throws IOException, MessagingException {
public void verifyEmailDuringAuthFlowAfterRefresh() throws URISyntaxException, IOException, MessagingException {
try (Closeable u = new UserAttributeUpdater(testRealm().users().get(testUserId))
.setEmailVerified(true)
.update()) {
final String testRealmName = testRealm().toRepresentation().getRealm();
accountPage.setAuthRealm(testRealmName);
// Browser 1: Log in
accountPage.navigateTo();
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
accountPage.assertCurrent();
TestAppHelper testAppHelper = new TestAppHelper(oauth, loginPage, appPage);
testAppHelper.login("test-user@localhost", "password");
appPage.assertCurrent();
// Browser 2: Log in
driver2.navigate().to(accountPage.buildUri().toString());
driver2.navigate().to(oauth.getLoginFormUrl());
assertThat(driver2.getTitle(), is("Sign in to " + testRealmName));
driver2.findElement(By.id("username")).sendKeys("test-user@localhost");
driver2.findElement(By.id("password")).sendKeys("password");
driver2.findElement(By.id("password")).submit();
assertThat(driver2.getCurrentUrl(), Matchers.startsWith(accountPage.buildUri().toString()));
assertThat(driver2.getCurrentUrl(), Matchers.startsWith(oauth.APP_AUTH_ROOT));
// Admin: set required action to VERIFY_EMAIL
try (Closeable u1 = new UserAttributeUpdater(testRealm().users().get(testUserId))
@ -810,17 +792,15 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
.update()) {
// Browser 2: Refresh window
driver2.navigate().refresh();
assertThat(driver2.getCurrentUrl(), Matchers.startsWith(accountPage.buildUri().toString()));
assertThat(driver2.getCurrentUrl(), Matchers.startsWith(oauth.APP_AUTH_ROOT));
// Browser 1: Logout
accountPage.logOut();
testAppHelper.logout();
appPage.assertCurrent();
// Browser 1: Go to account page
accountPage.navigateTo();
// Browser 1: Log in
loginPage.assertCurrent();
loginPage.login("test-user@localhost", "password");
testAppHelper.login("test-user@localhost", "password");
verifyEmailPage.assertCurrent();
@ -841,9 +821,9 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
assertThat(driver2.getPageSource(), Matchers.containsString("kc-info-message"));
assertThat(driver2.getPageSource(), Matchers.containsString("Your email address has been verified."));
// Browser 1: Expect land back to account after refresh
// Browser 1: Expect land back to app after refresh
driver.navigate().refresh();
accountPage.assertCurrent();
appPage.assertCurrent();
}
}
}
@ -853,12 +833,9 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
UserAttributeUpdater userAttributeUpdater = new UserAttributeUpdater(testRealm().users().get(testUserId));
userAttributeUpdater.setEmailVerified(true).update();
final String testRealmName = testRealm().toRepresentation().getRealm();
accountPage.setAuthRealm(testRealmName);
oauth.realm(testRealmName).clientId("account").redirectUri(getAuthServerRoot() + "realms/" + testRealmName + "/account");
loginPage.open();
loginPage.login("test-user@localhost", "password");
accountPage.assertCurrent();
appPage.assertCurrent();
userAttributeUpdater.setEmailVerified(false).setRequiredActions(RequiredAction.VERIFY_EMAIL).update();
@ -874,8 +851,8 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
// confirm
driver.navigate().to(verificationUrl);
// back to account, already logged in
accountPage.assertCurrent();
// back to app, already logged in
appPage.assertCurrent();
// email should be verified and required actions empty
UserRepresentation user = testRealm().users().get(testUserId).toRepresentation();
@ -891,9 +868,6 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
UserAttributeUpdater userAttributeUpdater = new UserAttributeUpdater(testRealm().users().get(testUserId));
userAttributeUpdater.setEmailVerified(false).update();
final String testRealmName = testRealm().toRepresentation().getRealm();
accountPage.setAuthRealm(testRealmName);
oauth.realm(testRealmName).clientId("account").redirectUri(getAuthServerRoot() + "realms/" + testRealmName + "/account");
loginPage.open();
String authSessionId = AuthenticationSessionFailoverClusterTest.getAuthSessionCookieValue(driver);
@ -916,8 +890,8 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
// confirm
driver.navigate().to(verificationUrl);
// back to account, already logged in
accountPage.assertCurrent();
// back to app, already logged in
appPage.assertCurrent();
// email should be verified and required actions empty
UserRepresentation user = testRealm().users().get(testUserId).toRepresentation();
@ -930,12 +904,9 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
UserAttributeUpdater userAttributeUpdater = new UserAttributeUpdater(testRealm().users().get(testUserId));
userAttributeUpdater.setEmailVerified(true).update();
final String testRealmName = testRealm().toRepresentation().getRealm();
accountPage.setAuthRealm(testRealmName);
oauth.realm(testRealmName).clientId("account").redirectUri(getAuthServerRoot() + "realms/" + testRealmName + "/account");
loginPage.open();
loginPage.login("test-user@localhost", "password");
accountPage.assertCurrent();
appPage.assertCurrent();
userAttributeUpdater.setEmailVerified(false).setRequiredActions(RequiredAction.VERIFY_EMAIL).update();
@ -960,9 +931,7 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
assertThat(driver2.getPageSource(), Matchers.containsString("kc-info-message"));
assertThat(driver2.getPageSource(), Matchers.containsString("Your email address has been verified."));
final WebElement backToApplicationLink = driver2.findElement(By.linkText("« Back to Application"));
assertThat(backToApplicationLink, Matchers.notNullValue());
backToApplicationLink.click();
driver2.navigate().to(oauth.getLoginFormUrl());
// login page should be shown in the second browser
assertThat(driver2.getPageSource(), Matchers.containsString("kc-login"));
@ -973,9 +942,9 @@ public class RequiredActionEmailVerificationTest extends AbstractTestRealmKeyclo
Assert.assertTrue(user.isEmailVerified());
Assert.assertThat(user.getRequiredActions(), Matchers.empty());
// after refresh in the first browser the account console should be shown
// after refresh in the first browser the app should be shown
driver.navigate().refresh();
accountPage.assertCurrent();
appPage.assertCurrent();
}
@Test