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

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

Introduction

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

Prototype

public void setPathInfo(@Nullable String pathInfo) 

Source Link

Usage

From source file:se.vgregion.urlservice.controllers.RedirectTest.java

@Test
public void redirectWithExistingUserHash() throws IOException {
    String path = "/u/" + OWNER.getName() + "/b/" + HASH;
    MockHttpServletRequest request = new MockHttpServletRequest("GET", SHORT_LINK_PREFIX + path);
    request.setServerName("s.vgregion.se");
    request.setPathInfo(path);
    ModelAndView mav = controller.redirect(path, request, response);

    Assert.assertEquals(301, response.getStatus());
    Assert.assertEquals("http://example.com", response.getHeader("Location"));
    Assert.assertEquals("http://example.com", mav.getModel().get("longUrl"));
}

From source file:se.vgregion.urlservice.controllers.RedirectTest.java

@Test
public void redirectWithRedirectRule() throws IOException {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "http://s.vgregion.se/bar");
    request.setServerName("s.vgregion.se");
    request.setPathInfo("/bar");
    ModelAndView mav = controller.redirect("/bar", request, response);

    Assert.assertEquals(301, response.getStatus());
    Assert.assertEquals("http://example.com", response.getHeader("Location"));
    Assert.assertEquals("http://example.com", mav.getModel().get("longUrl"));
}

From source file:se.vgregion.urlservice.controllers.RedirectTest.java

@Test
public void redirectWithExistingGlobalHash() throws IOException {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", SHORT_LINK_PREFIX + "/b/" + GLOBAL_HASH);
    request.setServerName("s.vgregion.se");
    request.setPathInfo("/b/" + GLOBAL_HASH);
    ModelAndView mav = controller.redirect("/b/" + GLOBAL_HASH, request, response);

    Assert.assertEquals(301, response.getStatus());
    Assert.assertEquals("http://example.com", response.getHeader("Location"));
    Assert.assertEquals("http://example.com", mav.getModel().get("longUrl"));
}

From source file:edu.internet2.middleware.shibboleth.idp.system.conf1.SAML1ArtifactResolutionTest.java

public void testArtifactResolution() throws Exception {
    String relyingPartyId = "urn:example.org:sp1";
    SAMLArtifactMapEntry artifactEntry = stageArtifact(relyingPartyId);
    String soapMessage = buildRequestMessage(relyingPartyId, artifactEntry.getArtifact());

    MockHttpServletRequest servletRequest = new MockHttpServletRequest();
    servletRequest.setMethod("POST");
    servletRequest.setPathInfo("/saml1/SOAP/ArtifactResolution");
    servletRequest.setContent(soapMessage.getBytes());

    MockHttpServletResponse servletResponse = new MockHttpServletResponse();

    ProfileHandlerManager handlerManager = (ProfileHandlerManager) getApplicationContext()
            .getBean("shibboleth.HandlerManager");
    ProfileHandler handler = handlerManager.getProfileHandler(servletRequest);
    assertNotNull(handler);//from   w ww  .  j av  a2 s.com

    // Process request
    HTTPInTransport profileRequest = new HttpServletRequestAdapter(servletRequest);
    HTTPOutTransport profileResponse = new HttpServletResponseAdapter(servletResponse, false);
    handler.processRequest(profileRequest, profileResponse);

    String response = servletResponse.getContentAsString();
    assertTrue(response.contains("saml1p:Success"));
    assertTrue(response.contains("saml1:Assertion"));
}

From source file:edu.internet2.middleware.shibboleth.idp.system.conf1.SAML1ArtifactResolutionTest.java

