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());
}
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());
}
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());
}
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));
}
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()));
}
Aggregations