Add RedirectToHttps to XML

Closes gh-16775
This commit is contained in:
Josh Cummings
2025-03-19 15:25:29 -06:00
parent 989aee244b
commit e6008b6067
8 changed files with 94 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2025 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.
@@ -109,6 +109,7 @@ import org.springframework.security.web.savedrequest.RequestCache;
import org.springframework.security.web.savedrequest.RequestCacheAwareFilter;
import org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter;
import org.springframework.security.web.session.DisableEncodeUrlFilter;
import org.springframework.security.web.transport.HttpsRedirectFilter;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
@@ -349,6 +350,21 @@ public class MiscHttpConfigTests {
assertThat(getFilter(ChannelProcessingFilter.class)).isNotNull();
}
@Test
public void configureWhenRedirectToHttpsThenFilterAdded() {
this.spring.configLocations(xml("RedirectToHttpsRequiresHttpsAny")).autowire();
assertThat(getFilter(HttpsRedirectFilter.class)).isNotNull();
}
@Test
public void getWhenRedirectToHttpsAnyThenRedirects() throws Exception {
this.spring.configLocations(xml("RedirectToHttpsRequiresHttpsAny")).autowire();
// @formatter:off
this.mvc.perform(get("http://localhost"))
.andExpect(redirectedUrl("https://localhost"));
// @formatter:on
}
@Test
public void getWhenPortsMappedThenRedirectedAccordingly() throws Exception {
this.spring.configLocations(xml("PortsMappedInterceptUrlMethodRequiresAny")).autowire();