|
@@ -20,15 +20,16 @@ import org.junit.Before;
|
|
import org.junit.Rule;
|
|
import org.junit.Rule;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
import org.junit.rules.ExpectedException;
|
|
import org.junit.rules.ExpectedException;
|
|
|
|
+
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
import org.springframework.mock.web.MockHttpServletRequest;
|
|
import org.springframework.mock.web.MockHttpServletResponse;
|
|
import org.springframework.mock.web.MockHttpServletResponse;
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
*
|
|
*
|
|
* @author Rafiullah Hamedy
|
|
* @author Rafiullah Hamedy
|
|
|
|
+ * @author Josh Cummings
|
|
*
|
|
*
|
|
* @see {@link ClearSiteDataHeaderWriter}
|
|
* @see {@link ClearSiteDataHeaderWriter}
|
|
*/
|
|
*/
|
|
@@ -43,53 +44,43 @@ public class ClearSiteDataHeaderWriterTests {
|
|
|
|
|
|
@Before
|
|
@Before
|
|
public void setup() {
|
|
public void setup() {
|
|
- request = new MockHttpServletRequest();
|
|
|
|
- request.setSecure(true);
|
|
|
|
- response = new MockHttpServletResponse();
|
|
|
|
|
|
+ this.request = new MockHttpServletRequest();
|
|
|
|
+ this.request.setSecure(true);
|
|
|
|
+ this.response = new MockHttpServletResponse();
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void createInstanceWhenMissingSourceThenThrowsException() {
|
|
public void createInstanceWhenMissingSourceThenThrowsException() {
|
|
this.thrown.expect(Exception.class);
|
|
this.thrown.expect(Exception.class);
|
|
- this.thrown.expectMessage("Sources cannot be empty or null.");
|
|
|
|
|
|
+ this.thrown.expectMessage("sources cannot be empty or null");
|
|
|
|
|
|
new ClearSiteDataHeaderWriter();
|
|
new ClearSiteDataHeaderWriter();
|
|
}
|
|
}
|
|
|
|
|
|
- @Test
|
|
|
|
- public void createInstanceWhenEmptySourceThenThrowsException() {
|
|
|
|
- this.thrown.expect(Exception.class);
|
|
|
|
- this.thrown.expectMessage("Sources cannot be empty or null.");
|
|
|
|
-
|
|
|
|
- new ClearSiteDataHeaderWriter(new String[] {});
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Test
|
|
@Test
|
|
public void writeHeaderWhenRequestNotSecureThenHeaderIsNotPresent() {
|
|
public void writeHeaderWhenRequestNotSecureThenHeaderIsNotPresent() {
|
|
this.request.setSecure(false);
|
|
this.request.setSecure(false);
|
|
-
|
|
|
|
ClearSiteDataHeaderWriter headerWriter = new ClearSiteDataHeaderWriter("cache");
|
|
ClearSiteDataHeaderWriter headerWriter = new ClearSiteDataHeaderWriter("cache");
|
|
- headerWriter.writeHeaders(request, response);
|
|
|
|
|
|
+ headerWriter.writeHeaders(this.request, this.response);
|
|
|
|
|
|
- assertThat(header().doesNotExist(HEADER_NAME));
|
|
|
|
|
|
+ assertThat(this.response.getHeader(HEADER_NAME)).isNull();
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void writeHeaderWhenRequestIsSecureThenHeaderValueMatchesPassedSource() {
|
|
public void writeHeaderWhenRequestIsSecureThenHeaderValueMatchesPassedSource() {
|
|
ClearSiteDataHeaderWriter headerWriter = new ClearSiteDataHeaderWriter("storage");
|
|
ClearSiteDataHeaderWriter headerWriter = new ClearSiteDataHeaderWriter("storage");
|
|
- headerWriter.writeHeaders(request, response);
|
|
|
|
|
|
+ headerWriter.writeHeaders(this.request, this.response);
|
|
|
|
|
|
- assertThat(header().stringValues(HEADER_NAME, "\"storage\""));
|
|
|
|
|
|
+ assertThat(this.response.getHeader(HEADER_NAME)).isEqualTo("\"storage\"");
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
public void writeHeaderWhenRequestIsSecureThenHeaderValueMatchesPassedSources() {
|
|
public void writeHeaderWhenRequestIsSecureThenHeaderValueMatchesPassedSources() {
|
|
ClearSiteDataHeaderWriter headerWriter =
|
|
ClearSiteDataHeaderWriter headerWriter =
|
|
new ClearSiteDataHeaderWriter("cache", "cookies", "storage", "executionContexts");
|
|
new ClearSiteDataHeaderWriter("cache", "cookies", "storage", "executionContexts");
|
|
|
|
+ headerWriter.writeHeaders(this.request, this.response);
|
|
|
|
|
|
- headerWriter.writeHeaders(request, response);
|
|
|
|
-
|
|
|
|
- assertThat(header().stringValues(HEADER_NAME, "\"cache\", \"cookies\", \"storage\","
|
|
|
|
- + " \"executionContexts\""));
|
|
|
|
|
|
+ assertThat(this.response.getHeader(HEADER_NAME))
|
|
|
|
+ .isEqualTo("\"cache\", \"cookies\", \"storage\", \"executionContexts\"");
|
|
}
|
|
}
|
|
}
|
|
}
|