Skip to content

Commit

Permalink
#2175: Generalized normalizing of homepage url + unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
ulischulte committed Dec 23, 2022
1 parent 0fae4b8 commit d7e0d62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ public SpringResourceTemplateResolver adminTemplateResolver() {
return resolver;
}

static String normalizeHomepageUrl(String homepage) {
if (!"/".equals(homepage)) {
homepage = PathUtils.normalizePath(homepage);
}
return homepage;
}

@Configuration(proxyBeanMethods = false)
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
public static class ReactiveUiConfiguration {
Expand Down Expand Up @@ -160,10 +167,7 @@ public AdminUiWebfluxConfig(AdminServerUiProperties adminUi, AdminServerProperti
public HomepageForwardingFilterConfig homepageForwardingFilterConfig() throws IOException {
String webFluxBasePath = webFluxProperties.getBasePath();
boolean webfluxBasePathSet = webFluxBasePath != null;
String homepage = webfluxBasePathSet ? webFluxBasePath + "/" : this.adminServer.path("/");
if (!"/".equals(homepage)) {
homepage = PathUtils.normalizePath(homepage);
}
String homepage = normalizeHomepageUrl(webfluxBasePathSet ? webFluxBasePath + "/" : this.adminServer.path("/"));

List<String> extensionRoutes = new UiRoutesScanner(this.applicationContext)
.scan(this.adminUi.getExtensionResourceLocations());
Expand Down Expand Up @@ -229,10 +233,7 @@ public void configurePathMatch(PathMatchConfigurer configurer) {

@Bean
public HomepageForwardingFilterConfig homepageForwardingFilterConfig() throws IOException {
String homepage = this.adminServer.path("/");
if (!"/".equals(homepage)) {
homepage = PathUtils.normalizePath(homepage);
}
String homepage = normalizeHomepageUrl(this.adminServer.path("/"));

List<String> extensionRoutes = new UiRoutesScanner(this.applicationContext)
.scan(this.adminUi.getExtensionResourceLocations());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
Expand Down Expand Up @@ -148,4 +149,9 @@ public void contextPathIsRespectedInIncludedRoutes(String routeIncludes) {

}

@Test
void testNormalizeHomepageUrl() {
assertThat(AdminServerUiAutoConfiguration.normalizeHomepageUrl("/test/")).isEqualTo("/test");
}

}

0 comments on commit d7e0d62

Please sign in to comment.