use of org.apereo.cas.web.support.gen.CookieRetrievingCookieGenerator in project cas by apereo.
the class CookieRetrievingCookieGeneratorTests method verifyCookieForRememberMeByAuthnRequest.
@Test
public void verifyCookieForRememberMeByAuthnRequest() {
val ctx = getCookieGenerationContext();
val gen = new CookieRetrievingCookieGenerator(ctx);
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
request.addParameter(RememberMeCredential.REQUEST_PARAMETER_REMEMBER_ME, "true");
WebUtils.putRememberMeAuthenticationEnabled(context, Boolean.TRUE);
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
gen.addCookie(request, response, CookieRetrievingCookieGenerator.isRememberMeAuthentication(context), "CAS-Cookie-Value");
val cookie = response.getCookie(ctx.getName());
assertNotNull(cookie);
assertEquals(ctx.getRememberMeMaxAge(), cookie.getMaxAge());
}
use of org.apereo.cas.web.support.gen.CookieRetrievingCookieGenerator in project cas by apereo.
the class CookieRetrievingCookieGeneratorTests method verifyCookieForRememberMeByRequestContext.
@Test
public void verifyCookieForRememberMeByRequestContext() {
val ctx = getCookieGenerationContext();
val gen = new CookieRetrievingCookieGenerator(ctx);
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val authn = CoreAuthenticationTestUtils.getAuthentication("casuser", CollectionUtils.wrap(RememberMeCredential.AUTHENTICATION_ATTRIBUTE_REMEMBER_ME, CollectionUtils.wrap(Boolean.TRUE)));
WebUtils.putAuthentication(authn, context);
WebUtils.putRememberMeAuthenticationEnabled(context, Boolean.TRUE);
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
gen.addCookie(request, response, CookieRetrievingCookieGenerator.isRememberMeAuthentication(context), "CAS-Cookie-Value");
val cookie = response.getCookie(ctx.getName());
assertNotNull(cookie);
assertEquals(ctx.getRememberMeMaxAge(), cookie.getMaxAge());
}
use of org.apereo.cas.web.support.gen.CookieRetrievingCookieGenerator in project cas by apereo.
the class CookieRetrievingCookieGeneratorTests method verifyCookieValueMissing.
@Test
public void verifyCookieValueMissing() {
val context = getCookieGenerationContext();
context.setName(StringUtils.EMPTY);
val gen = new CookieRetrievingCookieGenerator(context);
val request = new MockHttpServletRequest();
request.addHeader(context.getName(), "CAS-Cookie-Value");
val cookie = gen.retrieveCookieValue(request);
assertNull(cookie);
}
use of org.apereo.cas.web.support.gen.CookieRetrievingCookieGenerator in project cas by apereo.
the class CookieRetrievingCookieGeneratorTests method verifyCookieSameSiteLax.
@Test
public void verifyCookieSameSiteLax() {
val ctx = getCookieGenerationContext();
ctx.setSameSitePolicy("lax");
val gen = new CookieRetrievingCookieGenerator(ctx);
val context = new MockRequestContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
gen.addCookie(request, response, false, "CAS-Cookie-Value");
val cookie = (MockCookie) response.getCookie(ctx.getName());
assertNotNull(cookie);
assertEquals("Lax", cookie.getSameSite());
}
use of org.apereo.cas.web.support.gen.CookieRetrievingCookieGenerator in project cas by apereo.
the class CookieRetrievingCookieGeneratorTests method verifyExistingCookieInResponse.
@Test
public void verifyExistingCookieInResponse() {
val context = getCookieGenerationContext();
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val gen = new CookieRetrievingCookieGenerator(context);
var cookie = gen.addCookie(request, response, "some-value");
assertNotNull(cookie);
var headers = response.getHeaders("Set-Cookie");
assertEquals(1, headers.size());
assertTrue(headers.get(0).contains(context.getName() + '=' + cookie.getValue()));
cookie = gen.addCookie(request, response, "updated-value");
assertNotNull(cookie);
headers = response.getHeaders("Set-Cookie");
assertEquals(1, headers.size());
assertTrue(headers.get(0).contains(context.getName() + '=' + cookie.getValue()));
}
Aggregations