AbstractCustomAccountManagementTest - old account console dependencies removed. Closes #19668

This commit is contained in:
Lukas Hanusovsky 2023-05-03 16:05:11 +02:00 committed by Michal Hajas
parent 2ad8f7dd62
commit 130807fa7b
4 changed files with 59 additions and 69 deletions

View file

@ -20,7 +20,6 @@ package org.keycloak.testsuite.account.custom;
import org.jboss.arquillian.graphene.page.Page; import org.jboss.arquillian.graphene.page.Page;
import org.junit.Before; import org.junit.Before;
import org.keycloak.testsuite.AbstractAuthTest; import org.keycloak.testsuite.AbstractAuthTest;
import org.keycloak.testsuite.auth.page.account.AccountManagement;
import org.keycloak.testsuite.auth.page.account.fragment.AccountManagementPatternFlyAlert; import org.keycloak.testsuite.auth.page.account.fragment.AccountManagementPatternFlyAlert;
import static org.junit.Assert.assertTrue; 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 { public abstract class AbstractAccountManagementTest extends AbstractAuthTest {
@Page
protected AccountManagement testRealmAccountManagementPage;
@Page @Page
protected AccountManagementPatternFlyAlert alert; protected AccountManagementPatternFlyAlert alert;
@ -42,7 +38,6 @@ public abstract class AbstractAccountManagementTest extends AbstractAuthTest {
public void setDefaultPageUriParameters() { public void setDefaultPageUriParameters() {
super.setDefaultPageUriParameters(); super.setDefaultPageUriParameters();
testRealmPage.setAuthRealm(TEST); testRealmPage.setAuthRealm(TEST);
testRealmAccountManagementPage.setAuthRealm(TEST);
} }
@Before @Before

View file

@ -17,22 +17,25 @@
package org.keycloak.testsuite.account.custom; package org.keycloak.testsuite.account.custom;
import jakarta.ws.rs.core.Response;
import org.junit.Before; import org.junit.Before;
import org.keycloak.admin.client.resource.AuthenticationManagementResource; import org.keycloak.admin.client.resource.AuthenticationManagementResource;
import org.keycloak.common.Profile;
import org.keycloak.models.AuthenticationExecutionModel; import org.keycloak.models.AuthenticationExecutionModel;
import org.keycloak.representations.idm.AuthenticationExecutionInfoRepresentation; 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.List;
import java.util.Optional;
import java.util.function.Function; 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> * @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 { public abstract class AbstractCustomAccountManagementTest extends AbstractAccountManagementTest {
private AuthenticationManagementResource authMgmtResource; private AuthenticationManagementResource authMgmtResource;
@ -45,6 +48,18 @@ public abstract class AbstractCustomAccountManagementTest extends AbstractAccoun
@Before @Before
public void beforeTest() { public void beforeTest() {
authMgmtResource = testRealmResource().flows(); 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() { protected AuthenticationManagementResource getAuthMgmtResource() {

View file

@ -16,18 +16,11 @@
*/ */
package org.keycloak.testsuite.account.custom; package org.keycloak.testsuite.account.custom;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.keycloak.models.AuthenticationExecutionModel.Requirement; 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.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 { 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 @Test
public void cookieAlternative() { public void cookieAlternative() {
//test default setting of cookie provider //test default setting of cookie provider
//login to account management //login
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
//check SSO is working //check SSO is working
@ -71,11 +46,11 @@ public class CustomAuthFlowCookieTest extends AbstractCustomAccountManagementTes
//disable cookie //disable cookie
updateRequirement("browser", "auth-cookie", Requirement.DISABLED); updateRequirement("browser", "auth-cookie", Requirement.DISABLED);
//login to account management //login
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); 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 //navigate to different client of the same realm and verify user is not logged in
oauth.openLoginForm(); oauth.openLoginForm();
assertEquals("Sign in to test", driver.getTitle()); assertEquals("Sign in to test", driver.getTitle());

View file

@ -37,6 +37,8 @@ import org.keycloak.testsuite.updaters.RealmAttributeUpdater;
import jakarta.ws.rs.NotFoundException; import jakarta.ws.rs.NotFoundException;
import jakarta.ws.rs.core.Response; import jakarta.ws.rs.core.Response;
import org.keycloak.testsuite.util.AccountHelper;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -101,12 +103,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
private void configureOTP() { private void configureOTP() {
//configure OTP for test user //configure OTP for test user
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
String totpSecret = testRealmLoginPage.form().totpForm().getTotpSecret(); String totpSecret = testRealmLoginPage.form().totpForm().getTotpSecret();
testRealmLoginPage.form().totpForm().setTotp(totp.generateTOTP(totpSecret)); testRealmLoginPage.form().totpForm().setTotp(totp.generateTOTP(totpSecret));
testRealmLoginPage.form().totpForm().submit(); testRealmLoginPage.form().totpForm().submit();
testRealmAccountManagementPage.signOut(); AccountHelper.logout(testRealmResource(), testUser.getUsername());
//verify that user has OTP configured //verify that user has OTP configured
testUser = testRealmResource().users().get(testUser.getId()).toRepresentation(); testUser = testRealmResource().users().get(testUser.getId()).toRepresentation();
@ -122,11 +124,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
testRealmResource().update(realm); testRealmResource().update(realm);
updateRequirement("browser", Requirement.REQUIRED, (authExec) -> authExec.getDisplayName().equals("Browser - Conditional OTP")); updateRequirement("browser", Requirement.REQUIRED, (authExec) -> authExec.getDisplayName().equals("Browser - Conditional OTP"));
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertTrue(loginConfigTotpPage.isCurrent()); assertTrue(loginConfigTotpPage.isCurrent());
configureOTP(); configureOTP();
driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
//verify that the page is login page, not totp setup //verify that the page is login page, not totp setup
@ -155,12 +158,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
testRealmResource().update(realm); testRealmResource().update(realm);
updateRequirement("browser", Requirement.REQUIRED, (authExec) -> authExec.getDisplayName().equals("Browser - Conditional OTP")); updateRequirement("browser", Requirement.REQUIRED, (authExec) -> authExec.getDisplayName().equals("Browser - Conditional OTP"));
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertTrue(loginConfigTotpPage.isCurrent()); assertTrue(loginConfigTotpPage.isCurrent());
//configure OTP for test user //configure OTP for test user
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
final String totpSecret = testRealmLoginPage.form().totpForm().getTotpSecret(); final String totpSecret = testRealmLoginPage.form().totpForm().getTotpSecret();
@ -171,9 +174,9 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
testRealmLoginPage.form().totpForm().setTotp(generatedOtp); testRealmLoginPage.form().totpForm().setTotp(generatedOtp);
testRealmLoginPage.form().totpForm().submit(); testRealmLoginPage.form().totpForm().submit();
testRealmAccountManagementPage.signOut(); AccountHelper.logout(testRealmResource(), testUser.getUsername());
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
loginTotpPage.assertCurrent(); loginTotpPage.assertCurrent();
@ -195,7 +198,7 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
setConditionalOTPForm(config); setConditionalOTPForm(config);
//test OTP is required //test OTP is required
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
//verify that the page is login page, not totp setup //verify that the page is login page, not totp setup
@ -211,9 +214,9 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
setConditionalOTPForm(config); setConditionalOTPForm(config);
//test OTP is skipped //test OTP is skipped
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertCurrentUrlStartsWith(testRealmAccountManagementPage); assertCurrentUrlStartsWith(oauth.APP_AUTH_ROOT);
} }
@Test @Test
@ -226,11 +229,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
setConditionalOTPForm(config); setConditionalOTPForm(config);
//test OTP is forced //test OTP is forced
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertTrue(loginConfigTotpPage.isCurrent()); assertTrue(loginConfigTotpPage.isCurrent());
configureOTP(); configureOTP();
driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
//verify that the page is login page, not totp setup //verify that the page is login page, not totp setup
@ -252,7 +256,7 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
setConditionalOTPForm(config); setConditionalOTPForm(config);
//test OTP is required //test OTP is required
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
//verify that the page is login page, not totp setup //verify that the page is login page, not totp setup
@ -273,14 +277,13 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
setConditionalOTPForm(config); setConditionalOTPForm(config);
//test OTP is skipped //test OTP is skipped
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertCurrentUrlStartsWith(testRealmAccountManagementPage); assertCurrentUrlStartsWith(oauth.APP_AUTH_ROOT);
} }
@Test @Test
public void conditionalOTPDefaultForceWithChecks() { public void conditionalOTPDefaultForceWithChecks() {
//prepare config - default force //prepare config - default force
Map<String, String> config = new HashMap<>(); Map<String, String> config = new HashMap<>();
config.put(OTP_CONTROL_USER_ATTRIBUTE, "noSuchUserSkipAttribute"); config.put(OTP_CONTROL_USER_ATTRIBUTE, "noSuchUserSkipAttribute");
@ -293,11 +296,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
setConditionalOTPForm(config); setConditionalOTPForm(config);
//test OTP is forced //test OTP is forced
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertTrue(loginConfigTotpPage.isCurrent()); assertTrue(loginConfigTotpPage.isCurrent());
configureOTP(); configureOTP();
driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
//verify that the page is login page, not totp setup //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); testRealmResource().users().get(testUser.getId()).update(testUser);
//test OTP is skipped //test OTP is skipped
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertCurrentUrlStartsWith(testRealmAccountManagementPage); assertCurrentUrlStartsWith(oauth.APP_AUTH_ROOT);
} }
@Test @Test
public void conditionalOTPUserAttributeForce() { public void conditionalOTPUserAttributeForce() {
//prepare config - user attribute, default to skip //prepare config - user attribute, default to skip
Map<String, String> config = new HashMap<>(); Map<String, String> config = new HashMap<>();
config.put(OTP_CONTROL_USER_ATTRIBUTE, "userSkipAttribute"); config.put(OTP_CONTROL_USER_ATTRIBUTE, "userSkipAttribute");
@ -339,11 +342,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
testRealmResource().users().get(testUser.getId()).update(testUser); testRealmResource().users().get(testUser.getId()).update(testUser);
//test OTP is required //test OTP is required
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertTrue(loginConfigTotpPage.isCurrent()); assertTrue(loginConfigTotpPage.isCurrent());
configureOTP(); configureOTP();
driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
//verify that the page is login page, not totp setup //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); testRealmResource().users().get(testUser.getId()).roles().realmLevel().add(realmRoles);
//test OTP is skipped //test OTP is skipped
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertCurrentUrlStartsWith(testRealmAccountManagementPage); assertCurrentUrlStartsWith(oauth.APP_AUTH_ROOT);
} }
@Test @Test
@ -391,12 +395,13 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
testRealmResource().users().get(testUser.getId()).roles().realmLevel().add(realmRoles); testRealmResource().users().get(testUser.getId()).roles().realmLevel().add(realmRoles);
//test OTP is required //test OTP is required
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertTrue(loginConfigTotpPage.isCurrent()); assertTrue(loginConfigTotpPage.isCurrent());
configureOTP(); configureOTP();
driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
//verify that the page is login page, not totp setup //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()); testRealmResource().users().get(testUser.getId()).joinGroup(group.getId());
//test OTP is required //test OTP is required
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertTrue(loginConfigTotpPage.isCurrent()); assertTrue(loginConfigTotpPage.isCurrent());
configureOTP(); configureOTP();
driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
//verify that the page is login page, not totp setup //verify that the page is login page, not totp setup
@ -455,7 +461,6 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
} }
@Test @Test
public void conditionalOTPRequestHeaderSkip() { public void conditionalOTPRequestHeaderSkip() {
//prepare config - request header skip, default to force //prepare config - request header skip, default to force
Map<String, String> config = new HashMap<>(); Map<String, String> config = new HashMap<>();
@ -466,13 +471,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
setConditionalOTPForm(config); setConditionalOTPForm(config);
//test OTP is skipped //test OTP is skipped
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertCurrentUrlStartsWith(testRealmAccountManagementPage); assertCurrentUrlStartsWith(oauth.APP_AUTH_ROOT);
} }
@Test @Test
public void conditionalOTPRequestHeaderForce() { public void conditionalOTPRequestHeaderForce() {
//prepare config - equest header force, default to skip //prepare config - equest header force, default to skip
Map<String, String> config = new HashMap<>(); Map<String, String> config = new HashMap<>();
@ -483,11 +487,12 @@ public class CustomAuthFlowOTPTest extends AbstractCustomAccountManagementTest {
setConditionalOTPForm(config); setConditionalOTPForm(config);
//test OTP is required //test OTP is required
testRealmAccountManagementPage.navigateTo(); driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
assertEquals(PageUtils.getPageTitle(driver), "Mobile Authenticator Setup"); assertEquals(PageUtils.getPageTitle(driver), "Mobile Authenticator Setup");
configureOTP(); configureOTP();
driver.navigate().to(oauth.getLoginFormUrl());
testRealmLoginPage.form().login(testUser); testRealmLoginPage.form().login(testUser);
//verify that the page is login page, not totp setup //verify that the page is login page, not totp setup