use of org.springframework.mock.web.MockHttpServletRequest in project cas by apereo.
the class InspektrThrottledSubmissionByIpAddressAndUsernameHandlerInterceptorAdapterTests method loginUnsuccessfully.
@Override
protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress) throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
final MockHttpServletResponse response = new MockHttpServletResponse();
request.setMethod("POST");
request.setParameter("username", username);
request.setRemoteAddr(fromAddress);
final MockRequestContext context = new MockRequestContext();
context.setCurrentEvent(new Event(StringUtils.EMPTY, "error"));
request.setAttribute("flowRequestContext", context);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
throttle.preHandle(request, response, null);
try {
authenticationManager.authenticate(AuthenticationTransaction.wrap(CoreAuthenticationTestUtils.getService(), badCredentials(username)));
} catch (final AuthenticationException e) {
throttle.postHandle(request, response, null, null);
return response;
}
fail("Expected AbstractAuthenticationException");
return null;
}
use of org.springframework.mock.web.MockHttpServletRequest in project cas by apereo.
the class AllSpnegoKnownClientSystemsFilterActionTests method ensureRemoteIpShouldBeChecked.
@Test
public void ensureRemoteIpShouldBeChecked() {
final BaseSpnegoKnownClientSystemsFilterAction action = new BaseSpnegoKnownClientSystemsFilterAction("^192\\.158\\..+", "", 0);
final MockRequestContext ctx = new MockRequestContext();
final MockHttpServletRequest req = new MockHttpServletRequest();
req.setRemoteAddr("192.158.5.781");
final ServletExternalContext extCtx = new ServletExternalContext(new MockServletContext(), req, new MockHttpServletResponse());
ctx.setExternalContext(extCtx);
final Event ev = action.doExecute(ctx);
assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
use of org.springframework.mock.web.MockHttpServletRequest 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.MockHttpServletRequest 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.MockHttpServletRequest 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());
}
Aggregations