use of org.apereo.cas.web.support.gen.CookieRetrievingCookieGenerator in project cas by apereo.
the class InitialFlowSetupCookieActionTests method initialize.
@BeforeEach
public void initialize() throws Exception {
val warn = CookieGenerationContext.builder().name("warn").path(StringUtils.EMPTY).maxAge(2).domain(null).secure(false).httpOnly(false).comment("CAS Cookie").build();
val tgt = CookieGenerationContext.builder().name("tgt").path(StringUtils.EMPTY).maxAge(2).domain(null).secure(false).httpOnly(false).comment("CAS Cookie").build();
this.warnCookieGenerator = new CookieRetrievingCookieGenerator(warn);
this.warnCookieGenerator.setCookiePath(StringUtils.EMPTY);
this.tgtCookieGenerator = new CookieRetrievingCookieGenerator(tgt);
this.tgtCookieGenerator.setCookiePath(StringUtils.EMPTY);
val argExtractors = Collections.<ArgumentExtractor>singletonList(new DefaultArgumentExtractor(new WebApplicationServiceFactory()));
val servicesManager = mock(ServicesManager.class);
when(servicesManager.findServiceBy(any(Service.class))).thenReturn(RegisteredServiceTestUtils.getRegisteredService("test"));
val sso = new SingleSignOnProperties().setCreateSsoCookieOnRenewAuthn(true).setRenewAuthnEnabled(true);
this.action = new InitialFlowSetupAction(argExtractors, servicesManager, authenticationRequestServiceSelectionStrategies, tgtCookieGenerator, warnCookieGenerator, casProperties, authenticationEventExecutionPlan, new DefaultSingleSignOnParticipationStrategy(servicesManager, sso, mock(TicketRegistrySupport.class), mock(AuthenticationServiceSelectionPlan.class)), mock(TicketRegistrySupport.class));
this.action.afterPropertiesSet();
}
use of org.apereo.cas.web.support.gen.CookieRetrievingCookieGenerator in project cas by apereo.
the class CookieRetrievingCookieGeneratorTests method verifyCookiePathNotModified.
@Test
public void verifyCookiePathNotModified() {
val request = new MockHttpServletRequest();
var response = new MockHttpServletResponse();
var gen1 = new CookieRetrievingCookieGenerator(getCookieGenerationContext("/custom/path/"));
var cookie1 = gen1.addCookie(request, response, "some-value");
assertEquals("/custom/path/", cookie1.getPath());
gen1 = new CookieRetrievingCookieGenerator(getCookieGenerationContext(StringUtils.EMPTY));
cookie1 = gen1.addCookie(request, response, "some-value");
assertEquals("/", cookie1.getPath());
}
use of org.apereo.cas.web.support.gen.CookieRetrievingCookieGenerator in project cas by apereo.
the class CookieRetrievingCookieGeneratorTests method verifyOtherSetCookieHeaderIsNotDiscarded.
@Test
public void verifyOtherSetCookieHeaderIsNotDiscarded() {
val context = getCookieGenerationContext();
val gen = new CookieRetrievingCookieGenerator(context);
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
response.addHeader("Set-Cookie", gen.getCookieName() + "=some-cookie-value");
response.addHeader("Set-Cookie", "OtherCookie=other-cookie-value");
var headers = response.getHeaders("Set-Cookie");
assertEquals(2, headers.size());
val cookie = gen.addCookie(request, response, "some-value");
assertNotNull(cookie);
assertEquals("some-value", cookie.getValue());
var headersAfter = response.getHeaders("Set-Cookie");
assertEquals(2, headersAfter.size());
val headerValuesAfter = response.getHeaderValues("Set-Cookie").stream().map(String.class::cast).map(header -> Arrays.stream(header.split(";")).iterator().next()).collect(Collectors.toSet());
assertEquals(headerValuesAfter, CollectionUtils.wrapSet(cookie.getName() + "=some-value", "OtherCookie=other-cookie-value"));
}
use of org.apereo.cas.web.support.gen.CookieRetrievingCookieGenerator in project cas by apereo.
the class CookieRetrievingCookieGeneratorTests method verifyCookieValueByHeader.
@Test
public void verifyCookieValueByHeader() {
val context = getCookieGenerationContext();
val gen = new CookieRetrievingCookieGenerator(context);
val request = new MockHttpServletRequest();
request.addHeader(context.getName(), "CAS-Cookie-Value");
val cookie = gen.retrieveCookieValue(request);
assertNotNull(cookie);
assertEquals("CAS-Cookie-Value", cookie);
}
use of org.apereo.cas.web.support.gen.CookieRetrievingCookieGenerator in project cas by apereo.
the class CookieRetrievingCookieGeneratorTests method verifyRemoveAllCookiesByName.
@Test
public void verifyRemoveAllCookiesByName() {
val request = new MockHttpServletRequest();
var response = new MockHttpServletResponse();
val gen1 = new CookieRetrievingCookieGenerator(getCookieGenerationContext());
val cookie1 = gen1.addCookie(request, response, "some-value");
val gen2 = new CookieRetrievingCookieGenerator(getCookieGenerationContext("/cas"));
val cookie2 = gen2.addCookie(request, response, "some-value");
val gen3 = new CookieRetrievingCookieGenerator(getCookieGenerationContext("/cas/"));
val cookie3 = gen3.addCookie(request, response, "some-value");
request.setCookies(cookie1, cookie2, cookie3);
response = new MockHttpServletResponse();
gen1.removeAll(request, response);
assertEquals(9, response.getCookies().length);
assertTrue(Arrays.stream(response.getCookies()).allMatch(c -> c.getMaxAge() == 0));
}
Aggregations