use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class FirewalledResponseTests method addCookieWhenCookieValueContainsCrlfThenException.
@Test
public void addCookieWhenCookieValueContainsCrlfThenException() {
Cookie cookie = new Cookie("foo", "foo\r\nbar");
assertThatIllegalArgumentException().isThrownBy(() -> this.fwResponse.addCookie(cookie)).withMessageContaining(CRLF_MESSAGE);
}
use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class FirewalledResponseTests method addCookieWhenCookieNameContainsCrlfThenException.
@Test
public void addCookieWhenCookieNameContainsCrlfThenException() {
// Constructor validates the name
Cookie cookie = new Cookie("valid-since-constructor-validates", "bar") {
@Override
public String getName() {
return "foo\r\nbar";
}
};
assertThatIllegalArgumentException().isThrownBy(() -> this.fwResponse.addCookie(cookie)).withMessageContaining(CRLF_MESSAGE);
}
use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class CookieCsrfTokenRepositoryTests method saveTokenNull.
@Test
public void saveTokenNull() {
this.request.setSecure(true);
this.repository.saveToken(null, this.request, this.response);
Cookie tokenCookie = this.response.getCookie(CookieCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME);
assertThat(tokenCookie.getMaxAge()).isZero();
assertThat(tokenCookie.getName()).isEqualTo(CookieCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME);
assertThat(tokenCookie.getPath()).isEqualTo(this.request.getContextPath());
assertThat(tokenCookie.getSecure()).isEqualTo(this.request.isSecure());
assertThat(tokenCookie.getValue()).isEmpty();
}
use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class CookieCsrfTokenRepositoryTests method saveTokenHttpOnlyFalse.
@Test
public void saveTokenHttpOnlyFalse() {
this.repository.setCookieHttpOnly(false);
CsrfToken token = this.repository.generateToken(this.request);
this.repository.saveToken(token, this.request, this.response);
Cookie tokenCookie = this.response.getCookie(CookieCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME);
assertThat(tokenCookie.isHttpOnly()).isFalse();
}
use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.
the class CookieCsrfTokenRepositoryTests method saveTokenSecureFlagTrue.
@Test
public void saveTokenSecureFlagTrue() {
this.request.setSecure(false);
this.repository.setSecure(Boolean.TRUE);
CsrfToken token = this.repository.generateToken(this.request);
this.repository.saveToken(token, this.request, this.response);
Cookie tokenCookie = this.response.getCookie(CookieCsrfTokenRepository.DEFAULT_CSRF_COOKIE_NAME);
assertThat(tokenCookie.getSecure()).isTrue();
}
Aggregations