Search in sources :

Example 81 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class ConfirmLogoutActionTests method verifyByCookie.

@Test
public void verifyByCookie() throws Exception {
    val context = new MockRequestContext();
    val response = new MockHttpServletResponse();
    val request = new MockHttpServletRequest();
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    request.addHeader("User-Agent", "agent");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    val ticket = new MockTicketGrantingTicket("casuser");
    getCentralAuthenticationService().addTicket(ticket);
    val c = getTicketGrantingTicketCookieGenerator().addCookie(request, response, ticket.getId());
    request.setCookies(c);
    val result = action.execute(context);
    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, result.getId());
    assertNotNull(WebUtils.getAuthentication(context));
    assertNotNull(WebUtils.getTicketGrantingTicket(context));
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 82 with ClientInfo

use of org.apereo.inspektr.common.web.ClientInfo in project cas by apereo.

the class WsFederationCookieManagerTests method verifyOperation.

@Test
public void verifyOperation() {
    val context = new MockRequestContext();
    val request = new MockHttpServletRequest();
    val response = new MockHttpServletResponse();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    request.setRemoteAddr("185.86.151.11");
    request.setLocalAddr("185.88.151.11");
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "MSIE");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    request.addParameter(CasProtocolConstants.PARAMETER_METHOD, "POST");
    request.setAttribute("locale", "en");
    request.setAttribute("theme", "custom");
    val config = wsFederationConfigurations.toList().get(0);
    val wctx = config.getId();
    val original = RegisteredServiceTestUtils.getService();
    wsFederationCookieManager.store(request, response, wctx, original, config);
    request.addParameter(WsFederationCookieManager.WCTX, wctx);
    request.setCookies(response.getCookies());
    val service = wsFederationCookieManager.retrieve(context);
    assertNotNull(service);
    assertEquals(original.getId(), service.getId());
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Aggregations

ClientInfo (org.apereo.inspektr.common.web.ClientInfo)82 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)69 lombok.val (lombok.val)65 Test (org.junit.jupiter.api.Test)42 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)36 MockRequestContext (org.springframework.webflow.test.MockRequestContext)35 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)31 MockServletContext (org.springframework.mock.web.MockServletContext)29 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 MockWebServer (org.apereo.cas.util.MockWebServer)13 ByteArrayResource (org.springframework.core.io.ByteArrayResource)13 BeforeEach (org.junit.jupiter.api.BeforeEach)12 BeforeAll (org.junit.jupiter.api.BeforeAll)6 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)5 GeoLocationRequest (org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest)5 ClassPathResource (org.springframework.core.io.ClassPathResource)5 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)4 Cookie (javax.servlet.http.Cookie)4 GeoLocationResponse (org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse)4 AdaptiveAuthenticationProperties (org.apereo.cas.configuration.model.core.authentication.AdaptiveAuthenticationProperties)4