Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: huan415 <435826111@qq.com>
- Loading branch information
Showing
8 changed files
with
221 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...src/main/java/de/codecentric/boot/admin/server/ui/web/HomepageForwardingFilterConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2014-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package de.codecentric.boot.admin.server.ui.web; | ||
|
||
import java.util.List; | ||
|
||
import lombok.Value; | ||
|
||
@Value | ||
public class HomepageForwardingFilterConfig { | ||
|
||
private final String homepage; | ||
|
||
private final List<String> routesIncludes; | ||
|
||
private final List<String> routesExcludes; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
...t/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* Copyright 2014-2021 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package de.codecentric.boot.admin.server.ui.config; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletResponse; | ||
|
||
import org.assertj.core.api.WithAssertions; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner; | ||
import org.springframework.boot.test.context.runner.WebApplicationContextRunner; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.mock.http.server.reactive.MockServerHttpRequest; | ||
import org.springframework.mock.web.MockHttpServletRequest; | ||
import org.springframework.mock.web.MockHttpServletResponse; | ||
import org.springframework.mock.web.server.MockServerWebExchange; | ||
import org.springframework.web.server.ServerWebExchange; | ||
import org.springframework.web.server.WebFilterChain; | ||
|
||
import de.codecentric.boot.admin.server.config.AdminServerMarkerConfiguration; | ||
import de.codecentric.boot.admin.server.config.AdminServerProperties; | ||
import de.codecentric.boot.admin.server.config.SpringBootAdminServerEnabledCondition; | ||
import de.codecentric.boot.admin.server.ui.web.reactive.HomepageForwardingFilter; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.atMostOnce; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.verify; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class AdminServerUiAutoConfigurationTest implements WithAssertions { | ||
|
||
@Nested | ||
public class ReactiveUiConfigurationTest { | ||
|
||
private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner() | ||
.withPropertyValues("--spring.boot.admin.ui.available-languages=de", | ||
"--spring.boot.admin.contextPath=test") | ||
.withBean(AdminServerProperties.class) | ||
.withConfiguration(AutoConfigurations.of(AdminServerUiAutoConfiguration.class)); | ||
|
||
@Mock | ||
WebFilterChain webFilterChain; | ||
|
||
@ParameterizedTest | ||
@CsvSource({ "/test/extensions/myextension", "/test/instances/1/actuator/heapdump", | ||
"/test/instances/1/actuator/logfile" }) | ||
public void contextPathIsRespectedInExcludedRoutes(String routeExcludes) { | ||
MockServerHttpRequest serverHttpRequest = MockServerHttpRequest.get(routeExcludes) | ||
.header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE).build(); | ||
|
||
ServerWebExchange serverWebExchange = spy(MockServerWebExchange.from(serverHttpRequest)); | ||
|
||
this.contextRunner.withUserConfiguration(SpringBootAdminServerEnabledCondition.class, | ||
AdminServerMarkerConfiguration.Marker.class).run((context) -> { | ||
HomepageForwardingFilter bean = context.getBean(HomepageForwardingFilter.class); | ||
bean.filter(serverWebExchange, webFilterChain); | ||
|
||
verify(serverWebExchange, never()).mutate(); | ||
}); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ "/test/about", "/test/applications", "/test/instances", "/test/journal", "/test/wallboard", | ||
"/test/external" }) | ||
public void contextPathIsRespectedInIncludedRoutes(String routeIncludes) { | ||
MockServerHttpRequest serverHttpRequest = MockServerHttpRequest.get(routeIncludes) | ||
.header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE).build(); | ||
|
||
ServerWebExchange serverWebExchange = spy(MockServerWebExchange.from(serverHttpRequest)); | ||
|
||
this.contextRunner.withUserConfiguration(SpringBootAdminServerEnabledCondition.class, | ||
AdminServerMarkerConfiguration.Marker.class).run((context) -> { | ||
HomepageForwardingFilter bean = context.getBean(HomepageForwardingFilter.class); | ||
bean.filter(serverWebExchange, webFilterChain); | ||
|
||
verify(serverWebExchange, atMostOnce()).mutate(); | ||
}); | ||
} | ||
|
||
} | ||
|
||
@Nested | ||
public class ServletUiConfiguration { | ||
|
||
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() | ||
.withPropertyValues("--spring.boot.admin.ui.available-languages=de", | ||
"--spring.boot.admin.contextPath=test") | ||
.withBean(AdminServerProperties.class) | ||
.withConfiguration(AutoConfigurations.of(AdminServerUiAutoConfiguration.class)); | ||
|
||
@ParameterizedTest | ||
@CsvSource({ "/test/extensions/myextension", "/test/instances/1/actuator/heapdump", | ||
"/test/instances/1/actuator/logfile" }) | ||
public void contextPathIsRespectedInExcludedRoutes(String routeExcludes) { | ||
MockHttpServletRequest httpServletRequest = spy(new MockHttpServletRequest("GET", routeExcludes)); | ||
httpServletRequest.addHeader(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE); | ||
|
||
this.contextRunner.withUserConfiguration(SpringBootAdminServerEnabledCondition.class, | ||
AdminServerMarkerConfiguration.Marker.class).run((context) -> { | ||
de.codecentric.boot.admin.server.ui.web.servlet.HomepageForwardingFilter bean = context.getBean( | ||
de.codecentric.boot.admin.server.ui.web.servlet.HomepageForwardingFilter.class); | ||
bean.doFilter(httpServletRequest, mock(ServletResponse.class), mock(FilterChain.class)); | ||
|
||
verify(httpServletRequest, never()).getRequestDispatcher(any()); | ||
}); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource({ "/test/about", "/test/applications", "/test/instances", "/test/journal", "/test/wallboard", | ||
"/test/external" }) | ||
public void contextPathIsRespectedInIncludedRoutes(String routeIncludes) { | ||
MockHttpServletRequest httpServletRequest = spy(new MockHttpServletRequest("GET", routeIncludes)); | ||
httpServletRequest.addHeader(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE); | ||
|
||
this.contextRunner.withUserConfiguration(SpringBootAdminServerEnabledCondition.class, | ||
AdminServerMarkerConfiguration.Marker.class).run((context) -> { | ||
de.codecentric.boot.admin.server.ui.web.servlet.HomepageForwardingFilter bean = context.getBean( | ||
de.codecentric.boot.admin.server.ui.web.servlet.HomepageForwardingFilter.class); | ||
bean.doFilter(httpServletRequest, new MockHttpServletResponse(), mock(FilterChain.class)); | ||
|
||
verify(httpServletRequest, atMostOnce()).getRequestDispatcher(any()); | ||
}); | ||
} | ||
|
||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...-boot-admin-server-ui/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mock-maker-inline |