summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.test/tst
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2020-08-02 19:22:05 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2021-01-01 21:22:30 +0100
commit0853a2410f22c8bd97a179dec14e3c083a27abbb (patch)
tree9a32987a83f24e2f750aace815751ca4f956a228 /org.eclipse.jgit.http.test/tst
parent0f442d70836ee292ed916605448f806cc7d1fe78 (diff)
downloadjgit-0853a2410f22c8bd97a179dec14e3c083a27abbb.tar.gz
jgit-0853a2410f22c8bd97a179dec14e3c083a27abbb.zip
Client-side protocol V2 support for fetching
Make all transports request protocol V2 when fetching. Depending on the transport, set the GIT_PROTOCOL environment variable (file and ssh), pass the Git-Protocol header (http), or set the hidden "\0version=2\0" (git anon). We'll fall back to V0 if the server doesn't reply with a version 2 answer. A user can control which protocol the client requests via the git config protocol.version; if not set, JGit requests protocol V2 for fetching. Pushing always uses protocol V0 still. In the API, there is only a new Transport.openFetch() version that takes a collection of RefSpecs plus additional patterns to construct the Ref prefixes for the "ls-refs" command in protocol V2. If none are given, the server will still advertise all refs, even in protocol V2. BasePackConnection.readAdvertisedRefs() handles falling back to protocol V0. It newly returns true if V0 was used and the advertised refs were read, and false if V2 is used and an explicit "ls-refs" is needed. (This can't be done transparently inside readAdvertisedRefs() because a "stateless RPC" transport like TransportHttp may need to open a new connection for writing.) BasePackFetchConnection implements the changes needed for the protocol V2 "fetch" command (stateless protocol, simplified ACK handling, delimiters, section headers). In TransportHttp, change readSmartHeaders() to also recognize the "version 2" packet line as a valid smart server indication. Adapt tests, and run all the HTTP tests not only with both HTTP connection factories (JDK and Apache HttpClient) but also with both protocol V0 and V2. The SSH tests are much slower and much more focused on the SSH protocol and SSH key handling. Factor out two very simple cloning and pulling tests and make those run with protocol V2. Bug: 553083 Change-Id: I357c7f5daa7efb2872f1c64ee6f6d54229031ae1 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.http.test/tst')
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AllProtocolsHttpTestCase.java99
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java4
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java11
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerSslTest.java23
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java256
5 files changed, 304 insertions, 89 deletions
diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AllProtocolsHttpTestCase.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AllProtocolsHttpTestCase.java
new file mode 100644
index 0000000000..c6931ad5b9
--- /dev/null
+++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/AllProtocolsHttpTestCase.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2020, Thomas Wolf <thomas.wolf@paranor.ch> and others
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+package org.eclipse.jgit.http.test;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.jgit.junit.http.HttpTestCase;
+import org.eclipse.jgit.transport.HttpTransport;
+import org.eclipse.jgit.transport.http.HttpConnectionFactory;
+import org.eclipse.jgit.transport.http.JDKHttpConnectionFactory;
+import org.eclipse.jgit.transport.http.apache.HttpClientConnectionFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Abstract test base class for running HTTP-related tests with all connection
+ * factories provided in JGit and with both protocol V0 and V2.
+ */
+@Ignore
+@RunWith(Parameterized.class)
+public abstract class AllProtocolsHttpTestCase extends HttpTestCase {
+
+ protected static class TestParameters {
+
+ public final HttpConnectionFactory factory;
+
+ public final boolean enableProtocolV2;
+
+ public TestParameters(HttpConnectionFactory factory,
+ boolean enableProtocolV2) {
+ this.factory = factory;
+ this.enableProtocolV2 = enableProtocolV2;
+ }
+
+ @Override
+ public String toString() {
+ return factory.toString() + " protocol "
+ + (enableProtocolV2 ? "V2" : "V0");
+ }
+ }
+
+ @Parameters(name = "{0}")
+ public static Collection<TestParameters> data() {
+ // run all tests with both connection factories we have
+ HttpConnectionFactory[] factories = new HttpConnectionFactory[] {
+ new JDKHttpConnectionFactory() {
+
+ @Override
+ public String toString() {
+ return this.getClass().getSuperclass().getName();
+ }
+ }, new HttpClientConnectionFactory() {
+
+ @Override
+ public String toString() {
+ return this.getClass().getSuperclass().getName();
+ }
+ } };
+ List<TestParameters> result = new ArrayList<>();
+ for (HttpConnectionFactory factory : factories) {
+ result.add(new TestParameters(factory, false));
+ result.add(new TestParameters(factory, true));
+ }
+ return result;
+ }
+
+ protected final boolean enableProtocolV2;
+
+ protected AllProtocolsHttpTestCase(TestParameters params) {
+ HttpTransport.setConnectionFactory(params.factory);
+ enableProtocolV2 = params.enableProtocolV2;
+ }
+
+ private static HttpConnectionFactory originalFactory;
+
+ @BeforeClass
+ public static void saveConnectionFactory() {
+ originalFactory = HttpTransport.getConnectionFactory();
+ }
+
+ @AfterClass
+ public static void restoreConnectionFactory() {
+ HttpTransport.setConnectionFactory(originalFactory);
+ }
+
+}
diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java
index 6da5f86b3e..8b28c4292c 100644
--- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java
+++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientDumbServerTest.java
@@ -35,6 +35,7 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.FetchConnection;
@@ -77,6 +78,9 @@ public class DumbClientDumbServerTest extends AllFactoriesHttpTestCase {
remoteRepository = src.getRepository();
remoteURI = toURIish(app, srcGit.getName());
+ StoredConfig cfg = remoteRepository.getConfig();
+ cfg.setInt("protocol", null, "version", 0);
+ cfg.save();
A_txt = src.blob("A");
A = src.commit().add("A_txt", A_txt).create();
diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java
index ccde1fe55c..986b5ca92b 100644
--- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java
+++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DumbClientSmartServerTest.java
@@ -35,6 +35,7 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.FetchConnection;
@@ -42,11 +43,10 @@ import org.eclipse.jgit.transport.HttpTransport;
import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.TransportHttp;
import org.eclipse.jgit.transport.URIish;
-import org.eclipse.jgit.transport.http.HttpConnectionFactory;
import org.junit.Before;
import org.junit.Test;
-public class DumbClientSmartServerTest extends AllFactoriesHttpTestCase {
+public class DumbClientSmartServerTest extends AllProtocolsHttpTestCase {
private Repository remoteRepository;
private URIish remoteURI;
@@ -55,8 +55,8 @@ public class DumbClientSmartServerTest extends AllFactoriesHttpTestCase {
private RevCommit A, B;
- public DumbClientSmartServerTest(HttpConnectionFactory cf) {
- super(cf);
+ public DumbClientSmartServerTest(TestParameters params) {
+ super(params);
}
@Override
@@ -76,6 +76,9 @@ public class DumbClientSmartServerTest extends AllFactoriesHttpTestCase {
remoteRepository = src.getRepository();
remoteURI = toURIish(app, srcName);
+ StoredConfig cfg = remoteRepository.getConfig();
+ cfg.setInt("protocol", null, "version", enableProtocolV2 ? 2 : 0);
+ cfg.save();
A_txt = src.blob("A");
A = src.commit().add("A_txt", A_txt).create();
diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerSslTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerSslTest.java
index 597fb2e507..7bc50cad89 100644
--- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerSslTest.java
+++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerSslTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 Thomas Wolf <thomas.wolf@paranor.ch> and others
+ * Copyright (C) 2017, 2020 Thomas Wolf <thomas.wolf@paranor.ch> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -41,6 +41,7 @@ import org.eclipse.jgit.junit.http.AppServer;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.Repository;
+import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.CredentialItem;
@@ -48,7 +49,6 @@ import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.Transport;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
-import org.eclipse.jgit.transport.http.HttpConnectionFactory;
import org.eclipse.jgit.util.HttpSupport;
import org.junit.Before;
import org.junit.Test;
@@ -56,7 +56,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
-public class SmartClientSmartServerSslTest extends AllFactoriesHttpTestCase {
+public class SmartClientSmartServerSslTest extends AllProtocolsHttpTestCase {
// We run these tests with a server on localhost with a self-signed
// certificate. We don't do authentication tests here, so there's no need
@@ -112,8 +112,8 @@ public class SmartClientSmartServerSslTest extends AllFactoriesHttpTestCase {
private RevCommit A, B;
- public SmartClientSmartServerSslTest(HttpConnectionFactory cf) {
- super(cf);
+ public SmartClientSmartServerSslTest(TestParameters params) {
+ super(params);
}
@Override
@@ -128,10 +128,11 @@ public class SmartClientSmartServerSslTest extends AllFactoriesHttpTestCase {
final TestRepository<Repository> src = createTestRepository();
final String srcName = src.getRepository().getDirectory().getName();
- src.getRepository()
- .getConfig()
- .setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
- ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true);
+ StoredConfig cfg = src.getRepository().getConfig();
+ cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
+ ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true);
+ cfg.setInt("protocol", null, "version", enableProtocolV2 ? 2 : 0);
+ cfg.save();
GitServlet gs = new GitServlet();
@@ -238,7 +239,7 @@ public class SmartClientSmartServerSslTest extends AllFactoriesHttpTestCase {
fsck(dst, B);
List<AccessEvent> requests = getRequests();
- assertEquals(2, requests.size());
+ assertEquals(enableProtocolV2 ? 3 : 2, requests.size());
}
@Test
@@ -256,7 +257,7 @@ public class SmartClientSmartServerSslTest extends AllFactoriesHttpTestCase {
fsck(dst, B);
List<AccessEvent> requests = getRequests();
- assertEquals(3, requests.size());
+ assertEquals(enableProtocolV2 ? 4 : 3, requests.size());
}
@Test
diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
index 8d1870a87e..f3e56f85d3 100644
--- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
+++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010, 2017 Google Inc. and others
+ * Copyright (C) 2010, 2020 Google Inc. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -86,13 +86,12 @@ import org.eclipse.jgit.transport.TransportHttp;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.transport.UploadPack;
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider;
-import org.eclipse.jgit.transport.http.HttpConnectionFactory;
import org.eclipse.jgit.util.HttpSupport;
import org.eclipse.jgit.util.SystemReader;
import org.junit.Before;
import org.junit.Test;
-public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
+public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase {
private static final String HDR_TRANSFER_ENCODING = "Transfer-Encoding";
private AdvertiseRefsHook advertiseRefsHook;
@@ -120,8 +119,8 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
private RevCommit A, B, unreachableCommit;
- public SmartClientSmartServerTest(HttpConnectionFactory cf) {
- super(cf);
+ public SmartClientSmartServerTest(TestParameters params) {
+ super(params);
}
@Override
@@ -131,10 +130,11 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
final TestRepository<Repository> src = createTestRepository();
final String srcName = src.getRepository().getDirectory().getName();
- src.getRepository()
- .getConfig()
- .setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
- ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true);
+ StoredConfig cfg = src.getRepository().getConfig();
+ cfg.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
+ ConfigConstants.CONFIG_KEY_LOGALLREFUPDATES, true);
+ cfg.setInt("protocol", null, "version", enableProtocolV2 ? 2 : 0);
+ cfg.save();
GitServlet gs = new GitServlet();
gs.setUploadPackFactory((HttpServletRequest req, Repository db) -> {
@@ -448,7 +448,7 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
assertEquals(B, map.get(Constants.HEAD).getObjectId());
List<AccessEvent> requests = getRequests();
- assertEquals(1, requests.size());
+ assertEquals(enableProtocolV2 ? 2 : 1, requests.size());
AccessEvent info = requests.get(0);
assertEquals("GET", info.getMethod());
@@ -458,7 +458,22 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
assertEquals(200, info.getStatus());
assertEquals("application/x-git-upload-pack-advertisement", info
.getResponseHeader(HDR_CONTENT_TYPE));
- assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ if (!enableProtocolV2) {
+ assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ } else {
+ AccessEvent lsRefs = requests.get(1);
+ assertEquals("POST", lsRefs.getMethod());
+ assertEquals(join(remoteURI, "git-upload-pack"), lsRefs.getPath());
+ assertEquals(0, lsRefs.getParameters().size());
+ assertNotNull("has content-length",
+ lsRefs.getRequestHeader(HDR_CONTENT_LENGTH));
+ assertNull("not chunked",
+ lsRefs.getRequestHeader(HDR_TRANSFER_ENCODING));
+ assertEquals("version=2", lsRefs.getRequestHeader("Git-Protocol"));
+ assertEquals(200, lsRefs.getStatus());
+ assertEquals("application/x-git-upload-pack-result",
+ lsRefs.getResponseHeader(HDR_CONTENT_TYPE));
+ }
}
@Test
@@ -576,9 +591,10 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
}
List<AccessEvent> requests = getRequests();
- assertEquals(2, requests.size());
+ assertEquals(enableProtocolV2 ? 3 : 2, requests.size());
- AccessEvent info = requests.get(0);
+ int requestNumber = 0;
+ AccessEvent info = requests.get(requestNumber++);
assertEquals("GET", info.getMethod());
assertEquals(join(remoteURI, "info/refs"), info.getPath());
assertEquals(1, info.getParameters().size());
@@ -586,9 +602,24 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
assertEquals(200, info.getStatus());
assertEquals("application/x-git-upload-pack-advertisement", info
.getResponseHeader(HDR_CONTENT_TYPE));
- assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ if (!enableProtocolV2) {
+ assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ } else {
+ AccessEvent lsRefs = requests.get(requestNumber++);
+ assertEquals("POST", lsRefs.getMethod());
+ assertEquals(join(remoteURI, "git-upload-pack"), lsRefs.getPath());
+ assertEquals(0, lsRefs.getParameters().size());
+ assertNotNull("has content-length",
+ lsRefs.getRequestHeader(HDR_CONTENT_LENGTH));
+ assertNull("not chunked",
+ lsRefs.getRequestHeader(HDR_TRANSFER_ENCODING));
+ assertEquals("version=2", lsRefs.getRequestHeader("Git-Protocol"));
+ assertEquals(200, lsRefs.getStatus());
+ assertEquals("application/x-git-upload-pack-result",
+ lsRefs.getResponseHeader(HDR_CONTENT_TYPE));
+ }
- AccessEvent service = requests.get(1);
+ AccessEvent service = requests.get(requestNumber);
assertEquals("POST", service.getMethod());
assertEquals(join(remoteURI, "git-upload-pack"), service.getPath());
assertEquals(0, service.getParameters().size());
@@ -628,7 +659,8 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
}
List<AccessEvent> requests = getRequests();
- assertEquals(2 + nofRedirects, requests.size());
+ assertEquals((enableProtocolV2 ? 3 : 2) + nofRedirects,
+ requests.size());
int n = 0;
while (n < nofRedirects) {
@@ -644,7 +676,22 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
assertEquals(200, info.getStatus());
assertEquals("application/x-git-upload-pack-advertisement",
info.getResponseHeader(HDR_CONTENT_TYPE));
- assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ if (!enableProtocolV2) {
+ assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ } else {
+ AccessEvent lsRefs = requests.get(n++);
+ assertEquals("POST", lsRefs.getMethod());
+ assertEquals(join(remoteURI, "git-upload-pack"), lsRefs.getPath());
+ assertEquals(0, lsRefs.getParameters().size());
+ assertNotNull("has content-length",
+ lsRefs.getRequestHeader(HDR_CONTENT_LENGTH));
+ assertNull("not chunked",
+ lsRefs.getRequestHeader(HDR_TRANSFER_ENCODING));
+ assertEquals("version=2", lsRefs.getRequestHeader("Git-Protocol"));
+ assertEquals(200, lsRefs.getStatus());
+ assertEquals("application/x-git-upload-pack-result",
+ lsRefs.getResponseHeader(HDR_CONTENT_TYPE));
+ }
AccessEvent service = requests.get(n++);
assertEquals("POST", service.getMethod());
@@ -756,7 +803,7 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
}
List<AccessEvent> requests = getRequests();
- assertEquals(3, requests.size());
+ assertEquals(enableProtocolV2 ? 4 : 3, requests.size());
AccessEvent info = requests.get(0);
assertEquals("GET", info.getMethod());
@@ -766,24 +813,27 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
assertEquals(200, info.getStatus());
assertEquals("application/x-git-upload-pack-advertisement",
info.getResponseHeader(HDR_CONTENT_TYPE));
- assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ if (!enableProtocolV2) {
+ assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ }
AccessEvent redirect = requests.get(1);
assertEquals("POST", redirect.getMethod());
assertEquals(301, redirect.getStatus());
- AccessEvent service = requests.get(2);
- assertEquals("POST", service.getMethod());
- assertEquals(join(remoteURI, "git-upload-pack"), service.getPath());
- assertEquals(0, service.getParameters().size());
- assertNotNull("has content-length",
- service.getRequestHeader(HDR_CONTENT_LENGTH));
- assertNull("not chunked",
- service.getRequestHeader(HDR_TRANSFER_ENCODING));
-
- assertEquals(200, service.getStatus());
- assertEquals("application/x-git-upload-pack-result",
- service.getResponseHeader(HDR_CONTENT_TYPE));
+ for (int i = 2; i < requests.size(); i++) {
+ AccessEvent service = requests.get(i);
+ assertEquals("POST", service.getMethod());
+ assertEquals(join(remoteURI, "git-upload-pack"), service.getPath());
+ assertEquals(0, service.getParameters().size());
+ assertNotNull("has content-length",
+ service.getRequestHeader(HDR_CONTENT_LENGTH));
+ assertNull("not chunked",
+ service.getRequestHeader(HDR_TRANSFER_ENCODING));
+ assertEquals(200, service.getStatus());
+ assertEquals("application/x-git-upload-pack-result",
+ service.getResponseHeader(HDR_CONTENT_TYPE));
+ }
}
@Test
@@ -830,7 +880,7 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
}
List<AccessEvent> requests = getRequests();
- assertEquals(3, requests.size());
+ assertEquals(enableProtocolV2 ? 4 : 3, requests.size());
AccessEvent info = requests.get(0);
assertEquals("GET", info.getMethod());
@@ -844,20 +894,24 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
assertEquals(200, info.getStatus());
assertEquals("application/x-git-upload-pack-advertisement",
info.getResponseHeader(HDR_CONTENT_TYPE));
- assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
-
- AccessEvent service = requests.get(2);
- assertEquals("POST", service.getMethod());
- assertEquals(join(authURI, "git-upload-pack"), service.getPath());
- assertEquals(0, service.getParameters().size());
- assertNotNull("has content-length",
- service.getRequestHeader(HDR_CONTENT_LENGTH));
- assertNull("not chunked",
- service.getRequestHeader(HDR_TRANSFER_ENCODING));
+ if (!enableProtocolV2) {
+ assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ }
- assertEquals(200, service.getStatus());
- assertEquals("application/x-git-upload-pack-result",
- service.getResponseHeader(HDR_CONTENT_TYPE));
+ for (int i = 2; i < requests.size(); i++) {
+ AccessEvent service = requests.get(i);
+ assertEquals("POST", service.getMethod());
+ assertEquals(join(authURI, "git-upload-pack"), service.getPath());
+ assertEquals(0, service.getParameters().size());
+ assertNotNull("has content-length",
+ service.getRequestHeader(HDR_CONTENT_LENGTH));
+ assertNull("not chunked",
+ service.getRequestHeader(HDR_TRANSFER_ENCODING));
+
+ assertEquals(200, service.getStatus());
+ assertEquals("application/x-git-upload-pack-result",
+ service.getResponseHeader(HDR_CONTENT_TYPE));
+ }
}
@Test
@@ -937,19 +991,20 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
}
List<AccessEvent> requests = getRequests();
- assertEquals(4, requests.size());
+ assertEquals(enableProtocolV2 ? 5 : 4, requests.size());
- AccessEvent redirect = requests.get(0);
+ int requestNumber = 0;
+ AccessEvent redirect = requests.get(requestNumber++);
assertEquals("GET", redirect.getMethod());
assertEquals(join(cloneFrom, "info/refs"), redirect.getPath());
assertEquals(301, redirect.getStatus());
- AccessEvent info = requests.get(1);
+ AccessEvent info = requests.get(requestNumber++);
assertEquals("GET", info.getMethod());
assertEquals(join(authURI, "info/refs"), info.getPath());
assertEquals(401, info.getStatus());
- info = requests.get(2);
+ info = requests.get(requestNumber++);
assertEquals("GET", info.getMethod());
assertEquals(join(authURI, "info/refs"), info.getPath());
assertEquals(1, info.getParameters().size());
@@ -957,9 +1012,24 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
assertEquals(200, info.getStatus());
assertEquals("application/x-git-upload-pack-advertisement",
info.getResponseHeader(HDR_CONTENT_TYPE));
- assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ if (!enableProtocolV2) {
+ assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ } else {
+ AccessEvent lsRefs = requests.get(requestNumber++);
+ assertEquals("POST", lsRefs.getMethod());
+ assertEquals(join(authURI, "git-upload-pack"), lsRefs.getPath());
+ assertEquals(0, lsRefs.getParameters().size());
+ assertNotNull("has content-length",
+ lsRefs.getRequestHeader(HDR_CONTENT_LENGTH));
+ assertNull("not chunked",
+ lsRefs.getRequestHeader(HDR_TRANSFER_ENCODING));
+ assertEquals("version=2", lsRefs.getRequestHeader("Git-Protocol"));
+ assertEquals(200, lsRefs.getStatus());
+ assertEquals("application/x-git-upload-pack-result",
+ lsRefs.getResponseHeader(HDR_CONTENT_TYPE));
+ }
- AccessEvent service = requests.get(3);
+ AccessEvent service = requests.get(requestNumber);
assertEquals("POST", service.getMethod());
assertEquals(join(authURI, "git-upload-pack"), service.getPath());
assertEquals(0, service.getParameters().size());
@@ -987,7 +1057,7 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
}
List<AccessEvent> requests = getRequests();
- assertEquals(3, requests.size());
+ assertEquals(enableProtocolV2 ? 4 : 3, requests.size());
AccessEvent info = requests.get(0);
assertEquals("GET", info.getMethod());
@@ -997,25 +1067,30 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
assertEquals(200, info.getStatus());
assertEquals("application/x-git-upload-pack-advertisement",
info.getResponseHeader(HDR_CONTENT_TYPE));
- assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ if (!enableProtocolV2) {
+ assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ }
AccessEvent service = requests.get(1);
assertEquals("POST", service.getMethod());
assertEquals(join(authOnPostURI, "git-upload-pack"), service.getPath());
assertEquals(401, service.getStatus());
- service = requests.get(2);
- assertEquals("POST", service.getMethod());
- assertEquals(join(authOnPostURI, "git-upload-pack"), service.getPath());
- assertEquals(0, service.getParameters().size());
- assertNotNull("has content-length",
- service.getRequestHeader(HDR_CONTENT_LENGTH));
- assertNull("not chunked",
- service.getRequestHeader(HDR_TRANSFER_ENCODING));
-
- assertEquals(200, service.getStatus());
- assertEquals("application/x-git-upload-pack-result",
- service.getResponseHeader(HDR_CONTENT_TYPE));
+ for (int i = 2; i < requests.size(); i++) {
+ service = requests.get(i);
+ assertEquals("POST", service.getMethod());
+ assertEquals(join(authOnPostURI, "git-upload-pack"),
+ service.getPath());
+ assertEquals(0, service.getParameters().size());
+ assertNotNull("has content-length",
+ service.getRequestHeader(HDR_CONTENT_LENGTH));
+ assertNull("not chunked",
+ service.getRequestHeader(HDR_TRANSFER_ENCODING));
+
+ assertEquals(200, service.getStatus());
+ assertEquals("application/x-git-upload-pack-result",
+ service.getResponseHeader(HDR_CONTENT_TYPE));
+ }
}
@Test
@@ -1052,9 +1127,11 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
List<AccessEvent> requests = getRequests();
requests.removeAll(cloneRequests);
- assertEquals(2, requests.size());
- AccessEvent info = requests.get(0);
+ assertEquals(enableProtocolV2 ? 3 : 2, requests.size());
+
+ int requestNumber = 0;
+ AccessEvent info = requests.get(requestNumber++);
assertEquals("GET", info.getMethod());
assertEquals(join(remoteURI, "info/refs"), info.getPath());
assertEquals(1, info.getParameters().size());
@@ -1063,9 +1140,24 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
assertEquals("application/x-git-upload-pack-advertisement",
info.getResponseHeader(HDR_CONTENT_TYPE));
+ if (enableProtocolV2) {
+ AccessEvent lsRefs = requests.get(requestNumber++);
+ assertEquals("POST", lsRefs.getMethod());
+ assertEquals(join(remoteURI, "git-upload-pack"), lsRefs.getPath());
+ assertEquals(0, lsRefs.getParameters().size());
+ assertNotNull("has content-length",
+ lsRefs.getRequestHeader(HDR_CONTENT_LENGTH));
+ assertNull("not chunked",
+ lsRefs.getRequestHeader(HDR_TRANSFER_ENCODING));
+ assertEquals("version=2", lsRefs.getRequestHeader("Git-Protocol"));
+ assertEquals(200, lsRefs.getStatus());
+ assertEquals("application/x-git-upload-pack-result",
+ lsRefs.getResponseHeader(HDR_CONTENT_TYPE));
+ }
+
// We should have needed one request to perform the fetch.
//
- AccessEvent service = requests.get(1);
+ AccessEvent service = requests.get(requestNumber);
assertEquals("POST", service.getMethod());
assertEquals(join(remoteURI, "git-upload-pack"), service.getPath());
assertEquals(0, service.getParameters().size());
@@ -1116,9 +1208,10 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
List<AccessEvent> requests = getRequests();
requests.removeAll(cloneRequests);
- assertEquals(3, requests.size());
+ assertEquals(enableProtocolV2 ? 4 : 3, requests.size());
- AccessEvent info = requests.get(0);
+ int requestNumber = 0;
+ AccessEvent info = requests.get(requestNumber++);
assertEquals("GET", info.getMethod());
assertEquals(join(remoteURI, "info/refs"), info.getPath());
assertEquals(1, info.getParameters().size());
@@ -1127,10 +1220,25 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
assertEquals("application/x-git-upload-pack-advertisement", info
.getResponseHeader(HDR_CONTENT_TYPE));
+ if (enableProtocolV2) {
+ AccessEvent lsRefs = requests.get(requestNumber++);
+ assertEquals("POST", lsRefs.getMethod());
+ assertEquals(join(remoteURI, "git-upload-pack"), lsRefs.getPath());
+ assertEquals(0, lsRefs.getParameters().size());
+ assertNotNull("has content-length",
+ lsRefs.getRequestHeader(HDR_CONTENT_LENGTH));
+ assertNull("not chunked",
+ lsRefs.getRequestHeader(HDR_TRANSFER_ENCODING));
+ assertEquals("version=2", lsRefs.getRequestHeader("Git-Protocol"));
+ assertEquals(200, lsRefs.getStatus());
+ assertEquals("application/x-git-upload-pack-result",
+ lsRefs.getResponseHeader(HDR_CONTENT_TYPE));
+ }
+
// We should have needed two requests to perform the fetch
// due to the high number of local unknown commits.
//
- AccessEvent service = requests.get(1);
+ AccessEvent service = requests.get(requestNumber++);
assertEquals("POST", service.getMethod());
assertEquals(join(remoteURI, "git-upload-pack"), service.getPath());
assertEquals(0, service.getParameters().size());
@@ -1143,7 +1251,7 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
assertEquals("application/x-git-upload-pack-result", service
.getResponseHeader(HDR_CONTENT_TYPE));
- service = requests.get(2);
+ service = requests.get(requestNumber);
assertEquals("POST", service.getMethod());
assertEquals(join(remoteURI, "git-upload-pack"), service.getPath());
assertEquals(0, service.getParameters().size());
@@ -1211,7 +1319,8 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
Collections.<ObjectId> emptySet());
fail("Server accepted want " + id.name());
} catch (TransportException err) {
- assertEquals("want " + id.name() + " not valid", err.getMessage());
+ assertTrue(err.getMessage()
+ .contains("want " + id.name() + " not valid"));
}
}
@@ -1429,5 +1538,4 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
cfg.setBoolean("http", null, "receivepack", true);
cfg.save();
}
-
}