KEYCLOAK-17376 - Fix DeviceActivityTest, SigningInTest and PermissionsTest
This commit is contained in:
parent
b3ea6f74be
commit
95d9cd2b38
3 changed files with 27 additions and 8 deletions
|
@ -18,21 +18,25 @@
|
|||
package org.keycloak.testsuite.ui.account2;
|
||||
|
||||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.admin.client.resource.RoleScopeResource;
|
||||
import org.keycloak.representations.idm.RoleRepresentation;
|
||||
import org.keycloak.testsuite.ui.account2.page.ForbiddenPage;
|
||||
import org.keycloak.testsuite.ui.account2.page.PersonalInfoPage;
|
||||
import org.keycloak.testsuite.ui.account2.page.SigningInPage;
|
||||
import org.keycloak.testsuite.ui.account2.page.WelcomeScreen;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.keycloak.models.AccountRoles.MANAGE_ACCOUNT;
|
||||
import static org.keycloak.models.Constants.ACCOUNT_MANAGEMENT_CLIENT_ID;
|
||||
import static org.keycloak.testsuite.auth.page.AuthRealm.TEST;
|
||||
|
||||
/**
|
||||
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||
*/
|
||||
@Ignore // TODO Remove when KEYCLOAK-17366 is fixed
|
||||
public class PermissionsTest extends AbstractAccountTest {
|
||||
@Page
|
||||
private WelcomeScreen welcomeScreen;
|
||||
|
@ -46,14 +50,20 @@ public class PermissionsTest extends AbstractAccountTest {
|
|||
@Page
|
||||
private ForbiddenPage forbiddenPage;
|
||||
|
||||
private static final String DEFAULT_ROLE_NAME = "default-roles-" + TEST;
|
||||
|
||||
@Test
|
||||
public void manageAccountRoleRequired() {
|
||||
// remove the default role from test user
|
||||
// remove the default role from test user ACCOUNT_MANAGEMENT_CLIENT_ID
|
||||
String accountClientId = testRealmResource().clients().findByClientId(ACCOUNT_MANAGEMENT_CLIENT_ID).get(0).getId();
|
||||
RoleScopeResource roleScopes = testUserResource().roles().clientLevel(accountClientId);
|
||||
roleScopes.remove(roleScopes.listAll().stream()
|
||||
.filter(r -> MANAGE_ACCOUNT.equals(r.getName()))
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
List<RoleRepresentation> rolesToRemove = testRealmResource().roles()
|
||||
.get(DEFAULT_ROLE_NAME)
|
||||
.getClientRoleComposites(accountClientId).stream()
|
||||
.filter(role -> role.getName().equals(MANAGE_ACCOUNT))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
testRealmResource().roles().get(DEFAULT_ROLE_NAME).deleteComposites(rolesToRemove);
|
||||
|
||||
welcomeScreen.header().clickLoginBtn();
|
||||
loginToAccount();
|
||||
|
@ -70,5 +80,8 @@ public class PermissionsTest extends AbstractAccountTest {
|
|||
welcomeScreen.assertCurrent();
|
||||
welcomeScreen.header().assertLoginBtnVisible(true);
|
||||
welcomeScreen.header().assertLogoutBtnVisible(false);
|
||||
|
||||
// Revert role changes
|
||||
getCleanup().addCleanup((Runnable) () -> testRealmResource().roles().get(DEFAULT_ROLE_NAME).addComposites(rolesToRemove));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,7 +128,10 @@ public class DeviceActivityPage extends AbstractLoggedInPage {
|
|||
}
|
||||
|
||||
public String getLastAccess() {
|
||||
return getTextFromItem("last-access").split("Last accessed on ")[1];
|
||||
String lastAccessedText = getTextFromElement(
|
||||
driver.findElement(By.cssSelector("[id*='last-access'] strong")));
|
||||
|
||||
return getTextFromItem("last-access").substring(lastAccessedText.length()).trim();
|
||||
}
|
||||
|
||||
public String getClients() {
|
||||
|
|
|
@ -209,7 +209,10 @@ public class SigningInPage extends AbstractLoggedInPage {
|
|||
}
|
||||
|
||||
public String getCreatedAtStr() {
|
||||
return getTextFromItem(CREATED_AT).split("Created: ")[1];
|
||||
String lastCreatedAtText = getTextFromElement(
|
||||
driver.findElement(By.cssSelector("[id*='" + CREATED_AT + "'] strong")));
|
||||
|
||||
return getTextFromItem(CREATED_AT).substring(lastCreatedAtText.length()).trim();
|
||||
}
|
||||
|
||||
public LocalDateTime getCreatedAt() {
|
||||
|
|
Loading…
Reference in a new issue