public void testWithoutConfiguration() throws Exception {
    String relyingPartyId = "urn:example.org:BogusSP";
    SAMLArtifactMapEntry artifactEntry = stageArtifact(relyingPartyId);
    String soapMessage = buildRequestMessage(relyingPartyId, artifactEntry.getArtifact());

    MockHttpServletRequest servletRequest = new MockHttpServletRequest();
    servletRequest.setMethod("POST");
    servletRequest.setPathInfo("/saml1/SOAP/ArtifactResolution");
    servletRequest.setContent(soapMessage.getBytes());

    MockHttpServletResponse servletResponse = new MockHttpServletResponse();

    ProfileHandlerManager handlerManager = (ProfileHandlerManager) getApplicationContext()
            .getBean("shibboleth.HandlerManager");
    ProfileHandler handler = handlerManager.getProfileHandler(servletRequest);
    assertNotNull(handler);//from w  w  w  .  jav a2 s  .  c o m

    // Process request
    HTTPInTransport profileRequest = new HttpServletRequestAdapter(servletRequest);
    HTTPOutTransport profileResponse = new HttpServletResponseAdapter(servletResponse, false);
    handler.processRequest(profileRequest, profileResponse);

    String response = servletResponse.getContentAsString();
    assertTrue(response.contains("saml1p:Success"));
    assertTrue(response.contains("saml1p:RequestDenied"));
}

From source file:edu.internet2.middleware.shibboleth.idp.system.conf1.SAML1AttributeQueryTestCase.java

/** Tests that the attribute query handler correctly fails out if the profile is not configured. */
public void testAuthenticationWithoutConfiguredQuery() throws Exception {
    AttributeQuery query = buildAttributeQuery("urn:example.org:BogusSP");
    String soapMessage = getSOAPMessage(query);

    MockHttpServletRequest servletRequest = new MockHttpServletRequest();
    servletRequest.setMethod("POST");
    servletRequest.setPathInfo("/saml1/SOAP/AttributeQuery");
    servletRequest.setContent(soapMessage.getBytes());

    MockHttpServletResponse servletResponse = new MockHttpServletResponse();

    ProfileHandlerManager handlerManager = (ProfileHandlerManager) getApplicationContext()
            .getBean("shibboleth.HandlerManager");
    ProfileHandler handler = handlerManager.getProfileHandler(servletRequest);
    assertNotNull(handler);/*  w  w w. ja va  2s.  c om*/

    // Process request
    HTTPInTransport profileRequest = new HttpServletRequestAdapter(servletRequest);
    HTTPOutTransport profileResponse = new HttpServletResponseAdapter(servletResponse, false);
    handler.processRequest(profileRequest, profileResponse);

    String response = servletResponse.getContentAsString();
    assertTrue(response.contains("saml1p:Responder"));
    assertTrue(response.contains("saml1p:RequestDenied"));
}

From source file:edu.internet2.middleware.shibboleth.idp.system.conf1.SAML2AttributeQueryTestCase.java

/** Tests that the attribute query handler correctly fails out if the profile is not configured. */
public void testAuthenticationWithoutConfiguredQuery() throws Exception {
    AttributeQuery query = buildAttributeQuery("urn:example.org:BogusSP");
    String soapMessage = getSOAPMessage(query);

    MockHttpServletRequest servletRequest = new MockHttpServletRequest();
    servletRequest.setMethod("POST");
    servletRequest.setPathInfo("/saml2/SOAP/AttributeQuery");
    servletRequest.setContent(soapMessage.getBytes());

    MockHttpServletResponse servletResponse = new MockHttpServletResponse();

    ProfileHandlerManager handlerManager = (ProfileHandlerManager) getApplicationContext()
            .getBean("shibboleth.HandlerManager");
    ProfileHandler handler = handlerManager.getProfileHandler(servletRequest);
    assertNotNull(handler);/*ww  w  .ja  v  a 2s  . c o  m*/

    // Process request
    HTTPInTransport profileRequest = new HttpServletRequestAdapter(servletRequest);
    HTTPOutTransport profileResponse = new HttpServletResponseAdapter(servletResponse, false);
    handler.processRequest(profileRequest, profileResponse);

    String response = servletResponse.getContentAsString();
    assertTrue(response.contains("urn:oasis:names:tc:SAML:2.0:status:Responder"));
    assertTrue(response.contains("urn:oasis:names:tc:SAML:2.0:status:RequestDenied"));
}

From source file:edu.internet2.middleware.shibboleth.idp.system.conf1.SAML1AttributeQueryTestCase.java

