use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class CookieClearingLogoutHandlerTests method invalidAge.
@Test
public void invalidAge() {
Cookie cookie1 = new Cookie("my_cookie", null);
cookie1.setPath("/foo");
cookie1.setMaxAge(100);
assertThatIllegalArgumentException().isThrownBy(() -> new CookieClearingLogoutHandler(cookie1));
}
use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class CookieClearingLogoutHandlerTests method emptyContextRootIsConverted.
// SEC-2036
@Test
public void emptyContextRootIsConverted() {
MockHttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("");
CookieClearingLogoutHandler handler = new CookieClearingLogoutHandler("my_cookie");
handler.logout(request, response, mock(Authentication.class));
assertThat(response.getCookies()).hasSize(1);
for (Cookie c : response.getCookies()) {
assertThat(c.getPath()).isEqualTo("/");
assertThat(c.getMaxAge()).isZero();
}
}
use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class CookieClearingLogoutHandlerTests method configuredCookiesAreCleared.
@Test
public void configuredCookiesAreCleared() {
MockHttpServletResponse response = new MockHttpServletResponse();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setContextPath("/app");
CookieClearingLogoutHandler handler = new CookieClearingLogoutHandler("my_cookie", "my_cookie_too");
handler.logout(request, response, mock(Authentication.class));
assertThat(response.getCookies()).hasSize(2);
for (Cookie c : response.getCookies()) {
assertThat(c.getPath()).isEqualTo("/app");
assertThat(c.getMaxAge()).isZero();
}
}
use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class CookieMixinTests method serializeCookie.
// @formatter:on
@Test
public void serializeCookie() throws JsonProcessingException, JSONException {
Cookie cookie = new Cookie("demo", "cookie1");
String actualString = this.mapper.writeValueAsString(cookie);
JSONAssert.assertEquals(COOKIE_JSON, actualString, true);
}
use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class DefaultSavedRequestMixinTests method matchRequestBuildWithConstructorAndBuilder.
// @formatter:on
@Test
public void matchRequestBuildWithConstructorAndBuilder() {
DefaultSavedRequest request = new DefaultSavedRequest.Builder().setCookies(Collections.singletonList(new SavedCookie(new Cookie("SESSION", "123456789")))).setHeaders(Collections.singletonMap("x-auth-token", Collections.singletonList("12"))).setScheme("http").setRequestURL("http://localhost").setServerName("localhost").setRequestURI("").setLocales(Collections.singletonList(new Locale("en"))).setContextPath("").setMethod("").setServletPath("").build();
MockHttpServletRequest mockRequest = new MockHttpServletRequest();
mockRequest.setCookies(new Cookie("SESSION", "123456789"));
mockRequest.addHeader("x-auth-token", "12");
assertThat(request.doesRequestMatch(mockRequest, new PortResolverImpl())).isTrue();
}
Aggregations