private void assertUrlRewritten(String tagName, String attr, String orig, String rewritten) throws Exception { String markUp = "<" + tagName + " " + attr + "=\"" + orig + "\">"; String expected = attr + "=\"" + rewritten + "\""; testMarkup(markUp, expected); }
private void testMarkup(String markup, String expected, List<String> msgs) throws GadgetException{ Gadget gadget = makeGadget(); for (GadgetHtmlParser parser : parsers) { MutableContent mc = new MutableContent(parser, markup); rewriter.rewrite(gadget, mc); String actual = mc.getContent(); if (msgs != null) { for (String msg : msgs) { System.out.println("Msg:" + msg); assertThat(actual, containsString(msg)); } } } }
@Test public void testUrlRewrite() throws Exception { String uri = "http://www.example.com/"; String unproxied = uri; String proxied = "http://shindig.com/gadgets/proxy?url=" + uri; expect(proxyUriManager.make(EasyMock.anyObject(List.class), EasyMock.isNull(Integer.class))) .andReturn(ImmutableList.<Uri>of(Uri.parse(proxied))).anyTimes(); replay(proxyUriManager); // Uris that transistion the page assertUrlRewritten("a", "href", uri, unproxied); assertUrlRewritten("area", "href", uri, unproxied); // Uris that load media assertUrlRewritten("img", "src", uri, proxied); // Uris that have no effect on the document assertUrlRewritten("blockquote", "cite", uri, unproxied); assertUrlRewritten("q", "cite", uri, unproxied); assertUrlRewritten("del", "cite", uri, unproxied); assertUrlRewritten("ins", "cite", uri, unproxied); }
private void testMarkup(String markup, String expected, List<String> msgs) throws GadgetException{ Gadget gadget = makeGadget(); for (GadgetHtmlParser parser : parsers) { MutableContent mc = new MutableContent(parser, markup); rewriter.rewrite(gadget, mc); String actual = mc.getContent(); if (msgs != null) { for (String msg : msgs) { System.out.println("Msg:" + msg); assertThat(actual, containsString(msg)); } } } }
@Test public void testUrlRewrite() throws Exception { String uri = "http://www.example.com/"; String unproxied = uri; String proxied = "http://shindig.com/gadgets/proxy?url=" + uri; expect(proxyUriManager.make(EasyMock.anyObject(List.class), EasyMock.isNull(Integer.class))) .andReturn(ImmutableList.<Uri>of(Uri.parse(proxied))).anyTimes(); replay(proxyUriManager); // Uris that transistion the page assertUrlRewritten("a", "href", uri, unproxied); assertUrlRewritten("area", "href", uri, unproxied); // Uris that load media assertUrlRewritten("img", "src", uri, proxied); // Uris that have no effect on the document assertUrlRewritten("blockquote", "cite", uri, unproxied); assertUrlRewritten("q", "cite", uri, unproxied); assertUrlRewritten("del", "cite", uri, unproxied); assertUrlRewritten("ins", "cite", uri, unproxied); }
private void assertUrlRewritten(String tagName, String attr, String orig, String rewritten) throws Exception { String markUp = "<" + tagName + " " + attr + "=\"" + orig + "\">"; String expected = attr + "=\"" + rewritten + "\""; testMarkup(markUp, expected); }
private void testMarkup(String markup, String expected) throws GadgetException{ testMarkup(markup, expected, null); }
private void testMarkup(String markup, String expected) throws GadgetException{ testMarkup(markup, expected, null); }
@Test public void testErrorDuringRewrite() throws Exception { String markup = "<script>window['x']={}; with(x) {};</script>"; String expected = "<html><head></head><body><ul class=\"gadgets-messages\">"; List<String> messages = ImmutableList.of( ""with" blocks are not allowed"); testMarkup(markup, expected, messages); }
@Test public void testCssExpression() throws Exception { String markup = "<div style='top:expression(alert(0), 0)'>test</div>"; String expected = "<div>test</div>"; List<String> messages = ImmutableList.of( "css property top has bad value: ==>expression(alert(0), 0)"); testMarkup(markup, expected, messages); }
@Test public void testRewrite() throws Exception { String markup = "<script>window['a']=0;</script>"; String expected = "caja___.start"; List<String> messages = ImmutableList.of(); testMarkup(markup, expected, messages); }
@Test public void testRewrite() throws Exception { String markup = "<script>window['a']=0;</script>"; String expected = "caja___.start"; List<String> messages = ImmutableList.of(); testMarkup(markup, expected, messages); }
@Test public void testCssExpression() throws Exception { String markup = "<div style='top:expression(alert(0), 0)'>test</div>"; String expected = "<div>test</div>"; List<String> messages = ImmutableList.of( "css property top has bad value: ==>expression(alert(0), 0)"); testMarkup(markup, expected, messages); }
@Test public void testErrorDuringRewrite() throws Exception { String markup = "<script>window['x']={}; with(x) {};</script>"; String expected = "<html><head></head><body><ul class=\"gadgets-messages\">"; List<String> messages = ImmutableList.of( ""with" blocks are not allowed"); testMarkup(markup, expected, messages); }
public void testIncludedURLRequestMarkedInternal() throws Exception { CacheProvider lru = new LruCacheProvider(3); DefaultHtmlSerializer defaultSerializer = new DefaultHtmlSerializer(); CapturingPipeline pipeline = new CapturingPipeline(); rewriter = new CajaContentRewriter(lru, pipeline, defaultSerializer, proxyUriManager) { @Override protected PluginCompiler makePluginCompiler(PluginMeta m, MessageQueue q) { BuildInfo bi = EasyMock.createNiceMock(BuildInfo.class); expect(bi.getBuildInfo()).andReturn("bi").anyTimes(); expect(bi.getBuildTimestamp()).andReturn("0").anyTimes(); expect(bi.getBuildVersion()).andReturn("0").anyTimes(); expect(bi.getCurrentTime()).andReturn(0L).anyTimes(); replay(bi); return new PluginCompiler(bi, m, q); } }; // we don't really care what the result looks like, we just want to check the issued request String markup = "<script type=\"text/javascript\" src=\"http://www.example.com/scripts/scriptFile.js\"></script>"; String expected = ""; testMarkup( markup, expected ); assertNotNull( pipeline.request ); assertTrue( pipeline.request.isInternalRequest() ); }
public void testIncludedURLRequestMarkedInternal() throws Exception { CacheProvider lru = new LruCacheProvider(3); DefaultHtmlSerializer defaultSerializer = new DefaultHtmlSerializer(); CapturingPipeline pipeline = new CapturingPipeline(); rewriter = new CajaContentRewriter(lru, pipeline, defaultSerializer, proxyUriManager) { @Override protected PluginCompiler makePluginCompiler(PluginMeta m, MessageQueue q) { BuildInfo bi = EasyMock.createNiceMock(BuildInfo.class); expect(bi.getBuildInfo()).andReturn("bi").anyTimes(); expect(bi.getBuildTimestamp()).andReturn("0").anyTimes(); expect(bi.getBuildVersion()).andReturn("0").anyTimes(); expect(bi.getCurrentTime()).andReturn(0L).anyTimes(); replay(bi); return new PluginCompiler(bi, m, q); } }; // we don't really care what the result looks like, we just want to check the issued request String markup = "<script type=\"text/javascript\" src=\"http://www.example.com/scripts/scriptFile.js\"></script>"; String expected = ""; testMarkup( markup, expected ); assertNotNull( pipeline.request ); assertTrue( pipeline.request.isInternalRequest() ); }