Explorar el Código

Report all 4xx from write-latex API as MissingRepositoryException

Michael Walker hace 8 años
padre
commit
82c0873743

+ 6 - 8
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/snapshot/base/Request.java

@@ -70,14 +70,12 @@ public abstract class Request<T extends Result> {
             Throwable cause = e.getCause();
             if (cause instanceof HttpResponseException) {
                 HttpResponseException httpCause = (HttpResponseException) cause;
-                switch (httpCause.getStatusCode()) {
-                    case HttpServletResponse.SC_UNAUTHORIZED:
-                    case HttpServletResponse.SC_FORBIDDEN:
-                        throw new ForbiddenException();
-                    case HttpServletResponse.SC_GONE:
-                        throw new MissingRepositoryException();
-                    default:
-                        break;
+                int sc = httpCause.getStatusCode();
+                if (sc == HttpServletResponse.SC_UNAUTHORIZED || sc == HttpServletResponse.SC_FORBIDDEN) {
+                    throw new ForbiddenException();
+                }
+                if (sc >= 400 && sc < 500) {
+                    throw new MissingRepositoryException();
                 }
                 throw new FailedConnectionException(cause);
             } else {

+ 21 - 0
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeIntegrationTest.java

@@ -48,6 +48,9 @@ public class WLGitBridgeIntegrationTest {
         put("cannotCloneADisabledProject", new HashMap<String, SnapshotAPIState>() {{
             put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/cannotCloneADisabledProject/state/state.json")).build());
         }});
+        put("cannotCloneAMissingProject", new HashMap<String, SnapshotAPIState>() {{
+            put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/cannotCloneAMissingProject/state/state.json")).build());
+        }});
         put("canPullAModifiedTexFile", new HashMap<String, SnapshotAPIState>() {{
             put("base", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/base/state.json")).build());
             put("withModifiedTexFile", new SnapshotAPIStateBuilder(getResourceAsStream("/canPullAModifiedTexFile/withModifiedTexFile/state.json")).build());
@@ -748,6 +751,24 @@ public class WLGitBridgeIntegrationTest {
         assertNotEquals(0, gitProcess.waitFor());
     }
 
+    @Test
+    public void cannotCloneAMissingProject() throws IOException, GitAPIException, InterruptedException {
+        int gitBridgePort = 33880;
+        int mockServerPort = 3880;
+
+        MockSnapshotServer server = new MockSnapshotServer(mockServerPort, getResource("/cannotCloneAMissingProject").toFile());
+        server.start();
+        server.setState(states.get("cannotCloneAMissingProject").get("state"));
+        GitBridgeApp wlgb = new GitBridgeApp(new String[] {
+            makeConfigFile(gitBridgePort, mockServerPort)
+        });
+
+        wlgb.run();
+        Process gitProcess = runtime.exec("git clone http://127.0.0.1:" + gitBridgePort + "/testproj.git", null, dir);
+        wlgb.stop();
+        assertNotEquals(0, gitProcess.waitFor());
+    }
+
     private String makeConfigFile(
             int port,
             int apiPort

+ 18 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/cannotCloneAMissingProject/state/state.json

@@ -0,0 +1,18 @@
+[
+    {
+	"project": "missing",
+	"getDoc": {
+            "error": 404,
+            "versionID": 1,
+            "createdAt": "2018-02-06T13:29:00Z",
+            "email": "michael.walker@overleaf.com",
+            "name": "msw"
+	},
+	"getSavedVers": [],
+	"getForVers": [],
+	"push": "success",
+	"postback": {
+	    "type": "outOfDate"
+	}
+    }
+]