mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-02 02:10:53 +01:00
Omit default port in protocol urls (#2014)
This omits the port in the protocol urls when the port is the default port for the protocol. So if you have your server https://my.scm.net/scm and the repository admin/test, the protocol url is no longer https://my.scm.net:443/scm/repo/admin/test, but simply https://my.scm.net/scm/repo/admin/test without the :443.
This commit is contained in:
@@ -30,6 +30,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
@@ -40,6 +41,8 @@ import java.net.MalformedURLException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@@ -56,12 +59,14 @@ class DefaultRootURLTest {
|
||||
|
||||
private ScmConfiguration configuration;
|
||||
|
||||
private RootURL rootURL;
|
||||
private DefaultRootURL rootURL;
|
||||
@Spy
|
||||
private DefaultRootURL.UrlFromString cacheLoader;
|
||||
|
||||
@BeforeEach
|
||||
void init() {
|
||||
configuration = new ScmConfiguration();
|
||||
rootURL = new DefaultRootURL(requestProvider, configuration);
|
||||
rootURL = new DefaultRootURL(requestProvider, configuration, cacheLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,6 +89,13 @@ class DefaultRootURLTest {
|
||||
assertThat(rootURL.getAsString()).isEqualTo(URL_CONFIG);
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldSuppressDefaultPorts() {
|
||||
bindNonHttpScope();
|
||||
configuration.setBaseUrl("https://hitchhiker.com:443/from-configuration");
|
||||
assertThat(rootURL.getAsString()).isEqualTo(URL_CONFIG);
|
||||
}
|
||||
|
||||
private void bindNonHttpScope() {
|
||||
when(requestProvider.get()).thenThrow(
|
||||
new ProvisionException("no request available", new OutOfScopeException("out of scope"))
|
||||
@@ -106,7 +118,6 @@ class DefaultRootURLTest {
|
||||
|
||||
IllegalStateException exception = assertThrows(IllegalStateException.class, () -> rootURL.get());
|
||||
assertThat(exception.getMessage()).contains("malformed", "non_url");
|
||||
assertThat(exception.getCause()).isInstanceOf(MalformedURLException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,6 +134,16 @@ class DefaultRootURLTest {
|
||||
assertThat(rootURL.get()).hasHost("hitchhiker.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldUseUrlCache() throws MalformedURLException {
|
||||
bindForwardedRequestUrl();
|
||||
|
||||
rootURL.get();
|
||||
rootURL.get();
|
||||
|
||||
verify(cacheLoader).load(any());
|
||||
}
|
||||
|
||||
private void bindForwardedRequestUrl() {
|
||||
when(requestProvider.get()).thenReturn(request);
|
||||
when(request.getHeader(HttpUtil.HEADER_X_FORWARDED_HOST)).thenReturn("hitchhiker.com");
|
||||
|
||||
Reference in New Issue
Block a user