aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2011-05-27 12:04:19 -0700
committerShawn O. Pearce <spearce@spearce.org>2011-05-31 08:58:45 -0700
commit67a1a0993f3969357c554b2030cfd794b3c3af89 (patch)
treec05749de9ac453f37713528a9289c2e6490e72c2 /org.eclipse.jgit.test
parentc1525e2aa5e444a2a234de27d6b7189d5d7f715e (diff)
downloadjgit-67a1a0993f3969357c554b2030cfd794b3c3af89.tar.gz
jgit-67a1a0993f3969357c554b2030cfd794b3c3af89.zip
Ensure the HTTP request is fully consumed
Some servlet containers require the servlet to read the EOF marker from the input stream before a response can be output if the stream is using "Transfer-Encoding: chunked"... which is typical for any sort of large push to a repository over smart HTTP. Ensure the EOF is always read by the PackParser when it is handling the stream, and fail fast if there is more data present than expected since this does indicate a protocol error. Also ensure the EOF is read by UploadPack before it starts to output a partial response using packing progress meters. Change-Id: I131db9dea20b2324cb7c3272a814f21296bc64bd Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
index df89674e6f..719cc66671 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java
@@ -46,7 +46,9 @@
package org.eclipse.jgit.transport;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -54,8 +56,10 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
+import java.text.MessageFormat;
import java.util.zip.Deflater;
+import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Constants;
@@ -69,6 +73,7 @@ import org.eclipse.jgit.storage.file.ObjectDirectoryPackParser;
import org.eclipse.jgit.storage.file.PackFile;
import org.eclipse.jgit.util.NB;
import org.eclipse.jgit.util.TemporaryBuffer;
+import org.eclipse.jgit.util.io.UnionInputStream;
import org.junit.After;
import org.junit.Test;
@@ -177,6 +182,33 @@ public class PackParserTest extends RepositoryTestCase {
p.parse(NullProgressMonitor.INSTANCE);
}
+ @Test
+ public void testPackWithTrailingGarbage() throws Exception {
+ TestRepository d = new TestRepository(db);
+ RevBlob a = d.blob("a");
+
+ TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
+ packHeader(pack, 1);
+ pack.write((Constants.OBJ_REF_DELTA) << 4 | 4);
+ a.copyRawTo(pack);
+ deflate(pack, new byte[] { 0x1, 0x1, 0x1, 'b' });
+ digest(pack);
+
+ PackParser p = index(new UnionInputStream(
+ new ByteArrayInputStream(pack.toByteArray()),
+ new ByteArrayInputStream(new byte[] { 0x7e })));
+ p.setAllowThin(true);
+ p.setCheckEofAfterPackFooter(true);
+ try {
+ p.parse(NullProgressMonitor.INSTANCE);
+ fail("Pack with trailing garbage was accepted");
+ } catch (IOException err) {
+ assertEquals(
+ MessageFormat.format(JGitText.get().expectedEOFReceived, "\\x73"),
+ err.getMessage());
+ }
+ }
+
private void packHeader(TemporaryBuffer.Heap tinyPack, int cnt)
throws IOException {
final byte[] hdr = new byte[8];