Class SameSiteCookieHeaderFilterTest
- java.lang.Object
-
- net.shibboleth.utilities.java.support.net.SameSiteCookieHeaderFilterTest
-
public class SameSiteCookieHeaderFilterTest extends Object
Tests forSameSiteCookieHeaderFilter.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classSameSiteCookieHeaderFilterTest.TestOutputStreamServletServlet that opens an output stream on the response.classSameSiteCookieHeaderFilterTest.TestPrintWriterServletServlet that opens a print writer on the response.classSameSiteCookieHeaderFilterTest.TestRedirectServletServlet that initiates a redirect on the response.
-
Field Summary
Fields Modifier and Type Field Description private MockHttpServletRequestrequestprivate MockHttpServletResponseresponse
-
Constructor Summary
Constructors Constructor Description SameSiteCookieHeaderFilterTest()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidsetUp()voidtearDown()voidtestDuplicateInitValues()Test failure on duplicated cookie namesvoidtestEmptyCookieNameInitValue()Test an empty cookie name is not added to the internal map.voidtestEmptySameSiteCookieMap()Test empty SameSite cookie map, which should not trigger an exception, and just copy over the existing cookies.voidtestEmptySameSiteCookieMapAndNullDefault()Test empty SameSite cookie map and Null default, which should not trigger an exception, and just copy over the existing cookies.voidtestEmptySameSiteCookieMapWithDefault()Test empty SameSite cookie map, which should not trigger an exception, and should apply a default.private voidtestExpectedHeadersInResponse(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 thecookiesWithSamesitelist, and do not if named in thecookiesWithoutSameSitelist.voidtestGetOutputStreamResponse()Test the samesite filter works correctly when an output stream is written to and flushed.voidtestInitValues()Test the correct number of cookies are added to the internal filter cookie map.voidtestNullInitValues()Test a null init value, which should not trigger an exception.voidtestPrintWriterResponse()Test the samesite filter works correctly when the response print writer is written to and closed.voidtestRedirectResponseSameSiteLax()Test the samesite filter works correctly with Lax values when a redirect response is issued.voidtestRedirectResponseSameSiteNone()Test the samesite filter works correctly with None values when a redirect response is issued.voidtestRedirectResponseSameSiteNoneWithDefault()Test the samesite filter works correctly with None values when a redirect response is issued.voidtestRedirectResponseSameSiteStrict()Test the samesite filter works correctly with Strict values when a redirect response is issued.private voidtestSameSiteMapSize(String fieldName, int expectedSize, javax.servlet.Filter filter)Get the field from the filter (even if private), check the field is of typeSet, and compare the size of the set to the expected size.
-
-
-
Field Detail
-
request
private MockHttpServletRequest request
-
response
private MockHttpServletResponse response
-
-
Method Detail
-
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, javax.servlet.ServletExceptionTest empty SameSite cookie map, which should not trigger an exception, and just copy over the existing cookies.- Throws:
IOException- if something bad happensjavax.servlet.ServletException- if something bad happens
-
testEmptySameSiteCookieMapAndNullDefault
public void testEmptySameSiteCookieMapAndNullDefault() throws IOException, javax.servlet.ServletExceptionTest 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 happensjavax.servlet.ServletException- if something bad happens
-
testEmptySameSiteCookieMapWithDefault
public void testEmptySameSiteCookieMapWithDefault() throws IOException, javax.servlet.ServletExceptionTest empty SameSite cookie map, which should not trigger an exception, and should apply a default.- Throws:
IOException- if something bad happensjavax.servlet.ServletException- if something bad happens
-
testRedirectResponseSameSiteNone
public void testRedirectResponseSameSiteNone() throws IOException, javax.servlet.ServletExceptionTest the samesite filter works correctly with None values when a redirect response is issued.- Throws:
IOException- if something bad happensjavax.servlet.ServletException- if something bad happens
-
testRedirectResponseSameSiteNoneWithDefault
public void testRedirectResponseSameSiteNoneWithDefault() throws IOException, javax.servlet.ServletExceptionTest the samesite filter works correctly with None values when a redirect response is issued.- Throws:
IOException- if something bad happensjavax.servlet.ServletException- if something bad happens
-
testRedirectResponseSameSiteLax
public void testRedirectResponseSameSiteLax() throws IOException, javax.servlet.ServletExceptionTest the samesite filter works correctly with Lax values when a redirect response is issued.- Throws:
IOException- if something bad happensjavax.servlet.ServletException- if something bad happens
-
testRedirectResponseSameSiteStrict
public void testRedirectResponseSameSiteStrict() throws IOException, javax.servlet.ServletExceptionTest the samesite filter works correctly with Strict values when a redirect response is issued.- Throws:
IOException- if something bad happensjavax.servlet.ServletException- if something bad happens
-
testGetOutputStreamResponse
public void testGetOutputStreamResponse() throws IOException, javax.servlet.ServletExceptionTest the samesite filter works correctly when an output stream is written to and flushed.- Throws:
IOException- if something bad happensjavax.servlet.ServletException- if something bad happens
-
testPrintWriterResponse
public void testPrintWriterResponse() throws IOException, javax.servlet.ServletExceptionTest the samesite filter works correctly when the response print writer is written to and closed.- Throws:
IOException- if something bad happensjavax.servlet.ServletException- if something bad happens
-
testSameSiteMapSize
private void testSameSiteMapSize(String fieldName, int expectedSize, javax.servlet.Filter filter)
Get the field from the filter (even if private), check the field is of typeSet, and compare the size of the set to the expected size.- Parameters:
fieldName- the name of the field on the object of typeMap.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 thecookiesWithSamesitelist, and do not if named in thecookiesWithoutSameSitelist.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.
-
-