@Test public void testJs() throws Exception { HttpRequest req = new HttpRequest(CONTENT_URI); req.setRewriteMimeType("text/javascript"); req.setCajaRequested(true); HttpResponse response = new HttpResponseBuilder().setResponseString("var a;").create(); String sanitized = "$v.initOuter('a');"; assertTrue(rewrite(req, response).contains(sanitized)); }
@Test public void testJsWithoutCaja() throws Exception { HttpRequest req = new HttpRequest(CONTENT_URI); req.setRewriteMimeType("text/javascript"); req.setCajaRequested(false); HttpResponse response = new HttpResponseBuilder().setResponseString("var a;").create(); String sanitized = "var a;"; assertTrue(rewrite(req, response).contains(sanitized)); }
@Test public void testJs() throws Exception { Gadget gadget = mockGadget(); control.replay(); HttpRequest req = new HttpRequest(CONTENT_URI); req.setRewriteMimeType("text/javascript"); req.setCajaRequested(true); HttpResponse response = new HttpResponseBuilder().setResponseString("var a;").create(); String sanitized = "___.di(IMPORTS___,'a');"; assertTrue(rewrite(req, response).contains(sanitized)); assertTrue(rewrite(req, response, gadget).contains(sanitized)); }
@Test public void testJsWithoutCaja() throws Exception { Gadget gadget = mockGadget(); control.replay(); HttpRequest req = new HttpRequest(CONTENT_URI); req.setRewriteMimeType("text/javascript"); req.setCajaRequested(false); HttpResponse response = new HttpResponseBuilder().setResponseString("var a;").create(); String sanitized = "var a;"; assertTrue(rewrite(req, response).contains(sanitized)); assertTrue(rewrite(req, response, gadget).contains(sanitized)); }
@Test public void testJs() throws Exception { Gadget gadget = mockGadget(); control.replay(); HttpRequest req = new HttpRequest(CONTENT_URI); req.setRewriteMimeType("text/javascript"); req.setCajaRequested(true); HttpResponse response = new HttpResponseBuilder().setResponseString("var a;").create(); String sanitized = "___.di(IMPORTS___,'a');"; assertTrue(rewrite(req, response).contains(sanitized)); assertTrue(rewrite(req, response, gadget).contains(sanitized)); }
@Test public void testJsWithoutCaja() throws Exception { Gadget gadget = mockGadget(); control.replay(); HttpRequest req = new HttpRequest(CONTENT_URI); req.setRewriteMimeType("text/javascript"); req.setCajaRequested(false); HttpResponse response = new HttpResponseBuilder().setResponseString("var a;").create(); String sanitized = "var a;"; assertTrue(rewrite(req, response).contains(sanitized)); assertTrue(rewrite(req, response, gadget).contains(sanitized)); }
@Test public void testNonJs() throws Exception { HttpRequest req = new HttpRequest(CONTENT_URI); req.setRewriteMimeType("text/html"); req.setCajaRequested(true); HttpResponse response = new HttpResponseBuilder().setResponseString("<html></html>").create(); assertEquals("", rewrite(req, response)); } }
public HttpRequest makeHttpRequest(Uri targetUri) throws GadgetException { HttpRequest req = new HttpRequest(targetUri) .setIgnoreCache(isNoCache()) .setContainer(getContainer()); if (!StringUtils.isEmpty(getGadget())) { try { req.setGadget(Uri.parse(getGadget())); } catch (IllegalArgumentException e) { throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, "Invalid " + Param.GADGET.getKey() + " param: " + getGadget(), HttpResponse.SC_BAD_REQUEST); } } if (getRefresh() != null && getRefresh() >= 0) { req.setCacheTtl(getRefresh()); } // Allow the rewriter to use an externally forced MIME type. This is needed // allows proper rewriting of <script src="x"/> where x is returned with // a content type like text/html which unfortunately happens all too often if (rewriteMimeType != null) { req.setRewriteMimeType(getRewriteMimeType()); } req.setSanitizationRequested(sanitizeContent()); req.setCajaRequested(cajoleContent()); return req; }
public HttpRequest makeHttpRequest(Uri targetUri) throws GadgetException { HttpRequest req = new HttpRequest(targetUri) .setIgnoreCache(isNoCache()) .setContainer(getContainer()); if (!StringUtils.isEmpty(getGadget())) { try { req.setGadget(Uri.parse(getGadget())); } catch (IllegalArgumentException e) { throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, "Invalid " + Param.GADGET.getKey() + " param: " + getGadget(), HttpResponse.SC_BAD_REQUEST); } } if (getRefresh() != null && getRefresh() >= 0) { req.setCacheTtl(getRefresh()); } // Allow the rewriter to use an externally forced MIME type. This is needed // allows proper rewriting of <script src="x"/> where x is returned with // a content type like text/html which unfortunately happens all too often if (rewriteMimeType != null) { req.setRewriteMimeType(getRewriteMimeType()); } req.setSanitizationRequested(sanitizeContent()); req.setCajaRequested(cajoleContent()); return req; }
public HttpRequest makeHttpRequest(Uri targetUri) throws GadgetException { HttpRequest req = new HttpRequest(targetUri) .setIgnoreCache(isNoCache()) .setContainer(getContainer()); if (!Strings.isNullOrEmpty(getGadget())) { try { req.setGadget(Uri.parse(getGadget())); } catch (IllegalArgumentException e) { throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, "Invalid " + Param.GADGET.getKey() + " param: " + getGadget(), HttpResponse.SC_BAD_REQUEST); } } if (getRefresh() != null && getRefresh() >= 0) { req.setCacheTtl(getRefresh()); } // Allow the rewriter to use an externally forced MIME type. This is needed // allows proper rewriting of <script src="x"/> where x is returned with // a content type like text/html which unfortunately happens all too often if (rewriteMimeType != null) { req.setRewriteMimeType(getRewriteMimeType()); } req.setSanitizationRequested(sanitizeContent()); req.setCajaRequested(cajoleContent()); return req; }
@Test public void testNonJs() throws Exception { Gadget gadget = mockGadget(); control.replay(); HttpRequest req = new HttpRequest(CONTENT_URI); req.setRewriteMimeType("text/html"); req.setCajaRequested(true); HttpResponse response = new HttpResponseBuilder().setResponseString("<html></html>").create(); assertEquals("", rewrite(req, response)); assertEquals("", rewrite(req, response, gadget)); } }
@Test public void testNonJs() throws Exception { Gadget gadget = mockGadget(); control.replay(); HttpRequest req = new HttpRequest(CONTENT_URI); req.setRewriteMimeType("text/html"); req.setCajaRequested(true); HttpResponse response = new HttpResponseBuilder().setResponseString("<html></html>").create(); assertEquals("", rewrite(req, response)); assertEquals("", rewrite(req, response, gadget)); } }