From 58ed0cb840b29139483ce3b499354a6e5669498b Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 16 Mar 2011 19:19:15 -0700 Subject: smart HTTP: Return errors inside payload When the client is clearly making a smart HTTP request to our smart HTTP server, return any errors like RepositoryNotFoundException or ServiceNotEnabledException inside of the payload as a Git level ERR message, rather than an HTTP error code. This prevents the C Git command line client from retrying a failed "$URL/info/refs?service=git-upload-pack" request without the smart service URL, only to fail again with "403 Forbidden" when the dumb as-is service has been disabled by the server configuration, or is unavailable because the repository is not on the local filesystem. Change-Id: I57e8756d5026e885e0ca615979bfcd729703be6c Signed-off-by: Shawn O. Pearce --- .../jgit/http/test/SmartClientSmartServerTest.java | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'org.eclipse.jgit.http.test/tst') 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 209f161c9b..c3590a44fb 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 @@ -55,6 +55,7 @@ import static org.junit.Assert.fail; import java.io.IOException; import java.io.PrintWriter; +import java.net.URISyntaxException; import java.util.Collections; import java.util.List; import java.util.Map; @@ -73,6 +74,7 @@ import org.eclipse.jetty.servlet.FilterMapping; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jgit.JGitText; +import org.eclipse.jgit.errors.RemoteRepositoryException; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.http.server.GitServlet; @@ -223,6 +225,36 @@ public class SmartClientSmartServerTest extends HttpTestCase { assertEquals("gzip", info.getResponseHeader(HDR_CONTENT_ENCODING)); } + @Test + public void testListRemote_BadName() throws IOException, URISyntaxException { + Repository dst = createBareRepository(); + URIish uri = new URIish(this.remoteURI.toString() + ".invalid"); + Transport t = Transport.open(dst, uri); + try { + try { + t.openFetch(); + fail("fetch connection opened"); + } catch (RemoteRepositoryException notFound) { + assertEquals(uri + ": Git repository not found", + notFound.getMessage()); + } + } finally { + t.close(); + } + + List requests = getRequests(); + assertEquals(1, requests.size()); + + AccessEvent info = requests.get(0); + assertEquals("GET", info.getMethod()); + assertEquals(join(uri, "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)); + } + @Test public void testInitialClone_Small() throws Exception { Repository dst = createBareRepository(); -- cgit v1.2.3