Honor scheme in MockHttpServletRequest.isSecure()
Prior to this commit the implementation of isSecure() in MockHttpServletRequest simply returned the value of the 'secure' boolean flag. Thus setting the scheme to 'https' had no effect on the value returned by isSecure() even though most non-mock implementations (e.g., Tomcat, Jetty, etc.) base the return value on the actual scheme in the request. This commit makes the behavior of MockHttpServletRequest.isSecure() more intuitive by honoring both the 'secure' boolean flag and the current value of the scheme. Issue: SPR-12098
This commit is contained in:
@@ -334,6 +334,38 @@ public class MockHttpServletRequestTests {
|
||||
assertEquals("http://localhost", requestURL.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSecureWithHttpSchemeAndSecureFlagIsFalse() {
|
||||
assertFalse(request.isSecure());
|
||||
request.setScheme("http");
|
||||
request.setSecure(false);
|
||||
assertFalse(request.isSecure());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSecureWithHttpSchemeAndSecureFlagIsTrue() {
|
||||
assertFalse(request.isSecure());
|
||||
request.setScheme("http");
|
||||
request.setSecure(true);
|
||||
assertTrue(request.isSecure());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSecureWithHttpsSchemeAndSecureFlagIsFalse() {
|
||||
assertFalse(request.isSecure());
|
||||
request.setScheme("https");
|
||||
request.setSecure(false);
|
||||
assertTrue(request.isSecure());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSecureWithHttpsSchemeAndSecureFlagIsTrue() {
|
||||
assertFalse(request.isSecure());
|
||||
request.setScheme("https");
|
||||
request.setSecure(true);
|
||||
assertTrue(request.isSecure());
|
||||
}
|
||||
|
||||
private void assertEqualEnumerations(Enumeration<?> enum1, Enumeration<?> enum2) {
|
||||
assertNotNull(enum1);
|
||||
assertNotNull(enum2);
|
||||
|
||||
Reference in New Issue
Block a user