use of org.eclipse.scout.rt.server.commons.ServerCommonsConfigProperties.CspEnabledProperty in project scout.rt by eclipse.
the class HttpServletControlTest method runTestSetResponseHeader.
protected void runTestSetResponseHeader(boolean mshtml, boolean cspEnabled, String method, boolean expectCspHeader) {
CspEnabledProperty cspProperty = Mockito.mock(CspEnabledProperty.class);
Mockito.when(cspProperty.getValue(ArgumentMatchers.<String>any())).thenReturn(cspEnabled);
s_beans.add(TestingUtility.registerBean(new BeanMetaData(CspEnabledProperty.class, cspProperty)));
HttpClientInfo httpClientInfo = Mockito.mock(HttpClientInfo.class);
Mockito.when(httpClientInfo.isMshtml()).thenReturn(mshtml);
HttpServletControl httpServletControl = new HttpServletControl();
httpServletControl.setCspToken(TEST_CSP_TOKEN);
HttpServlet servlet = Mockito.mock(HttpServlet.class);
HttpSession session = Mockito.mock(HttpSession.class);
HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
HttpServletResponse resp = Mockito.mock(HttpServletResponse.class);
Mockito.when(req.getMethod()).thenReturn(method);
Mockito.when(req.getSession(false)).thenReturn(session);
Mockito.when(session.getAttribute(HttpClientInfo.HTTP_CLIENT_INFO_ATTRIBUTE_NAME)).thenReturn(httpClientInfo);
httpServletControl.setResponseHeaders(servlet, req, resp);
Mockito.verifyZeroInteractions(servlet);
if (expectCspHeader) {
Mockito.verify(resp).setHeader(HttpServletControl.HTTP_HEADER_X_FRAME_OPTIONS, HttpServletControl.SAMEORIGIN);
Mockito.verify(resp).setHeader(HttpServletControl.HTTP_HEADER_X_XSS_PROTECTION, HttpServletControl.XSS_MODE_BLOCK);
if (mshtml) {
Mockito.verify(resp).setHeader(HttpServletControl.HTTP_HEADER_CSP_LEGACY, TEST_CSP_TOKEN);
} else {
Mockito.verify(resp).setHeader(HttpServletControl.HTTP_HEADER_CSP, TEST_CSP_TOKEN);
}
}
}
Aggregations