Ejemplo n.º 1
0
 /**
  * Performs request method with HttpContext. HttpContext typically contains cookie store with all
  * cookies to include with request
  *
  * @param method request method
  * @param context httpcontext
  * @return request response
  * @throws Exception
  */
 protected HttpResponse perform(HttpRequestBase method, HttpContext context) throws Exception {
   HttpResponse response = getHttpClient().execute(method, context);
   Header cspHeaders[] = response.getHeaders(CSP.Header.REPORT_ONLY);
   if (response.getStatusLine().getStatusCode() == 200) {
     // TODO(fabbott): Although a request for e.g. moment.js from testSetRunner.app
     // does have a header, the same request from AuraFrameworkServletHttpTest does
     // not.  I suspect this is because the test has no UID, but the "real life" one
     // does... but for now, let's validate the CSP header only if it's actually there.
     if (cspHeaders.length != 0) {
       assertEquals(1, cspHeaders.length);
       assertTrue(
           "No connect-src in default CSP",
           cspHeaders[0].getValue().contains("; connect-src 'self';"));
     }
   }
   return response;
 }
Ejemplo n.º 2
0
 /**
  * Gets content type of response
  *
  * @param response request response
  * @return content type
  */
 protected static ContentType getContentType(HttpResponse response) {
   return ContentType.getOrDefault(response.getEntity());
 }
Ejemplo n.º 3
0
 /**
  * Gets string body of response
  *
  * @param response request response
  * @return response body
  * @throws IOException
  */
 protected static String getResponseBody(HttpResponse response) throws IOException {
   HttpEntity entity = response.getEntity();
   return entity == null ? null : EntityUtils.toString(entity);
 }
Ejemplo n.º 4
0
 /**
  * Gets status code of response
  *
  * @param response request response
  * @return status code
  */
 protected static int getStatusCode(HttpResponse response) {
   return response.getStatusLine().getStatusCode();
 }