Class SameSiteCookieHeaderFilterTest

java.lang.Object
net.shibboleth.shared.spring.servlet.impl.SameSiteCookieHeaderFilterTest

public class SameSiteCookieHeaderFilterTest extends Object
  • Field Details

  • Constructor Details

    • SameSiteCookieHeaderFilterTest

      public SameSiteCookieHeaderFilterTest()
  • Method Details

    • setUp

      @BeforeMethod public void setUp()
    • tearDown

      @AfterMethod public void tearDown()
    • testNullInitValues

      public void testNullInitValues()
      Test a null init value, which should not trigger an exception.
    • testEmptyCookieNameInitValue

      public void testEmptyCookieNameInitValue()
      Test an empty cookie name is not added to the internal map.
    • testInitValues

      public void testInitValues()
      Test the correct number of cookies are added to the internal filter cookie map.
    • testDuplicateInitValues

      public void testDuplicateInitValues()
      Test failure on duplicated cookie names
    • testEmptySameSiteCookieMap

      public void testEmptySameSiteCookieMap() throws IOException, ServletException
      Test empty SameSite cookie map, which should not trigger an exception, and just copy over the existing cookies.
      Throws:
      IOException - if something bad happens
      ServletException - if something bad happens
    • testEmptySameSiteCookieMapAndNullDefault

      public void testEmptySameSiteCookieMapAndNullDefault() throws IOException, ServletException
      Test empty SameSite cookie map and Null default, which should not trigger an exception, and just copy over the existing cookies.
      Throws:
      IOException - if something bad happens
      ServletException - if something bad happens
    • testEmptySameSiteCookieMapWithDefault

      public void testEmptySameSiteCookieMapWithDefault() throws IOException, ServletException
      Test empty SameSite cookie map, which should not trigger an exception, and should apply a default.
      Throws:
      IOException - if something bad happens
      ServletException - if something bad happens
    • testRedirectResponseSameSiteNone

      public void testRedirectResponseSameSiteNone() throws IOException, ServletException
      Test the samesite filter works correctly with None values when a redirect response is issued.
      Throws:
      IOException - if something bad happens
      ServletException - if something bad happens
    • testRedirectResponseSameSiteNoneWithDefault

      public void testRedirectResponseSameSiteNoneWithDefault() throws IOException, ServletException
      Test the samesite filter works correctly with None values when a redirect response is issued.
      Throws:
      IOException - if something bad happens
      ServletException - if something bad happens
    • testRedirectResponseSameSiteLax

      public void testRedirectResponseSameSiteLax() throws IOException, ServletException
      Test the samesite filter works correctly with Lax values when a redirect response is issued.
      Throws:
      IOException - if something bad happens
      ServletException - if something bad happens
    • testRedirectResponseSameSiteStrict

      public void testRedirectResponseSameSiteStrict() throws IOException, ServletException
      Test the samesite filter works correctly with Strict values when a redirect response is issued.
      Throws:
      IOException - if something bad happens
      ServletException - if something bad happens
    • testGetOutputStreamResponse

      public void testGetOutputStreamResponse() throws IOException, ServletException
      Test the samesite filter works correctly when an output stream is written to and flushed.
      Throws:
      IOException - if something bad happens
      ServletException - if something bad happens
    • testPrintWriterResponse

      public void testPrintWriterResponse() throws IOException, ServletException
      Test the samesite filter works correctly when the response print writer is written to and closed.
      Throws:
      IOException - if something bad happens
      ServletException - if something bad happens
    • testSameSiteMapSize

      private void testSameSiteMapSize(@Nonnull String fieldName, int expectedSize, @Nonnull Filter filter)
      Get the field from the filter (even if private), check the field is of type Set, and compare the size of the set to the expected size.
      Parameters:
      fieldName - the name of the field on the object of type Map.
      expectedSize - the expected size of the map.
      filter - the filter with the field to get.
    • testExpectedHeadersInResponse

      private void testExpectedHeadersInResponse(String sameSiteValue, MockHttpServletResponse response, List<String> cookiesWithSamesite, List<String> cookiesWithoutSameSite, int numberOfHeaders)
      Test the Set-Cookie headers in the response contain the SameSite=<sameSiteValue> attribute if they are named in the cookiesWithSamesite list, and do not if named in the cookiesWithoutSameSite list.

      Also checks the number of Set-Cookie headers matches numberOfHeaders. This makes sure the filter is not adding or removing headers during operation - it should only ever append the SameSite attribute to existing cookies.

      Parameters:
      sameSiteValue - the value of samesite to check for.
      response - the http servlet response.
      cookiesWithSamesite - the list of cookies that should have the SameSite=None attribute set.
      cookiesWithoutSameSite - the list of cookies that should not have the SameSite attribute set.
      numberOfHeaders - the number of Set-Cookie headers expected in the response.