Additional test case added to check the text in the 'Back to application' link
This commit is contained in:
parent
c72ceadfce
commit
1c66ce7dd7
4 changed files with 81 additions and 8 deletions
|
@ -788,7 +788,11 @@ public class AccountService extends AbstractSecuredLocalService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (referrerUri != null) {
|
if (referrerUri != null) {
|
||||||
return new String[]{referrerClient.getName(), referrerUri};
|
String referrerName = referrerClient.getName();
|
||||||
|
if (Validation.isBlank(referrerName)) {
|
||||||
|
referrerName = referrer;
|
||||||
|
}
|
||||||
|
return new String[]{referrerName, referrerUri};
|
||||||
}
|
}
|
||||||
} else if (referrerUri != null) {
|
} else if (referrerUri != null) {
|
||||||
referrerClient = realm.getClientByClientId(referrer);
|
referrerClient = realm.getClientByClientId(referrer);
|
||||||
|
|
|
@ -20,6 +20,7 @@ package org.keycloak.testsuite.pages;
|
||||||
import org.keycloak.models.Constants;
|
import org.keycloak.models.Constants;
|
||||||
import org.keycloak.services.resources.RealmsResource;
|
import org.keycloak.services.resources.RealmsResource;
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.NoSuchElementException;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.support.FindBy;
|
import org.openqa.selenium.support.FindBy;
|
||||||
|
|
||||||
|
@ -144,6 +145,24 @@ public class AccountUpdateProfilePage extends AbstractAccountPage {
|
||||||
backToApplicationLink.click();
|
backToApplicationLink.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getBackToApplicationLinkText() {
|
||||||
|
try {
|
||||||
|
// Optional screen element, may not be present
|
||||||
|
return backToApplicationLink.getText();
|
||||||
|
} catch (NoSuchElementException ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBackToApplicationLinkHref() {
|
||||||
|
try {
|
||||||
|
// Optional screen element, may not be present
|
||||||
|
return backToApplicationLink.getAttribute("href");
|
||||||
|
} catch (NoSuchElementException ignored) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getSuccess(){
|
public String getSuccess(){
|
||||||
return successMessage.getText();
|
return successMessage.getText();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,16 +16,26 @@
|
||||||
*/
|
*/
|
||||||
package org.keycloak.testsuite.account;
|
package org.keycloak.testsuite.account;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.UriBuilder;
|
||||||
|
|
||||||
import org.jboss.arquillian.drone.api.annotation.Drone;
|
import org.jboss.arquillian.drone.api.annotation.Drone;
|
||||||
import org.jboss.arquillian.graphene.page.Page;
|
import org.jboss.arquillian.graphene.page.Page;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.keycloak.admin.client.resource.RealmResource;
|
||||||
import org.keycloak.events.Details;
|
import org.keycloak.events.Details;
|
||||||
import org.keycloak.events.Errors;
|
import org.keycloak.events.Errors;
|
||||||
import org.keycloak.events.EventType;
|
import org.keycloak.events.EventType;
|
||||||
import org.keycloak.models.utils.TimeBasedOTP;
|
import org.keycloak.models.utils.TimeBasedOTP;
|
||||||
|
import org.keycloak.representations.idm.ClientRepresentation;
|
||||||
import org.keycloak.representations.idm.EventRepresentation;
|
import org.keycloak.representations.idm.EventRepresentation;
|
||||||
import org.keycloak.representations.idm.RealmRepresentation;
|
import org.keycloak.representations.idm.RealmRepresentation;
|
||||||
import org.keycloak.representations.idm.UserRepresentation;
|
import org.keycloak.representations.idm.UserRepresentation;
|
||||||
|
@ -53,13 +63,6 @@ import org.keycloak.testsuite.util.UserBuilder;
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
||||||
import javax.ws.rs.core.UriBuilder;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||||
* @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc.
|
* @author Stan Silvert ssilvert@redhat.com (C) 2016 Red Hat Inc.
|
||||||
|
@ -829,4 +832,40 @@ public class AccountTest extends TestRealmKeycloakTest {
|
||||||
|
|
||||||
events.clear();
|
events.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testReferrerLinkContents() {
|
||||||
|
RealmResource testRealm = testRealm();
|
||||||
|
List<ClientRepresentation> foundClients = testRealm.clients().findByClientId("named-test-app");
|
||||||
|
if (foundClients.isEmpty()) {
|
||||||
|
Assert.fail("Unable to find named-test-app");
|
||||||
|
}
|
||||||
|
ClientRepresentation namedClient = foundClients.get(0);
|
||||||
|
|
||||||
|
driver.navigate().to(profilePage.getPath() + "?referrer=" + namedClient.getClientId());
|
||||||
|
loginPage.login("test-user@localhost", "password");
|
||||||
|
Assert.assertTrue(profilePage.isCurrent());
|
||||||
|
// When a client has a name provided, the name should be available to the back link
|
||||||
|
Assert.assertEquals("Back to " + namedClient.getName(), profilePage.getBackToApplicationLinkText());
|
||||||
|
Assert.assertEquals(namedClient.getBaseUrl(), profilePage.getBackToApplicationLinkHref());
|
||||||
|
|
||||||
|
foundClients = testRealm.clients().findByClientId("test-app");
|
||||||
|
if (foundClients.isEmpty()) {
|
||||||
|
Assert.fail("Unable to find test-app");
|
||||||
|
}
|
||||||
|
ClientRepresentation namelessClient = foundClients.get(0);
|
||||||
|
|
||||||
|
driver.navigate().to(profilePage.getPath() + "?referrer=" + namelessClient.getClientId());
|
||||||
|
Assert.assertTrue(profilePage.isCurrent());
|
||||||
|
// When a client has no name provided, the client-id should be available to the back link
|
||||||
|
Assert.assertEquals("Back to " + namelessClient.getClientId(), profilePage.getBackToApplicationLinkText());
|
||||||
|
Assert.assertEquals(namelessClient.getBaseUrl(), profilePage.getBackToApplicationLinkHref());
|
||||||
|
|
||||||
|
driver.navigate().to(profilePage.getPath() + "?referrer=test-invalid");
|
||||||
|
Assert.assertTrue(profilePage.isCurrent());
|
||||||
|
// When a client is invalid, the back link should not exist
|
||||||
|
Assert.assertNull(profilePage.getBackToApplicationLinkText());
|
||||||
|
|
||||||
|
events.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -304,6 +304,17 @@
|
||||||
"/test-app-authz/*"
|
"/test-app-authz/*"
|
||||||
],
|
],
|
||||||
"secret": "secret"
|
"secret": "secret"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"clientId": "named-test-app",
|
||||||
|
"name": "My Named Test App",
|
||||||
|
"enabled": true,
|
||||||
|
"baseUrl": "http://localhost:8180/namedapp/base",
|
||||||
|
"redirectUris": [
|
||||||
|
"http://localhost:8180/namedapp/base/*"
|
||||||
|
],
|
||||||
|
"adminUrl": "http://localhost:8180/namedapp/base/admin",
|
||||||
|
"secret": "password"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"roles" : {
|
"roles" : {
|
||||||
|
|
Loading…
Reference in a new issue