public DataLinkInfo createDataLink() { return new DataLinkInfoImpl(); }
public void setContent(String content) { validate(content); this.content = content; }
@Test public void testSetRelativeUrlAbsolutePath() { DataLinkInfoImpl info = new DataLinkInfoImpl(); info.setContent("/foo"); }
@Test public void testSetAbsoluteHttp() { DataLinkInfoImpl info = new DataLinkInfoImpl(); info.setContent("http://example.com/foo"); }
@Test public void testSetAbsoluteHttps() { DataLinkInfoImpl info = new DataLinkInfoImpl(); info.setContent("https://example.com/foo"); }
@Test public void testProxyDataURLBackReference() throws Exception { createAppContext("http://foo.org/geoserver"); DataLinkInfo link = new DataLinkInfoImpl(); link.setContent("/metadata.xml?foo=bar"); String url = ResponseUtils.proxifyDataLink(link, "http://localhost/geoserver"); assertEquals("http://foo.org/geoserver/metadata.xml?foo=bar", url); }
private Object readResolve() { validate(content); return this; }
@Test public void testSetRelativeUrlRelativePath() { DataLinkInfoImpl info = new DataLinkInfoImpl(); info.setContent("foo/bar"); }
@Test public void testDataURLBackReferenceNoProxyBaseUrl() throws Exception { createAppContext(null); DataLinkInfo link = new DataLinkInfoImpl(); link.setContent("/metadata.xml?foo=bar"); String url = ResponseUtils.proxifyDataLink(link, "http://localhost/geoserver"); assertEquals("http://localhost/geoserver/metadata.xml?foo=bar", url); } }
@Override public void validate(IValidatable<String> validatable) { String url = validatable.getValue(); if (url != null) { try { DataLinkInfoImpl.validate(url); } catch (IllegalArgumentException ex) { IValidationError err = new ValidationError("invalidDataLinkURL") .addKey("invalidDataLinkURL") .setVariable("url", url); validatable.error(err); } } } }
@Test public void testSetRelativeUrlRelativeCurrentPath() { DataLinkInfoImpl info = new DataLinkInfoImpl(); info.setContent("./foo"); }
@Test public void testProxyDataURL() throws Exception { createAppContext("http://foo.org/geoserver"); DataLinkInfo link = new DataLinkInfoImpl(); link.setContent("http://bar.com/geoserver/metadata.xml?foo=bar"); String url = ResponseUtils.proxifyDataLink(link, "http://localhost/geoserver"); assertEquals(link.getContent(), url); }
@Test public void testSetAbsoluteFtp() { DataLinkInfoImpl info = new DataLinkInfoImpl(); info.setContent("ftp://example.com/foo"); }
@Test public void testSetRelativeUrlRelativeParentPath() { DataLinkInfoImpl info = new DataLinkInfoImpl(); info.setContent("../foo"); }
@Test public void testNotAURLButStartsOK() { DataLinkInfoImpl info = new DataLinkInfoImpl(); thrown.expect(IllegalArgumentException.class); info.setContent("https://example.com/::^%/[*] FOO ::"); } }
@Test public void testSetNotAURL() { DataLinkInfoImpl info = new DataLinkInfoImpl(); thrown.expect(IllegalArgumentException.class); info.setContent("::^%/[*] FOO ::"); }
@Test public void testSetAbsoluteTelnet() { DataLinkInfoImpl info = new DataLinkInfoImpl(); thrown.expect(IllegalArgumentException.class); info.setContent("telnet:example.com"); }