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:
Sam Brannen
2014-08-28 15:05:36 +02:00
parent fbfb7a3c48
commit 0b0ddc6ed1
2 changed files with 55 additions and 3 deletions

View File

@@ -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);