summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-02-25 10:29:07 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2021-02-28 00:58:04 +0100
commitf6597971991e3350df568b0cde05c014dcd69c47 (patch)
treecb61592af3f53da45174beed517b3284d7bd55c6 /org.eclipse.jgit.http.test
parent286ad23cb56ffeac77d4bfd03be575358fd5217c (diff)
parent789c0479a9294417db0375cce9f1949fe9052d8c (diff)
downloadjgit-f6597971991e3350df568b0cde05c014dcd69c47.tar.gz
jgit-f6597971991e3350df568b0cde05c014dcd69c47.zip
Merge branch 'master' into next
* master: (143 commits) Prepare 5.11.0-SNAPSHOT builds JGit v5.11.0.202102240950-m3 [releng] japicmp: update last release version IgnoreNode: include path to file for invalid .gitignore patterns FastIgnoreRule: include bad pattern in log message init: add config option to set default for the initial branch name init: allow specifying the initial branch name for the new repository Fail clone if initial branch doesn't exist in remote repository GPG: fix reading unprotected old-format secret keys Update Orbit to S20210216215844 Add missing bazel dependency for o.e.j.gpg.bc.test GPG: handle extended private key format dfs: handle short copies [GPG] Provide a factory for the BouncyCastleGpgSigner Fix boxing warnings GPG: compute the keygrip to find a secret key GPG signature verification via BouncyCastle Post commit hook failure should not cause commit failure Allow to define additional Hook classes outside JGit GitHook: use default charset for output and error streams ... Change-Id: I689f4070e79f4a0ac1c02b35698ccaab68ad2f34
Diffstat (limited to 'org.eclipse.jgit.http.test')
-rw-r--r--org.eclipse.jgit.http.test/.settings/org.eclipse.jdt.core.prefs4
-rw-r--r--org.eclipse.jgit.http.test/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.jgit.http.test/build.properties2
-rw-r--r--org.eclipse.jgit.http.test/src/org/eclipse/jgit/http/test/RefsUnreadableInMemoryRepository.java11
-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/HttpClientTests.java23
-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.java556
10 files changed, 631 insertions, 105 deletions
diff --git a/org.eclipse.jgit.http.test/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jgit.http.test/.settings/org.eclipse.jdt.core.prefs
index 3dd5840397..b853c6a7ed 100644
--- a/org.eclipse.jgit.http.test/.settings/org.eclipse.jdt.core.prefs
+++ b/org.eclipse.jgit.http.test/.settings/org.eclipse.jdt.core.prefs
@@ -51,8 +51,8 @@ org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=error
org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=protected
-org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=return_tag
-org.eclipse.jdt.core.compiler.problem.missingJavadocTags=error
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=no_tag
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private
diff --git a/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF
index a63ebdaebf..c085e7eff9 100644
--- a/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF
@@ -12,7 +12,7 @@ Import-Package: javax.servlet;version="[2.5.0,3.2.0)",
org.apache.commons.codec;version="[1.6.0,2.0.0)",
org.apache.commons.codec.binary;version="[1.6.0,2.0.0)",
org.apache.http;version="[4.3.0,5.0.0)",
- org.apache.http.client;version="[4.3.0,5.0.0)",
+ org.apache.http.client;version="[4.4.0,5.0.0)",
org.apache.http.message;version="[4.3.0,5.0.0)",
org.eclipse.jetty.continuation;version="[9.4.5,10.0.0)",
org.eclipse.jetty.http;version="[9.4.5,10.0.0)",
@@ -28,6 +28,7 @@ Import-Package: javax.servlet;version="[2.5.0,3.2.0)",
org.eclipse.jetty.util.log;version="[9.4.5,10.0.0)",
org.eclipse.jetty.util.security;version="[9.4.5,10.0.0)",
org.eclipse.jetty.util.thread;version="[9.4.5,10.0.0)",
+ org.eclipse.jgit.api;version="[6.0.0,6.1.0)",
org.eclipse.jgit.errors;version="[6.0.0,6.1.0)",
org.eclipse.jgit.http.server;version="[6.0.0,6.1.0)",
org.eclipse.jgit.http.server.glue;version="[6.0.0,6.1.0)",
diff --git a/org.eclipse.jgit.http.test/build.properties b/org.eclipse.jgit.http.test/build.properties
index e8bacac9ac..a909f1301f 100644
--- a/org.eclipse.jgit.http.test/build.properties
+++ b/org.eclipse.jgit.http.test/build.properties
@@ -4,3 +4,5 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.properties
+additional.bundles = org.apache.log4j,\
+ org.slf4j.binding.log4j12
diff --git a/org.eclipse.jgit.http.test/src/org/eclipse/jgit/http/test/RefsUnreadableInMemoryRepository.java b/org.eclipse.jgit.http.test/src/org/eclipse/jgit/http/test/RefsUnreadableInMemoryRepository.java
index 80cbe8738c..4167b038e1 100644
--- a/org.eclipse.jgit.http.test/src/org/eclipse/jgit/http/test/RefsUnreadableInMemoryRepository.java
+++ b/org.eclipse.jgit.http.test/src/org/eclipse/jgit/http/test/RefsUnreadableInMemoryRepository.java
@@ -85,6 +85,17 @@ class RefsUnreadableInMemoryRepository extends InMemoryRepository {
/** {@inheritDoc} */
@Override
+ public List<Ref> getRefsByPrefixWithExclusions(String include, Set<String> excludes)
+ throws IOException {
+ if (failing) {
+ throw new IOException("disk failed, no refs found");
+ }
+
+ return super.getRefsByPrefixWithExclusions(include, excludes);
+ }
+
+ /** {@inheritDoc} */
+ @Override
public Set<Ref> getTipsWithSha1(ObjectId id) throws IOException {
if (failing) {
throw new IOException("disk failed, no refs found");
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/HttpClientTests.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
index 96657761cf..df093c185b 100644
--- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
+++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java
@@ -324,7 +324,22 @@ public class HttpClientTests extends AllFactoriesHttpTestCase {
}
@Test
- public void testHttpClientWantsV2ButServerNotConfigured() throws Exception {
+ public void testHttpClientWantsV2AndServerNotConfigured() throws Exception {
+ String url = smartAuthNoneURI.toString() + "/info/refs?service=git-upload-pack";
+ HttpConnection c = HttpTransport.getConnectionFactory()
+ .create(new URL(url));
+ c.setRequestMethod("GET");
+ c.setRequestProperty("Git-Protocol", "version=2");
+ assertEquals(200, c.getResponseCode());
+
+ PacketLineIn pckIn = new PacketLineIn(c.getInputStream());
+ assertThat(pckIn.readString(), is("version 2"));
+ }
+
+ @Test
+ public void testHttpServerConfiguredToV0() throws Exception {
+ remoteRepository.getRepository().getConfig().setInt(
+ "protocol", null, "version", 0);
String url = smartAuthNoneURI.toString() + "/info/refs?service=git-upload-pack";
HttpConnection c = HttpTransport.getConnectionFactory()
.create(new URL(url));
@@ -342,9 +357,6 @@ public class HttpClientTests extends AllFactoriesHttpTestCase {
@Test
public void testV2HttpFirstResponse() throws Exception {
- remoteRepository.getRepository().getConfig().setInt(
- "protocol", null, "version", 2);
-
String url = smartAuthNoneURI.toString() + "/info/refs?service=git-upload-pack";
HttpConnection c = HttpTransport.getConnectionFactory()
.create(new URL(url));
@@ -364,9 +376,6 @@ public class HttpClientTests extends AllFactoriesHttpTestCase {
@Test
public void testV2HttpSubsequentResponse() throws Exception {
- remoteRepository.getRepository().getConfig().setInt(
- "protocol", null, "version", 2);
-
String url = smartAuthNoneURI.toString() + "/git-upload-pack";
HttpConnection c = HttpTransport.getConnectionFactory()
.create(new URL(url));
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..887e970a0c 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
@@ -22,10 +22,17 @@ import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.io.Writer;
+import java.net.Proxy;
import java.net.URI;
import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.text.MessageFormat;
import java.util.Collections;
import java.util.EnumSet;
@@ -48,6 +55,8 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.TransportConfigCallback;
import org.eclipse.jgit.errors.RemoteRepositoryException;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.errors.UnsupportedCredentialItem;
@@ -70,6 +79,7 @@ import org.eclipse.jgit.lib.ReflogEntry;
import org.eclipse.jgit.lib.ReflogReader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.lib.TextProgressMonitor;
import org.eclipse.jgit.revwalk.RevBlob;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
@@ -86,13 +96,14 @@ 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.HttpConnection;
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 +131,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 +142,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 +460,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 +470,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 +603,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 +614,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());
@@ -602,6 +645,63 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
.getResponseHeader(HDR_CONTENT_TYPE));
}
+ @Test
+ public void test_CloneWithCustomFactory() throws Exception {
+ HttpConnectionFactory globalFactory = HttpTransport
+ .getConnectionFactory();
+ HttpConnectionFactory failingConnectionFactory = new HttpConnectionFactory() {
+
+ @Override
+ public HttpConnection create(URL url) throws IOException {
+ throw new IOException("Should not be reached");
+ }
+
+ @Override
+ public HttpConnection create(URL url, Proxy proxy)
+ throws IOException {
+ throw new IOException("Should not be reached");
+ }
+ };
+ HttpTransport.setConnectionFactory(failingConnectionFactory);
+ try {
+ File tmp = createTempDirectory("cloneViaApi");
+ boolean[] localFactoryUsed = { false };
+ TransportConfigCallback callback = new TransportConfigCallback() {
+
+ @Override
+ public void configure(Transport transport) {
+ if (transport instanceof TransportHttp) {
+ ((TransportHttp) transport).setHttpConnectionFactory(
+ new HttpConnectionFactory() {
+
+ @Override
+ public HttpConnection create(URL url)
+ throws IOException {
+ localFactoryUsed[0] = true;
+ return globalFactory.create(url);
+ }
+
+ @Override
+ public HttpConnection create(URL url,
+ Proxy proxy) throws IOException {
+ localFactoryUsed[0] = true;
+ return globalFactory.create(url, proxy);
+ }
+ });
+ }
+ }
+ };
+ try (Git git = Git.cloneRepository().setDirectory(tmp)
+ .setTransportConfigCallback(callback)
+ .setURI(remoteURI.toPrivateString()).call()) {
+ assertTrue("Should have used the local HttpConnectionFactory",
+ localFactoryUsed[0]);
+ }
+ } finally {
+ HttpTransport.setConnectionFactory(globalFactory);
+ }
+ }
+
private void initialClone_Redirect(int nofRedirects, int code)
throws Exception {
initialClone_Redirect(nofRedirects, code, false);
@@ -628,7 +728,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 +745,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 +872,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 +882,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
@@ -817,6 +936,35 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
}
}
+ private void assertFetchRequests(List<AccessEvent> requests, int index) {
+ AccessEvent info = requests.get(index++);
+ assertEquals("GET", info.getMethod());
+ assertEquals(join(authURI, "info/refs"), info.getPath());
+ assertEquals(1, info.getParameters().size());
+ assertEquals("git-upload-pack", info.getParameter("service"));
+ assertEquals(200, info.getStatus());
+ assertEquals("application/x-git-upload-pack-advertisement",
+ info.getResponseHeader(HDR_CONTENT_TYPE));
+ if (!enableProtocolV2) {
+ assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ }
+
+ for (int i = index; 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
public void testInitialClone_WithAuthentication() throws Exception {
try (Repository dst = createBareRepository();
@@ -830,34 +978,167 @@ 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());
assertEquals(401, info.getStatus());
- info = requests.get(1);
+ assertFetchRequests(requests, 1);
+ }
+
+ @Test
+ public void testInitialClone_WithPreAuthentication() throws Exception {
+ try (Repository dst = createBareRepository();
+ Transport t = Transport.open(dst, authURI)) {
+ assertFalse(dst.getObjectDatabase().has(A_txt));
+ ((TransportHttp) t).setPreemptiveBasicAuthentication(
+ AppServer.username, AppServer.password);
+ t.fetch(NullProgressMonitor.INSTANCE, mirror(master));
+ assertTrue(dst.getObjectDatabase().has(A_txt));
+ assertEquals(B, dst.exactRef(master).getObjectId());
+ fsck(dst, B);
+ }
+
+ List<AccessEvent> requests = getRequests();
+ assertEquals(enableProtocolV2 ? 3 : 2, requests.size());
+
+ assertFetchRequests(requests, 0);
+ }
+
+ @Test
+ public void testInitialClone_WithPreAuthenticationCleared()
+ throws Exception {
+ try (Repository dst = createBareRepository();
+ Transport t = Transport.open(dst, authURI)) {
+ assertFalse(dst.getObjectDatabase().has(A_txt));
+ ((TransportHttp) t).setPreemptiveBasicAuthentication(
+ AppServer.username, AppServer.password);
+ ((TransportHttp) t).setPreemptiveBasicAuthentication(null, null);
+ t.setCredentialsProvider(testCredentials);
+ t.fetch(NullProgressMonitor.INSTANCE, mirror(master));
+ assertTrue(dst.getObjectDatabase().has(A_txt));
+ assertEquals(B, dst.exactRef(master).getObjectId());
+ fsck(dst, B);
+ }
+
+ List<AccessEvent> requests = getRequests();
+ assertEquals(enableProtocolV2 ? 4 : 3, requests.size());
+
+ AccessEvent info = requests.get(0);
assertEquals("GET", info.getMethod());
- assertEquals(join(authURI, "info/refs"), info.getPath());
- assertEquals(1, info.getParameters().size());
- assertEquals("git-upload-pack", info.getParameter("service"));
- assertEquals(200, info.getStatus());
- assertEquals("application/x-git-upload-pack-advertisement",
- info.getResponseHeader(HDR_CONTENT_TYPE));
- assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING));
+ assertEquals(401, info.getStatus());
- 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));
+ assertFetchRequests(requests, 1);
+ }
- assertEquals(200, service.getStatus());
- assertEquals("application/x-git-upload-pack-result",
- service.getResponseHeader(HDR_CONTENT_TYPE));
+ @Test
+ public void testInitialClone_PreAuthenticationTooLate() throws Exception {
+ try (Repository dst = createBareRepository();
+ Transport t = Transport.open(dst, authURI)) {
+ assertFalse(dst.getObjectDatabase().has(A_txt));
+ ((TransportHttp) t).setPreemptiveBasicAuthentication(
+ AppServer.username, AppServer.password);
+ t.fetch(NullProgressMonitor.INSTANCE, mirror(master));
+ assertTrue(dst.getObjectDatabase().has(A_txt));
+ assertEquals(B, dst.exactRef(master).getObjectId());
+ fsck(dst, B);
+ List<AccessEvent> requests = getRequests();
+ assertEquals(enableProtocolV2 ? 3 : 2, requests.size());
+ assertFetchRequests(requests, 0);
+ assertThrows(IllegalStateException.class,
+ () -> ((TransportHttp) t).setPreemptiveBasicAuthentication(
+ AppServer.username, AppServer.password));
+ assertThrows(IllegalStateException.class, () -> ((TransportHttp) t)
+ .setPreemptiveBasicAuthentication(null, null));
+ }
+ }
+
+ @Test
+ public void testInitialClone_WithWrongPreAuthenticationAndCredentialProvider()
+ throws Exception {
+ try (Repository dst = createBareRepository();
+ Transport t = Transport.open(dst, authURI)) {
+ assertFalse(dst.getObjectDatabase().has(A_txt));
+ ((TransportHttp) t).setPreemptiveBasicAuthentication(
+ AppServer.username, AppServer.password + 'x');
+ t.setCredentialsProvider(testCredentials);
+ t.fetch(NullProgressMonitor.INSTANCE, mirror(master));
+ assertTrue(dst.getObjectDatabase().has(A_txt));
+ assertEquals(B, dst.exactRef(master).getObjectId());
+ fsck(dst, B);
+ }
+
+ List<AccessEvent> requests = getRequests();
+ assertEquals(enableProtocolV2 ? 4 : 3, requests.size());
+
+ AccessEvent info = requests.get(0);
+ assertEquals("GET", info.getMethod());
+ assertEquals(401, info.getStatus());
+
+ assertFetchRequests(requests, 1);
+ }
+
+ @Test
+ public void testInitialClone_WithWrongPreAuthentication() throws Exception {
+ try (Repository dst = createBareRepository();
+ Transport t = Transport.open(dst, authURI)) {
+ assertFalse(dst.getObjectDatabase().has(A_txt));
+ ((TransportHttp) t).setPreemptiveBasicAuthentication(
+ AppServer.username, AppServer.password + 'x');
+ TransportException e = assertThrows(TransportException.class,
+ () -> t.fetch(NullProgressMonitor.INSTANCE,
+ mirror(master)));
+ String msg = e.getMessage();
+ assertTrue("Unexpected exception message: " + msg,
+ msg.contains("no CredentialsProvider"));
+ }
+ List<AccessEvent> requests = getRequests();
+ assertEquals(1, requests.size());
+
+ AccessEvent info = requests.get(0);
+ assertEquals("GET", info.getMethod());
+ assertEquals(401, info.getStatus());
+ }
+
+ @Test
+ public void testInitialClone_WithUserInfo() throws Exception {
+ URIish withUserInfo = authURI.setUser(AppServer.username)
+ .setPass(AppServer.password);
+ try (Repository dst = createBareRepository();
+ Transport t = Transport.open(dst, withUserInfo)) {
+ assertFalse(dst.getObjectDatabase().has(A_txt));
+ t.fetch(NullProgressMonitor.INSTANCE, mirror(master));
+ assertTrue(dst.getObjectDatabase().has(A_txt));
+ assertEquals(B, dst.exactRef(master).getObjectId());
+ fsck(dst, B);
+ }
+
+ List<AccessEvent> requests = getRequests();
+ assertEquals(enableProtocolV2 ? 3 : 2, requests.size());
+
+ assertFetchRequests(requests, 0);
+ }
+
+ @Test
+ public void testInitialClone_PreAuthOverridesUserInfo() throws Exception {
+ URIish withUserInfo = authURI.setUser(AppServer.username)
+ .setPass(AppServer.password + 'x');
+ try (Repository dst = createBareRepository();
+ Transport t = Transport.open(dst, withUserInfo)) {
+ assertFalse(dst.getObjectDatabase().has(A_txt));
+ ((TransportHttp) t).setPreemptiveBasicAuthentication(
+ AppServer.username, AppServer.password);
+ t.fetch(NullProgressMonitor.INSTANCE, mirror(master));
+ assertTrue(dst.getObjectDatabase().has(A_txt));
+ assertEquals(B, dst.exactRef(master).getObjectId());
+ fsck(dst, B);
+ }
+
+ List<AccessEvent> requests = getRequests();
+ assertEquals(enableProtocolV2 ? 3 : 2, requests.size());
+
+ assertFetchRequests(requests, 0);
}
@Test
@@ -937,19 +1218,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 +1239,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 +1284,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 +1294,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 +1354,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 +1367,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 +1435,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 +1447,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 +1478,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());
@@ -1158,6 +1493,64 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
}
@Test
+ public void testFetch_MaxHavesCutoffAfterAckOnly() throws Exception {
+ // Bootstrap by doing the clone.
+ //
+ TestRepository dst = createTestRepository();
+ try (Transport t = Transport.open(dst.getRepository(), remoteURI)) {
+ t.fetch(NullProgressMonitor.INSTANCE, mirror(master));
+ }
+ assertEquals(B, dst.getRepository().exactRef(master).getObjectId());
+
+ // Force enough into the local client that enumeration will
+ // need more than MAX_HAVES (256) haves to be sent. The server
+ // doesn't know any of these, so it will never ACK. The client
+ // should keep going.
+ //
+ // If it does, client and server will find a common commit, and
+ // the pack file will contain exactly the one commit object Z
+ // we create on the remote, which we can test for via the progress
+ // monitor, which should have something like
+ // "Receiving objects: 100% (1/1)". If the client sends a "done"
+ // too early, the server will send more objects, and we'll have
+ // a line like "Receiving objects: 100% (8/8)".
+ TestRepository.BranchBuilder b = dst.branch(master);
+ // The client will send 32 + 64 + 128 + 256 + 512 haves. Only the
+ // last one will be a common commit. If the cutoff kicks in too
+ // early (after 480), we'll get too many objects in the fetch.
+ for (int i = 0; i < 992; i++)
+ b.commit().tick(3600 /* 1 hour */).message("c" + i).create();
+
+ // Create a new commit on the remote.
+ //
+ RevCommit Z;
+ try (TestRepository<Repository> tr = new TestRepository<>(
+ remoteRepository)) {
+ b = tr.branch(master);
+ Z = b.commit().message("Z").create();
+ }
+
+ // Now incrementally update.
+ //
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ Writer writer = new OutputStreamWriter(buffer, StandardCharsets.UTF_8);
+ TextProgressMonitor monitor = new TextProgressMonitor(writer);
+ try (Transport t = Transport.open(dst.getRepository(), remoteURI)) {
+ t.fetch(monitor, mirror(master));
+ }
+ assertEquals(Z, dst.getRepository().exactRef(master).getObjectId());
+
+ String progressMessages = new String(buffer.toByteArray(),
+ StandardCharsets.UTF_8);
+ Pattern expected = Pattern
+ .compile("Receiving objects:\\s+100% \\(1/1\\)\n");
+ if (!expected.matcher(progressMessages).find()) {
+ System.out.println(progressMessages);
+ fail("Expected only one object to be sent");
+ }
+ }
+
+ @Test
public void testInitialClone_BrokenServer() throws Exception {
try (Repository dst = createBareRepository();
Transport t = Transport.open(dst, brokenURI)) {
@@ -1211,7 +1604,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"));
}
}
@@ -1224,6 +1618,8 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
new DfsRepositoryDescription(repoName));
final TestRepository<Repository> repo = new TestRepository<>(
badRefsRepo);
+ badRefsRepo.getConfig().setInt("protocol", null, "version",
+ enableProtocolV2 ? 2 : 0);
ServletContextHandler app = noRefServer.addContext("/git");
GitServlet gs = new GitServlet();
@@ -1253,7 +1649,8 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
Collections.<ObjectId> emptySet());
fail("Successfully served ref with value " + c.getRef(master));
} catch (TransportException err) {
- assertEquals("Internal server error", err.getMessage());
+ assertTrue("Unexpected exception message " + err.getMessage(),
+ err.getMessage().contains("Internal server error"));
}
} finally {
noRefServer.tearDown();
@@ -1429,5 +1826,4 @@ public class SmartClientSmartServerTest extends AllFactoriesHttpTestCase {
cfg.setBoolean("http", null, "receivepack", true);
cfg.save();
}
-
}