|
|
@ -429,17 +429,7 @@ public class UploadPackTest { |
|
|
|
RefFilter refFilter, ProtocolV2Hook hook, String... inputLines) |
|
|
|
RefFilter refFilter, ProtocolV2Hook hook, String... inputLines) |
|
|
|
throws Exception { |
|
|
|
throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream send = new ByteArrayOutputStream(); |
|
|
|
ByteArrayInputStream send = linesAsInputStream(inputLines); |
|
|
|
PacketLineOut pckOut = new PacketLineOut(send); |
|
|
|
|
|
|
|
for (String line : inputLines) { |
|
|
|
|
|
|
|
if (line == PacketLineIn.END) { |
|
|
|
|
|
|
|
pckOut.end(); |
|
|
|
|
|
|
|
} else if (line == PacketLineIn.DELIM) { |
|
|
|
|
|
|
|
pckOut.writeDelim(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pckOut.writeString(line); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server.getConfig().setString("protocol", null, "version", "2"); |
|
|
|
server.getConfig().setString("protocol", null, "version", "2"); |
|
|
|
UploadPack up = new UploadPack(server); |
|
|
|
UploadPack up = new UploadPack(server); |
|
|
@ -453,11 +443,28 @@ public class UploadPackTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream recv = new ByteArrayOutputStream(); |
|
|
|
ByteArrayOutputStream recv = new ByteArrayOutputStream(); |
|
|
|
up.upload(new ByteArrayInputStream(send.toByteArray()), recv, null); |
|
|
|
up.upload(send, recv, null); |
|
|
|
|
|
|
|
|
|
|
|
return new ByteArrayInputStream(recv.toByteArray()); |
|
|
|
return new ByteArrayInputStream(recv.toByteArray()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static ByteArrayInputStream linesAsInputStream(String... inputLines) |
|
|
|
|
|
|
|
throws IOException { |
|
|
|
|
|
|
|
try (ByteArrayOutputStream send = new ByteArrayOutputStream()) { |
|
|
|
|
|
|
|
PacketLineOut pckOut = new PacketLineOut(send); |
|
|
|
|
|
|
|
for (String line : inputLines) { |
|
|
|
|
|
|
|
if (line == PacketLineIn.END) { |
|
|
|
|
|
|
|
pckOut.end(); |
|
|
|
|
|
|
|
} else if (line == PacketLineIn.DELIM) { |
|
|
|
|
|
|
|
pckOut.writeDelim(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
pckOut.writeString(line); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return new ByteArrayInputStream(send.toByteArray()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
* Invokes UploadPack with protocol v2 and sends it the given lines. |
|
|
|
* Invokes UploadPack with protocol v2 and sends it the given lines. |
|
|
|
* Returns UploadPack's output stream, not including the capability |
|
|
|
* Returns UploadPack's output stream, not including the capability |
|
|
@ -1552,6 +1559,45 @@ public class UploadPackTest { |
|
|
|
assertTrue(client.hasObject(three.toObjectId())); |
|
|
|
assertTrue(client.hasObject(three.toObjectId())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testGetPeerAgentProtocolV0() throws Exception { |
|
|
|
|
|
|
|
RevCommit one = remote.commit().message("1").create(); |
|
|
|
|
|
|
|
remote.update("one", one); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UploadPack up = new UploadPack(server); |
|
|
|
|
|
|
|
ByteArrayInputStream send = linesAsInputStream( |
|
|
|
|
|
|
|
"want " + one.getName() + " agent=JGit-test/1.2.3\n", |
|
|
|
|
|
|
|
PacketLineIn.END, |
|
|
|
|
|
|
|
"have 11cedf1b796d44207da702f7d420684022fc0f09\n", "done\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream recv = new ByteArrayOutputStream(); |
|
|
|
|
|
|
|
up.upload(send, recv, null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(up.getPeerUserAgent(), "JGit-test/1.2.3"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void testGetPeerAgentProtocolV2() throws Exception { |
|
|
|
|
|
|
|
server.getConfig().setString("protocol", null, "version", "2"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RevCommit one = remote.commit().message("1").create(); |
|
|
|
|
|
|
|
remote.update("one", one); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
UploadPack up = new UploadPack(server); |
|
|
|
|
|
|
|
up.setExtraParameters(Sets.of("version=2")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayInputStream send = linesAsInputStream( |
|
|
|
|
|
|
|
"command=fetch\n", "agent=JGit-test/1.2.4\n", |
|
|
|
|
|
|
|
PacketLineIn.DELIM, "want " + one.getName() + "\n", |
|
|
|
|
|
|
|
"have 11cedf1b796d44207da702f7d420684022fc0f09\n", "done\n", |
|
|
|
|
|
|
|
PacketLineIn.END); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteArrayOutputStream recv = new ByteArrayOutputStream(); |
|
|
|
|
|
|
|
up.upload(send, recv, null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(up.getPeerUserAgent(), "JGit-test/1.2.4"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static class RejectAllRefFilter implements RefFilter { |
|
|
|
private static class RejectAllRefFilter implements RefFilter { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Map<String, Ref> filter(Map<String, Ref> refs) { |
|
|
|
public Map<String, Ref> filter(Map<String, Ref> refs) { |
|
|
|