Example usage for org.springframework.mock.web MockHttpServletRequest setScheme

List of usage examples for org.springframework.mock.web MockHttpServletRequest setScheme

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletRequest setScheme.

Prototype

public void setScheme(String scheme) 

Source Link

Usage

From source file:org.jasig.cas.client.util.CommonUtilsTests.java

public void testConstructServiceUrlWithEncodedParamsSaml() {
    final String CONST_MY_URL = "https://www.myserver.com/hello/hithere/";
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/");
    request.setScheme("https");
    request.setSecure(true);// w  w w . j av a 2 s  .  co  m
    request.setQueryString("TARGET%3Dthis%26SAMLart%3Dthat%26custom%3Dcustom");

    final MockHttpServletResponse response = new MockHttpServletResponse();
    final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, "www.myserver.com",
            Protocol.SAML11.getServiceParameterName(), Protocol.SAML11.getArtifactParameterName(), false);

    assertEquals("https://www.myserver.com/hello/hithere/?custom=custom", constructedUrl);
}

From source file:org.jasig.cas.client.util.CommonUtilsTests.java

public void testConstructServiceUrlWithNoServiceParametersPassed() {
    final String CONST_MY_URL = "https://www.myserver.com/hello/hithere/";
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/");
    request.setScheme("https");
    request.setSecure(true);/*from w  ww. j ava 2 s . c  o  m*/
    request.setQueryString("TARGET=Test1&service=Test2&custom=custom");

    final MockHttpServletResponse response = new MockHttpServletResponse();
    final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, "www.myserver.com",
            Protocol.SAML11.getArtifactParameterName(), true);

    assertEquals("https://www.myserver.com/hello/hithere/?custom=custom", constructedUrl);
}

From source file:org.jasig.cas.client.util.CommonUtilsTests.java

public void testConstructServiceUrlWithParamsCasAndServerNameWithSchema() {
    final String CONST_MY_URL = "https://www.myserver.com/hello/hithere/";
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/");
    request.setScheme("https");
    request.setSecure(true);/*from w  w  w  .j  a v  a2  s. c om*/
    request.setQueryString("service=this&ticket=that&custom=custom");

    final MockHttpServletResponse response = new MockHttpServletResponse();
    final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null,
            "https://www.myserver.com", Protocol.CAS3.getServiceParameterName(),
            Protocol.CAS3.getArtifactParameterName(), false);

    assertEquals("https://www.myserver.com/hello/hithere/?custom=custom", constructedUrl);
}

From source file:org.jasig.cas.client.util.CommonUtilsTests.java

public void testConstructServiceUrlWithEncodedParams2Saml() {
    final String CONST_MY_URL = "https://www.myserver.com/hello/hithere/";
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/");
    request.setScheme("https");
    request.setSecure(true);/*from   w  w  w.  ja v a 2  s .  co m*/
    request.setQueryString("TARGET%3Dthis%26SAMLart%3Dthat%26custom%3Dcustom%20value%20here%26another%3Dgood");

    final MockHttpServletResponse response = new MockHttpServletResponse();
    final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, "www.myserver.com",
            Protocol.SAML11.getServiceParameterName(), Protocol.SAML11.getArtifactParameterName(), true);

    assertEquals("https://www.myserver.com/hello/hithere/?custom=custom+value+here&another=good",
            constructedUrl);
}

From source file:org.jasig.cas.client.util.CommonUtilsTests.java

public void testConstructServiceUrlWithoutEncodedParamsSamlAndNoEncoding() {
    final String CONST_MY_URL = "https://www.myserver.com/hello/hithere/";
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/");
    request.setScheme("https");
    request.setSecure(true);/*from w  w w. jav a2 s.  c  o m*/
    request.setQueryString("TARGET=this&SAMLart=that&custom=custom value here&another=good");

    final MockHttpServletResponse response = new MockHttpServletResponse();
    final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, "www.myserver.com",
            Protocol.SAML11.getServiceParameterName(), Protocol.SAML11.getArtifactParameterName(), false);

    assertEquals("https://www.myserver.com/hello/hithere/?custom=custom value here&another=good",
            constructedUrl);
}

