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;
|
package org.keycloak.testsuite.ui.account2;
|
||||||
|
|
||||||
import org.jboss.arquillian.graphene.page.Page;
|
import org.jboss.arquillian.graphene.page.Page;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
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.ForbiddenPage;
|
||||||
import org.keycloak.testsuite.ui.account2.page.PersonalInfoPage;
|
import org.keycloak.testsuite.ui.account2.page.PersonalInfoPage;
|
||||||
import org.keycloak.testsuite.ui.account2.page.SigningInPage;
|
import org.keycloak.testsuite.ui.account2.page.SigningInPage;
|
||||||
import org.keycloak.testsuite.ui.account2.page.WelcomeScreen;
|
import org.keycloak.testsuite.ui.account2.page.WelcomeScreen;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.keycloak.models.AccountRoles.MANAGE_ACCOUNT;
|
import static org.keycloak.models.AccountRoles.MANAGE_ACCOUNT;
|
||||||
import static org.keycloak.models.Constants.ACCOUNT_MANAGEMENT_CLIENT_ID;
|
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>
|
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||||
*/
|
*/
|
||||||
|
@Ignore // TODO Remove when KEYCLOAK-17366 is fixed
|
||||||
public class PermissionsTest extends AbstractAccountTest {
|
public class PermissionsTest extends AbstractAccountTest {
|
||||||
@Page
|
@Page
|
||||||
private WelcomeScreen welcomeScreen;
|
private WelcomeScreen welcomeScreen;
|
||||||
|
@ -46,14 +50,20 @@ public class PermissionsTest extends AbstractAccountTest {
|
||||||
@Page
|
@Page
|
||||||
private ForbiddenPage forbiddenPage;
|
private ForbiddenPage forbiddenPage;
|
||||||
|
|
||||||
|
private static final String DEFAULT_ROLE_NAME = "default-roles-" + TEST;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void manageAccountRoleRequired() {
|
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();
|
String accountClientId = testRealmResource().clients().findByClientId(ACCOUNT_MANAGEMENT_CLIENT_ID).get(0).getId();
|
||||||
RoleScopeResource roleScopes = testUserResource().roles().clientLevel(accountClientId);
|
|
||||||
roleScopes.remove(roleScopes.listAll().stream()
|
List<RoleRepresentation> rolesToRemove = testRealmResource().roles()
|
||||||
.filter(r -> MANAGE_ACCOUNT.equals(r.getName()))
|
.get(DEFAULT_ROLE_NAME)
|
||||||
.collect(Collectors.toList()));
|
.getClientRoleComposites(accountClientId).stream()
|
||||||
|
.filter(role -> role.getName().equals(MANAGE_ACCOUNT))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
testRealmResource().roles().get(DEFAULT_ROLE_NAME).deleteComposites(rolesToRemove);
|
||||||
|
|
||||||
welcomeScreen.header().clickLoginBtn();
|
welcomeScreen.header().clickLoginBtn();
|
||||||
loginToAccount();
|
loginToAccount();
|
||||||
|
@ -70,5 +80,8 @@ public class PermissionsTest extends AbstractAccountTest {
|
||||||
welcomeScreen.assertCurrent();
|
welcomeScreen.assertCurrent();
|
||||||
welcomeScreen.header().assertLoginBtnVisible(true);
|
welcomeScreen.header().assertLoginBtnVisible(true);
|
||||||
welcomeScreen.header().assertLogoutBtnVisible(false);
|
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() {
|
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() {
|
public String getClients() {
|
||||||
|
|
|
@ -209,7 +209,10 @@ public class SigningInPage extends AbstractLoggedInPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCreatedAtStr() {
|
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() {
|
public LocalDateTime getCreatedAt() {
|
||||||
|
|
Loading…
Reference in a new issue