From 18a56446cee9fa4a4b3c3fba6a74a23ee260fec8 Mon Sep 17 00:00:00 2001 From: reger Date: Wed, 26 Feb 2014 02:01:40 +0100 Subject: reorg URL test classes add isLocal test with some IPv6 examples - putting in default location and clean old package names - add some valid RFC IPv6 sample urls (which don't pass the isLocal test) --- .../yacy/cora/document/MultiProtocolURITest.java | 34 ------- test/net/yacy/cora/document/id/DigestURLTest.java | 33 +++++++ .../cora/document/id/MultiProtocolURLTest.java | 109 +++++++++++++++++++++ 3 files changed, 142 insertions(+), 34 deletions(-) delete mode 100644 test/net/yacy/cora/document/MultiProtocolURITest.java create mode 100644 test/net/yacy/cora/document/id/DigestURLTest.java create mode 100644 test/net/yacy/cora/document/id/MultiProtocolURLTest.java (limited to 'test/net') diff --git a/test/net/yacy/cora/document/MultiProtocolURITest.java b/test/net/yacy/cora/document/MultiProtocolURITest.java deleted file mode 100644 index ae6cf5ab1..000000000 --- a/test/net/yacy/cora/document/MultiProtocolURITest.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.yacy.cora.document; - -import static org.junit.Assert.*; - -import java.net.MalformedURLException; -import java.util.TreeSet; -import net.yacy.cora.document.id.MultiProtocolURL; - -import org.junit.Test; - - -public class MultiProtocolURITest { - - @Test public void testSessionIdRemoval() throws MalformedURLException { - String[][] testURIs = new String[][] { - // meaning: original uri, stripped version - new String[]{"http://test.de/bla.php?phpsessionid=asdf", "http://test.de/bla.php"}, - new String[]{"http://test.de/bla?phpsessionid=asdf&fdsa=asdf", "http://test.de/bla?fdsa=asdf"}, - new String[]{"http://test.de/bla?asdf=fdsa&phpsessionid=asdf", "http://test.de/bla?asdf=fdsa"}, - new String[]{"http://test.de/bla?asdf=fdsa&phpsessionid=asdf&fdsa=asdf", "http://test.de/bla?asdf=fdsa&fdsa=asdf"}, - }; - TreeSet idNames = new TreeSet(); - idNames.add("phpsessionid"); - - MultiProtocolURL.initSessionIDNames(idNames); - - for (int i=0; i " + resolvedURL); + + } + } + +} diff --git a/test/net/yacy/cora/document/id/MultiProtocolURLTest.java b/test/net/yacy/cora/document/id/MultiProtocolURLTest.java new file mode 100644 index 000000000..09b50c4ac --- /dev/null +++ b/test/net/yacy/cora/document/id/MultiProtocolURLTest.java @@ -0,0 +1,109 @@ +package net.yacy.cora.document.id; + +import static org.junit.Assert.*; + +import java.net.MalformedURLException; +import java.util.LinkedHashMap; +import java.util.TreeSet; + +import org.junit.Test; +//import junit.framework.TestCase; + +public class MultiProtocolURLTest { + + @Test + public void testSessionIdRemoval() throws MalformedURLException { + String[][] testURIs = new String[][]{ + // meaning: original uri, stripped version + new String[]{"http://test.de/bla.php?phpsessionid=asdf", "http://test.de/bla.php"}, + new String[]{"http://test.de/bla?phpsessionid=asdf&fdsa=asdf", "http://test.de/bla?fdsa=asdf"}, + new String[]{"http://test.de/bla?asdf=fdsa&phpsessionid=asdf", "http://test.de/bla?asdf=fdsa"}, + new String[]{"http://test.de/bla?asdf=fdsa&phpsessionid=asdf&fdsa=asdf", "http://test.de/bla?asdf=fdsa&fdsa=asdf"},}; + TreeSet idNames = new TreeSet(); + idNames.add("phpsessionid"); + + MultiProtocolURL.initSessionIDNames(idNames); + + for (int i = 0; i < testURIs.length; i++) { + MultiProtocolURL uri = new MultiProtocolURL(testURIs[i][0]); + + assertEquals(uri.toNormalform(true, true), testURIs[i][1]); + } + } + + @Test + public void testResolveBackpath() { + String[][] testStrings = new String[][]{ + new String[]{"/..home", "/..home"}, + new String[]{"/test/..home/test.html", "/test/..home/test.html"}, + new String[]{"/../", "/../"}, + new String[]{"/..", "/.."}, + new String[]{"/test/..", "/"}, + new String[]{"/test/../", "/"}, + new String[]{"/test/test2/..", "/test"}, + new String[]{"/test/test2/../", "/test/"}, + new String[]{"/test/test2/../hallo", "/test/hallo"}, + new String[]{"/test/test2/../hallo/", "/test/hallo/"}, + new String[]{"/home/..test/../hallo/../", "/home/"} + }; + String testhost = "http://localhost"; + for (int i = 0; i < testStrings.length; i++) { + // desired conversion result + System.out.print("testResolveBackpath: " + testStrings[i][0]); + String shouldBe = testhost + testStrings[i][1]; + + // conversion result + String resolvedURL = ""; + try { + resolvedURL = (new MultiProtocolURL(testhost + testStrings[i][0])).toString(); + } catch (final MalformedURLException ex) { + fail("malformed URL"); + } + // test if equal + assertEquals(shouldBe, resolvedURL); + System.out.println(" -> " + resolvedURL); + + } + } + + /** + * Test of isLocal method, of class MultiProtocolURL. including IPv6 url + * data + * + * @throws java.net.MalformedURLException + */ + @Test + public void testIsLocal() throws MalformedURLException { + LinkedHashMap testurls = new LinkedHashMap(); // + + // valid IPv6 local loopback addresses + testurls.put("http://[0:0:0:0:0:0:0:1]/index.html", Boolean.TRUE); + testurls.put("http://[::1]/index.html", Boolean.TRUE); + + // test urls for issue with IPv6 misinterpretation + testurls.put("http://fcedit.com", Boolean.FALSE); + testurls.put("http://fdedit.com", Boolean.FALSE); + + // valid IPv6 examples taken from http://www.ietf.org/rfc/rfc2732.txt cap 2. + testurls.put("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html", Boolean.FALSE); + testurls.put("http://[1080:0:0:0:8:800:200C:417A]/index.html", Boolean.FALSE); + testurls.put("http://[3ffe:2a00:100:7031::1]", Boolean.FALSE); + testurls.put("http://[1080::8:800:200C:417A]/foo", Boolean.FALSE); + testurls.put("http://[::192.9.5.5]/ipng", Boolean.FALSE); + testurls.put("http://[::FFFF:129.144.52.38]:80/index.html", Boolean.FALSE); + testurls.put("http://[2010:836B:4179::836B:4179]", Boolean.FALSE); + + for (String u : testurls.keySet()) { + + MultiProtocolURL uri = new MultiProtocolURL(u); + boolean result = uri.isLocal(); + + assertEquals(u, testurls.get(u), result); + System.out.println ("testIsLocal: " + u + " -> " + result); + + } + } +} + + + -- cgit v1.2.3