Skip to content

Commit 118d789

Browse files
erikpetzoldSteKoe
andauthored
fix: basepath in routes (#2141)
* fix basepath in reactive environment test did not really test this due to wrong verification * add more tests for different combinations of path properties * fix formatting * chore: checkstyle Co-authored-by: Stephan Köninger <[email protected]>
1 parent ca67bd9 commit 118d789

File tree

7 files changed

+283
-153
lines changed

7 files changed

+283
-153
lines changed

spring-boot-admin-server-ui/src/main/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfiguration.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,12 @@ public HomepageForwardingFilterConfig homepageForwardingFilterConfig() throws IO
156156
List<String> extensionRoutes = new UiRoutesScanner(this.applicationContext)
157157
.scan(this.adminUi.getExtensionResourceLocations());
158158
List<String> routesIncludes = Stream.concat(DEFAULT_UI_ROUTES.stream(), extensionRoutes.stream())
159-
.map(this.adminServer::path).collect(Collectors.toList());
159+
.map((path) -> webfluxBasePathSet ? webFluxBasePath + path : this.adminServer.path(path))
160+
.collect(Collectors.toList());
160161
routesIncludes.add("");
161162

162-
List<String> routesExcludes = DEFAULT_UI_ROUTE_EXCLUDES.stream().map(this.adminServer::path)
163+
List<String> routesExcludes = DEFAULT_UI_ROUTE_EXCLUDES.stream()
164+
.map((path) -> webfluxBasePathSet ? webFluxBasePath + path : this.adminServer.path(path))
163165
.collect(Collectors.toList());
164166

165167
return new HomepageForwardingFilterConfig(homepage, routesIncludes, routesExcludes);

spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfigurationTest.java

Lines changed: 0 additions & 151 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2014-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package de.codecentric.boot.admin.server.ui.config;
18+
19+
import org.springframework.boot.autoconfigure.AutoConfigurations;
20+
import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
21+
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
22+
23+
import de.codecentric.boot.admin.server.config.AdminServerProperties;
24+
25+
public class ReactiveAdminServerUiAutoConfigurationAdminContextPathTest
26+
extends ReactiveAdminServerUiAutoConfigurationTest {
27+
28+
@Override
29+
protected ReactiveWebApplicationContextRunner getContextRunner() {
30+
return new ReactiveWebApplicationContextRunner()
31+
.withPropertyValues("--spring.boot.admin.ui.available-languages=de",
32+
"--spring.boot.admin.contextPath=test")
33+
.withBean(AdminServerProperties.class).withBean(WebFluxProperties.class)
34+
.withConfiguration(AutoConfigurations.of(AdminServerUiAutoConfiguration.class));
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2014-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package de.codecentric.boot.admin.server.ui.config;
18+
19+
import org.springframework.boot.autoconfigure.AutoConfigurations;
20+
import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
21+
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
22+
23+
import de.codecentric.boot.admin.server.config.AdminServerProperties;
24+
25+
public class ReactiveAdminServerUiAutoConfigurationBothPathsTest extends ReactiveAdminServerUiAutoConfigurationTest {
26+
27+
@Override
28+
protected ReactiveWebApplicationContextRunner getContextRunner() {
29+
return new ReactiveWebApplicationContextRunner()
30+
.withPropertyValues("--spring.boot.admin.ui.available-languages=de",
31+
"--spring.boot.admin.contextPath=different", "--spring.webflux.base-path=test")
32+
.withBean(AdminServerProperties.class).withBean(WebFluxProperties.class)
33+
.withConfiguration(AutoConfigurations.of(AdminServerUiAutoConfiguration.class));
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2014-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package de.codecentric.boot.admin.server.ui.config;
18+
19+
import org.junit.jupiter.api.extension.ExtendWith;
20+
import org.junit.jupiter.params.ParameterizedTest;
21+
import org.junit.jupiter.params.provider.CsvSource;
22+
import org.mockito.Mock;
23+
import org.mockito.junit.jupiter.MockitoExtension;
24+
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
25+
import org.springframework.http.HttpHeaders;
26+
import org.springframework.http.MediaType;
27+
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
28+
import org.springframework.mock.web.server.MockServerWebExchange;
29+
import org.springframework.web.server.ServerWebExchange;
30+
import org.springframework.web.server.WebFilterChain;
31+
32+
import de.codecentric.boot.admin.server.config.AdminServerMarkerConfiguration;
33+
import de.codecentric.boot.admin.server.config.SpringBootAdminServerEnabledCondition;
34+
import de.codecentric.boot.admin.server.ui.web.reactive.HomepageForwardingFilter;
35+
36+
import static org.mockito.Mockito.never;
37+
import static org.mockito.Mockito.spy;
38+
import static org.mockito.Mockito.verify;
39+
40+
@ExtendWith(MockitoExtension.class)
41+
public abstract class ReactiveAdminServerUiAutoConfigurationTest {
42+
43+
protected abstract ReactiveWebApplicationContextRunner getContextRunner();
44+
45+
@Mock
46+
WebFilterChain webFilterChain;
47+
48+
@ParameterizedTest
49+
@CsvSource({ "/test/extensions/myextension", "/test/instances/1/actuator/heapdump",
50+
"/test/instances/1/actuator/logfile" })
51+
public void contextPathIsRespectedInExcludedRoutes(String routeExcludes) {
52+
MockServerHttpRequest serverHttpRequest = MockServerHttpRequest.get(routeExcludes)
53+
.header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE).build();
54+
55+
ServerWebExchange serverWebExchange = spy(MockServerWebExchange.from(serverHttpRequest));
56+
57+
this.getContextRunner().withUserConfiguration(SpringBootAdminServerEnabledCondition.class,
58+
AdminServerMarkerConfiguration.Marker.class).run((context) -> {
59+
HomepageForwardingFilter bean = context.getBean(HomepageForwardingFilter.class);
60+
bean.filter(serverWebExchange, webFilterChain);
61+
62+
verify(serverWebExchange, never()).mutate();
63+
});
64+
}
65+
66+
@ParameterizedTest
67+
@CsvSource({ "/test/about", "/test/applications", "/test/instances", "/test/journal", "/test/wallboard",
68+
"/test/external" })
69+
public void contextPathIsRespectedInIncludedRoutes(String routeIncludes) {
70+
MockServerHttpRequest serverHttpRequest = MockServerHttpRequest.get(routeIncludes)
71+
.header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE).build();
72+
73+
ServerWebExchange serverWebExchange = spy(MockServerWebExchange.from(serverHttpRequest));
74+
75+
this.getContextRunner().withUserConfiguration(SpringBootAdminServerEnabledCondition.class,
76+
AdminServerMarkerConfiguration.Marker.class).run((context) -> {
77+
HomepageForwardingFilter bean = context.getBean(HomepageForwardingFilter.class);
78+
bean.filter(serverWebExchange, webFilterChain);
79+
80+
verify(serverWebExchange).mutate();
81+
});
82+
}
83+
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2014-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package de.codecentric.boot.admin.server.ui.config;
18+
19+
import org.springframework.boot.autoconfigure.AutoConfigurations;
20+
import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
21+
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
22+
23+
import de.codecentric.boot.admin.server.config.AdminServerProperties;
24+
25+
public class ReactiveAdminServerUiAutoConfigurationWebfluxBasePathTest
26+
extends ReactiveAdminServerUiAutoConfigurationTest {
27+
28+
@Override
29+
protected ReactiveWebApplicationContextRunner getContextRunner() {
30+
return new ReactiveWebApplicationContextRunner()
31+
.withPropertyValues("--spring.boot.admin.ui.available-languages=de", "--spring.webflux.base-path=test")
32+
.withBean(AdminServerProperties.class).withBean(WebFluxProperties.class)
33+
.withConfiguration(AutoConfigurations.of(AdminServerUiAutoConfiguration.class));
34+
}
35+
36+
}

0 commit comments

Comments
 (0)