/** Tests that the attribute query handler correctly handles an incomming query. */
public void testAttributeQuery() throws Exception {
    AttributeQuery query = buildAttributeQuery("urn:example.org:sp1");
    String soapMessage = getSOAPMessage(query);

    MockHttpServletRequest servletRequest = new MockHttpServletRequest();
    servletRequest.setMethod("POST");
    servletRequest.setPathInfo("/saml1/SOAP/AttributeQuery");
    servletRequest.setContent(soapMessage.getBytes());

    MockHttpServletResponse servletResponse = new MockHttpServletResponse();

    ProfileHandlerManager handlerManager = (ProfileHandlerManager) getApplicationContext()
            .getBean("shibboleth.HandlerManager");
    ProfileHandler handler = handlerManager.getProfileHandler(servletRequest);
    assertNotNull(handler);/*w  w w .ja  va 2  s .  co m*/

    // Process request
    HTTPInTransport profileRequest = new HttpServletRequestAdapter(servletRequest);
    HTTPOutTransport profileResponse = new HttpServletResponseAdapter(servletResponse, false);
    handler.processRequest(profileRequest, profileResponse);

    String response = servletResponse.getContentAsString();
    assertTrue(response.contains("saml1p:Success"));
    assertTrue(response.contains("AttributeName=\"urn:mace:dir:attribute-def:eduPersonEntitlement\""));
    assertTrue(response.contains("urn:example.org:entitlement:entitlement1"));
}

From source file:edu.internet2.middleware.shibboleth.idp.system.conf1.SAML2ArtifactResolutionTest.java

public void testWithoutConfiguration() throws Exception {
    String relyingPartyId = "urn:example.org:BogusSP";
    SAMLArtifactMapEntry artifactEntry = stageArtifact(relyingPartyId);
    String soapMessage = buildRequestMessage(relyingPartyId, artifactEntry.getArtifact());

    MockHttpServletRequest servletRequest = new MockHttpServletRequest();
    servletRequest.setMethod("POST");
    servletRequest.setPathInfo("/saml2/SOAP/ArtifactResolution");
    servletRequest.setContent(soapMessage.getBytes());

    MockHttpServletResponse servletResponse = new MockHttpServletResponse();

    ProfileHandlerManager handlerManager = (ProfileHandlerManager) getApplicationContext()
            .getBean("shibboleth.HandlerManager");
    ProfileHandler handler = handlerManager.getProfileHandler(servletRequest);
    assertNotNull(handler);/*from  w  w w  .ja v  a  2s . c om*/

    // Process request
    HTTPInTransport profileRequest = new HttpServletRequestAdapter(servletRequest);
    HTTPOutTransport profileResponse = new HttpServletResponseAdapter(servletResponse, false);
    handler.processRequest(profileRequest, profileResponse);
    String response = servletResponse.getContentAsString();
    assertTrue(response.contains("urn:oasis:names:tc:SAML:2.0:status:Success"));
    assertTrue(response.contains("urn:oasis:names:tc:SAML:2.0:status:RequestDenied"));
}

From source file:edu.internet2.middleware.shibboleth.idp.system.conf1.SAML2AttributeQueryTestCase.java

/** Tests that the attribute query handler correctly handles an incomming query. */
public void testAttributeQuery() throws Exception {
    AttributeQuery query = buildAttributeQuery("urn:example.org:sp1");
    String soapMessage = getSOAPMessage(query);

    MockHttpServletRequest servletRequest = new MockHttpServletRequest();
    servletRequest.setMethod("POST");
    servletRequest.setPathInfo("/saml2/SOAP/AttributeQuery");
    servletRequest.setContent(soapMessage.getBytes());

    MockHttpServletResponse servletResponse = new MockHttpServletResponse();

    ProfileHandlerManager handlerManager = (ProfileHandlerManager) getApplicationContext()
            .getBean("shibboleth.HandlerManager");
    ProfileHandler handler = handlerManager.getProfileHandler(servletRequest);
    assertNotNull(handler);//  w  ww . j  a  va  2  s.c  om

    // Process request
    HTTPInTransport profileRequest = new HttpServletRequestAdapter(servletRequest);
    HTTPOutTransport profileResponse = new HttpServletResponseAdapter(servletResponse, false);
    handler.processRequest(profileRequest, profileResponse);

    String response = servletResponse.getContentAsString();
    assertTrue(response.contains("urn:oasis:names:tc:SAML:2.0:status:Success"));
    assertTrue(response.contains(" Name=\"urn:oid:1.3.6.1.4.1.5923.1.1.1.7\""));
    assertTrue(response.contains("urn:example.org:entitlement:entitlement1"));
}