From 17117820cc14f87f5990ddce80ef38a0e2e7f314 Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Fri, 28 Oct 2022 12:26:59 +0200 Subject: [PATCH] Remove AccountFormServiceTest (#15197) Closes #15196 --- .../testsuite/pages/AccountLogPage.java | 57 - .../testsuite/pages/AccountSessionsPage.java | 72 - .../testsuite/account/AccountBrokerTest.java | 191 -- .../account/AccountFormServiceTest.java | 1591 ----------------- .../account/custom/CustomThemeTest.java | 2 - 5 files changed, 1913 deletions(-) delete mode 100755 testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AccountLogPage.java delete mode 100755 testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AccountSessionsPage.java delete mode 100755 testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountBrokerTest.java delete mode 100644 testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountFormServiceTest.java diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AccountLogPage.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AccountLogPage.java deleted file mode 100755 index 9775d0c1060..00000000000 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AccountLogPage.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.testsuite.pages; - -import org.keycloak.services.Urls; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; - -import java.util.LinkedList; -import java.util.List; - -/** - * @author Stian Thorgersen - */ -public class AccountLogPage extends AbstractAccountPage { - - public boolean isCurrent() { - return driver.getTitle().contains("Account Management") && driver.getCurrentUrl().endsWith("/account/log"); - } - - private String getPath() { - return Urls.accountLogPage(getAuthServerRoot(), "test").toString(); - } - - public void open() { - driver.navigate().to(getPath()); - } - - public List> getEvents() { - List> table = new LinkedList>(); - for (WebElement r : driver.findElements(By.tagName("tr"))) { - List row = new LinkedList(); - for (WebElement col : r.findElements(By.tagName("td"))) { - row.add(col.getText()); - } - table.add(row); - } - table.remove(0); - return table; - } - -} diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AccountSessionsPage.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AccountSessionsPage.java deleted file mode 100755 index d6c04855806..00000000000 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/pages/AccountSessionsPage.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.keycloak.testsuite.pages; - -import org.keycloak.services.Urls; -import org.openqa.selenium.By; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; - -import java.util.LinkedList; -import java.util.List; - -/** - * @author Stian Thorgersen - */ -public class AccountSessionsPage extends AbstractAccountPage { - - private String realmName = "test"; - - @FindBy(id = "logout-all-sessions") - private WebElement logoutAllLink; - - - public boolean isCurrent() { - return driver.getTitle().contains("Account Management") && driver.getCurrentUrl().endsWith("/account/sessions"); - } - - public void realm(String realmName) { - this.realmName = realmName; - } - - public String getPath() { - return Urls.accountSessionsPage(getAuthServerRoot(), realmName).toString(); - } - - public void open() { - driver.navigate().to(getPath()); - } - - public void logoutAll() { - logoutAllLink.click(); - } - - public List> getSessions() { - List> table = new LinkedList>(); - for (WebElement r : driver.findElements(By.tagName("tr"))) { - List row = new LinkedList(); - for (WebElement col : r.findElements(By.tagName("td"))) { - row.add(col.getText()); - } - table.add(row); - } - table.remove(0); - return table; - } - -} diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountBrokerTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountBrokerTest.java deleted file mode 100755 index 44244fda94a..00000000000 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountBrokerTest.java +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.keycloak.testsuite.account; - -import org.jboss.arquillian.graphene.page.Page; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.keycloak.admin.client.resource.IdentityProviderResource; -import org.keycloak.admin.client.resource.RealmResource; -import org.keycloak.representations.idm.ClientRepresentation; -import org.keycloak.representations.idm.IdentityProviderRepresentation; -import org.keycloak.representations.idm.UserRepresentation; -import org.keycloak.testsuite.admin.ApiUtil; -import org.keycloak.testsuite.broker.AbstractBaseBrokerTest; -import org.keycloak.testsuite.broker.BrokerConfiguration; -import org.keycloak.testsuite.broker.KcOidcBrokerConfiguration; -import org.keycloak.testsuite.pages.AccountFederatedIdentityPage; -import org.keycloak.testsuite.util.UserBuilder; - -import javax.ws.rs.core.Response; - -import java.util.List; - -import static org.keycloak.testsuite.admin.ApiUtil.createUserWithAdminClient; -import static org.keycloak.testsuite.admin.ApiUtil.resetUserPassword; - -/** - * @author Stian Thorgersen - * @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc. - */ -public class AccountBrokerTest extends AbstractBaseBrokerTest { - - @Page - protected AccountFederatedIdentityPage identityPage; - - @Override - protected BrokerConfiguration getBrokerConfiguration() { - return KcOidcBrokerConfiguration.INSTANCE; - } - - @Before - public void createUser() { - log.debug("creating user for realm " + bc.providerRealmName()); - - UserRepresentation user = new UserRepresentation(); - user.setUsername(bc.getUserLogin()); - user.setEmail(bc.getUserEmail()); - user.setEmailVerified(true); - user.setEnabled(true); - - RealmResource realmResource = adminClient.realm(bc.providerRealmName()); - userId = createUserWithAdminClient(realmResource, user); - - resetUserPassword(realmResource.users().get(userId), bc.getUserPassword(), false); - } - - @Before - public void addIdentityProviderToProviderRealm() { - log.debug("adding identity provider to realm " + bc.consumerRealmName()); - - RealmResource realm = adminClient.realm(bc.consumerRealmName()); - realm.identityProviders().create(bc.setUpIdentityProvider()).close(); - realm.identityProviders().get(bc.getIDPAlias()); - } - - @Before - public void addClients() { - List clients = bc.createProviderClients(); - if (clients != null) { - RealmResource providerRealm = adminClient.realm(bc.providerRealmName()); - for (ClientRepresentation client : clients) { - log.debug("adding client " + client.getName() + " to realm " + bc.providerRealmName()); - - // Remove default client scopes for this test -// client.setDefaultClientScopes(Collections.emptyList()); - - fixAuthServerHostAndPortForClientRepresentation(client); - - providerRealm.clients().create(client).close(); - } - } - - clients = bc.createConsumerClients(); - if (clients != null) { - RealmResource consumerRealm = adminClient.realm(bc.consumerRealmName()); - for (ClientRepresentation client : clients) { - log.debug("adding client " + client.getName() + " to realm " + bc.consumerRealmName()); - - fixAuthServerHostAndPortForClientRepresentation(client); - - consumerRealm.clients().create(client).close(); - } - } - } - - @Before - public void before() { - Response response = adminClient.realm(KcOidcBrokerConfiguration.INSTANCE.consumerRealmName()).users().create(UserBuilder.create().username("accountbrokertest").build()); - String userId = ApiUtil.getCreatedId(response); - ApiUtil.resetUserPassword(adminClient.realm(KcOidcBrokerConfiguration.INSTANCE.consumerRealmName()).users().get(userId), "password", false); - } - - @After - public void after() { - RealmResource consumerRealm = adminClient.realm(KcOidcBrokerConfiguration.INSTANCE.consumerRealmName()); - UserRepresentation userRep = ApiUtil.findUserByUsername(consumerRealm, "accountbrokertest"); - if (userRep != null) { - consumerRealm.users().get(userRep.getId()).remove(); - } - } - - @Test - public void add() { - identityPage.realm(KcOidcBrokerConfiguration.INSTANCE.consumerRealmName()); - identityPage.open(); - loginPage.login("accountbrokertest", "password"); - Assert.assertTrue(identityPage.isCurrent()); - - List identities = identityPage.getIdentities(); - Assert.assertEquals(1, identities.size()); - - Assert.assertEquals("kc-oidc-idp", identities.get(0).getProvider()); - Assert.assertEquals("", identities.get(0).getSubject()); - Assert.assertEquals("add-link-kc-oidc-idp", identities.get(0).getAction().getAttribute("id")); - - identities.get(0).getAction().click(); - - loginPage.login(bc.getUserLogin(), bc.getUserPassword()); - - Assert.assertTrue(identityPage.isCurrent()); - - identities = identityPage.getIdentities(); - Assert.assertEquals(1, identities.size()); - - Assert.assertEquals("kc-oidc-idp", identities.get(0).getProvider()); - Assert.assertEquals("testuser", identities.get(0).getSubject()); - Assert.assertEquals("remove-link-kc-oidc-idp", identities.get(0).getAction().getAttribute("id")); - - identities.get(0).getAction().click(); - - Assert.assertTrue(identityPage.isCurrent()); - - identities = identityPage.getIdentities(); - - Assert.assertEquals("kc-oidc-idp", identities.get(0).getProvider()); - Assert.assertEquals("", identities.get(0).getSubject()); - Assert.assertEquals("add-link-kc-oidc-idp", identities.get(0).getAction().getAttribute("id")); - } - - @Test - public void displayEnabledIdentityProviders() { - identityPage.realm(KcOidcBrokerConfiguration.INSTANCE.consumerRealmName()); - identityPage.open(); - loginPage.login("accountbrokertest", "password"); - Assert.assertTrue(identityPage.isCurrent()); - - List identities = identityPage.getIdentities(); - Assert.assertEquals(1, identities.size()); - - // Disable the identity provider - RealmResource realm = adminClient.realm(bc.consumerRealmName()); - IdentityProviderResource providerResource = realm.identityProviders().get(bc.getIDPAlias()); - IdentityProviderRepresentation provider = providerResource.toRepresentation(); - provider.setEnabled(false); - providerResource.update(provider); - - // Reload federated identities page - identityPage.open(); - Assert.assertTrue(identityPage.isCurrent()); - - identities = identityPage.getIdentities(); - Assert.assertEquals(0, identities.size()); - } - -} diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountFormServiceTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountFormServiceTest.java deleted file mode 100644 index 3026fa2bf46..00000000000 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/account/AccountFormServiceTest.java +++ /dev/null @@ -1,1591 +0,0 @@ -/* - * Copyright 2016 Red Hat, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.keycloak.testsuite.account; - -import org.jboss.arquillian.drone.api.annotation.Drone; -import org.jboss.arquillian.graphene.page.Page; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.keycloak.admin.client.resource.RealmResource; -import org.keycloak.admin.client.resource.UserResource; -import org.keycloak.common.Profile; -import org.keycloak.credential.CredentialModel; -import org.keycloak.events.Details; -import org.keycloak.events.Errors; -import org.keycloak.events.EventType; -import org.keycloak.models.AccountRoles; -import org.keycloak.models.AdminRoles; -import org.keycloak.models.Constants; -import org.keycloak.models.PasswordPolicy; -import org.keycloak.models.RealmModel; -import org.keycloak.models.UserModel; -import org.keycloak.models.credential.OTPCredentialModel; -import org.keycloak.models.utils.TimeBasedOTP; -import org.keycloak.representations.idm.ClientRepresentation; -import org.keycloak.representations.idm.CredentialRepresentation; -import org.keycloak.representations.idm.EventRepresentation; -import org.keycloak.representations.idm.RealmRepresentation; -import org.keycloak.representations.idm.UserRepresentation; -import org.keycloak.testsuite.AbstractTestRealmKeycloakTest; -import org.keycloak.testsuite.AssertEvents; -import org.keycloak.testsuite.admin.ApiUtil; -import org.keycloak.testsuite.arquillian.AuthServerTestEnricher; -import org.keycloak.testsuite.arquillian.annotation.DisableFeature; -import org.keycloak.testsuite.drone.Different; -import org.keycloak.testsuite.pages.AccountApplicationsPage; -import org.keycloak.testsuite.pages.AccountFederatedIdentityPage; -import org.keycloak.testsuite.pages.AccountLogPage; -import org.keycloak.testsuite.pages.AccountPasswordPage; -import org.keycloak.testsuite.pages.AccountSessionsPage; -import org.keycloak.testsuite.pages.AccountTotpPage; -import org.keycloak.testsuite.pages.AccountUpdateProfilePage; -import org.keycloak.testsuite.pages.AppPage; -import org.keycloak.testsuite.pages.AppPage.RequestType; -import org.keycloak.testsuite.pages.ErrorPage; -import org.keycloak.testsuite.pages.LoginPage; -import org.keycloak.testsuite.pages.RegisterPage; -import org.keycloak.testsuite.updaters.ClientAttributeUpdater; -import org.keycloak.testsuite.updaters.RoleScopeUpdater; -import org.keycloak.testsuite.util.DroneUtils; -import org.keycloak.testsuite.util.IdentityProviderBuilder; -import org.keycloak.testsuite.util.OAuthClient; -import org.keycloak.testsuite.util.RealmBuilder; -import org.keycloak.testsuite.util.UIUtils; -import org.keycloak.testsuite.util.URLUtils; -import org.keycloak.testsuite.util.UserBuilder; -import org.keycloak.userprofile.UserProfileContext; - -import java.util.Collections; -import org.openqa.selenium.By; -import org.openqa.selenium.NoSuchElementException; -import org.openqa.selenium.WebDriver; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import org.hamcrest.Matchers; -import org.junit.Assume; - -import static org.hamcrest.Matchers.anyOf; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.keycloak.testsuite.util.ServerURLs.AUTH_SERVER_SSL_REQUIRED; -import static org.keycloak.testsuite.util.ServerURLs.getAuthServerContextRoot; - -/** - * @author Stian Thorgersen - * @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc. - */ -@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true) -public class AccountFormServiceTest extends AbstractTestRealmKeycloakTest { - - public static final String ROOT_URL_CLIENT = "root-url-client"; - public static final String REALM_NAME = "test"; - - @Override - public void configureTestRealm(RealmRepresentation testRealm) { - //UserRepresentation user = findUserInRealmRep(testRealm, "test-user@localhost"); - //ClientRepresentation accountApp = findClientInRealmRep(testRealm, ACCOUNT_MANAGEMENT_CLIENT_ID); - UserRepresentation user2 = UserBuilder.create() - .enabled(true) - .username("test-user-no-access@localhost") - .email("test-user-no-access@localhost") - .password("password") - .build(); - UserRepresentation realmAdmin = UserBuilder.create() - .enabled(true) - .username("realm-admin") - .password("password") - .role(Constants.REALM_MANAGEMENT_CLIENT_ID, AdminRoles.REALM_ADMIN) - .role(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID, AccountRoles.MANAGE_ACCOUNT) - .build(); - - testRealm.addIdentityProvider(IdentityProviderBuilder.create() - .providerId("github") - .alias("github") - .build()); - testRealm.addIdentityProvider(IdentityProviderBuilder.create() - .providerId("saml") - .alias("mysaml") - .build()); - testRealm.addIdentityProvider(IdentityProviderBuilder.create() - .providerId("oidc") - .alias("myoidc") - .displayName("MyOIDC") - .build()); - testRealm.addIdentityProvider(IdentityProviderBuilder.create() - .providerId("oidc") - .alias("myhiddenoidc") - .displayName("MyHiddenOIDC") - .hideOnLoginPage() - .build()); - - RealmBuilder.edit(testRealm) - .user(user2) - .user(realmAdmin); - - if (AUTH_SERVER_SSL_REQUIRED) { - // Some scenarios here use redirections, so we need to fix the base url - findTestApp(testRealm) - .setBaseUrl(String.format("%s/auth/realms/master/app/auth", getAuthServerContextRoot())); - } - } - - // Create second session - @Drone - @Different - WebDriver driver2; - - @Rule - public AssertEvents events = new AssertEvents(this); - - @Page - protected AppPage appPage; - - @Page - protected LoginPage loginPage; - - @Page - protected RegisterPage registerPage; - - @Page - protected AccountPasswordPage changePasswordPage; - - @Page - protected AccountUpdateProfilePage profilePage; - - @Page - protected AccountTotpPage totpPage; - - @Page - protected AccountLogPage logPage; - - @Page - protected AccountSessionsPage sessionsPage; - - @Page - protected AccountApplicationsPage applicationsPage; - - @Page - protected AccountFederatedIdentityPage federatedIdentityPage; - - @Page - protected ErrorPage errorPage; - - private TimeBasedOTP totp = new TimeBasedOTP(); - private String userId; - - @Before - public void before() { - UserRepresentation user = findUser("test-user@localhost"); - - user.setEmail("test-user@localhost"); - updateUser(user); - - userId = user.getId(); - - // Revert any password policy and user password changes - setPasswordPolicy(""); - ApiUtil.resetUserPassword(testRealm().users().get(userId), "password", false); - } - - @Test - public void returnToAppFromQueryParam() { - driver.navigate().to(profilePage.getPath() + "?referrer=test-app"); - loginPage.login("test-user@localhost", "password"); - Assert.assertTrue(profilePage.isCurrent()); - profilePage.backToApplication(); - - Assert.assertTrue(appPage.isCurrent()); - - driver.navigate().to(String.format("%s?referrer=test-app&referrer_uri=%s/auth/realms/master/app/auth?test", profilePage.getPath(), getAuthServerContextRoot())); - Assert.assertTrue(profilePage.isCurrent()); - profilePage.backToApplication(); - - Assert.assertTrue(appPage.isCurrent()); - Assert.assertEquals(oauth.APP_AUTH_ROOT + "?test", driver.getCurrentUrl()); - - driver.navigate().to(profilePage.getPath() + "?referrer=test-app"); - Assert.assertTrue(profilePage.isCurrent()); - - driver.findElement(By.linkText("Authenticator")).click(); - Assert.assertTrue(totpPage.isCurrent()); - - driver.findElement(By.linkText("Account")).click(); - Assert.assertTrue(profilePage.isCurrent()); - - profilePage.backToApplication(); - - Assert.assertTrue(appPage.isCurrent()); - - events.clear(); - } - - @Test - public void referrerEscaped() { - profilePage.open(); - loginPage.login("test-user@localhost", "password"); - - driver.navigate().to(profilePage.getPath() + "?referrer=test-app&referrer_uri=http%3A%2F%2Flocalhost%3A8180%2Fauth%2Frealms%2Fmaster%2Fapp%2Fauth%2Ftest%2Ffkrenu%3Fq%3D%2522%253E%253Cscript%253Ealert%25281%2529%253C%252fscript%253E"); - profilePage.assertCurrent(); - - assertFalse(driver.getPageSource().contains("