AbstractCustomAccountManagementTest - old account console dependencies removed. Closes #19668
This commit is contained in:
parent
2ad8f7dd62
commit
130807fa7b
4 changed files with 59 additions and 69 deletions
|
@ -20,7 +20,6 @@ package org.keycloak.testsuite.account.custom;
|
|||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.junit.Before;
|
||||
import org.keycloak.testsuite.AbstractAuthTest;
|
||||
import org.keycloak.testsuite.auth.page.account.AccountManagement;
|
||||
import org.keycloak.testsuite.auth.page.account.fragment.AccountManagementPatternFlyAlert;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -32,9 +31,6 @@ import static org.keycloak.testsuite.auth.page.AuthRealm.TEST;
|
|||
*/
|
||||
public abstract class AbstractAccountManagementTest extends AbstractAuthTest {
|
||||
|
||||
@Page
|
||||
protected AccountManagement testRealmAccountManagementPage;
|
||||
|
||||
@Page
|
||||
protected AccountManagementPatternFlyAlert alert;
|
||||
|
||||
|
@ -42,7 +38,6 @@ public abstract class AbstractAccountManagementTest extends AbstractAuthTest {
|
|||
public void setDefaultPageUriParameters() {
|
||||
super.setDefaultPageUriParameters();
|
||||
testRealmPage.setAuthRealm(TEST);
|
||||
testRealmAccountManagementPage.setAuthRealm(TEST);
|
||||
}
|
||||
|
||||
@Before
|
||||
|
|
|
@ -17,22 +17,25 @@
|
|||
|
||||
package org.keycloak.testsuite.account.custom;
|
||||
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.Before;
|
||||
import org.keycloak.admin.client.resource.AuthenticationManagementResource;
|
||||
import org.keycloak.common.Profile;
|
||||
import org.keycloak.models.AuthenticationExecutionModel;
|
||||
import org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation;
|
||||
import org.keycloak.testsuite.arquillian.annotation.DisableFeature;
|
||||
import org.keycloak.representations.idm.ClientRepresentation;
|
||||
import org.keycloak.testsuite.admin.ApiUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.keycloak.testsuite.util.OAuthClient.APP_ROOT;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:vramik@redhat.com">Vlastislav Ramik</a>
|
||||
*/
|
||||
@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true) // TODO remove this (KEYCLOAK-16228)
|
||||
public abstract class AbstractCustomAccountManagementTest extends AbstractAccountManagementTest {
|
||||
|
||||
private AuthenticationManagementResource authMgmtResource;
|
||||
|
@ -45,6 +48,18 @@ public abstract class AbstractCustomAccountManagementTest extends AbstractAccoun
|
|||
@Before
|
||||
public void beforeTest() {
|
||||
authMgmtResource = testRealmResource().flows();
|
||||
|
||||
ClientRepresentation testApp = new ClientRepresentation();
|
||||
testApp.setClientId("test-app");
|
||||
testApp.setEnabled(true);
|
||||
testApp.setBaseUrl(APP_ROOT);
|
||||
testApp.setRedirectUris(Arrays.asList(new String[]{APP_ROOT + "/*"}));
|
||||
testApp.setAdminUrl(APP_ROOT + "/logout");
|
||||
testApp.setSecret("password");
|
||||
Response response = testRealmResource().clients().create(testApp);
|
||||
assertEquals(201, response.getStatus());
|
||||
getCleanup().addClientUuid(ApiUtil.getCreatedId(response));
|
||||
response.close();
|
||||
}
|
||||
|
||||
protected AuthenticationManagementResource getAuthMgmtResource() {
|
||||
|
|
|
@ -16,18 +16,11 @@
|
|||
*/
|
||||
package org.keycloak.testsuite.account.custom;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.models.AuthenticationExecutionModel.Requirement;
|
||||
import org.keycloak.representations.idm.ClientRepresentation;
|
||||
import org.keycloak.testsuite.admin.ApiUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.keycloak.testsuite.util.OAuthClient.APP_ROOT;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -35,29 +28,11 @@ import static org.keycloak.testsuite.util.OAuthClient.APP_ROOT;
|
|||
*/
|
||||
public class CustomAuthFlowCookieTest extends AbstractCustomAccountManagementTest {
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void beforeTest() {
|
||||
super.beforeTest();
|
||||
|
||||
ClientRepresentation testApp = new ClientRepresentation();
|
||||
testApp.setClientId("test-app");
|
||||
testApp.setEnabled(true);
|
||||
testApp.setBaseUrl(APP_ROOT);
|
||||
testApp.setRedirectUris(Arrays.asList(new String[]{APP_ROOT + "/*"}));
|
||||
testApp.setAdminUrl(APP_ROOT + "/logout");
|
||||
testApp.setSecret("password");
|
||||
Response response = testRealmResource().clients().create(testApp);
|
||||
assertEquals(201, response.getStatus());
|
||||
getCleanup().addClientUuid(ApiUtil.getCreatedId(response));
|
||||
response.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cookieAlternative() {
|
||||
//test default setting of cookie provider
|
||||
//login to account management
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
//login
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
//check SSO is working
|
||||
|
@ -71,11 +46,11 @@ public class CustomAuthFlowCookieTest extends AbstractCustomAccountManagementTes
|
|||
//disable cookie
|
||||
updateRequirement("browser", "auth-cookie", Requirement.DISABLED);
|
||||
|
||||
//login to account management
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
//login
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
//SSO shouln't work
|
||||
//SSO shouldn't work
|
||||
//navigate to different client of the same realm and verify user is not logged in
|
||||
oauth.openLoginForm();
|
||||
assertEquals("Sign in to test", driver.getTitle());
|
||||
|
|
|
@ -37,6 +37,8 @@ import org.keycloak.testsuite.updaters.RealmAttributeUpdater;
|
|||
|
||||
import jakarta.ws.rs.NotFoundException;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.keycloak.testsuite.util.AccountHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -101,12 +103,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
|
||||
private void configureOTP() {
|
||||
//configure OTP for test user
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
String totpSecret = testRealmLoginPage.form().totpForm().getTotpSecret();
|
||||
testRealmLoginPage.form().totpForm().setTotp(totp.generateTOTP(totpSecret));
|
||||
testRealmLoginPage.form().totpForm().submit();
|
||||
testRealmAccountManagementPage.signOut();
|
||||
AccountHelper.logout(testRealmResource(), testUser.getUsername());
|
||||
|
||||
//verify that user has OTP configured
|
||||
testUser = testRealmResource().users().get(testUser.getId()).toRepresentation();
|
||||
|
@ -122,11 +124,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
testRealmResource().update(realm);
|
||||
|
||||
updateRequirement("browser", Requirement.REQUIRED, (authExec) -> authExec.getDisplayName().equals("Browser - Conditional OTP"));
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
assertTrue(loginConfigTotpPage.isCurrent());
|
||||
|
||||
configureOTP();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
//verify that the page is login page, not totp setup
|
||||
|
@ -155,12 +158,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
testRealmResource().update(realm);
|
||||
|
||||
updateRequirement("browser", Requirement.REQUIRED, (authExec) -> authExec.getDisplayName().equals("Browser - Conditional OTP"));
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
assertTrue(loginConfigTotpPage.isCurrent());
|
||||
|
||||
//configure OTP for test user
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
final String totpSecret = testRealmLoginPage.form().totpForm().getTotpSecret();
|
||||
|
@ -171,9 +174,9 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
|
||||
testRealmLoginPage.form().totpForm().setTotp(generatedOtp);
|
||||
testRealmLoginPage.form().totpForm().submit();
|
||||
testRealmAccountManagementPage.signOut();
|
||||
AccountHelper.logout(testRealmResource(), testUser.getUsername());
|
||||
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
loginTotpPage.assertCurrent();
|
||||
|
@ -195,7 +198,7 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
setConditionalOTPForm(config);
|
||||
|
||||
//test OTP is required
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
//verify that the page is login page, not totp setup
|
||||
|
@ -211,9 +214,9 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
setConditionalOTPForm(config);
|
||||
|
||||
//test OTP is skipped
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
assertCurrentUrlStartsWith(testRealmAccountManagementPage);
|
||||
assertCurrentUrlStartsWith(oauth.APP_AUTH_ROOT);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -226,11 +229,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
setConditionalOTPForm(config);
|
||||
|
||||
//test OTP is forced
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
assertTrue(loginConfigTotpPage.isCurrent());
|
||||
|
||||
configureOTP();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
//verify that the page is login page, not totp setup
|
||||
|
@ -252,7 +256,7 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
setConditionalOTPForm(config);
|
||||
|
||||
//test OTP is required
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
//verify that the page is login page, not totp setup
|
||||
|
@ -273,14 +277,13 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
setConditionalOTPForm(config);
|
||||
|
||||
//test OTP is skipped
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
assertCurrentUrlStartsWith(testRealmAccountManagementPage);
|
||||
assertCurrentUrlStartsWith(oauth.APP_AUTH_ROOT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conditionalOTPDefaultForceWithChecks() {
|
||||
|
||||
//prepare config - default force
|
||||
Map<String, String> config = new HashMap<>();
|
||||
config.put(OTP_CONTROL_USER_ATTRIBUTE, "noSuchUserSkipAttribute");
|
||||
|
@ -293,11 +296,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
setConditionalOTPForm(config);
|
||||
|
||||
//test OTP is forced
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
assertTrue(loginConfigTotpPage.isCurrent());
|
||||
|
||||
configureOTP();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
//verify that the page is login page, not totp setup
|
||||
|
@ -318,15 +322,14 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
testRealmResource().users().get(testUser.getId()).update(testUser);
|
||||
|
||||
//test OTP is skipped
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
assertCurrentUrlStartsWith(testRealmAccountManagementPage);
|
||||
assertCurrentUrlStartsWith(oauth.APP_AUTH_ROOT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conditionalOTPUserAttributeForce() {
|
||||
|
||||
//prepare config - user attribute, default to skip
|
||||
Map<String, String> config = new HashMap<>();
|
||||
config.put(OTP_CONTROL_USER_ATTRIBUTE, "userSkipAttribute");
|
||||
|
@ -339,11 +342,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
testRealmResource().users().get(testUser.getId()).update(testUser);
|
||||
|
||||
//test OTP is required
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
assertTrue(loginConfigTotpPage.isCurrent());
|
||||
|
||||
configureOTP();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
//verify that the page is login page, not totp setup
|
||||
|
@ -368,9 +372,9 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
testRealmResource().users().get(testUser.getId()).roles().realmLevel().add(realmRoles);
|
||||
|
||||
//test OTP is skipped
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
assertCurrentUrlStartsWith(testRealmAccountManagementPage);
|
||||
assertCurrentUrlStartsWith(oauth.APP_AUTH_ROOT);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -391,12 +395,13 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
testRealmResource().users().get(testUser.getId()).roles().realmLevel().add(realmRoles);
|
||||
|
||||
//test OTP is required
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
assertTrue(loginConfigTotpPage.isCurrent());
|
||||
|
||||
configureOTP();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
//verify that the page is login page, not totp setup
|
||||
|
@ -419,12 +424,13 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
testRealmResource().users().get(testUser.getId()).joinGroup(group.getId());
|
||||
|
||||
//test OTP is required
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
assertTrue(loginConfigTotpPage.isCurrent());
|
||||
|
||||
configureOTP();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
//verify that the page is login page, not totp setup
|
||||
|
@ -455,7 +461,6 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
|
||||
public void conditionalOTPRequestHeaderSkip() {
|
||||
//prepare config - request header skip, default to force
|
||||
Map<String, String> config = new HashMap<>();
|
||||
|
@ -466,13 +471,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
setConditionalOTPForm(config);
|
||||
|
||||
//test OTP is skipped
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
assertCurrentUrlStartsWith(testRealmAccountManagementPage);
|
||||
assertCurrentUrlStartsWith(oauth.APP_AUTH_ROOT);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
public void conditionalOTPRequestHeaderForce() {
|
||||
//prepare config - equest header force, default to skip
|
||||
Map<String, String> config = new HashMap<>();
|
||||
|
@ -483,11 +487,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
|
|||
setConditionalOTPForm(config);
|
||||
|
||||
//test OTP is required
|
||||
testRealmAccountManagementPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
assertEquals(PageUtils.getPageTitle(driver), "Mobile Authenticator Setup");
|
||||
|
||||
configureOTP();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
//verify that the page is login page, not totp setup
|
||||
|
|
Loading…
Reference in a new issue