Remove account package from testsuite (#20990)
* Removal of testsuite account package Related to #19668 Also closes #20527 * Fix failures + remove login folder from base-ui --------- Co-authored-by: Ivan Khomyn <ikhomyn@redhat.com> Co-authored-by: wojnarfilip <fwojnar@redhat.com>
This commit is contained in:
parent
6b1f08ce26
commit
a36be17a5c
31 changed files with 95 additions and 1466 deletions
|
@ -1,85 +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.auth.page.account;
|
||||
|
||||
import org.keycloak.testsuite.util.URLUtils;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Petr Mensik
|
||||
*/
|
||||
public class Account extends AccountManagement {
|
||||
|
||||
@FindBy(id = "username")
|
||||
private WebElement username;
|
||||
|
||||
@FindBy(id = "email")
|
||||
private WebElement email;
|
||||
|
||||
@FindBy(id = "lastName")
|
||||
private WebElement lastName;
|
||||
|
||||
@FindBy(id = "firstName")
|
||||
private WebElement firstName;
|
||||
|
||||
public String getUsername() {
|
||||
return username.getAttribute("value");
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email.getAttribute("value");
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName.getAttribute("value");
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName.getAttribute("value");
|
||||
}
|
||||
|
||||
public Account setUsername(String value) {
|
||||
username.clear();
|
||||
username.sendKeys(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Account setEmail(String value) {
|
||||
email.clear();
|
||||
email.sendKeys(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Account setFirstName(String value) {
|
||||
firstName.clear();
|
||||
firstName.sendKeys(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Account setLastName(String value) {
|
||||
lastName.clear();
|
||||
lastName.sendKeys(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isCurrent() {
|
||||
return URLUtils.currentUrlStartsWith(toString()); // Sometimes after login the URL ends with /# or similar
|
||||
}
|
||||
|
||||
}
|
|
@ -1,131 +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.auth.page.account;
|
||||
|
||||
import org.jboss.arquillian.graphene.findby.FindByJQuery;
|
||||
import org.keycloak.testsuite.auth.page.AuthRealm;
|
||||
import org.keycloak.testsuite.page.PageWithLogOutAction;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
import jakarta.ws.rs.core.UriBuilder;
|
||||
|
||||
import static org.keycloak.testsuite.util.WaitUtils.waitForPageToLoad;
|
||||
import static org.keycloak.testsuite.util.WaitUtils.waitUntilElement;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:pmensik@redhat.com">Petr Mensik</a>
|
||||
* @author tkyjovsk
|
||||
*/
|
||||
public class AccountManagement extends AuthRealm implements PageWithLogOutAction {
|
||||
|
||||
@Override
|
||||
public UriBuilder createUriBuilder() {
|
||||
return super.createUriBuilder()
|
||||
.path("account");
|
||||
}
|
||||
|
||||
@FindBy(xpath = "//a[@id='referer']")
|
||||
private WebElement backToRefererLink;
|
||||
|
||||
@FindBy(linkText = "Sign out")
|
||||
private WebElement signOutLink;
|
||||
|
||||
@FindBy(linkText = "Account")
|
||||
private WebElement accountLink;
|
||||
|
||||
@FindBy(linkText = "Password")
|
||||
private WebElement passwordLink;
|
||||
|
||||
@FindBy(linkText = "Authenticator")
|
||||
private WebElement authenticatorLink;
|
||||
|
||||
@FindBy(linkText = "Sessions")
|
||||
private WebElement sessionsLink;
|
||||
|
||||
@FindBy(linkText = "Applications")
|
||||
private WebElement applicationsLink;
|
||||
|
||||
@FindBy(linkText = "Federated Identity")
|
||||
private WebElement federatedIdentityLink;
|
||||
|
||||
@FindByJQuery("button[value='Save']")
|
||||
private WebElement save;
|
||||
|
||||
@FindBy(xpath = "//div[@id='kc-error-message']/p")
|
||||
private WebElement error;
|
||||
|
||||
public String getErrorMessage() {
|
||||
waitUntilElement(error, "Error message should be present").is().present();
|
||||
return error.getText();
|
||||
}
|
||||
|
||||
public void backToReferer() {
|
||||
backToRefererLink.click();
|
||||
}
|
||||
|
||||
public void signOut() {
|
||||
signOutLink.click();
|
||||
waitForPageToLoad();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logOut() {
|
||||
signOut();
|
||||
}
|
||||
|
||||
public void account() {
|
||||
accountLink.click();
|
||||
waitForPageToLoad();
|
||||
}
|
||||
|
||||
public void password() {
|
||||
passwordLink.click();
|
||||
waitForPageToLoad();
|
||||
}
|
||||
|
||||
public void authenticator() {
|
||||
authenticatorLink.click();
|
||||
waitForPageToLoad();
|
||||
}
|
||||
|
||||
public void sessions() {
|
||||
sessionsLink.click();
|
||||
waitForPageToLoad();
|
||||
}
|
||||
|
||||
public void applications() {
|
||||
applicationsLink.click();
|
||||
waitForPageToLoad();
|
||||
}
|
||||
|
||||
public void federatedIdentity() {
|
||||
federatedIdentityLink.click();
|
||||
waitForPageToLoad();
|
||||
}
|
||||
|
||||
public void save() {
|
||||
save.click();
|
||||
waitForPageToLoad();
|
||||
}
|
||||
|
||||
// public RealmResource realmResource() {
|
||||
// return keycloak().realm(getAuthRealm());
|
||||
// }
|
||||
|
||||
}
|
|
@ -1,81 +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.auth.page.account;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
import jakarta.ws.rs.core.UriBuilder;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Petr Mensik
|
||||
* @author mhajas
|
||||
*/
|
||||
public class Applications extends AccountManagement {
|
||||
|
||||
@Override
|
||||
public UriBuilder createUriBuilder() {
|
||||
return super.createUriBuilder()
|
||||
.path("applications");
|
||||
}
|
||||
|
||||
public static final String XPATH_APP_TABLE = "//table[./thead[//td[text()='Application']]]";
|
||||
|
||||
@FindBy(xpath = XPATH_APP_TABLE)
|
||||
protected WebElement appTable;
|
||||
|
||||
@FindBy(xpath = XPATH_APP_TABLE + "//tr")
|
||||
private List<WebElement> applicationRows;
|
||||
|
||||
public boolean containsApplication(String application) {
|
||||
return getRowForLinkText(application) != null;
|
||||
}
|
||||
|
||||
public void clickApplication(String application) {
|
||||
WebElement row = getRowForLinkText(application);
|
||||
if (row == null) {
|
||||
log.error("Application: " + application + " doesn't exist");
|
||||
throw new IllegalArgumentException("Application: " + application + " doesn't exist");
|
||||
}
|
||||
|
||||
row.findElement(By.xpath(".//a")).click();
|
||||
}
|
||||
|
||||
public void revokeGrantForApplication(String application) {
|
||||
WebElement row = getRowForLinkText(application);
|
||||
if (row == null) {
|
||||
log.error("Application: " + application + " doesn't exist");
|
||||
throw new IllegalArgumentException("Application: " + application + " doesn't exist");
|
||||
}
|
||||
|
||||
row.findElement(By.xpath("//button[@id='revoke-" + application + "']")).click();
|
||||
}
|
||||
|
||||
private WebElement getRowForLinkText(String appLink) {
|
||||
for (WebElement appRow : applicationRows) {
|
||||
if (appRow.findElement(By.xpath(".//td")).getText().equals(appLink)) {
|
||||
return appRow;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,35 +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.auth.page.account;
|
||||
|
||||
import jakarta.ws.rs.core.UriBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tkyjovsk
|
||||
*/
|
||||
public class Autheticator extends AccountManagement {
|
||||
|
||||
@Override
|
||||
public UriBuilder createUriBuilder() {
|
||||
return super.createUriBuilder()
|
||||
.path("totp");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,44 +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.auth.page.account;
|
||||
|
||||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.keycloak.testsuite.auth.page.PasswordFields;
|
||||
|
||||
import jakarta.ws.rs.core.UriBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Petr Mensik
|
||||
*/
|
||||
public class ChangePassword extends AccountManagement {
|
||||
|
||||
@Override
|
||||
public UriBuilder createUriBuilder() {
|
||||
return super.createUriBuilder()
|
||||
.path("password");
|
||||
}
|
||||
|
||||
@Page
|
||||
private PasswordFields passwordFields;
|
||||
|
||||
public void changePasswords(String password, String newPassword, String confirmPassword) {
|
||||
passwordFields.setPasswords(password, newPassword, confirmPassword);
|
||||
save();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +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.auth.page.account;
|
||||
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
import jakarta.ws.rs.core.UriBuilder;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.keycloak.testsuite.util.UIUtils.clickLink;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:pmensik@redhat.com">Petr Mensik</a>
|
||||
*/
|
||||
public class Sessions extends AccountManagement {
|
||||
|
||||
@Override
|
||||
public UriBuilder createUriBuilder() {
|
||||
return super.createUriBuilder()
|
||||
.path("sessions");
|
||||
}
|
||||
|
||||
@FindBy(id = "logout-all-sessions")
|
||||
private WebElement logoutAllLink;
|
||||
|
||||
public void logoutAll() {
|
||||
clickLink(logoutAllLink);
|
||||
}
|
||||
|
||||
public List<List<String>> getSessions() {
|
||||
List<List<String>> table = new LinkedList<>();
|
||||
for (WebElement r : driver.findElements(By.tagName("tr"))) {
|
||||
List<String> row = new LinkedList<>();
|
||||
for (WebElement col : r.findElements(By.tagName("td"))) {
|
||||
row.add(col.getText());
|
||||
}
|
||||
table.add(row);
|
||||
}
|
||||
table.remove(0);
|
||||
return table;
|
||||
}
|
||||
}
|
|
@ -1,31 +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.auth.page.account.fragment;
|
||||
|
||||
import org.keycloak.testsuite.page.AbstractPatternFlyAlert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tkyjovsk
|
||||
*/
|
||||
public class AccountManagementPatternFlyAlert extends AbstractPatternFlyAlert {
|
||||
|
||||
public boolean isError() {
|
||||
return checkAlertType("error");
|
||||
}
|
||||
|
||||
}
|
|
@ -24,12 +24,9 @@ import org.keycloak.representations.idm.RealmRepresentation;
|
|||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
import org.keycloak.testsuite.admin.ApiUtil;
|
||||
import org.keycloak.testsuite.auth.page.AuthRealm;
|
||||
import org.keycloak.testsuite.auth.page.account.Account;
|
||||
import org.keycloak.testsuite.auth.page.login.OIDCLogin;
|
||||
import org.keycloak.testsuite.auth.page.login.SAMLPostLogin;
|
||||
import org.keycloak.testsuite.auth.page.login.SAMLRedirectLogin;
|
||||
import org.keycloak.testsuite.util.ClientBuilder;
|
||||
import org.keycloak.testsuite.util.RealmBuilder;
|
||||
import org.openqa.selenium.Cookie;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
@ -51,8 +48,6 @@ public abstract class AbstractAuthTest extends AbstractKeycloakTest {
|
|||
protected AuthRealm testRealmPage;
|
||||
@Page
|
||||
protected OIDCLogin testRealmLoginPage;
|
||||
@Page
|
||||
protected Account testRealmAccountPage;
|
||||
|
||||
@Page
|
||||
protected SAMLPostLogin testRealmSAMLPostLoginPage;
|
||||
|
@ -82,7 +77,7 @@ public abstract class AbstractAuthTest extends AbstractKeycloakTest {
|
|||
@Before
|
||||
public void beforeAuthTest() {
|
||||
testRealmLoginPage.setAuthRealm(testRealmPage);
|
||||
testRealmAccountPage.setAuthRealm(testRealmPage);
|
||||
oauth.realm("test");
|
||||
|
||||
testUser = createUserRepresentation("test", "test@email.test", "test", "user", true);
|
||||
setPasswordFor(testUser, PASSWORD);
|
||||
|
@ -111,15 +106,15 @@ public abstract class AbstractAuthTest extends AbstractKeycloakTest {
|
|||
}
|
||||
|
||||
protected void deleteAllCookiesForTestRealm() {
|
||||
deleteAllCookiesForRealm(testRealmAccountPage.getAuthRealm());
|
||||
deleteAllCookiesForRealm(loginPage.getAuthRealm());
|
||||
}
|
||||
|
||||
protected void deleteAllSessionsInTestRealm() {
|
||||
deleteAllSessionsInRealm(testRealmAccountPage.getAuthRealm());
|
||||
deleteAllSessionsInRealm(loginPage.getAuthRealm());
|
||||
}
|
||||
|
||||
protected void resetTestRealmSession() {
|
||||
resetRealmSession(testRealmAccountPage.getAuthRealm());
|
||||
resetRealmSession(loginPage.getAuthRealm());
|
||||
}
|
||||
|
||||
public void listCookies() {
|
||||
|
|
|
@ -57,7 +57,6 @@ import org.keycloak.testsuite.auth.page.AuthRealm;
|
|||
import org.keycloak.testsuite.auth.page.AuthServer;
|
||||
import org.keycloak.testsuite.auth.page.AuthServerContextRoot;
|
||||
import org.keycloak.testsuite.auth.page.WelcomePage;
|
||||
import org.keycloak.testsuite.auth.page.account.Account;
|
||||
import org.keycloak.testsuite.auth.page.login.OIDCLogin;
|
||||
import org.keycloak.testsuite.auth.page.login.UpdatePassword;
|
||||
import org.keycloak.testsuite.client.KeycloakTestingClient;
|
||||
|
@ -146,9 +145,6 @@ public abstract class AbstractKeycloakTest {
|
|||
@Page
|
||||
protected AuthRealm masterRealmPage;
|
||||
|
||||
@Page
|
||||
protected Account accountPage;
|
||||
|
||||
@Page
|
||||
protected OIDCLogin loginPage;
|
||||
|
||||
|
@ -293,7 +289,7 @@ public abstract class AbstractKeycloakTest {
|
|||
protected void deleteAllCookiesForRealm(String realmName) {
|
||||
// we can't use /auth/realms/{realmName} because some browsers (e.g. Chrome) apparently don't send cookies
|
||||
// to JSON pages and therefore can't delete realms cookies there; a non existing page will do just fine
|
||||
navigateToUri(accountPage.getAuthRoot() + "/realms/" + realmName + "/super-random-page");
|
||||
navigateToUri(oauth.SERVER_ROOT + "/auth/realms/" + realmName + "/super-random-page");
|
||||
log.info("deleting cookies in '" + realmName + "' realm");
|
||||
driver.manage().deleteAllCookies();
|
||||
}
|
||||
|
|
|
@ -17,12 +17,9 @@
|
|||
|
||||
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.fragment.AccountManagementPatternFlyAlert;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.keycloak.testsuite.auth.page.AuthRealm.TEST;
|
||||
|
||||
/**
|
||||
|
@ -31,9 +28,6 @@ import static org.keycloak.testsuite.auth.page.AuthRealm.TEST;
|
|||
*/
|
||||
public abstract class AbstractAccountManagementTest extends AbstractAuthTest {
|
||||
|
||||
@Page
|
||||
protected AccountManagementPatternFlyAlert alert;
|
||||
|
||||
@Override
|
||||
public void setDefaultPageUriParameters() {
|
||||
super.setDefaultPageUriParameters();
|
||||
|
@ -46,12 +40,4 @@ public abstract class AbstractAccountManagementTest extends AbstractAuthTest {
|
|||
createTestUserWithAdminClient();
|
||||
}
|
||||
|
||||
public void assertAlertSuccess() {
|
||||
assertTrue(alert.isSuccess());
|
||||
}
|
||||
|
||||
public void assertAlertError() {
|
||||
assertTrue(alert.isError());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import org.keycloak.testsuite.adapter.page.CorsDatabaseServiceTestApp;
|
|||
import org.keycloak.testsuite.arquillian.annotation.AppServerContainer;
|
||||
import org.keycloak.testsuite.util.JavascriptBrowser;
|
||||
import org.keycloak.testsuite.utils.arquillian.ContainerConstants;
|
||||
import org.keycloak.testsuite.auth.page.account.Account;
|
||||
import org.keycloak.testsuite.auth.page.login.OIDCLogin;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
|
@ -86,10 +85,6 @@ public class CorsExampleAdapterTest extends AbstractExampleAdapterTest {
|
|||
@JavascriptBrowser
|
||||
private AngularCorsProductTestApp jsDriverAngularCorsProductPage;
|
||||
|
||||
@Page
|
||||
@JavascriptBrowser
|
||||
private Account jsDriverTestRealmAccount;
|
||||
|
||||
@Deployment(name = AngularCorsProductTestApp.DEPLOYMENT_NAME, managed = false)
|
||||
protected static WebArchive angularCorsProductExample() throws IOException {
|
||||
return exampleDeployment(AngularCorsProductTestApp.CLIENT_ID);
|
||||
|
@ -124,7 +119,7 @@ public class CorsExampleAdapterTest extends AbstractExampleAdapterTest {
|
|||
public void setDefaultPageUriParameters() {
|
||||
super.setDefaultPageUriParameters();
|
||||
jsDriverTestRealmLoginPage.setAuthRealm(CORS);
|
||||
jsDriverTestRealmAccount.setAuthRealm(CORS);
|
||||
oauth.realm(CORS);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.keycloak.representations.idm.UserRepresentation;
|
|||
import org.keycloak.testsuite.Assert;
|
||||
import org.keycloak.testsuite.adapter.AbstractServletsAdapterTest;
|
||||
import org.keycloak.testsuite.adapter.page.SessionPortal;
|
||||
import org.keycloak.testsuite.auth.page.account.Sessions;
|
||||
import org.keycloak.testsuite.auth.page.login.Login;
|
||||
import org.keycloak.testsuite.arquillian.annotation.AppServerContainer;
|
||||
import org.keycloak.testsuite.pages.InfoPage;
|
||||
|
@ -65,9 +64,6 @@ public class SessionServletAdapterTest extends AbstractServletsAdapterTest {
|
|||
@Page
|
||||
private SessionPortal sessionPortalPage;
|
||||
|
||||
@Page
|
||||
private Sessions testRealmSessions;
|
||||
|
||||
@Page
|
||||
protected LogoutConfirmPage logoutConfirmPage;
|
||||
|
||||
|
@ -77,7 +73,7 @@ public class SessionServletAdapterTest extends AbstractServletsAdapterTest {
|
|||
@Override
|
||||
public void setDefaultPageUriParameters() {
|
||||
super.setDefaultPageUriParameters();
|
||||
testRealmSessions.setAuthRealm(DEMO);
|
||||
oauth.realm(DEMO);
|
||||
}
|
||||
|
||||
@Deployment(name = SessionPortal.DEPLOYMENT_NAME)
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.keycloak.testsuite.adapter.servlet.ErrorServlet;
|
|||
import org.keycloak.testsuite.adapter.servlet.ProductServlet;
|
||||
import org.keycloak.testsuite.adapter.servlet.ServletTestUtils;
|
||||
import org.keycloak.testsuite.arquillian.annotation.AppServerContainer;
|
||||
import org.keycloak.testsuite.util.AccountHelper;
|
||||
|
||||
import static org.keycloak.testsuite.arquillian.AuthServerTestEnricher.AUTH_SERVER_CONTAINER_DEFAULT;
|
||||
import static org.keycloak.testsuite.auth.page.AuthRealm.DEMO;
|
||||
|
@ -114,8 +115,8 @@ public class UndertowRelaviteUriAdapterTest extends AbstractServletsAdapterTest
|
|||
Assert.assertEquals(1, Integer.parseInt(productPortalStats.get("active")));
|
||||
|
||||
// test logout
|
||||
testRealmAccountPage.navigateTo();
|
||||
testRealmAccountPage.logOut();
|
||||
AccountHelper.logout(testRealmResource(), testUser.getUsername());
|
||||
|
||||
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
|
||||
productPortal.navigateTo();
|
||||
assertCurrentUrlStartsWithLoginUrlOf(testRealmPage);
|
||||
|
|
|
@ -349,7 +349,6 @@ public class ConsentsTest extends AbstractKeycloakTest {
|
|||
*/
|
||||
@Test
|
||||
public void testRetrieveConsentsForUserWithClientsWithGrantedOfflineAccess() throws Exception {
|
||||
|
||||
RealmResource providerRealm = adminClient.realm(providerRealmName());
|
||||
|
||||
RealmRepresentation providerRealmRep = providerRealm.toRepresentation();
|
||||
|
@ -406,36 +405,35 @@ public class ConsentsTest extends AbstractKeycloakTest {
|
|||
@Test
|
||||
public void testConsentCancel() {
|
||||
// setup account client to require consent
|
||||
createAppClientInRealm(providerRealmName());
|
||||
RealmResource providerRealm = adminClient.realm(providerRealmName());
|
||||
ClientResource accountClient = findClientByClientId(providerRealm, "account");
|
||||
ClientResource accountClient = findClientByClientId(providerRealm, "test-app");
|
||||
|
||||
ClientRepresentation clientRepresentation = accountClient.toRepresentation();
|
||||
clientRepresentation.setConsentRequired(true);
|
||||
accountClient.update(clientRepresentation);
|
||||
|
||||
// setup correct realm
|
||||
accountPage.setAuthRealm(providerRealmName());
|
||||
oauth.realm(providerRealmName());
|
||||
|
||||
// navigate to account console and login
|
||||
accountPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
loginPage.form().login(getUserLogin(), getUserPassword());
|
||||
|
||||
consentPage.assertCurrent();
|
||||
|
||||
consentPage.cancel();
|
||||
|
||||
// check an error page after cancelling the consent
|
||||
errorPage.assertCurrent();
|
||||
assertEquals("No access", errorPage.getError());
|
||||
|
||||
// follow the link "back to application"
|
||||
errorPage.clickBackToApplication();
|
||||
assertTrue(driver.getTitle().contains("AUTH_RESPONSE"));
|
||||
assertTrue(driver.getCurrentUrl().contains("error=access_denied"));
|
||||
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
loginPage.form().login(getUserLogin(), getUserPassword());
|
||||
consentPage.confirm();
|
||||
|
||||
// successful login
|
||||
accountPage.assertCurrent();
|
||||
assertFalse(driver.getCurrentUrl().contains("error"));
|
||||
assertTrue("Test user should be successfully logged in.", driver.getTitle().contains("AUTH_RESPONSE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -474,7 +472,7 @@ public class ConsentsTest extends AbstractKeycloakTest {
|
|||
public void testConsentWithAdditionalClientAttributes() {
|
||||
// setup account client to require consent
|
||||
RealmResource providerRealm = adminClient.realm(providerRealmName());
|
||||
ClientResource accountClient = findClientByClientId(providerRealm, "account");
|
||||
ClientResource accountClient = findClientByClientId(providerRealm, "test-app");
|
||||
|
||||
ClientRepresentation clientRepresentation = accountClient.toRepresentation();
|
||||
clientRepresentation.setConsentRequired(true);
|
||||
|
@ -484,13 +482,14 @@ public class ConsentsTest extends AbstractKeycloakTest {
|
|||
accountClient.update(clientRepresentation);
|
||||
|
||||
// setup correct realm
|
||||
accountPage.setAuthRealm(providerRealmName());
|
||||
oauth.realm(providerRealmName());
|
||||
|
||||
// navigate to account console and login
|
||||
accountPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
loginPage.form().login(getUserLogin(), getUserPassword());
|
||||
|
||||
consentPage.assertCurrent();
|
||||
|
||||
assertTrue("logoUri must be presented", driver.findElement(By.xpath("//img[@src='https://www.keycloak.org/resources/images/keycloak_logo_480x108.png']")).isDisplayed());
|
||||
assertTrue("policyUri must be presented", driver.findElement(By.xpath("//a[@href='https://www.keycloak.org/policy']")).isDisplayed());
|
||||
assertTrue("tosUri must be presented", driver.findElement(By.xpath("//a[@href='https://www.keycloak.org/tos']")).isDisplayed());
|
||||
|
@ -498,7 +497,7 @@ public class ConsentsTest extends AbstractKeycloakTest {
|
|||
consentPage.confirm();
|
||||
|
||||
// successful login
|
||||
accountPage.assertCurrent();
|
||||
assertTrue("Test user should be successfully logged in.", driver.getTitle().contains("AUTH_RESPONSE"));
|
||||
}
|
||||
|
||||
private String getAccountUrl(String realmName) {
|
||||
|
|
|
@ -52,7 +52,7 @@ public abstract class AbstractClientTest extends AbstractAuthTest {
|
|||
public void setDefaultPageUriParameters() {
|
||||
super.setDefaultPageUriParameters();
|
||||
testRealmPage.setAuthRealm("test");
|
||||
accountPage.setAuthRealm("test");
|
||||
oauth.realm("test");
|
||||
}
|
||||
|
||||
@Before
|
||||
|
|
|
@ -48,7 +48,7 @@ public abstract class AbstractEventTest extends AbstractAuthTest {
|
|||
@Override
|
||||
public void setDefaultPageUriParameters() {
|
||||
testRealmPage.setAuthRealm("test");
|
||||
accountPage.setAuthRealm("test");
|
||||
oauth.realm("test");
|
||||
}
|
||||
|
||||
protected void saveConfig() {
|
||||
|
|
|
@ -17,33 +17,20 @@
|
|||
|
||||
package org.keycloak.testsuite.admin.event;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.admin.client.resource.RealmResource;
|
||||
import org.keycloak.common.Profile;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.events.email.EmailEventListenerProviderFactory;
|
||||
import org.keycloak.representations.idm.EventRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.testsuite.arquillian.annotation.DisableFeature;
|
||||
import org.keycloak.testsuite.console.page.events.LoginEvents;
|
||||
import org.keycloak.testsuite.util.GreenMailRule;
|
||||
import org.keycloak.testsuite.util.UserBuilder;
|
||||
|
||||
@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true) // TODO remove this (KEYCLOAK-16228)
|
||||
public class EmailEventListenerTest extends AbstractEventTest {
|
||||
|
||||
@Rule
|
||||
|
@ -68,12 +55,13 @@ public class EmailEventListenerTest extends AbstractEventTest {
|
|||
.emailVerified(true)
|
||||
.password("alice").build());
|
||||
|
||||
createAppClientInRealm("test");
|
||||
realmResource.clearEvents();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eventAttributesTest() {
|
||||
accountPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
loginPage.form().login("alice", "invalid");
|
||||
loginPage.assertCurrent();
|
||||
assertNotNull(greenMail.getLastReceivedMessage());
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.keycloak.testsuite.broker;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.keycloak.testsuite.broker.BrokerTestConstants.IDP_OIDC_ALIAS;
|
||||
import static org.keycloak.testsuite.broker.BrokerTestConstants.IDP_OIDC_PROVIDER_ID;
|
||||
import static org.keycloak.testsuite.broker.BrokerTestConstants.USER_EMAIL;
|
||||
|
@ -115,7 +117,7 @@ public class KcOidcBrokerLoginHintTest extends AbstractBrokerTest {
|
|||
idpConfirmLinkPage.clickLinkAccount();
|
||||
|
||||
loginPage.login(bc.getUserPassword());
|
||||
accountPage.isCurrent();
|
||||
assertTrue("Test user should be successfully logged in.", driver.getTitle().contains("AUTH_RESPONSE"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,10 @@ import org.openqa.selenium.By;
|
|||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||
import org.openqa.selenium.support.ui.ExpectedConditions;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
|
||||
import static org.keycloak.testsuite.broker.BrokerTestTools.waitForPage;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
@ -1122,9 +1125,8 @@ public class ResetPasswordTest extends AbstractTestRealmKeycloakTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true) // TODO remove this (KEYCLOAK-16228)
|
||||
public void resetPasswordLinkNewTabAndProperRedirectAccount() throws IOException {
|
||||
final String REQUIRED_URI = OAuthClient.AUTH_SERVER_ROOT + "/realms/test/account/applications";
|
||||
final String REQUIRED_URI = getAuthServerRoot() + "realms/test/account/login-redirect?path=applications";
|
||||
final String REDIRECT_URI = getAccountRedirectUrl() + "?path=applications";
|
||||
final String CLIENT_ID = "account";
|
||||
final String ACCOUNT_MANAGEMENT_TITLE = "Keycloak Account Management";
|
||||
|
@ -1132,14 +1134,19 @@ public class ResetPasswordTest extends AbstractTestRealmKeycloakTest {
|
|||
try (BrowserTabUtil tabUtil = BrowserTabUtil.getInstanceAndSetEnv(driver)) {
|
||||
assertThat(tabUtil.getCountOfTabs(), Matchers.is(1));
|
||||
|
||||
AccountHelper.logout(testRealm(), "login-test");
|
||||
driver.navigate().to(REQUIRED_URI);
|
||||
oauth.redirectUri(REDIRECT_URI);
|
||||
oauth.clientId(CLIENT_ID);
|
||||
|
||||
loginPage.open();
|
||||
resetPasswordTwiceInNewTab(defaultUser, CLIENT_ID, false, REDIRECT_URI, REQUIRED_URI);
|
||||
assertThat(driver.getTitle(), Matchers.equalTo(ACCOUNT_MANAGEMENT_TITLE));
|
||||
|
||||
AccountHelper.logout(testRealm(), "login-test");
|
||||
String logoutUrl = oauth.getLogoutUrl().build();
|
||||
driver.navigate().to(logoutUrl);
|
||||
logoutConfirmPage.assertCurrent();
|
||||
logoutConfirmPage.confirmLogout();
|
||||
|
||||
driver.navigate().to(REQUIRED_URI);
|
||||
loginPage.open();
|
||||
resetPasswordTwiceInNewTab(defaultUser, CLIENT_ID, true, REDIRECT_URI, REQUIRED_URI);
|
||||
assertThat(driver.getTitle(), Matchers.equalTo(ACCOUNT_MANAGEMENT_TITLE));
|
||||
}
|
||||
|
|
|
@ -133,46 +133,42 @@ public class SSOTest extends AbstractTestRealmKeycloakTest {
|
|||
|
||||
EventRepresentation login1 = events.expectLogin().assertEvent();
|
||||
|
||||
try {
|
||||
//OAuthClient oauth2 = new OAuthClient(driver2);
|
||||
OAuthClient oauth2 = new OAuthClient();
|
||||
oauth2.init(driver2);
|
||||
//OAuthClient oauth2 = new OAuthClient(driver2);
|
||||
OAuthClient oauth2 = new OAuthClient();
|
||||
oauth2.init(driver2);
|
||||
|
||||
oauth2.doLogin("test-user@localhost", "password");
|
||||
oauth2.doLogin("test-user@localhost", "password");
|
||||
|
||||
EventRepresentation login2 = events.expectLogin().assertEvent();
|
||||
EventRepresentation login2 = events.expectLogin().assertEvent();
|
||||
|
||||
Assert.assertEquals(RequestType.AUTH_RESPONSE, RequestType.valueOf(driver2.getTitle()));
|
||||
Assert.assertNotNull(oauth2.getCurrentQuery().get(OAuth2Constants.CODE));
|
||||
Assert.assertEquals(RequestType.AUTH_RESPONSE, RequestType.valueOf(driver2.getTitle()));
|
||||
Assert.assertNotNull(oauth2.getCurrentQuery().get(OAuth2Constants.CODE));
|
||||
|
||||
assertNotEquals(login1.getSessionId(), login2.getSessionId());
|
||||
assertNotEquals(login1.getSessionId(), login2.getSessionId());
|
||||
|
||||
OAuthClient.AccessTokenResponse tokenResponse = sendTokenRequestAndGetResponse(login1);
|
||||
oauth.idTokenHint(tokenResponse.getIdToken()).openLogout();
|
||||
events.expectLogout(login1.getSessionId()).assertEvent();
|
||||
OAuthClient.AccessTokenResponse tokenResponse = sendTokenRequestAndGetResponse(login1);
|
||||
oauth.idTokenHint(tokenResponse.getIdToken()).openLogout();
|
||||
events.expectLogout(login1.getSessionId()).assertEvent();
|
||||
|
||||
oauth.openLoginForm();
|
||||
oauth.openLoginForm();
|
||||
|
||||
assertTrue(loginPage.isCurrent());
|
||||
assertTrue(loginPage.isCurrent());
|
||||
|
||||
oauth2.openLoginForm();
|
||||
oauth2.openLoginForm();
|
||||
|
||||
events.expectLogin().session(login2.getSessionId()).removeDetail(Details.USERNAME).assertEvent();
|
||||
Assert.assertEquals(RequestType.AUTH_RESPONSE, RequestType.valueOf(driver2.getTitle()));
|
||||
Assert.assertNotNull(oauth2.getCurrentQuery().get(OAuth2Constants.CODE));
|
||||
events.expectLogin().session(login2.getSessionId()).removeDetail(Details.USERNAME).assertEvent();
|
||||
Assert.assertEquals(RequestType.AUTH_RESPONSE, RequestType.valueOf(driver2.getTitle()));
|
||||
Assert.assertNotNull(oauth2.getCurrentQuery().get(OAuth2Constants.CODE));
|
||||
|
||||
String code = new OAuthClient.AuthorizationEndpointResponse(oauth2).getCode();
|
||||
OAuthClient.AccessTokenResponse response = oauth2.doAccessTokenRequest(code, "password");
|
||||
events.poll();
|
||||
oauth2.idTokenHint(response.getIdToken()).openLogout();
|
||||
events.expectLogout(login2.getSessionId()).assertEvent();
|
||||
String code = new OAuthClient.AuthorizationEndpointResponse(oauth2).getCode();
|
||||
OAuthClient.AccessTokenResponse response = oauth2.doAccessTokenRequest(code, "password");
|
||||
events.poll();
|
||||
oauth2.idTokenHint(response.getIdToken()).openLogout();
|
||||
events.expectLogout(login2.getSessionId()).assertEvent();
|
||||
|
||||
oauth2.openLoginForm();
|
||||
oauth2.openLoginForm();
|
||||
|
||||
assertTrue(driver2.getTitle().equals("Sign in to test"));
|
||||
} finally {
|
||||
driver2.close();
|
||||
}
|
||||
assertTrue(driver2.getTitle().equals("Sign in to test"));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.keycloak.testsuite.Assert;
|
|||
import org.keycloak.testsuite.AssertEvents;
|
||||
import org.keycloak.testsuite.admin.ApiUtil;
|
||||
import org.keycloak.testsuite.arquillian.SuiteContext;
|
||||
import org.keycloak.testsuite.auth.page.account.Applications;
|
||||
import org.keycloak.testsuite.auth.page.login.OAuthGrant;
|
||||
import org.keycloak.testsuite.auth.page.login.UpdatePassword;
|
||||
import org.keycloak.testsuite.updaters.RealmAttributeUpdater;
|
||||
|
@ -77,10 +76,6 @@ public class JavascriptAdapterTest extends AbstractJavascriptTest {
|
|||
@Rule
|
||||
public AssertEvents events = new AssertEvents(this);
|
||||
|
||||
@Page
|
||||
@JavascriptBrowser
|
||||
private Applications applicationsPage;
|
||||
|
||||
@Page
|
||||
@JavascriptBrowser
|
||||
private OAuthGrant oAuthGrantPage;
|
||||
|
@ -102,7 +97,7 @@ public class JavascriptAdapterTest extends AbstractJavascriptTest {
|
|||
|
||||
jsDriverTestRealmLoginPage.setAuthRealm(REALM_NAME);
|
||||
oAuthGrantPage.setAuthRealm(REALM_NAME);
|
||||
applicationsPage.setAuthRealm(REALM_NAME);
|
||||
oauth.realm(REALM_NAME);
|
||||
|
||||
jsDriver.navigate().to(oauth.getLoginFormUrl());
|
||||
waitForPageToLoad();
|
||||
|
@ -315,7 +310,7 @@ public class JavascriptAdapterTest extends AbstractJavascriptTest {
|
|||
|
||||
testExecutor.init(defaultArguments(), this::assertInitAuth);
|
||||
|
||||
applicationsPage.navigateTo();
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
events.expectCodeToToken(codeId, loginEvent.getSessionId()).client(CLIENT_ID).assertEvent();
|
||||
|
||||
AccountHelper.revokeConsents(adminClient.realm(REALM_NAME), testUser.getUsername(),CLIENT_ID);
|
||||
|
|
|
@ -44,7 +44,6 @@ import org.keycloak.testsuite.AbstractTestRealmKeycloakTest;
|
|||
import org.keycloak.testsuite.Assert;
|
||||
import org.keycloak.testsuite.AssertEvents;
|
||||
import org.keycloak.testsuite.admin.ApiUtil;
|
||||
import org.keycloak.testsuite.auth.page.account.AccountManagement;
|
||||
import org.keycloak.testsuite.pages.AppPage;
|
||||
import org.keycloak.testsuite.pages.ErrorPage;
|
||||
import org.keycloak.testsuite.pages.InfoPage;
|
||||
|
@ -89,9 +88,6 @@ public class LegacyLogoutTest extends AbstractTestRealmKeycloakTest {
|
|||
@Page
|
||||
protected InfoPage infoPage;
|
||||
|
||||
@Page
|
||||
protected AccountManagement accountManagementPage;
|
||||
|
||||
@Page
|
||||
private ErrorPage errorPage;
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ import org.keycloak.OAuth2Constants;
|
|||
import org.keycloak.OAuthErrorException;
|
||||
import org.keycloak.admin.client.resource.ClientsResource;
|
||||
import org.keycloak.admin.client.resource.UserResource;
|
||||
import org.keycloak.common.Profile;
|
||||
import org.keycloak.common.util.UriUtils;
|
||||
import org.keycloak.events.Details;
|
||||
import org.keycloak.events.Errors;
|
||||
|
@ -47,7 +46,6 @@ import org.keycloak.testsuite.Assert;
|
|||
import org.keycloak.testsuite.AssertEvents;
|
||||
import org.keycloak.testsuite.AbstractTestRealmKeycloakTest;
|
||||
import org.keycloak.testsuite.admin.ApiUtil;
|
||||
import org.keycloak.testsuite.arquillian.annotation.DisableFeature;
|
||||
import org.keycloak.testsuite.pages.AppPage;
|
||||
import org.keycloak.testsuite.pages.ErrorPage;
|
||||
import org.keycloak.testsuite.pages.InfoPage;
|
||||
|
@ -57,7 +55,6 @@ import java.io.Closeable;
|
|||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -76,7 +73,6 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.junit.Assert.fail;
|
||||
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlEquals;
|
||||
|
||||
import org.keycloak.testsuite.auth.page.account.AccountManagement;
|
||||
import org.keycloak.testsuite.pages.LogoutConfirmPage;
|
||||
import org.keycloak.testsuite.pages.OAuthGrantPage;
|
||||
import org.keycloak.testsuite.pages.PageUtils;
|
||||
|
@ -123,9 +119,6 @@ public class RPInitiatedLogoutTest extends AbstractTestRealmKeycloakTest {
|
|||
@Page
|
||||
protected InfoPage infoPage;
|
||||
|
||||
@Page
|
||||
protected AccountManagement accountManagementPage;
|
||||
|
||||
@Page
|
||||
private ErrorPage errorPage;
|
||||
|
||||
|
@ -274,14 +267,15 @@ public class RPInitiatedLogoutTest extends AbstractTestRealmKeycloakTest {
|
|||
|
||||
//KEYCLOAK-2741
|
||||
@Test
|
||||
@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true) // TODO remove this (KEYCLOAK-16228)
|
||||
public void logoutWithRememberMe() throws IOException {
|
||||
try (RealmAttributeUpdater update = new RealmAttributeUpdater(testRealm()).setRememberMe(true).update()) {
|
||||
String testUsername = "test-user@localhost";
|
||||
String testUserPassword = "password";
|
||||
loginPage.open();
|
||||
assertFalse(loginPage.isRememberMeChecked());
|
||||
loginPage.setRememberMe(true);
|
||||
assertTrue(loginPage.isRememberMeChecked());
|
||||
loginPage.login("test-user@localhost", "password");
|
||||
loginPage.login(testUsername, testUserPassword);
|
||||
|
||||
String sessionId = events.expectLogin().assertEvent().getSessionId();
|
||||
|
||||
|
@ -291,17 +285,21 @@ public class RPInitiatedLogoutTest extends AbstractTestRealmKeycloakTest {
|
|||
// Assert rememberMe checked and username/email prefilled
|
||||
loginPage.open();
|
||||
assertTrue(loginPage.isRememberMeChecked());
|
||||
assertEquals("test-user@localhost", loginPage.getUsername());
|
||||
assertEquals(testUsername, loginPage.getUsername());
|
||||
|
||||
loginPage.login("test-user@localhost", "password");
|
||||
loginPage.login(testUsername, testUserPassword);
|
||||
|
||||
//log out
|
||||
appPage.openAccount();
|
||||
accountManagementPage.signOut();
|
||||
String logoutUrl = oauth.getLogoutUrl().build();
|
||||
driver.navigate().to(logoutUrl);
|
||||
logoutConfirmPage.assertCurrent();
|
||||
logoutConfirmPage.confirmLogout();
|
||||
|
||||
loginPage.open();
|
||||
// Assert rememberMe not checked nor username/email prefilled
|
||||
assertTrue(loginPage.isCurrent());
|
||||
assertFalse(loginPage.isRememberMeChecked());
|
||||
assertNotEquals("test-user@localhost", loginPage.getUsername());
|
||||
assertNotEquals(testUsername, loginPage.getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.keycloak.admin.client.resource.ProtocolMappersResource;
|
|||
import org.keycloak.admin.client.resource.UserResource;
|
||||
import org.keycloak.authentication.authenticators.client.JWTClientAuthenticator;
|
||||
import org.keycloak.broker.provider.util.SimpleHttp;
|
||||
import org.keycloak.common.Profile;
|
||||
import org.keycloak.common.util.Base64Url;
|
||||
import org.keycloak.common.util.MultivaluedHashMap;
|
||||
import org.keycloak.common.util.Time;
|
||||
|
@ -50,7 +49,6 @@ import org.keycloak.jose.jws.JWSBuilder;
|
|||
import org.keycloak.keys.Attributes;
|
||||
import org.keycloak.keys.KeyProvider;
|
||||
import org.keycloak.models.AuthenticatedClientSessionModel;
|
||||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.models.RealmModel;
|
||||
import org.keycloak.models.UserSessionModel;
|
||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
||||
|
@ -69,14 +67,12 @@ import org.keycloak.representations.idm.ComponentRepresentation;
|
|||
import org.keycloak.representations.idm.EventRepresentation;
|
||||
import org.keycloak.representations.idm.KeysMetadataRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.services.resources.RealmsResource;
|
||||
import org.keycloak.services.util.CertificateInfoHelper;
|
||||
import org.keycloak.testsuite.AbstractTestRealmKeycloakTest;
|
||||
import org.keycloak.testsuite.Assert;
|
||||
import org.keycloak.testsuite.AssertEvents;
|
||||
import org.keycloak.testsuite.admin.AbstractAdminTest;
|
||||
import org.keycloak.testsuite.admin.ApiUtil;
|
||||
import org.keycloak.testsuite.arquillian.annotation.DisableFeature;
|
||||
import org.keycloak.testsuite.client.resources.TestApplicationResourceUrls;
|
||||
import org.keycloak.testsuite.client.resources.TestOIDCEndpointsApplicationResource;
|
||||
import org.keycloak.testsuite.pages.AppPage;
|
||||
|
@ -84,9 +80,13 @@ import org.keycloak.testsuite.pages.ErrorPage;
|
|||
import org.keycloak.testsuite.pages.LoginPage;
|
||||
import org.keycloak.testsuite.pages.OAuthGrantPage;
|
||||
import org.keycloak.testsuite.rest.resource.TestingOIDCEndpointsApplicationResource;
|
||||
import org.keycloak.testsuite.util.*;
|
||||
import org.keycloak.util.JWKSUtils;
|
||||
import org.keycloak.util.JsonSerialization;
|
||||
import org.keycloak.testsuite.util.OAuthClient;
|
||||
import org.keycloak.testsuite.util.ClientManager;
|
||||
import org.keycloak.testsuite.util.AdminClientUtil;
|
||||
import org.keycloak.testsuite.util.UserInfoClientUtil;
|
||||
import org.keycloak.testsuite.util.KeyUtils;
|
||||
|
||||
import jakarta.ws.rs.client.Client;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
@ -114,7 +114,6 @@ import static org.keycloak.testsuite.admin.ApiUtil.findClientResourceByClientId;
|
|||
*
|
||||
* @author <a href="mailto:mposolda@redhat.com">Marek Posolda</a>
|
||||
*/
|
||||
@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true) // TODO remove this (KEYCLOAK-16228)
|
||||
public class OIDCAdvancedRequestParamsTest extends AbstractTestRealmKeycloakTest {
|
||||
|
||||
@Rule
|
||||
|
@ -312,26 +311,19 @@ public class OIDCAdvancedRequestParamsTest extends AbstractTestRealmKeycloakTest
|
|||
ClientManager.realm(adminClient.realm("test")).clientId("test-app").consentRequired(true);
|
||||
|
||||
try {
|
||||
driver.navigate().to(RealmsResource.accountUrl(UriBuilder.fromUri(getAuthServerRoot())).build("test").toString());
|
||||
assertTrue(loginPage.isCurrent());
|
||||
loginPage.login("test-user@localhost", "password");
|
||||
assertEquals(driver.getCurrentUrl(), getAuthServerRoot() + "realms/test/account/");
|
||||
|
||||
events.expectLogin().client(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID)
|
||||
.removeDetail(Details.REDIRECT_URI)
|
||||
.detail(Details.USERNAME, "test-user@localhost").assertEvent();
|
||||
|
||||
// Assert error shown when trying prompt=none and consent not yet retrieved
|
||||
// Assert error shown when trying prompt=none and consent not yet granted
|
||||
driver.navigate().to(oauth.getLoginFormUrl() + "&prompt=none");
|
||||
assertTrue(appPage.isCurrent());
|
||||
Assert.assertEquals(AppPage.RequestType.AUTH_RESPONSE, appPage.getRequestType());
|
||||
|
||||
OAuthClient.AuthorizationEndpointResponse resp = new OAuthClient.AuthorizationEndpointResponse(oauth);
|
||||
Assert.assertNull(resp.getCode());
|
||||
Assert.assertEquals(OAuthErrorException.INTERACTION_REQUIRED, resp.getError());
|
||||
Assert.assertEquals(OAuthErrorException.LOGIN_REQUIRED, resp.getError());
|
||||
|
||||
// Confirm consent
|
||||
driver.navigate().to(oauth.getLoginFormUrl());
|
||||
// Login and confirm consent
|
||||
loginPage.open();
|
||||
assertTrue(loginPage.isCurrent());
|
||||
loginPage.login("test-user@localhost", "password");
|
||||
grantPage.assertCurrent();
|
||||
grantPage.accept();
|
||||
|
||||
|
|
|
@ -84,7 +84,6 @@ public class LDAPAccountTest extends AbstractAccountTest {
|
|||
});
|
||||
|
||||
testRealmLoginPage.setAuthRealm(testRealmPage);
|
||||
testRealmAccountPage.setAuthRealm(testRealmPage);
|
||||
|
||||
testUser = createUserRepresentation(userName, email, firstName, lastName, true);
|
||||
setPasswordFor(testUser, PASSWORD);
|
||||
|
|
|
@ -143,8 +143,8 @@ public class LinkedAccountsTest extends BaseAccountPageTest {
|
|||
assertEquals(SYSTEM_IDP_ALIAS, fid.getIdentityProvider());
|
||||
assertEquals(homerUser.getUsername(), fid.getUserName());
|
||||
|
||||
// try to login using IdP
|
||||
deleteAllSessionsInTestRealm();
|
||||
// logout user and try to login using IdP
|
||||
testUserResource().logout();
|
||||
linkedAccountsPage.navigateTo();
|
||||
loginPageWithSocialBtns.clickSocial(SYSTEM_IDP_ALIAS);
|
||||
linkedAccountsPage.assertCurrent(); // no need for re-login to REALM2
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 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.ui.login;
|
||||
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.testsuite.ui.AbstractUiTest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlDoesntStartWith;
|
||||
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith;
|
||||
|
||||
/**
|
||||
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||
*/
|
||||
public abstract class AbstractLoginTest extends AbstractUiTest {
|
||||
@Override
|
||||
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
||||
super.addTestRealms(testRealms);
|
||||
RealmRepresentation testRealmRep = testRealms.get(0);
|
||||
configureInternationalizationForRealm(testRealmRep);
|
||||
}
|
||||
|
||||
protected void assertLoginFailed(String message) {
|
||||
assertCurrentUrlDoesntStartWith(testRealmAccountPage);
|
||||
assertTrue("Feedback message should be an error", loginPage.feedbackMessage().isError());
|
||||
assertEquals(message, loginPage.feedbackMessage().getText());
|
||||
}
|
||||
|
||||
protected void assertLoginSuccessful() {
|
||||
assertCurrentUrlStartsWith(testRealmAccountPage);
|
||||
}
|
||||
}
|
|
@ -1,273 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 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.ui.login;
|
||||
|
||||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
import org.keycloak.testsuite.auth.page.login.Registration;
|
||||
import org.keycloak.testsuite.auth.page.login.ResetCredentials;
|
||||
import org.keycloak.testsuite.auth.page.login.UpdateAccount;
|
||||
import org.keycloak.testsuite.auth.page.login.UpdatePassword;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.keycloak.testsuite.auth.page.AuthRealm.TEST;
|
||||
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWithLoginUrlOf;
|
||||
|
||||
/**
|
||||
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||
*/
|
||||
public class LoginPageTest extends AbstractLoginTest {
|
||||
@Page
|
||||
private UpdateAccount updateAccountPage;
|
||||
|
||||
@Page
|
||||
private UpdatePassword updatePasswordPage;
|
||||
|
||||
@Page
|
||||
private Registration registrationPage;
|
||||
|
||||
@Page
|
||||
private ResetCredentials resetCredentialsPage;
|
||||
|
||||
@Override
|
||||
public void setDefaultPageUriParameters() {
|
||||
super.setDefaultPageUriParameters();
|
||||
updateAccountPage.setAuthRealm(TEST);
|
||||
updatePasswordPage.setAuthRealm(TEST);
|
||||
registrationPage.setAuthRealm(TEST);
|
||||
resetCredentialsPage.setAuthRealm(TEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
||||
super.addTestRealms(testRealms);
|
||||
RealmRepresentation testRealmRep = testRealms.get(0);
|
||||
testRealmRep.setDisplayNameHtml("Test realm <b>HTML</b>");
|
||||
testRealmRep.setRememberMe(true);
|
||||
testRealmRep.setResetPasswordAllowed(true);
|
||||
testRealmRep.setRegistrationAllowed(true);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void beforeLoginTest() {
|
||||
deleteAllCookiesForTestRealm();
|
||||
testRealmAccountPage.navigateTo();
|
||||
assertCurrentUrlStartsWithLoginUrlOf(testRealmAccountPage);
|
||||
assertFalse(testRealmLoginPage.feedbackMessage().isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrongCredentials() {
|
||||
assertFalse(testRealmLoginPage.form().isRememberMe());
|
||||
testRealmLoginPage.form().rememberMe(true);
|
||||
assertTrue(testRealmLoginPage.form().isRememberMe());
|
||||
testRealmLoginPage.form().login("some-user", "badPwd");
|
||||
assertTrue(testRealmLoginPage.form().isRememberMe());
|
||||
|
||||
assertLoginFailed("Invalid username or password.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disabledUser() {
|
||||
testUser.setEnabled(false);
|
||||
testUserResource().update(testUser);
|
||||
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
assertLoginFailed("Account is disabled, contact your administrator.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void labelsTest() {
|
||||
assertEquals("test realm html", testRealmLoginPage.getHeaderText().toLowerCase()); // we need to convert to lower case as Safari handles getText() differently
|
||||
assertEquals("Username or email", testRealmLoginPage.form().getUsernameLabel());
|
||||
assertEquals("Password", testRealmLoginPage.form().getPasswordLabel());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loginSuccessful() {
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
assertLoginSuccessful();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void internationalizationTest() {
|
||||
final String rememberMeLabel = "[TEST LOCALE] Zapamatuj si mě";
|
||||
|
||||
// required action set up
|
||||
testUser.setRequiredActions(Arrays.asList(updatePasswordPage.getActionId(), updateAccountPage.getActionId()));
|
||||
testUserResource().update(testUser);
|
||||
|
||||
assertEquals("Remember me", testRealmLoginPage.form().getRememberMeLabel());
|
||||
testRealmLoginPage.localeDropdown().selectByText(CUSTOM_LOCALE_NAME);
|
||||
assertEquals(rememberMeLabel, testRealmLoginPage.form().getRememberMeLabel());
|
||||
|
||||
testRealmLoginPage.form().login();
|
||||
assertLoginFailed("[TEST LOCALE] Chybné jméno nebo heslo");
|
||||
assertEquals(rememberMeLabel, testRealmLoginPage.form().getRememberMeLabel());
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
|
||||
if (updatePasswordPage.isCurrent()) {
|
||||
updatePassword();
|
||||
updateProfile();
|
||||
}
|
||||
else {
|
||||
updateProfile();
|
||||
updatePassword();
|
||||
}
|
||||
|
||||
assertLoginSuccessful();
|
||||
}
|
||||
|
||||
private void updateProfile() {
|
||||
assertEquals("[TEST LOCALE] aktualizovat profil", updateAccountPage.feedbackMessage().getText());
|
||||
updateAccountPage.submit(); // should be pre-filled
|
||||
}
|
||||
|
||||
private void updatePassword() {
|
||||
updatePasswordPage.updatePasswords("some wrong", "password");
|
||||
assertEquals("[TEST LOCALE] hesla se neshodují", updatePasswordPage.feedbackMessage().getText());
|
||||
updatePasswordPage.updatePasswords("matchingPassword", "matchingPassword");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerTest() {
|
||||
testRealmLoginPage.form().register();
|
||||
|
||||
registrationPage.assertCurrent();
|
||||
|
||||
registrationPage.localeDropdown().selectByText(CUSTOM_LOCALE_NAME);
|
||||
registrationPage.submit();
|
||||
|
||||
assertTrue(registrationPage.feedbackMessage().isError());
|
||||
assertEquals("[TEST LOCALE] křestní jméno", registrationPage.accountFields().getFirstNameLabel());
|
||||
|
||||
registrationPage.backToLogin();
|
||||
testRealmLoginPage.form().register();
|
||||
|
||||
registrationPage.localeDropdown().selectByText(ENGLISH_LOCALE_NAME);
|
||||
|
||||
final String username = "vmuzikar";
|
||||
final String email = "vmuzikar@redhat.com";
|
||||
final String firstName = "Vaclav";
|
||||
final String lastName = "Muzikar";
|
||||
final UserRepresentation newUser = createUserRepresentation(username, email, firstName, lastName, true, "password");
|
||||
|
||||
// empty form
|
||||
registrationPage.submit();
|
||||
assertRegistrationFields(null, null, null, null, false, true);
|
||||
|
||||
// email filled in
|
||||
registrationPage.accountFields().setEmail(email);
|
||||
registrationPage.submit();
|
||||
assertRegistrationFields(null, null, email, null, false, true);
|
||||
|
||||
// first name filled in
|
||||
registrationPage.accountFields().setEmail(null);
|
||||
registrationPage.accountFields().setFirstName(firstName);
|
||||
registrationPage.submit();
|
||||
assertRegistrationFields(firstName, null, null, null, false, true);
|
||||
|
||||
// last name filled in
|
||||
registrationPage.accountFields().setFirstName(null);
|
||||
registrationPage.accountFields().setLastName(lastName);
|
||||
registrationPage.submit();
|
||||
assertRegistrationFields(null, lastName, null, null, false, true);
|
||||
|
||||
// username filled in
|
||||
registrationPage.accountFields().setLastName(null);
|
||||
registrationPage.accountFields().setUsername(username);
|
||||
registrationPage.submit();
|
||||
assertRegistrationFields(null, null, null, username, false, true);
|
||||
|
||||
// password mismatch
|
||||
registrationPage.accountFields().setValues(newUser);
|
||||
registrationPage.passwordFields().setPassword("wrong");
|
||||
registrationPage.passwordFields().setConfirmPassword("password");
|
||||
registrationPage.submit();
|
||||
assertRegistrationFields(firstName, lastName, email, username, true, false);
|
||||
|
||||
// success
|
||||
registrationPage.register(newUser);
|
||||
assertLoginSuccessful();
|
||||
}
|
||||
|
||||
private void assertRegistrationFields(String firstName, String lastName, String email, String username, boolean password, boolean passwordConfirm) {
|
||||
assertTrue(registrationPage.feedbackMessage().isError());
|
||||
|
||||
assertRegistrationAvailability(firstName != null, registrationPage.accountFields().hasFirstNameError(),
|
||||
firstName, registrationPage.accountFields().getFirstName());
|
||||
|
||||
assertRegistrationAvailability(lastName != null, registrationPage.accountFields().hasLastNameError(),
|
||||
lastName, registrationPage.accountFields().getLastName());
|
||||
|
||||
assertRegistrationAvailability(email != null, registrationPage.accountFields().hasEmailError(),
|
||||
email, registrationPage.accountFields().getEmail());
|
||||
|
||||
assertRegistrationAvailability(username != null, registrationPage.accountFields().hasUsernameError(),
|
||||
username, registrationPage.accountFields().getUsername());
|
||||
|
||||
assertRegistrationAvailability(password, registrationPage.passwordFields().hasPasswordError());
|
||||
assertRegistrationAvailability(passwordConfirm, registrationPage.passwordFields().hasConfirmPasswordError());
|
||||
}
|
||||
|
||||
private void assertRegistrationAvailability(boolean isAvailable, boolean state) {
|
||||
assertRegistrationAvailability(isAvailable, state, null, null);
|
||||
}
|
||||
|
||||
private void assertRegistrationAvailability(boolean isAvailable, boolean state, String expected, String actual) {
|
||||
if (isAvailable) {
|
||||
assertFalse(state);
|
||||
if (expected != null && actual != null) {
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
} else {
|
||||
assertTrue(state);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetCredentialsTest() {
|
||||
testRealmLoginPage.form().forgotPassword();
|
||||
resetCredentialsPage.localeDropdown().selectByText(CUSTOM_LOCALE_NAME);
|
||||
resetCredentialsPage.assertCurrent();
|
||||
resetCredentialsPage.backToLogin();
|
||||
|
||||
testRealmLoginPage.form().forgotPassword();
|
||||
assertEquals("[TEST LOCALE] Zapomenuté heslo", resetCredentialsPage.getTitleText());
|
||||
|
||||
// empty form
|
||||
assertFalse(resetCredentialsPage.feedbackMessage().isPresent());
|
||||
resetCredentialsPage.submit();
|
||||
resetCredentialsPage.assertCurrent();
|
||||
assertTrue(resetCredentialsPage.feedbackMessage().isPresent());
|
||||
assertTrue(resetCredentialsPage.feedbackMessage().isError());
|
||||
|
||||
// non-empty form
|
||||
resetCredentialsPage.resetCredentials(testUser.getUsername());
|
||||
// there will be probably an error sending email, so no further action here
|
||||
}
|
||||
}
|
|
@ -1,520 +0,0 @@
|
|||
/*
|
||||
* Copyright 2018 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.ui.login;
|
||||
|
||||
import com.google.zxing.BinaryBitmap;
|
||||
import com.google.zxing.Result;
|
||||
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
|
||||
import com.google.zxing.common.HybridBinarizer;
|
||||
import com.google.zxing.qrcode.QRCodeReader;
|
||||
import org.jboss.arquillian.graphene.page.Page;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.admin.client.resource.ClientResource;
|
||||
import org.keycloak.models.utils.Base32;
|
||||
import org.keycloak.models.utils.HmacOTP;
|
||||
import org.keycloak.models.utils.TimeBasedOTP;
|
||||
import org.keycloak.representations.idm.ClientRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.representations.idm.RequiredActionProviderRepresentation;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
import org.keycloak.testsuite.auth.page.login.LoginError;
|
||||
import org.keycloak.testsuite.auth.page.login.OAuthGrant;
|
||||
import org.keycloak.testsuite.auth.page.login.OTPSetup;
|
||||
import org.keycloak.testsuite.auth.page.login.OneTimeCode;
|
||||
import org.keycloak.testsuite.auth.page.login.RequiredActions;
|
||||
import org.keycloak.testsuite.auth.page.login.TermsAndConditions;
|
||||
import org.keycloak.testsuite.auth.page.login.UpdateAccount;
|
||||
import org.keycloak.testsuite.auth.page.login.UpdatePassword;
|
||||
import org.keycloak.testsuite.auth.page.login.VerifyEmail;
|
||||
import org.openqa.selenium.OutputType;
|
||||
import org.openqa.selenium.TakesScreenshot;
|
||||
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.google.zxing.BarcodeFormat.QR_CODE;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
import static org.keycloak.models.ClientScopeModel.CONSENT_SCREEN_TEXT;
|
||||
import static org.keycloak.models.ClientScopeModel.DISPLAY_ON_CONSENT_SCREEN;
|
||||
import static org.keycloak.models.Constants.ACCOUNT_MANAGEMENT_CLIENT_ID;
|
||||
import static org.keycloak.representations.idm.CredentialRepresentation.PASSWORD;
|
||||
import static org.keycloak.testsuite.admin.ApiUtil.createUserAndResetPasswordWithAdminClient;
|
||||
import static org.keycloak.testsuite.auth.page.AuthRealm.TEST;
|
||||
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWithLoginUrlOf;
|
||||
|
||||
/**
|
||||
* @author Vaclav Muzikar <vmuzikar@redhat.com>
|
||||
*/
|
||||
public class RequiredActionsTest extends AbstractLoginTest {
|
||||
public static final String GRANT_REALM = "grant-realm";
|
||||
public static final String CONSENT_TEXT = "Příliš žluťoučký kůň úpěl ďábelské ódy";
|
||||
|
||||
private UserRepresentation grantRealmUser = createUserRepresentation("test", PASSWORD);
|
||||
|
||||
public static final String TOTP = "totp";
|
||||
public static final String HOTP = "hotp";
|
||||
|
||||
@Page
|
||||
private TermsAndConditions termsAndConditionsPage;
|
||||
|
||||
@Page
|
||||
private UpdatePassword updatePasswordPage;
|
||||
|
||||
@Page
|
||||
private UpdateAccount updateAccountPage;
|
||||
|
||||
@Page
|
||||
private VerifyEmail verifyEmailPage;
|
||||
|
||||
@Page
|
||||
private OTPSetup otpSetupPage;
|
||||
|
||||
@Page
|
||||
private OneTimeCode oneTimeCodePage;
|
||||
|
||||
@Page
|
||||
private OAuthGrant oAuthGrantPage;
|
||||
|
||||
@Page
|
||||
private LoginError loginErrorPage;
|
||||
|
||||
private TimeBasedOTP otpGenerator = new TimeBasedOTP();
|
||||
|
||||
@Override
|
||||
public void setDefaultPageUriParameters() {
|
||||
super.setDefaultPageUriParameters();
|
||||
termsAndConditionsPage.setAuthRealm(TEST);
|
||||
updatePasswordPage.setAuthRealm(TEST);
|
||||
updateAccountPage.setAuthRealm(TEST);
|
||||
verifyEmailPage.setAuthRealm(TEST);
|
||||
otpSetupPage.setAuthRealm(TEST);
|
||||
oneTimeCodePage.setAuthRealm(TEST);
|
||||
oAuthGrantPage.setAuthRealm(GRANT_REALM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTestRealms(List<RealmRepresentation> testRealms) {
|
||||
super.addTestRealms(testRealms);
|
||||
|
||||
RealmRepresentation testRealmRep = new RealmRepresentation();
|
||||
testRealmRep.setId(GRANT_REALM);
|
||||
testRealmRep.setRealm(GRANT_REALM);
|
||||
configureInternationalizationForRealm(testRealmRep);
|
||||
testRealmRep.setEnabled(true);
|
||||
|
||||
testRealms.add(testRealmRep);
|
||||
}
|
||||
|
||||
// Some actions we need to do after the realm is created and configured
|
||||
@Override
|
||||
protected void afterAbstractKeycloakTestRealmImport() {
|
||||
super.afterAbstractKeycloakTestRealmImport();
|
||||
|
||||
// create test user
|
||||
createUserAndResetPasswordWithAdminClient(adminClient.realm(GRANT_REALM), grantRealmUser, PASSWORD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void termsAndConditions() {
|
||||
RequiredActionProviderRepresentation termsAndCondRep = testRealmResource().flows().getRequiredAction(termsAndConditionsPage.getActionId());
|
||||
termsAndCondRep.setEnabled(true);
|
||||
testRealmResource().flows().updateRequiredAction(termsAndConditionsPage.getActionId(), termsAndCondRep);
|
||||
|
||||
initiateRequiredAction(termsAndConditionsPage);
|
||||
|
||||
termsAndConditionsPage.localeDropdown().selectAndAssert(CUSTOM_LOCALE_NAME);
|
||||
|
||||
termsAndConditionsPage.acceptTerms();
|
||||
assertLoginSuccessful();
|
||||
|
||||
deleteAllSessionsInTestRealm();
|
||||
initiateRequiredAction(termsAndConditionsPage);
|
||||
assertEquals("[TEST LOCALE] souhlas s podmínkami", termsAndConditionsPage.getText());
|
||||
termsAndConditionsPage.declineTerms();
|
||||
loginErrorPage.assertCurrent();
|
||||
assertNoAccess();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updatePassword() {
|
||||
initiateRequiredAction(updatePasswordPage);
|
||||
|
||||
updatePasswordPage.localeDropdown().selectAndAssert(CUSTOM_LOCALE_NAME);
|
||||
assertTrue(updatePasswordPage.feedbackMessage().isWarning());
|
||||
assertEquals("You need to change your password to activate your account.", updatePasswordPage.feedbackMessage().getText());
|
||||
assertEquals("New Password", updatePasswordPage.fields().getNewPasswordLabel());
|
||||
assertEquals("Confirm password", updatePasswordPage.fields().getConfirmPasswordLabel());
|
||||
|
||||
updatePasswordPage.updatePasswords("some wrong", "password");
|
||||
assertTrue(updatePasswordPage.feedbackMessage().isError());
|
||||
assertEquals("[TEST LOCALE] hesla se neshodují", updatePasswordPage.feedbackMessage().getText());
|
||||
|
||||
updatePasswordPage.localeDropdown().selectAndAssert(ENGLISH_LOCALE_NAME);
|
||||
updatePasswordPage.updatePasswords("matchingPassword", "matchingPassword");
|
||||
assertLoginSuccessful();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateProfile() {
|
||||
initiateRequiredAction(updateAccountPage);
|
||||
|
||||
// prefilled profile
|
||||
assertTrue(updateAccountPage.feedbackMessage().isWarning());
|
||||
updateAccountPage.localeDropdown().selectAndAssert(CUSTOM_LOCALE_NAME);
|
||||
assertEquals("[TEST LOCALE] aktualizovat profil", updateAccountPage.feedbackMessage().getText());
|
||||
updateAccountPage.localeDropdown().selectAndAssert(ENGLISH_LOCALE_NAME);
|
||||
assertFalse(updateAccountPage.fields().isUsernamePresent());
|
||||
assertEquals("Email", updateAccountPage.fields().getEmailLabel());
|
||||
assertEquals("First name", updateAccountPage.fields().getFirstNameLabel());
|
||||
assertEquals("Last name", updateAccountPage.fields().getLastNameLabel());
|
||||
assertFalse(updateAccountPage.fields().hasEmailError());
|
||||
assertFalse(updateAccountPage.fields().hasFirstNameError());
|
||||
assertFalse(updateAccountPage.fields().hasLastNameError());
|
||||
assertEquals(testUser.getEmail(), updateAccountPage.fields().getEmail());
|
||||
assertEquals(testUser.getFirstName(), updateAccountPage.fields().getFirstName());
|
||||
assertEquals(testUser.getLastName(), updateAccountPage.fields().getLastName());
|
||||
updateAccountPage.localeDropdown().selectAndAssert(CUSTOM_LOCALE_NAME);
|
||||
|
||||
// empty form
|
||||
updateAccountPage.updateAccount(null, null, null);
|
||||
assertTrue(updateAccountPage.feedbackMessage().isError());
|
||||
String errorMsg = updateAccountPage.feedbackMessage().getText();
|
||||
assertTrue(errorMsg.contains("first name") && errorMsg.contains("last name") && errorMsg.contains("email"));
|
||||
assertTrue(updateAccountPage.fields().hasEmailError());
|
||||
assertTrue(updateAccountPage.fields().hasFirstNameError());
|
||||
assertTrue(updateAccountPage.fields().hasLastNameError());
|
||||
|
||||
final String email = "vmuzikar@redhat.com";
|
||||
final String firstName = "Vaclav";
|
||||
final String lastName = "Muzikar";
|
||||
|
||||
// email filled in
|
||||
updateAccountPage.fields().setEmail(email);
|
||||
updateAccountPage.submit();
|
||||
assertTrue(updateAccountPage.feedbackMessage().isError());
|
||||
errorMsg = updateAccountPage.feedbackMessage().getText();
|
||||
assertTrue(errorMsg.contains("first name") && errorMsg.contains("last name") && !errorMsg.contains("email"));
|
||||
assertFalse(updateAccountPage.fields().hasEmailError());
|
||||
assertTrue(updateAccountPage.fields().hasFirstNameError());
|
||||
assertTrue(updateAccountPage.fields().hasLastNameError());
|
||||
assertEquals(email, updateAccountPage.fields().getEmail());
|
||||
|
||||
// first name filled in
|
||||
updateAccountPage.fields().setFirstName(firstName);
|
||||
updateAccountPage.submit();
|
||||
assertTrue(updateAccountPage.feedbackMessage().isError());
|
||||
errorMsg = updateAccountPage.feedbackMessage().getText();
|
||||
assertTrue(!errorMsg.contains("first name") && errorMsg.contains("last name") && !errorMsg.contains("email"));
|
||||
assertFalse(updateAccountPage.fields().hasEmailError());
|
||||
assertFalse(updateAccountPage.fields().hasFirstNameError());
|
||||
assertTrue(updateAccountPage.fields().hasLastNameError());
|
||||
assertEquals(email, updateAccountPage.fields().getEmail());
|
||||
assertEquals(firstName, updateAccountPage.fields().getFirstName());
|
||||
|
||||
// last name filled in
|
||||
updateAccountPage.fields().setFirstName(null);
|
||||
updateAccountPage.fields().setLastName(lastName);
|
||||
updateAccountPage.submit();
|
||||
assertTrue(updateAccountPage.feedbackMessage().isError());
|
||||
errorMsg = updateAccountPage.feedbackMessage().getText();
|
||||
assertTrue(errorMsg.contains("first name") && !errorMsg.contains("last name") && !errorMsg.contains("email"));
|
||||
assertFalse(updateAccountPage.fields().hasEmailError());
|
||||
assertTrue(updateAccountPage.fields().hasFirstNameError());
|
||||
assertFalse(updateAccountPage.fields().hasLastNameError());
|
||||
assertEquals(email, updateAccountPage.fields().getEmail());
|
||||
assertEquals(lastName, updateAccountPage.fields().getLastName());
|
||||
|
||||
// success
|
||||
assertEquals("[TEST LOCALE] křestní jméno", updateAccountPage.fields().getFirstNameLabel());
|
||||
updateAccountPage.updateAccount(email, firstName, lastName);
|
||||
assertLoginSuccessful();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyEmail() {
|
||||
initiateRequiredAction(verifyEmailPage);
|
||||
|
||||
verifyEmailPage.localeDropdown().selectAndAssert(CUSTOM_LOCALE_NAME);
|
||||
|
||||
boolean firstAttempt = true;
|
||||
while (true) {
|
||||
assertTrue(verifyEmailPage.feedbackMessage().isWarning());
|
||||
assertEquals("[TEST LOCALE] je třeba ověřit emailovou adresu", verifyEmailPage.feedbackMessage().getText());
|
||||
assertEquals("An email with instructions to verify your email address has been sent to your address test@email.test.", verifyEmailPage.getInstructionMessage());
|
||||
|
||||
if (firstAttempt) {
|
||||
verifyEmailPage.clickResend();
|
||||
firstAttempt = false;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureManualTotp() {
|
||||
setRealmOtpType(TOTP);
|
||||
testManualOtp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureManualHotp() {
|
||||
setRealmOtpType(HOTP);
|
||||
testManualOtp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureBarcodeTotp() throws Exception {
|
||||
setRealmOtpType(TOTP);
|
||||
testBarcodeOtp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configureBarcodeHotp() throws Exception {
|
||||
setRealmOtpType(HOTP);
|
||||
testBarcodeOtp();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clientConsent() {
|
||||
testRealmPage.setAuthRealm(GRANT_REALM);
|
||||
testRealmAccountPage.setAuthRealm(GRANT_REALM);
|
||||
testRealmLoginPage.setAuthRealm(GRANT_REALM);
|
||||
|
||||
final List<String> defaultClientScopesToApprove = Arrays.asList("Email address", "User profile");
|
||||
|
||||
// custom consent text
|
||||
initiateClientScopesConsent(true, CONSENT_TEXT);
|
||||
oAuthGrantPage.localeDropdown().selectAndAssert(CUSTOM_LOCALE_NAME);
|
||||
List<String> clientScopesToApprove = new LinkedList<>(defaultClientScopesToApprove);
|
||||
clientScopesToApprove.add(CONSENT_TEXT);
|
||||
oAuthGrantPage.assertClientScopes(clientScopesToApprove);
|
||||
|
||||
// default consent text
|
||||
initiateClientScopesConsent(true, null);
|
||||
clientScopesToApprove = new LinkedList<>(defaultClientScopesToApprove);
|
||||
clientScopesToApprove.add("Account");
|
||||
oAuthGrantPage.assertClientScopes(clientScopesToApprove);
|
||||
|
||||
// consent with missing client
|
||||
initiateClientScopesConsent(false, CONSENT_TEXT);
|
||||
oAuthGrantPage.assertClientScopes(defaultClientScopesToApprove);
|
||||
|
||||
// test buttons
|
||||
oAuthGrantPage.cancel();
|
||||
assertNoAccess();
|
||||
testRealmLoginPage.form().login(grantRealmUser);
|
||||
assertEquals("[TEST LOCALE] Udělit přístup Account", oAuthGrantPage.getTitleText());
|
||||
oAuthGrantPage.accept();
|
||||
assertLoginSuccessful();
|
||||
}
|
||||
|
||||
private void testManualOtp() {
|
||||
initiateRequiredAction(otpSetupPage);
|
||||
|
||||
otpSetupPage.localeDropdown().selectAndAssert(CUSTOM_LOCALE_NAME);
|
||||
|
||||
otpSetupPage.clickManualMode();
|
||||
assertFalse(otpSetupPage.isBarcodePresent());
|
||||
assertTrue(otpSetupPage.feedbackMessage().isWarning());
|
||||
assertEquals("You need to set up Mobile Authenticator to activate your account.", otpSetupPage.feedbackMessage().getText());
|
||||
|
||||
// empty input
|
||||
otpSetupPage.submit();
|
||||
assertTrue(otpSetupPage.feedbackMessage().isError());
|
||||
assertEquals("Please specify authenticator code.", otpSetupPage.feedbackMessage().getText());
|
||||
|
||||
final String replacePattern = "^.+: ";
|
||||
|
||||
// extract data
|
||||
String type = otpSetupPage.getOtpType().replaceAll(replacePattern, "");
|
||||
if (type.equals("Time-based")) type = TOTP;
|
||||
else if (type.equals("Counter-based")) type = HOTP;
|
||||
String secret = otpSetupPage.getSecretKey();
|
||||
int digits = Integer.parseInt(otpSetupPage.getOtpDigits().replaceAll(replacePattern, ""));
|
||||
String algorithm = otpSetupPage.getOtpAlgorithm().replaceAll(replacePattern, "");
|
||||
Integer period = type.equals(TOTP) ? Integer.parseInt(otpSetupPage.getOtpPeriod().replaceAll(replacePattern, "")) : null;
|
||||
Integer counter = type.equals(HOTP) ? Integer.parseInt(otpSetupPage.getOtpCounter().replaceAll(replacePattern, "")) : null;
|
||||
|
||||
// the actual test
|
||||
testOtp(type, algorithm, digits, period, counter, secret);
|
||||
}
|
||||
|
||||
private void testBarcodeOtp() throws Exception {
|
||||
assumeFalse(driver instanceof HtmlUnitDriver); // HtmlUnit browser cannot take screenshots
|
||||
TakesScreenshot screenshotDriver = (TakesScreenshot) driver;
|
||||
QRCodeReader qrCodeReader = new QRCodeReader();
|
||||
|
||||
initiateRequiredAction(otpSetupPage);
|
||||
|
||||
otpSetupPage.localeDropdown().selectAndAssert(CUSTOM_LOCALE_NAME);
|
||||
|
||||
otpSetupPage.clickManualMode();
|
||||
otpSetupPage.clickBarcodeMode();
|
||||
|
||||
assertTrue(otpSetupPage.isBarcodePresent());
|
||||
assertFalse(otpSetupPage.isSecretKeyPresent());
|
||||
assertTrue(otpSetupPage.feedbackMessage().isWarning());
|
||||
assertEquals("You need to set up Mobile Authenticator to activate your account.", otpSetupPage.feedbackMessage().getText());
|
||||
|
||||
// empty input
|
||||
otpSetupPage.submit();
|
||||
assertTrue(otpSetupPage.feedbackMessage().isError());
|
||||
assertEquals("Please specify authenticator code.", otpSetupPage.feedbackMessage().getText());
|
||||
|
||||
// take a screenshot of the QR code
|
||||
byte[] screenshot = screenshotDriver.getScreenshotAs(OutputType.BYTES);
|
||||
BufferedImage screenshotImg = ImageIO.read(new ByteArrayInputStream(screenshot));
|
||||
BinaryBitmap screenshotBinaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(screenshotImg)));
|
||||
Result qrCode = qrCodeReader.decode(screenshotBinaryBitmap);
|
||||
|
||||
// parse the QR code string
|
||||
Pattern qrUriPattern = Pattern.compile("^otpauth:\\/\\/(?<type>.+)\\/(?<realm>.+):(?<user>.+)\\?secret=(?<secret>.+)&digits=(?<digits>.+)&algorithm=(?<algorithm>.+)&issuer=(?<issuer>.+)&(?:period=(?<period>.+)|counter=(?<counter>.+))$");
|
||||
Matcher qrUriMatcher = qrUriPattern.matcher(qrCode.getText());
|
||||
assertTrue(qrUriMatcher.find());
|
||||
|
||||
// extract data
|
||||
String type = qrUriMatcher.group("type");
|
||||
String realm = qrUriMatcher.group("realm");
|
||||
String user = qrUriMatcher.group("user");
|
||||
String secret = qrUriMatcher.group("secret");
|
||||
int digits = Integer.parseInt(qrUriMatcher.group("digits"));
|
||||
String algorithm = qrUriMatcher.group("algorithm");
|
||||
String issuer = qrUriMatcher.group("issuer");
|
||||
Integer period = type.equals(TOTP) ? Integer.parseInt(qrUriMatcher.group("period")) : null;
|
||||
Integer counter = type.equals(HOTP) ? Integer.parseInt(qrUriMatcher.group("counter")) : null;
|
||||
|
||||
RealmRepresentation realmRep = testRealmResource().toRepresentation();
|
||||
String expectedRealmName = realmRep.getDisplayName() != null && !realmRep.getDisplayName().isEmpty() ? realmRep.getDisplayName() : realmRep.getRealm();
|
||||
|
||||
// basic assertations
|
||||
assertEquals(QR_CODE, qrCode.getBarcodeFormat());
|
||||
assertEquals(expectedRealmName, realm);
|
||||
assertEquals(expectedRealmName, issuer);
|
||||
assertEquals(testUser.getUsername(), user);
|
||||
|
||||
// the actual test
|
||||
testOtp(type, algorithm, digits, period, counter, secret);
|
||||
}
|
||||
|
||||
private void testOtp(String type, String algorithm, int digits, Integer period, Integer counter, String secret) {
|
||||
switch (algorithm) {
|
||||
case "SHA1":
|
||||
algorithm = TimeBasedOTP.HMAC_SHA1;
|
||||
break;
|
||||
case "SHA256":
|
||||
algorithm = TimeBasedOTP.HMAC_SHA256;
|
||||
break;
|
||||
case "SHA512":
|
||||
algorithm = TimeBasedOTP.HMAC_SHA512;
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Wrong algorithm type");
|
||||
}
|
||||
|
||||
HmacOTP otpGenerator;
|
||||
String secretDecoded = new String(Base32.decode(secret));
|
||||
String code;
|
||||
|
||||
switch (type) {
|
||||
case TOTP:
|
||||
otpGenerator = new TimeBasedOTP(algorithm, digits, period, 0);
|
||||
code = ((TimeBasedOTP) otpGenerator).generateTOTP(secretDecoded);
|
||||
break;
|
||||
case HOTP:
|
||||
otpGenerator = new HmacOTP(digits, algorithm, 0);
|
||||
code = otpGenerator.generateHOTP(secretDecoded, counter);
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Wrong OTP type");
|
||||
}
|
||||
|
||||
// fill in the form
|
||||
otpSetupPage.setTotp(code);
|
||||
otpSetupPage.submit();
|
||||
assertLoginSuccessful();
|
||||
|
||||
// try the code is working
|
||||
deleteAllSessionsInTestRealm();
|
||||
testRealmAccountPage.navigateTo();
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
oneTimeCodePage.assertCurrent();
|
||||
//assertEquals("One-time code", oneTimeCodePage.getTotpLabel());
|
||||
|
||||
// bad attempt
|
||||
oneTimeCodePage.submit();
|
||||
assertTrue(oneTimeCodePage.feedbackMessage().isError());
|
||||
assertEquals("[TEST LOCALE] vložen chybný kód", oneTimeCodePage.feedbackMessage().getText());
|
||||
oneTimeCodePage.sendCode("XXXXXX");
|
||||
assertTrue(oneTimeCodePage.feedbackMessage().isError());
|
||||
assertEquals("[TEST LOCALE] vložen chybný kód", oneTimeCodePage.feedbackMessage().getText());
|
||||
|
||||
// generate new code
|
||||
code = type.equals(TOTP) ? ((TimeBasedOTP) otpGenerator).generateTOTP(secretDecoded) : otpGenerator.generateHOTP(secretDecoded, ++counter);
|
||||
oneTimeCodePage.sendCode(code);
|
||||
assertLoginSuccessful();
|
||||
}
|
||||
|
||||
private void setRealmOtpType(String otpType) {
|
||||
RealmRepresentation realmRep = testRealmResource().toRepresentation();
|
||||
realmRep.setOtpPolicyType(otpType);
|
||||
testRealmResource().update(realmRep);
|
||||
}
|
||||
|
||||
private void initiateRequiredAction(RequiredActions requiredActionPage) {
|
||||
testUser.setRequiredActions(Collections.singletonList(requiredActionPage.getActionId()));
|
||||
testUserResource().update(testUser);
|
||||
|
||||
testRealmAccountPage.navigateTo();
|
||||
assertCurrentUrlStartsWithLoginUrlOf(testRealmAccountPage);
|
||||
|
||||
testRealmLoginPage.form().login(testUser);
|
||||
requiredActionPage.assertCurrent();
|
||||
}
|
||||
|
||||
private void initiateClientScopesConsent(boolean displayOnConsentScreen, String consentScreenText) {
|
||||
ClientRepresentation accountClientRep = testRealmResource().clients().findByClientId(ACCOUNT_MANAGEMENT_CLIENT_ID).get(0);
|
||||
ClientResource accountClient = testRealmResource().clients().get(accountClientRep.getId());
|
||||
accountClientRep.setConsentRequired(true);
|
||||
accountClientRep.getAttributes().put(DISPLAY_ON_CONSENT_SCREEN, String.valueOf(displayOnConsentScreen));
|
||||
accountClientRep.getAttributes().put(CONSENT_SCREEN_TEXT, consentScreenText);
|
||||
accountClient.update(accountClientRep);
|
||||
|
||||
testRealmAccountPage.navigateTo();
|
||||
testRealmLoginPage.form().login(grantRealmUser);
|
||||
oAuthGrantPage.assertCurrent();
|
||||
}
|
||||
|
||||
private void assertNoAccess() {
|
||||
assertEquals("No access", loginErrorPage.getErrorMessage());
|
||||
loginErrorPage.backToApplication();
|
||||
assertCurrentUrlStartsWithLoginUrlOf(testRealmLoginPage);
|
||||
}
|
||||
}
|
|
@ -55,7 +55,6 @@ import static org.keycloak.testsuite.util.ServerURLs.getAuthServerContextRoot;
|
|||
import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith;
|
||||
import static org.keycloak.testsuite.util.WaitUtils.pause;
|
||||
|
||||
@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true) // TODO remove this (KEYCLOAK-16228)
|
||||
public class AccountLinkSpringBootTest extends AbstractSpringBootTest {
|
||||
|
||||
private static final String PARENT_REALM = "parent-realm";
|
||||
|
|
|
@ -33,7 +33,6 @@ import static org.keycloak.testsuite.util.URLAssert.assertCurrentUrlStartsWith;
|
|||
import static org.keycloak.testsuite.util.WaitUtils.pause;
|
||||
import static org.keycloak.testsuite.util.WaitUtils.waitForPageToLoad;
|
||||
|
||||
@DisableFeature(value = Profile.Feature.ACCOUNT2, skipRestart = true) // TODO remove this (KEYCLOAK-16228)
|
||||
public class SessionSpringBootTest extends AbstractSpringBootTest {
|
||||
|
||||
private static final String SERVLET_URL = BASE_URL + "/SessionServlet";
|
||||
|
|
Loading…
Reference in a new issue