Search in sources :

Example 81 with MockServletContext

use of org.springframework.mock.web.MockServletContext in project cas by apereo.

the class AllSpnegoKnownClientSystemsFilterActionTests method ensureRemoteIpShouldNotBeChecked.

@Test
public void ensureRemoteIpShouldNotBeChecked() {
    final BaseSpnegoKnownClientSystemsFilterAction action = new BaseSpnegoKnownClientSystemsFilterAction("^192\\.158\\..+", "", 0);
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("193.158.5.781");
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.doExecute(ctx);
    assertNotEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test)

Example 82 with MockServletContext

use of org.springframework.mock.web.MockServletContext in project cas by apereo.

the class AllSpnegoKnownClientSystemsFilterActionTests method verifyIpMismatchWhenCheckingHostnameForSpnego.

@Test
public void verifyIpMismatchWhenCheckingHostnameForSpnego() {
    final HostNameSpnegoKnownClientSystemsFilterAction action = new HostNameSpnegoKnownClientSystemsFilterAction("14\\..+", "", 0, "\\w+\\.\\w+\\.\\w+");
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr(ALTERNATE_REMOTE_IP);
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().no(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test)

Example 83 with MockServletContext

use of org.springframework.mock.web.MockServletContext in project cas by apereo.

the class LdapSpnegoKnownClientSystemsFilterActionTests method ensureLdapAttributeShouldDoSpnego.

@Test
public void ensureLdapAttributeShouldDoSpnego() throws Exception {
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("localhost");
    final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);
    final Event ev = action.execute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) Event(org.springframework.webflow.execution.Event) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 84 with MockServletContext

use of org.springframework.mock.web.MockServletContext in project grails-core by grails.

the class GrailsApplicationAttributesTests method testGetViewUri.

/*
     * Test method for 'org.grails.web.servlet.DefaultGrailsApplicationAttributes.getViewUri(String, ServletRequest)'
     */
public void testGetViewUri() throws Exception {
    GrailsApplicationAttributes attrs = new DefaultGrailsApplicationAttributes(new MockServletContext());
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class<?> controllerClass = gcl.parseClass("class TestController {\n" + "def controllerUri = '/test'\n" + "def controllerName = 'test'\n" + "}");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setAttribute(GrailsApplicationAttributes.CONTROLLER, controllerClass.newInstance());
    assertEquals("/WEB-INF/grails-app/views/test/aView.gsp", attrs.getViewUri("aView", request));
    assertEquals("/WEB-INF/grails-app/views/shared.gsp", attrs.getViewUri("/shared", request));
}
Also used : GrailsApplicationAttributes(org.grails.web.util.GrailsApplicationAttributes) GroovyClassLoader(groovy.lang.GroovyClassLoader) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockServletContext(org.springframework.mock.web.MockServletContext)

Example 85 with MockServletContext

use of org.springframework.mock.web.MockServletContext in project grails-core by grails.

the class GrailsResourceUtilsTests method testGetPluginContextPath.

public void testGetPluginContextPath() throws Exception {
    MockServletContext servletContext = new MockServletContext("/myapp");
    MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
    request.setContextPath("/myapp");
    assertEquals("", GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(TEST_CONTROLLER_URL), null));
    assertEquals("plugins/myplugin", GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(TEST_PLUGIN_CTRL), null));
    assertEquals("", GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(WEBINF_CONTROLLER), null));
    assertEquals("plugins/myplugin", GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(WEBINF_PLUGIN_CTRL), null));
    assertEquals("/myapp", GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(WEBINF_CONTROLLER), request.getContextPath()));
    assertEquals("/myapp/plugins/myplugin", GrailsResourceUtils.getStaticResourcePathForResource(new UrlResource(WEBINF_PLUGIN_CTRL), request.getContextPath()));
}
Also used : UrlResource(org.grails.io.support.UrlResource) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockServletContext(org.springframework.mock.web.MockServletContext)

Aggregations

MockServletContext (org.springframework.mock.web.MockServletContext)173 Test (org.junit.Test)126 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)79 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)71 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)63 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)43 MockRequestContext (org.springframework.webflow.test.MockRequestContext)38 Before (org.junit.Before)14 MockMvc (org.springframework.test.web.servlet.MockMvc)13 Event (org.springframework.webflow.execution.Event)11 TicketGrantingTicket (org.apereo.cas.ticket.TicketGrantingTicket)10 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)9 WebStatFilter (com.alibaba.druid.support.http.WebStatFilter)8 MockFilterChain (org.springframework.mock.web.MockFilterChain)8 MockHttpSession (org.springframework.mock.web.MockHttpSession)8 Map (java.util.Map)7 Credential (org.apereo.cas.authentication.Credential)7 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)7 FilterChainProxy (org.springframework.security.web.FilterChainProxy)6 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)6