Search in sources :

Example 21 with MockHttpServletRequest

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

the class DateTimeAuthenticationRequestRiskCalculatorTests method verifyTestWhenNoAuthnEventsFoundForUser.

@Test
public void verifyTestWhenNoAuthnEventsFoundForUser() {
    final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("datetimeperson");
    final RegisteredService service = RegisteredServiceTestUtils.getRegisteredService("test");
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final AuthenticationRiskScore score = authenticationRiskEvaluator.eval(authentication, service, request);
    assertTrue(score.isHighestRisk());
}
Also used : AuthenticationRiskScore(org.apereo.cas.api.AuthenticationRiskScore) RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with MockHttpServletRequest

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

the class GeoLocationAuthenticationRequestRiskCalculatorTests method verifyTestWhenAuthnEventsFoundForUser.

@Test
public void verifyTestWhenAuthnEventsFoundForUser() {
    final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("casuser");
    final RegisteredService service = RegisteredServiceTestUtils.getRegisteredService("test");
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("107.181.69.221");
    request.setLocalAddr("127.0.0.1");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    final AuthenticationRiskScore score = authenticationRiskEvaluator.eval(authentication, service, request);
    assertTrue(score.isHighestRisk());
}
Also used : AuthenticationRiskScore(org.apereo.cas.api.AuthenticationRiskScore) RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with MockHttpServletRequest

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

the class IpAddressAuthenticationRequestRiskCalculatorTests method verifyTestWhenNoAuthnEventsFoundForUser.

@Test
public void verifyTestWhenNoAuthnEventsFoundForUser() {
    final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("nobody");
    final RegisteredService service = RegisteredServiceTestUtils.getRegisteredService("test");
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final AuthenticationRiskScore score = authenticationRiskEvaluator.eval(authentication, service, request);
    assertTrue(score.isHighestRisk());
}
Also used : AuthenticationRiskScore(org.apereo.cas.api.AuthenticationRiskScore) RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 24 with MockHttpServletRequest

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

the class IpAddressAuthenticationRequestRiskCalculatorTests method verifyTestWhenAuthnEventsFoundForUser.

@Test
public void verifyTestWhenAuthnEventsFoundForUser() {
    final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("casuser");
    final RegisteredService service = RegisteredServiceTestUtils.getRegisteredService("test");
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("107.181.69.221");
    request.setLocalAddr("127.0.0.1");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    final AuthenticationRiskScore score = authenticationRiskEvaluator.eval(authentication, service, request);
    assertTrue(score.isRiskGreaterThan(casProperties.getAuthn().getAdaptive().getRisk().getThreshold()));
}
Also used : AuthenticationRiskScore(org.apereo.cas.api.AuthenticationRiskScore) RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 25 with MockHttpServletRequest

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

the class UserAgentAuthenticationRequestRiskCalculatorTests method verifyTestWhenAuthnEventsFoundForUser.

@Test
public void verifyTestWhenAuthnEventsFoundForUser() {
    final Authentication authentication = CoreAuthenticationTestUtils.getAuthentication("casuser");
    final RegisteredService service = RegisteredServiceTestUtils.getRegisteredService("test");
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader(WebUtils.USER_AGENT_HEADER, "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)");
    request.setRemoteAddr("107.181.69.221");
    request.setLocalAddr("127.0.0.1");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    final AuthenticationRiskScore score = authenticationRiskEvaluator.eval(authentication, service, request);
    assertTrue(score.isRiskGreaterThan(casProperties.getAuthn().getAdaptive().getRisk().getThreshold()));
}
Also used : AuthenticationRiskScore(org.apereo.cas.api.AuthenticationRiskScore) RegisteredService(org.apereo.cas.services.RegisteredService) Authentication(org.apereo.cas.authentication.Authentication) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1056 Test (org.junit.Test)827 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)557 Before (org.junit.Before)92 MockFilterChain (org.springframework.mock.web.MockFilterChain)89 FilterChain (javax.servlet.FilterChain)79 MockServletContext (org.springframework.mock.web.MockServletContext)71 Authentication (org.springframework.security.core.Authentication)70 HttpServletRequest (javax.servlet.http.HttpServletRequest)51 MockHttpSession (org.springframework.mock.web.MockHttpSession)49 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)47 Cookie (javax.servlet.http.Cookie)44 MockRequestContext (org.springframework.webflow.test.MockRequestContext)42 HttpServletResponse (javax.servlet.http.HttpServletResponse)39 HashMap (java.util.HashMap)32 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)32 ModelAndView (org.springframework.web.servlet.ModelAndView)32 MockPortletWindowId (org.apereo.portal.mock.portlet.om.MockPortletWindowId)30 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)30 RegisteredService (org.apereo.cas.services.RegisteredService)27