To fix Bitbucket/GitHub oauth, and probably many other placestags/7.5
@@ -19,6 +19,7 @@ | |||
*/ | |||
package org.sonar.server.platform; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.ce.ComputeEngineSide; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.server.ServerSide; | |||
@@ -52,7 +53,8 @@ public class UrlSettings { | |||
if (isEmpty(url)) { | |||
url = computeBaseUrl(); | |||
} | |||
return url; | |||
// Remove trailing slashes | |||
return StringUtils.removeEnd(url, "/"); | |||
} | |||
public String getContextPath() { |
@@ -57,6 +57,13 @@ public class UrlSettingsTest { | |||
assertThat(underTest().getBaseUrl()).isEqualTo("http://mydomain.com"); | |||
} | |||
@Test | |||
public void remove_trailing_slash() { | |||
settings.setProperty("sonar.core.serverBaseURL", "http://mydomain.com/"); | |||
assertThat(underTest().getBaseUrl()).isEqualTo("http://mydomain.com"); | |||
} | |||
@Test | |||
public void is_secured_on_https_server() { | |||
settings.setProperty("sonar.core.serverBaseURL", "https://mydomain.com"); |
@@ -20,6 +20,7 @@ | |||
package org.sonar.api.config; | |||
import java.util.List; | |||
import org.apache.commons.lang.StringUtils; | |||
import org.sonar.api.PropertyType; | |||
import org.sonar.api.ce.ComputeEngineSide; | |||
import org.sonar.api.server.ServerSide; | |||
@@ -94,7 +95,9 @@ public class EmailSettings { | |||
} | |||
public String getServerBaseURL() { | |||
return get(SERVER_BASE_URL, SERVER_BASE_URL_DEFAULT_VALUE); | |||
return config.get(SERVER_BASE_URL) | |||
.map(t -> StringUtils.removeEnd(t, "/")) | |||
.orElse(SERVER_BASE_URL_DEFAULT_VALUE); | |||
} | |||
private String get(String key, String defaultValue) { |
@@ -86,7 +86,7 @@ public abstract class Server { | |||
public abstract String getContextPath(); | |||
/** | |||
* Return the public root url, for instance : https://nemo.sonarqube.org. | |||
* Return the public root url, without trailing slash, for instance : https://nemo.sonarqube.org. | |||
* Default value is {@link org.sonar.api.CoreProperties#SERVER_BASE_URL_DEFAULT_VALUE} | |||
* | |||
* @since 5.4 |
@@ -19,15 +19,18 @@ | |||
*/ | |||
package org.sonar.api.config; | |||
import org.apache.commons.lang.RandomStringUtils; | |||
import org.junit.Test; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.api.CoreProperties.SERVER_BASE_URL; | |||
public class EmailSettingsTest { | |||
private EmailSettings underTest = new EmailSettings(new MapSettings().asConfig()); | |||
private MapSettings settings = new MapSettings(); | |||
private EmailSettings underTest = new EmailSettings(settings.asConfig()); | |||
@Test | |||
public void should_return_default_values() { | |||
@@ -42,6 +45,21 @@ public class EmailSettingsTest { | |||
assertThat(underTest.getServerBaseURL()).isEqualTo(CoreProperties.SERVER_BASE_URL_DEFAULT_VALUE); | |||
} | |||
@Test | |||
public void getServerBaseUrl_returns_property_value() { | |||
String expected = RandomStringUtils.randomAlphabetic(15); | |||
settings.setProperty(SERVER_BASE_URL, expected); | |||
assertThat(underTest.getServerBaseURL()).isEqualTo(expected); | |||
} | |||
@Test | |||
public void getServerBaseUrl_removes_trailing_slash_from_property_value() { | |||
settings.setProperty(SERVER_BASE_URL, "http://www.acme.com/"); | |||
assertThat(underTest.getServerBaseURL()).isEqualTo("http://www.acme.com"); | |||
} | |||
@Test | |||
public void return_definitions() { | |||
assertThat(EmailSettings.definitions()).hasSize(8); |