Removes trailing slash from the base url

This commit is contained in:
Bartosz Majsak 2017-03-15 22:21:06 +01:00
parent beee0c1e67
commit a250f08b6c
2 changed files with 41 additions and 1 deletions

View file

@ -15,6 +15,13 @@ public class OpenshifV3IdentityProviderConfig extends OAuth2IdentityProviderConf
}
public void setBaseUrl(String baseUrl) {
getConfig().put(BASE_URL, baseUrl);
getConfig().put(BASE_URL, trimTrailingSlash(baseUrl));
}
private String trimTrailingSlash(String baseUrl) {
if (baseUrl != null && baseUrl.endsWith("/")) {
baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
}
return baseUrl;
}
}

View file

@ -0,0 +1,33 @@
package org.keycloak.social.openshift;
import org.junit.Assert;
import org.junit.Test;
import org.keycloak.models.IdentityProviderModel;
public class OpenshiftV3IdentityProviderTest {
@Test
public void shouldConstructProviderUrls() throws Exception {
final OpenshifV3IdentityProviderConfig config = new OpenshifV3IdentityProviderConfig(new IdentityProviderModel());
config.setBaseUrl("http://openshift.io:8443");
final OpenshiftV3IdentityProvider openshiftV3IdentityProvider = new OpenshiftV3IdentityProvider(null, config);
assertConfiguredUrls(openshiftV3IdentityProvider);
}
@Test
public void shouldConstructProviderUrlsForBaseUrlWithTrailingSlash() throws Exception {
final OpenshifV3IdentityProviderConfig config = new OpenshifV3IdentityProviderConfig(new IdentityProviderModel());
config.setBaseUrl("http://openshift.io:8443/");
final OpenshiftV3IdentityProvider openshiftV3IdentityProvider = new OpenshiftV3IdentityProvider(null, config);
assertConfiguredUrls(openshiftV3IdentityProvider);
}
private void assertConfiguredUrls(OpenshiftV3IdentityProvider openshiftV3IdentityProvider) {
Assert.assertEquals("http://openshift.io:8443/oauth/authorize", openshiftV3IdentityProvider.getConfig().getAuthorizationUrl());
Assert.assertEquals("http://openshift.io:8443/oauth/token", openshiftV3IdentityProvider.getConfig().getTokenUrl());
Assert.assertEquals("http://openshift.io:8443/oapi/v1/users/~", openshiftV3IdentityProvider.getConfig().getUserInfoUrl());
}
}