Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: basepath in routes #2141

Merged
merged 4 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ public HomepageForwardingFilterConfig homepageForwardingFilterConfig() throws IO
List<String> extensionRoutes = new UiRoutesScanner(this.applicationContext)
.scan(this.adminUi.getExtensionResourceLocations());
List<String> routesIncludes = Stream.concat(DEFAULT_UI_ROUTES.stream(), extensionRoutes.stream())
.map(this.adminServer::path).collect(Collectors.toList());
.map((path) -> webfluxBasePathSet ? webFluxBasePath + path : this.adminServer.path(path))
.collect(Collectors.toList());
routesIncludes.add("");

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

return new HomepageForwardingFilterConfig(homepage, routesIncludes, routesExcludes);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2014-2022 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
*
* https://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 org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;

import de.codecentric.boot.admin.server.config.AdminServerProperties;

public class ReactiveAdminServerUiAutoConfigurationAdminContextPathTest
extends ReactiveAdminServerUiAutoConfigurationTest {

@Override
protected ReactiveWebApplicationContextRunner getContextRunner() {
return new ReactiveWebApplicationContextRunner()
.withPropertyValues("--spring.boot.admin.ui.available-languages=de",
"--spring.boot.admin.contextPath=test")
.withBean(AdminServerProperties.class).withBean(WebFluxProperties.class)
.withConfiguration(AutoConfigurations.of(AdminServerUiAutoConfiguration.class));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2014-2022 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
*
* https://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 org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;

import de.codecentric.boot.admin.server.config.AdminServerProperties;

public class ReactiveAdminServerUiAutoConfigurationBothPathsTest extends ReactiveAdminServerUiAutoConfigurationTest {

@Override
protected ReactiveWebApplicationContextRunner getContextRunner() {
return new ReactiveWebApplicationContextRunner()
.withPropertyValues("--spring.boot.admin.ui.available-languages=de",
"--spring.boot.admin.contextPath=different", "--spring.webflux.base-path=test")
.withBean(AdminServerProperties.class).withBean(WebFluxProperties.class)
.withConfiguration(AutoConfigurations.of(AdminServerUiAutoConfiguration.class));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 2014-2022 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
*
* https://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 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.test.context.runner.ReactiveWebApplicationContextRunner;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
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.SpringBootAdminServerEnabledCondition;
import de.codecentric.boot.admin.server.ui.web.reactive.HomepageForwardingFilter;

import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
public abstract class ReactiveAdminServerUiAutoConfigurationTest {

protected abstract ReactiveWebApplicationContextRunner getContextRunner();

@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.getContextRunner().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.getContextRunner().withUserConfiguration(SpringBootAdminServerEnabledCondition.class,
AdminServerMarkerConfiguration.Marker.class).run((context) -> {
HomepageForwardingFilter bean = context.getBean(HomepageForwardingFilter.class);
bean.filter(serverWebExchange, webFilterChain);

verify(serverWebExchange).mutate();
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2014-2022 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
*
* https://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 org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.web.reactive.WebFluxProperties;
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;

import de.codecentric.boot.admin.server.config.AdminServerProperties;

public class ReactiveAdminServerUiAutoConfigurationWebfluxBasePathTest
extends ReactiveAdminServerUiAutoConfigurationTest {

@Override
protected ReactiveWebApplicationContextRunner getContextRunner() {
return new ReactiveWebApplicationContextRunner()
.withPropertyValues("--spring.boot.admin.ui.available-languages=de", "--spring.webflux.base-path=test")
.withBean(AdminServerProperties.class).withBean(WebFluxProperties.class)
.withConfiguration(AutoConfigurations.of(AdminServerUiAutoConfiguration.class));
}

}