summaryrefslogtreecommitdiff
path: root/test/net
diff options
context:
space:
mode:
authorreger <reger18@arcor.de>2014-02-26 02:01:40 +0100
committerreger <reger18@arcor.de>2014-02-26 02:01:40 +0100
commit18a56446cee9fa4a4b3c3fba6a74a23ee260fec8 (patch)
tree653a7c6f869ad033cb68aa71b3c4a136e0937723 /test/net
parentf1a395ed461c70231efc10ddd62a80fdbe9e6da8 (diff)
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)
Diffstat (limited to 'test/net')
-rw-r--r--test/net/yacy/cora/document/MultiProtocolURITest.java34
-rw-r--r--test/net/yacy/cora/document/id/DigestURLTest.java33
-rw-r--r--test/net/yacy/cora/document/id/MultiProtocolURLTest.java109
3 files changed, 142 insertions, 34 deletions
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<String> idNames = new TreeSet<String>();
- 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]);
- }
- }
-}
-
diff --git a/test/net/yacy/cora/document/id/DigestURLTest.java b/test/net/yacy/cora/document/id/DigestURLTest.java
new file mode 100644
index 000000000..a5dc2dc94
--- /dev/null
+++ b/test/net/yacy/cora/document/id/DigestURLTest.java
@@ -0,0 +1,33 @@
+package net.yacy.cora.document.id;
+
+import java.net.MalformedURLException;
+
+import junit.framework.TestCase;
+
+public class DigestURLTest extends TestCase {
+
+
+ public void testIdentPort() throws MalformedURLException {
+ String[][] testStrings = new String[][]{
+ new String[]{"http://www.yacy.net:", "http://www.yacy.net/"},
+ new String[]{"http://www.yacy.net:-1", "http://www.yacy.net/"},
+ new String[]{"http://www.yacy.net:/", "http://www.yacy.net/"},
+ new String[]{"http://www.yacy.net: /", "http://www.yacy.net/"}
+ };
+
+ for (int i = 0; i < testStrings.length; i++) {
+ // desired conversion result
+ System.out.print("testIdentPort: " + testStrings[i][0]);
+ String shouldBe = testStrings[i][1];
+
+ // conversion result
+ String resolvedURL = (new DigestURL(testStrings[i][0])).toString();
+
+ // test if equal
+ assertEquals(shouldBe, resolvedURL);
+ System.out.println(" -> " + 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<String> idNames = new TreeSet<String>();
+ 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<String,Boolean> testurls = new LinkedHashMap<String,Boolean>(); // <url,expected_result>
+
+ // 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);
+
+ }
+ }
+}
+
+
+