|
| 1 | +/* |
| 2 | + * Copyright 2013-2024 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 org.springframework.cloud.gateway.server.mvc; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +import org.springframework.boot.autoconfigure.AutoConfigurations; |
| 22 | +import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration; |
| 23 | +import org.springframework.boot.autoconfigure.web.client.RestClientAutoConfiguration; |
| 24 | +import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration; |
| 25 | +import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
| 26 | +import org.springframework.cloud.gateway.server.mvc.filter.FormFilter; |
| 27 | +import org.springframework.cloud.gateway.server.mvc.filter.ForwardedRequestHeadersFilter; |
| 28 | +import org.springframework.cloud.gateway.server.mvc.filter.RemoveContentLengthRequestHeadersFilter; |
| 29 | +import org.springframework.cloud.gateway.server.mvc.filter.RemoveHopByHopRequestHeadersFilter; |
| 30 | +import org.springframework.cloud.gateway.server.mvc.filter.RemoveHopByHopResponseHeadersFilter; |
| 31 | +import org.springframework.cloud.gateway.server.mvc.filter.TransferEncodingNormalizationRequestHeadersFilter; |
| 32 | +import org.springframework.cloud.gateway.server.mvc.filter.WeightCalculatorFilter; |
| 33 | +import org.springframework.cloud.gateway.server.mvc.filter.XForwardedRequestHeadersFilter; |
| 34 | + |
| 35 | +import static org.assertj.core.api.Assertions.assertThat; |
| 36 | + |
| 37 | +public class GatewayServerMvcAutoConfigurationTests { |
| 38 | + |
| 39 | + @Test |
| 40 | + void filterEnabledPropertiesWork() { |
| 41 | + new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(GatewayServerMvcAutoConfiguration.class, |
| 42 | + RestTemplateAutoConfiguration.class, RestClientAutoConfiguration.class, SslAutoConfiguration.class)) |
| 43 | + .withPropertyValues("spring.cloud.gateway.mvc.form-filter.enabled=false", |
| 44 | + "spring.cloud.gateway.mvc.forwarded-request-headers-filter.enabled=false", |
| 45 | + "spring.cloud.gateway.mvc.remove-content-length-request-headers-filter.enabled=false", |
| 46 | + "spring.cloud.gateway.mvc.remove-hop-by-hop-request-headers-filter.enabled=false", |
| 47 | + "spring.cloud.gateway.mvc.remove-hop-by-hop-response-headers-filter.enabled=false", |
| 48 | + "spring.cloud.gateway.mvc.transfer-encoding-normalization-request-headers-filter.enabled=false", |
| 49 | + "spring.cloud.gateway.mvc.weight-calculator-filter.enabled=false", |
| 50 | + "spring.cloud.gateway.mvc.x-forwarded-request-headers-filter.enabled=false") |
| 51 | + .run(context -> { |
| 52 | + assertThat(context).doesNotHaveBean(FormFilter.class); |
| 53 | + assertThat(context).doesNotHaveBean(ForwardedRequestHeadersFilter.class); |
| 54 | + assertThat(context).doesNotHaveBean(RemoveContentLengthRequestHeadersFilter.class); |
| 55 | + assertThat(context).doesNotHaveBean(RemoveHopByHopRequestHeadersFilter.class); |
| 56 | + assertThat(context).doesNotHaveBean(RemoveHopByHopResponseHeadersFilter.class); |
| 57 | + assertThat(context).doesNotHaveBean(TransferEncodingNormalizationRequestHeadersFilter.class); |
| 58 | + assertThat(context).doesNotHaveBean(WeightCalculatorFilter.class); |
| 59 | + assertThat(context).doesNotHaveBean(XForwardedRequestHeadersFilter.class); |
| 60 | + }); |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments