Merge branch 'KEYCLOAK-4004' of https://github.com/l-robinson/keycloak into l-robinson-KEYCLOAK-4004
This commit is contained in:
commit
04179c5681
4 changed files with 74 additions and 2 deletions
|
@ -800,7 +800,11 @@ public class AccountService extends AbstractSecuredLocalService {
|
|||
}
|
||||
|
||||
if (referrerUri != null) {
|
||||
return new String[]{referrer, referrerUri};
|
||||
String referrerName = referrerClient.getName();
|
||||
if (Validation.isBlank(referrerName)) {
|
||||
referrerName = referrer;
|
||||
}
|
||||
return new String[]{referrerName, referrerUri};
|
||||
}
|
||||
} else if (referrerUri != null) {
|
||||
referrerClient = realm.getClientByClientId(referrer);
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.keycloak.testsuite.pages;
|
|||
import org.keycloak.models.Constants;
|
||||
import org.keycloak.services.resources.RealmsResource;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.NoSuchElementException;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
|
@ -144,6 +145,24 @@ public class AccountUpdateProfilePage extends AbstractAccountPage {
|
|||
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(){
|
||||
return successMessage.getText();
|
||||
}
|
||||
|
|
|
@ -23,11 +23,13 @@ import org.junit.Before;
|
|||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.keycloak.admin.client.resource.RealmResource;
|
||||
import org.keycloak.events.Details;
|
||||
import org.keycloak.events.Errors;
|
||||
import org.keycloak.events.EventType;
|
||||
import org.keycloak.models.PasswordPolicy;
|
||||
import org.keycloak.models.utils.TimeBasedOTP;
|
||||
import org.keycloak.representations.idm.ClientRepresentation;
|
||||
import org.keycloak.representations.idm.EventRepresentation;
|
||||
import org.keycloak.representations.idm.RealmRepresentation;
|
||||
import org.keycloak.representations.idm.UserRepresentation;
|
||||
|
@ -862,7 +864,7 @@ public class AccountTest extends TestRealmKeycloakTest {
|
|||
Assert.assertTrue(applicationsPage.isCurrent());
|
||||
|
||||
Map<String, AccountApplicationsPage.AppEntry> apps = applicationsPage.getApplications();
|
||||
Assert.assertThat(apps.keySet(), containsInAnyOrder("Account", "test-app", "test-app-scope", "third-party", "test-app-authz"));
|
||||
Assert.assertThat(apps.keySet(), containsInAnyOrder("Account", "test-app", "test-app-scope", "third-party", "test-app-authz", "My Named Test App"));
|
||||
|
||||
AccountApplicationsPage.AppEntry accountEntry = apps.get("Account");
|
||||
Assert.assertEquals(2, accountEntry.getRolesAvailable().size());
|
||||
|
@ -933,4 +935,40 @@ public class AccountTest extends TestRealmKeycloakTest {
|
|||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -320,6 +320,17 @@
|
|||
"/test-app-authz/*"
|
||||
],
|
||||
"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" : {
|
||||
|
|
Loading…
Reference in a new issue