Search in sources :

Example 1 with CspEnabledProperty

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);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) HttpServlet(javax.servlet.http.HttpServlet) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) CspEnabledProperty(org.eclipse.scout.rt.server.commons.ServerCommonsConfigProperties.CspEnabledProperty)

Aggregations

HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)1 CspEnabledProperty (org.eclipse.scout.rt.server.commons.ServerCommonsConfigProperties.CspEnabledProperty)1