summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.http.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2022-05-09 22:09:05 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2022-05-09 22:09:05 +0200
commite1efd4dd1fd4d2683c3340d005d8a965f987b00b (patch)
tree3d11bbcab23b8af1936eb4148471c9b0fe8fc8e9 /org.eclipse.jgit.http.test
parentb969c44c00895a4ffe532502be535aee4d5d2444 (diff)
parent8984e1f663b5b58f74cd0381043133f0059e004d (diff)
downloadjgit-e1efd4dd1fd4d2683c3340d005d8a965f987b00b.tar.gz
jgit-e1efd4dd1fd4d2683c3340d005d8a965f987b00b.zip
Merge branch 'stable-6.1' into stable-6.2
* stable-6.1: HTTP Smart: set correct HTTP status on error Change-Id: I792d6cdfe9e76a3d2e6d1e01ec1dc96805ed2900
Diffstat (limited to 'org.eclipse.jgit.http.test')
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/HttpClientTests.java6
-rw-r--r--org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/SmartClientSmartServerTest.java27
2 files changed, 24 insertions, 9 deletions
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 df093c185b..3438c52c8d 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
@@ -23,6 +23,7 @@ import java.io.File;
import java.io.OutputStream;
import java.net.URI;
import java.net.URL;
+import java.text.MessageFormat;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
@@ -308,7 +309,10 @@ public class HttpClientTests extends AllFactoriesHttpTestCase {
fail("connection opened even though service disabled");
} catch (TransportException err) {
String exp = smartAuthNoneURI + ": "
- + JGitText.get().serviceNotEnabledNoName;
+ + MessageFormat.format(
+ JGitText.get().serviceNotPermitted,
+ smartAuthNoneURI.toString() + "/",
+ "git-upload-pack");
assertEquals(exp, err.getMessage());
}
}
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 887e970a0c..8f3888e4d5 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
@@ -57,7 +57,7 @@ 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.NoRemoteRepositoryException;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.errors.UnsupportedCredentialItem;
import org.eclipse.jgit.http.server.GitServlet;
@@ -496,8 +496,9 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase {
try {
t.openFetch();
fail("fetch connection opened");
- } catch (RemoteRepositoryException notFound) {
- assertEquals(uri + ": Git repository not found",
+ } catch (NoRemoteRepositoryException notFound) {
+ assertEquals(uri + ": " + uri
+ + "/info/refs?service=git-upload-pack not found: Not Found",
notFound.getMessage());
}
}
@@ -510,7 +511,7 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase {
assertEquals(join(uri, "info/refs"), info.getPath());
assertEquals(1, info.getParameters().size());
assertEquals("git-upload-pack", info.getParameter("service"));
- assertEquals(200, info.getStatus());
+ assertEquals(404, info.getStatus());
assertEquals("application/x-git-upload-pack-advertisement",
info.getResponseHeader(HDR_CONTENT_TYPE));
}
@@ -536,8 +537,9 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase {
Collections.singletonList(
new RefSpec(unreachableCommit.name()))));
assertTrue(e.getMessage().contains(
- "want " + unreachableCommit.name() + " not valid"));
+ "Bad Request"));
}
+ assertLastRequestStatusCode(400);
}
@Test
@@ -558,8 +560,9 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase {
() -> t.fetch(NullProgressMonitor.INSTANCE,
Collections.singletonList(new RefSpec(A.name()))));
assertTrue(
- e.getMessage().contains("want " + A.name() + " not valid"));
+ e.getMessage().contains("Bad Request"));
}
+ assertLastRequestStatusCode(400);
}
@Test
@@ -916,6 +919,7 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase {
} catch (TransportException e) {
assertTrue(e.getMessage().contains("301"));
}
+ assertLastRequestStatusCode(301);
}
@Test
@@ -934,6 +938,7 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase {
assertTrue(
e.getMessage().contains("http.followRedirects is false"));
}
+ assertLastRequestStatusCode(301);
}
private void assertFetchRequests(List<AccessEvent> requests, int index) {
@@ -1605,8 +1610,9 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase {
fail("Server accepted want " + id.name());
} catch (TransportException err) {
assertTrue(err.getMessage()
- .contains("want " + id.name() + " not valid"));
+ .contains("Bad Request"));
}
+ assertLastRequestStatusCode(400);
}
@Test
@@ -1650,7 +1656,7 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase {
fail("Successfully served ref with value " + c.getRef(master));
} catch (TransportException err) {
assertTrue("Unexpected exception message " + err.getMessage(),
- err.getMessage().contains("Internal server error"));
+ err.getMessage().contains("Server Error"));
}
} finally {
noRefServer.tearDown();
@@ -1821,6 +1827,11 @@ public class SmartClientSmartServerTest extends AllProtocolsHttpTestCase {
.getResponseHeader(HDR_CONTENT_TYPE));
}
+ private void assertLastRequestStatusCode(int statusCode) {
+ List<AccessEvent> requests = getRequests();
+ assertEquals(statusCode, requests.get(requests.size() - 1).getStatus());
+ }
+
private void enableReceivePack() throws IOException {
final StoredConfig cfg = remoteRepository.getConfig();
cfg.setBoolean("http", null, "receivepack", true);