@Test public void csslinkVisitReserved() throws Exception { checkVisitReserved("link", true, "rel", "stylesheet", "type", "text/css"); }
private void checkVisitReserved(String tag, boolean result, String ... attrs) throws Exception { tag = tag.toLowerCase(); assertEquals(result, getVisitReserved(tag, true, true, attrs)); assertEquals(result, getVisitReserved(tag.toUpperCase(), true, true, attrs)); assertFalse(getVisitReserved(tag, false, true, attrs)); assertFalse(getVisitReserved(tag, true, false, attrs)); assertFalse(getVisitReserved(tag, false, false, attrs)); }
Element e1 = elem("script", "src", scriptSrc); Element e2 = elem("script", "src", "^!,,|BLARGH"); Element e3 = elem("IMG", "src", imgSrc); Element e4 = elem("script", "src", " " + scriptSrc + " "); List<Node> nodes = ImmutableList.<Node>of(e1, e2, e3, e4); ProxyUriManager uriManager = createMock(ProxyUriManager.class); expect(uriManager.make(capture(cap), capture(intCap))).andReturn(returned).once(); replay(config, uriManager); Gadget gadget = gadget();
private boolean getVisitReserved(String tag, boolean resUrl, boolean resTag, String ... attrs) throws Exception { // Reserved when lower-case and both URL and Tag reserved. String attrName = ALL_RESOURCES.get(tag.toLowerCase()); attrName = attrName != null ? attrName : "src"; ArrayList <String> attrsList = Lists.newArrayList(attrs); attrsList.add(0, attrName); attrsList.add(1, URL_STRING); attrs = attrsList.toArray(attrs); Node node = elem(tag, attrs); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL(URL_STRING)).andReturn(resUrl).anyTimes(); expect(config.shouldRewriteTag(tag.toLowerCase())).andReturn(resTag).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); return status != VisitStatus.BYPASS; }
Element e1 = elem("script", "src", scriptSrc); Element e2 = elem("script", "src", "^!,,|BLARGH"); Element e3 = elem("IMG", "src", imgSrc); Element e4 = elem("script", "src", " " + scriptSrc + " "); List<Node> nodes = ImmutableList.<Node>of(e1, e2, e3, e4); ProxyUriManager uriManager = createMock(ProxyUriManager.class); expect(uriManager.make(capture(cap), capture(intCap))).andReturn(returned).once(); replay(config, uriManager); Gadget gadget = gadget();
private boolean getVisitReserved(String tag, boolean resUrl, boolean resTag, String ... attrs) throws Exception { // Reserved when lower-case and both URL and Tag reserved. String attrName = ALL_RESOURCES.get(tag.toLowerCase()); attrName = attrName != null ? attrName : "src"; ArrayList <String> attrsList = Lists.newArrayList(attrs); attrsList.add(0, attrName); attrsList.add(1, URL_STRING); attrs = attrsList.toArray(attrs); Node node = elem(tag, attrs); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL(URL_STRING)).andReturn(resUrl).anyTimes(); expect(config.shouldRewriteTag(tag.toLowerCase())).andReturn(resTag).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); return status != VisitStatus.BYPASS; }
@Test public void altlinkVisitReserved() throws Exception { checkVisitReserved("link", false, "rel", "alternate", "hreflang", "el"); }
Element e1 = elem("script", "src", scriptSrc); Element e2 = elem("script", "src", "^!,,|BLARGH"); Element e3 = elem("IMG", "src", imgSrc); Element e4 = elem("script", "src", " " + scriptSrc + " "); List<Node> nodes = ImmutableList.<Node>of(e1, e2, e3, e4); ProxyUriManager uriManager = createMock(ProxyUriManager.class); expect(uriManager.make(capture(cap), capture(intCap))).andReturn(returned).once(); replay(config, uriManager); Gadget gadget = gadget();
private boolean getVisitReserved(String tag, boolean resUrl, boolean resTag, String ... attrs) throws Exception { // Reserved when lower-case and both URL and Tag reserved. String attrName = ALL_RESOURCES.get(tag.toLowerCase()); attrName = attrName != null ? attrName : "src"; ArrayList <String> attrsList = Lists.newArrayList(attrs); attrsList.add(0, attrName); attrsList.add(1, URL_STRING); attrs = attrsList.toArray(attrs); Node node = elem(tag, attrs); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL(URL_STRING)).andReturn(resUrl).anyTimes(); expect(config.shouldRewriteTag(tag.toLowerCase())).andReturn(resTag).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); return status != VisitStatus.BYPASS; }
private void checkVisitReserved(String tag, boolean result, String ... attrs) throws Exception { tag = tag.toLowerCase(); assertEquals(result, getVisitReserved(tag, true, true, attrs)); assertEquals(result, getVisitReserved(tag.toUpperCase(), true, true, attrs)); assertFalse(getVisitReserved(tag, false, true, attrs)); assertFalse(getVisitReserved(tag, true, false, attrs)); assertFalse(getVisitReserved(tag, false, false, attrs)); }
@Test public void imgVisitReserved() throws Exception { checkVisitReserved("img", true); }
@Test public void imgWithEmptySrc() throws Exception { Node node = elem("img", "src", ""); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL("")).andReturn(true).anyTimes(); expect(config.shouldRewriteTag("img")).andReturn(true).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); assertEquals("Empty attribute should not be rewritten", VisitStatus.BYPASS, status); }
private void checkVisitReserved(String tag, boolean result, String ... attrs) throws Exception { tag = tag.toLowerCase(); assertEquals(result, getVisitReserved(tag, true, true, attrs)); assertEquals(result, getVisitReserved(tag.toUpperCase(), true, true, attrs)); assertFalse(getVisitReserved(tag, false, true, attrs)); assertFalse(getVisitReserved(tag, true, false, attrs)); assertFalse(getVisitReserved(tag, false, false, attrs)); }
@Test public void linkWithNoTypeVisitReserved() throws Exception { checkVisitReserved("link", false, "rel", "stylesheet"); }
@Test public void imgWithEmptySrc() throws Exception { Node node = elem("img", "src", ""); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL("")).andReturn(true).anyTimes(); expect(config.shouldRewriteTag("img")).andReturn(true).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); assertEquals("Empty attribute should not be rewritten", VisitStatus.BYPASS, status); }
@Test public void bodyVisitReserved() throws Exception { checkVisitReserved("body", true); }
@Test public void imgWithEmptySrc() throws Exception { Node node = elem("img", "src", ""); ContentRewriterFeature.Config config = createMock(ContentRewriterFeature.Config.class); expect(config.shouldRewriteURL("")).andReturn(true).anyTimes(); expect(config.shouldRewriteTag("img")).andReturn(true).anyTimes(); replay(config); ProxyingVisitor rewriter = new ProxyingVisitor(config, null, ProxyingVisitor.Tags.SCRIPT, ProxyingVisitor.Tags.STYLESHEET, ProxyingVisitor.Tags.EMBEDDED_IMAGES); VisitStatus status = rewriter.visit(null, node); verify(config); assertEquals("Empty attribute should not be rewritten", VisitStatus.BYPASS, status); }
@Test public void scriptVisitReserved() throws Exception { checkVisitReserved("script", true); }
@Test public void inputVisitReserved() throws Exception { checkVisitReserved("input", true); }
@Test public void inputVisitReserved() throws Exception { checkVisitReserved("input", true); }