@Test
 public void isSecureWithHttpsSchemeAndSecureFlagIsTrue() {
   assertFalse(request.isSecure());
   request.setScheme("https");
   request.setSecure(true);
   assertTrue(request.isSecure());
 }
 @Test
 public void isSecureWithHttpSchemeAndSecureFlagIsFalse() {
   assertFalse(request.isSecure());
   request.setScheme("http");
   request.setSecure(false);
   assertFalse(request.isSecure());
 }
 @Test
 public void getRequestURLWithDefaultsAndHttps() {
   request.setScheme("https");
   request.setServerPort(443);
   StringBuffer requestURL = request.getRequestURL();
   assertEquals("https://localhost", requestURL.toString());
 }
  private MockHttpServletRequest newMockRequest(
      String method, String requestUri, String host, int port) {
    MockHttpServletRequest req = new MockHttpServletRequest(method, requestUri);
    req.setRemoteHost(host);
    req.setContentType("application/x-www-form-urlencoded");
    req.setRemotePort(port);
    if (port == 443) {
      req.setScheme("https");
      req.setSecure(true);
    } else {
      req.setScheme("http");
      req.setSecure(false);
    }

    return req;
  }
  private MockHttpServletRequest createMockAuthenticationRequest() {
    MockHttpServletRequest request = new MockHttpServletRequest();

    request.setServletPath("/j_mock_post");
    request.setScheme("http");
    request.setServerName("www.example.com");
    request.setRequestURI("/mycontext/j_mock_post");
    request.setContextPath("/mycontext");

    return request;
  }
  @Test
  public void getRequestURL() {
    request.setServerPort(8080);
    request.setRequestURI("/path");
    assertEquals("http://localhost:8080/path", request.getRequestURL().toString());

    request.setScheme("https");
    request.setServerName("example.com");
    request.setServerPort(8443);
    assertEquals("https://example.com:8443/path", request.getRequestURL().toString());
  }
示例#7
0
  @Test
  public void uri() throws IOException {
    final MockHttpServletRequest httpRequest = prepareEmptyRequest();
    httpRequest.setScheme("https");
    httpRequest.setServerName("example.com");
    httpRequest.setServerPort(1234);
    httpRequest.setRequestURI("/test/a/b?a=1");

    Request req = RequestUtils.convert(httpRequest);
    assertThat(req.getURI(), is(URI.create("https://example.com:1234/test/a/b?a=1")));
  }