From source file:org.jasig.cas.client.util.CommonUtilsTests.java

public void testConstructServiceUrlWithEncodedParamsSamlAndNoEncoding() {
    final String CONST_MY_URL = "https://www.myserver.com/hello/hithere/";
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/");
    request.setScheme("https");
    request.setSecure(true);//  w w w .  j a va2 s  .c om
    request.setQueryString("TARGET=this&SAMLart=that&custom=custom+value+here&another=good");

    final MockHttpServletResponse response = new MockHttpServletResponse();
    final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, "www.myserver.com",
            Protocol.SAML11.getServiceParameterName(), Protocol.SAML11.getArtifactParameterName(), true);

    assertEquals("https://www.myserver.com/hello/hithere/?custom=custom+value+here&another=good",
            constructedUrl);
}

From source file:org.jasig.cas.client.util.CommonUtilsTests.java

public void testConstructUrlWithMultipleHostsNoPortsOrProtocol() {
    final String CONST_MY_URL = "https://www.myserver.com/hello/hithere/";
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/");
    request.addHeader("Host", "www.myserver.com");
    request.setScheme("https");
    request.setSecure(true);/*  www . j a  v a2  s.com*/
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null,
            "www.amazon.com www.bestbuy.com www.myserver.com", "service", "ticket", false);
    assertEquals(CONST_MY_URL, constructedUrl);
}

From source file:org.jasig.cas.client.util.CommonUtilsTests.java

private void constructUrlNonStandardPortAndNoPortInConfigTest(final String serverNameList) {
    final String CONST_MY_URL = "https://www.myserver.com:555/hello/hithere/";
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/");
    request.addHeader("Host", "www.myserver.com");
    request.setScheme("https");
    request.setSecure(true);/*w w w  .  ja  va  2  s  .c  om*/
    request.setServerPort(555);
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null, serverNameList,
            "service", "ticket", false);
    assertEquals(CONST_MY_URL, constructedUrl);
}

From source file:org.jasig.cas.client.util.CommonUtilsTests.java

public void testConstructURlWithMultipleHostsAndPorts() {
    final String CONST_MY_URL = "https://www.myserver.com/hello/hithere/";
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hello/hithere/");
    request.addHeader("Host", "www.myserver.com");
    request.setScheme("https");
    request.setSecure(true);//from  w  w w .ja v a 2s. com
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final String constructedUrl = CommonUtils.constructServiceUrl(request, response, null,
            "http://www.amazon.com https://www.bestbuy.com https://www.myserver.com", "service", "ticket",
            false);
    assertEquals(CONST_MY_URL, constructedUrl);
}

From source file:org.jasig.cas.client.authentication.AuthenticationFilterTests.java

@Test
public void testIgnorePatternsWithExactMatching() throws Exception {
    final AuthenticationFilter f = new AuthenticationFilter();
    final MockServletContext context = new MockServletContext();
    context.addInitParameter("casServerLoginUrl", CAS_LOGIN_URL);

    final URL url = new URL(CAS_SERVICE_URL + "?param=valueToIgnore");

    context.addInitParameter("ignorePattern", url.toExternalForm());
    context.addInitParameter("ignoreUrlPatternType", "EXACT");
    context.addInitParameter("service", CAS_SERVICE_URL);
    f.init(new MockFilterConfig(context));

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setScheme(url.getProtocol());
    request.setServerName(url.getHost());
    request.setServerPort(url.getPort());
    request.setQueryString(url.getQuery());
    request.setRequestURI(url.getPath());

    final MockHttpSession session = new MockHttpSession();
    request.setSession(session);//from  w  w  w. j  av a  2 s .c  o m

    final MockHttpServletResponse response = new MockHttpServletResponse();

    final FilterChain filterChain = new FilterChain() {
        public void doFilter(ServletRequest request, ServletResponse response)
                throws IOException, ServletException {
        }
    };

    f.doFilter(request, response, filterChain);
    assertNull(response.getRedirectedUrl());
}