I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit c8866beb authored by mathiasdm's avatar mathiasdm
Browse files

Added tests to fix HTTPTunnelServer header fix.

parent 99ebad30
No related branches found
No related tags found
No related merge requests found
...@@ -141,6 +141,52 @@ ...@@ -141,6 +141,52 @@
splitindex="true" splitindex="true"
windowtitle="I2PTunnel" /> windowtitle="I2PTunnel" />
</target> </target>
<target name="compileTest">
<mkdir dir="./build" />
<mkdir dir="./build/obj" />
<javac srcdir="./src:./test" debug="true" source="1.5" target="1.5" deprecation="on" destdir="./build/obj" >
<compilerarg line="${javac.compilerargs}" />
<classpath>
<pathelement location="../../../core/java/build/i2p.jar" />
<pathelement location="../../ministreaming/java/build/mstreaming.jar" />
</classpath>
</javac>
</target>
<target name="test" depends="clean, compileTest">
<junit printsummary="on" fork="yes">
<classpath>
<pathelement path="${classpath}" />
<pathelement location="./build/obj" />
<pathelement location="../../../core/java/build/i2p.jar" />
</classpath>
<batchtest>
<fileset dir="./test/">
<include name="**/*Test.java" />
</fileset>
</batchtest>
<formatter type="xml"/>
</junit>
<mkdir dir="../../../reports/" />
<mkdir dir="../../../reports/i2ptunnel/" />
<mkdir dir="../../../reports/i2ptunnel/junit/" />
<delete>
<fileset dir="../../../reports/i2ptunnel/junit">
<include name="TEST-*.xml"/>
</fileset>
</delete>
<copy todir="../../../reports/i2ptunnel/junit">
<fileset dir=".">
<include name="TEST-*.xml"/>
</fileset>
</copy>
<delete>
<fileset dir=".">
<include name="TEST-*.xml"/>
</fileset>
</delete>
</target>
<target name="clean"> <target name="clean">
<delete dir="./build" /> <delete dir="./build" />
<delete dir="../jsp/WEB-INF/" /> <delete dir="../jsp/WEB-INF/" />
......
...@@ -418,7 +418,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer { ...@@ -418,7 +418,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
} }
} }
private static Map<String, List<String>> readHeaders(InputStream in, StringBuilder command, String[] skipHeaders, I2PAppContext ctx) throws IOException { protected static Map<String, List<String>> readHeaders(InputStream in, StringBuilder command, String[] skipHeaders, I2PAppContext ctx) throws IOException {
HashMap<String, List<String>> headers = new HashMap<String, List<String>>(); HashMap<String, List<String>> headers = new HashMap<String, List<String>>();
StringBuilder buf = new StringBuilder(128); StringBuilder buf = new StringBuilder(128);
......
package net.i2p.i2ptunnel;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.Map;
import java.util.List;
import junit.framework.TestCase;
public class I2PTunnelHTTPServerTest extends TestCase {
public InputStream fillInputStream(String headers) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(baos));
bw.write(headers);
bw.flush();
byte[] bytes = baos.toByteArray();
return new ByteArrayInputStream(bytes);
}
public void testSimpleHeader() throws IOException {
String headerString = "GET /blah HTTP/1.1\r\n";
headerString += "BLAH: something\r\n";
headerString += "\r\n";
InputStream in = fillInputStream(headerString);
Map<String, List<String>> headers = I2PTunnelHTTPServer.readHeaders(in, new StringBuilder(128), new String[0], null);
assertEquals(headers.size(), 1); //One header
}
public void testDuplicateHeader() throws IOException {
String headerString = "GET /something HTTP/1.1\r\n";
headerString += "someHeader: blabla bla bloooo\r\n";
headerString += "someHeader: oh my, duplication!\r\n";
headerString += "\r\n";
InputStream in = fillInputStream(headerString);
Map<String, List<String>> headers = I2PTunnelHTTPServer.readHeaders(in, new StringBuilder(128), new String[0], null);
assertEquals(headers.size(), 1);
assertEquals(headers.get("someHeader").size(), 2);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment