mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #81 from overleaf/sk-lfs-error-message
Handle Git LFS requests, with error message
This commit is contained in:
commit
1041b8d332
3 changed files with 74 additions and 0 deletions
|
@ -130,6 +130,7 @@ public class GitBridgeServer {
|
|||
HandlerCollection handlers = new HandlerList();
|
||||
handlers.addHandler(new StatusHandler(bridge));
|
||||
handlers.addHandler(new HealthCheckHandler(bridge));
|
||||
handlers.addHandler(new GitLfsHandler(bridge));
|
||||
base.setHandler(handlers);
|
||||
return base;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package uk.ac.ic.wlgitbridge.server;
|
||||
|
||||
import org.eclipse.jetty.server.HttpConnection;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import uk.ac.ic.wlgitbridge.bridge.Bridge;
|
||||
import uk.ac.ic.wlgitbridge.util.Log;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GitLfsHandler extends AbstractHandler {
|
||||
|
||||
private final Bridge bridge;
|
||||
|
||||
public GitLfsHandler(Bridge bridge) {
|
||||
this.bridge = bridge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(
|
||||
String target,
|
||||
Request baseRequest,
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response
|
||||
) throws IOException {
|
||||
String method = baseRequest.getMethod();
|
||||
if (
|
||||
("POST".equals(method))
|
||||
&& target != null
|
||||
&& target.matches("^/[0-9a-z]+\\.git/info/lfs/objects/batch/?$")
|
||||
) {
|
||||
Log.info(method + " <- /<project>.git/info/lfs/objects/batch");
|
||||
response.setContentType("application/vnd.git-lfs+json");
|
||||
response.setStatus(422);
|
||||
response.getWriter().println("{\"message\": \"ERROR: Git LFS is not supported on Overleaf\"}");
|
||||
baseRequest.setHandled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -5,12 +5,18 @@ import org.apache.commons.io.IOUtils;
|
|||
import static org.asynchttpclient.Dsl.*;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.ParseException;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpHead;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.http.ParseException;
|
||||
|
||||
import org.asynchttpclient.*;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.junit.After;
|
||||
|
@ -968,6 +974,27 @@ public class WLGitBridgeIntegrationTest {
|
|||
assertEquals(200, healthCheckResponse.getStatusLine().getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gitLfsBatchEndpoint() throws ClientProtocolException, IOException, ParseException {
|
||||
int gitBridgePort = 33890;
|
||||
int mockServerPort = 3890;
|
||||
server = new MockSnapshotServer(mockServerPort, getResource("/canCloneARepository").toFile());
|
||||
server.start();
|
||||
server.setState(states.get("canCloneARepository").get("state"));
|
||||
wlgb = new GitBridgeApp(new String[] {
|
||||
makeConfigFile(gitBridgePort, mockServerPort)
|
||||
});
|
||||
wlgb.run();
|
||||
HttpClient client = HttpClients.createDefault();
|
||||
String urlBase = "http://127.0.0.1:" + gitBridgePort;
|
||||
HttpPost gitLfsRequest = new HttpPost(urlBase+"/5f2419407929eb0026641967.git/info/lfs/objects/batch");
|
||||
HttpResponse gitLfsResponse = client.execute(gitLfsRequest);
|
||||
assertEquals(422, gitLfsResponse.getStatusLine().getStatusCode());
|
||||
HttpEntity entity = gitLfsResponse.getEntity();
|
||||
String responseString = EntityUtils.toString(entity, "UTF-8");
|
||||
assertTrue(responseString.contains("Git LFS is not supported on Overleaf"));
|
||||
}
|
||||
|
||||
private String makeConfigFile(
|
||||
int port,
|
||||
int apiPort
|
||||
|
|
Loading…
Reference in a new issue