Search in sources :

Example 16 with Cookie

use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.

the class SavedCookieMixinTests method serializeWithDefaultConfigurationTest.

// @formatter:on
@Test
public void serializeWithDefaultConfigurationTest() throws JsonProcessingException, JSONException {
    SavedCookie savedCookie = new SavedCookie(new Cookie("SESSION", "123456789"));
    String actualJson = this.mapper.writeValueAsString(savedCookie);
    JSONAssert.assertEquals(COOKIE_JSON, actualJson, true);
}
Also used : Cookie(jakarta.servlet.http.Cookie) SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) Test(org.junit.jupiter.api.Test)

Example 17 with Cookie

use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.

the class SavedCookieMixinTests method serializeSavedCookieWithList.

@Test
public void serializeSavedCookieWithList() throws JsonProcessingException, JSONException {
    List<SavedCookie> savedCookies = new ArrayList<>();
    savedCookies.add(new SavedCookie(new Cookie("SESSION", "123456789")));
    String actualJson = this.mapper.writeValueAsString(savedCookies);
    JSONAssert.assertEquals(COOKIES_JSON, actualJson, true);
}
Also used : Cookie(jakarta.servlet.http.Cookie) SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 18 with Cookie

use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.

the class SavedCookieMixinTests method serializeWithOverrideConfigurationTest.

@Test
public void serializeWithOverrideConfigurationTest() throws JsonProcessingException, JSONException {
    SavedCookie savedCookie = new SavedCookie(new Cookie("SESSION", "123456789"));
    this.mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.PUBLIC_ONLY).setVisibility(PropertyAccessor.GETTER, JsonAutoDetect.Visibility.ANY);
    String actualJson = this.mapper.writeValueAsString(savedCookie);
    JSONAssert.assertEquals(COOKIE_JSON, actualJson, true);
}
Also used : Cookie(jakarta.servlet.http.Cookie) SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) SavedCookie(org.springframework.security.web.savedrequest.SavedCookie) Test(org.junit.jupiter.api.Test)

Example 19 with Cookie

use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.

the class FirewalledResponseTests method addCookieWhenCookieCommentContainsCrlfThenException.

@Test
public void addCookieWhenCookieCommentContainsCrlfThenException() {
    Cookie cookie = new Cookie("foo", "bar");
    cookie.setComment("foo\r\nbar");
    assertThatIllegalArgumentException().isThrownBy(() -> this.fwResponse.addCookie(cookie)).withMessageContaining(CRLF_MESSAGE);
}
Also used : Cookie(jakarta.servlet.http.Cookie) Test(org.junit.jupiter.api.Test)

Example 20 with Cookie

use of jakarta.servlet.http.Cookie in project spring-security by spring-projects.

the class FirewalledResponseTests method addCookieWhenCookiePathContainsCrlfThenException.

@Test
public void addCookieWhenCookiePathContainsCrlfThenException() {
    Cookie cookie = new Cookie("foo", "bar");
    cookie.setPath("/foo\r\nbar");
    assertThatIllegalArgumentException().isThrownBy(() -> this.fwResponse.addCookie(cookie)).withMessageContaining(CRLF_MESSAGE);
}
Also used : Cookie(jakarta.servlet.http.Cookie) Test(org.junit.jupiter.api.Test)

Aggregations

Cookie (jakarta.servlet.http.Cookie)197 Test (org.junit.jupiter.api.Test)137 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)45 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)40 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)30 Locale (java.util.Locale)19 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)19 MvcResult (org.springframework.test.web.servlet.MvcResult)15 Authentication (org.springframework.security.core.Authentication)11 Test (org.junit.Test)10 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)9 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)9 IOException (java.io.IOException)8 LocaleContext (org.springframework.context.i18n.LocaleContext)8 SimpleLocaleContext (org.springframework.context.i18n.SimpleLocaleContext)8 SimpleTimeZoneAwareLocaleContext (org.springframework.context.i18n.SimpleTimeZoneAwareLocaleContext)8 TimeZoneAwareLocaleContext (org.springframework.context.i18n.TimeZoneAwareLocaleContext)8 Map (java.util.Map)6 SavedCookie (org.springframework.security.web.savedrequest.SavedCookie)6 ModelAndView (org.springframework.web.servlet.ModelAndView)6