Search in sources :

Example 6 with DefaultCasCookieValueManager

use of org.apereo.cas.web.support.mgmr.DefaultCasCookieValueManager in project cas by apereo.

the class DefaultCasCookieValueManagerTests method verifyBadAgent.

@Test
public void verifyBadAgent() {
    val props = new TicketGrantingCookieProperties();
    val mgr = new DefaultCasCookieValueManager(CipherExecutor.noOp(), props);
    assertThrows(InvalidCookieException.class, () -> mgr.obtainCookieValue("something@" + ClientInfoHolder.getClientInfo().getClientIpAddress() + "@agent", new MockHttpServletRequest()));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TicketGrantingCookieProperties(org.apereo.cas.configuration.model.support.cookie.TicketGrantingCookieProperties) DefaultCasCookieValueManager(org.apereo.cas.web.support.mgmr.DefaultCasCookieValueManager) Test(org.junit.jupiter.api.Test)

Example 7 with DefaultCasCookieValueManager

use of org.apereo.cas.web.support.mgmr.DefaultCasCookieValueManager in project cas by apereo.

the class DefaultCasCookieValueManagerTests method verifyMissingClientInfo.

@Test
public void verifyMissingClientInfo() {
    val props = new TicketGrantingCookieProperties();
    val mgr = new DefaultCasCookieValueManager(CipherExecutor.noOp(), props);
    ClientInfoHolder.clear();
    assertThrows(InvalidCookieException.class, () -> mgr.obtainCookieValue("something@" + CLIENT_IP + '@' + USER_AGENT, new MockHttpServletRequest()));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TicketGrantingCookieProperties(org.apereo.cas.configuration.model.support.cookie.TicketGrantingCookieProperties) DefaultCasCookieValueManager(org.apereo.cas.web.support.mgmr.DefaultCasCookieValueManager) Test(org.junit.jupiter.api.Test)

Example 8 with DefaultCasCookieValueManager

use of org.apereo.cas.web.support.mgmr.DefaultCasCookieValueManager in project cas by apereo.

the class DefaultCasCookieValueManagerTests method verifyBadIp.

@Test
public void verifyBadIp() {
    val props = new TicketGrantingCookieProperties();
    val mgr = new DefaultCasCookieValueManager(CipherExecutor.noOp(), props);
    assertThrows(InvalidCookieException.class, () -> mgr.obtainCookieValue("something@1@agent", new MockHttpServletRequest()));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TicketGrantingCookieProperties(org.apereo.cas.configuration.model.support.cookie.TicketGrantingCookieProperties) DefaultCasCookieValueManager(org.apereo.cas.web.support.mgmr.DefaultCasCookieValueManager) Test(org.junit.jupiter.api.Test)

Example 9 with DefaultCasCookieValueManager

use of org.apereo.cas.web.support.mgmr.DefaultCasCookieValueManager in project cas by apereo.

the class DefaultCasCookieValueManagerTests method verifySessionPinning.

@Test
public void verifySessionPinning() {
    val request = new MockHttpServletRequest();
    request.setRemoteAddr(CLIENT_IP);
    request.setLocalAddr(CLIENT_IP);
    request.removeHeader("User-Agent");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    val props = new TicketGrantingCookieProperties();
    assertThrows(IllegalStateException.class, () -> new DefaultCasCookieValueManager(CipherExecutor.noOp(), props).buildCookieValue(VALUE, request));
    props.setPinToSession(false);
    assertNotNull(new DefaultCasCookieValueManager(CipherExecutor.noOp(), props).buildCookieValue(VALUE, request));
}
Also used : lombok.val(lombok.val) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TicketGrantingCookieProperties(org.apereo.cas.configuration.model.support.cookie.TicketGrantingCookieProperties) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) DefaultCasCookieValueManager(org.apereo.cas.web.support.mgmr.DefaultCasCookieValueManager) Test(org.junit.jupiter.api.Test)

Aggregations

lombok.val (lombok.val)9 TicketGrantingCookieProperties (org.apereo.cas.configuration.model.support.cookie.TicketGrantingCookieProperties)9 DefaultCasCookieValueManager (org.apereo.cas.web.support.mgmr.DefaultCasCookieValueManager)9 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)9 Test (org.junit.jupiter.api.Test)8 ClientInfo (org.apereo.inspektr.common.web.ClientInfo)3 BeforeEach (org.junit.jupiter.api.BeforeEach)1