Просмотр исходного кода

Merge pull request #53 from overleaf/sk-refuse-v1-ids

Refuse to process project-ids that look like they come from v1
Shane Kilkelly 7 лет назад
Родитель
Сommit
6d9e8d38e9

+ 18 - 0
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/git/handler/WLRepositoryResolver.java

@@ -18,6 +18,7 @@ import uk.ac.ic.wlgitbridge.util.Util;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.Optional;
 import java.util.Optional;
 
 
 /**
 /**
@@ -82,6 +83,23 @@ public class WLRepositoryResolver
              ServiceNotAuthorizedException,
              ServiceNotAuthorizedException,
              ServiceMayNotContinueException {
              ServiceMayNotContinueException {
         Log.info("[{}] Request to open git repo", name);
         Log.info("[{}] Request to open git repo", name);
+        // Reject v1 ids, the request will be rejected by v1 anyway
+        if (name.matches("^[0-9]+[bcdfghjklmnpqrstvwxyz]{6,12}$") && !name.matches("^[0-9a-f]{24}$")) {
+            Log.info("[{}] Request for v1 project, refusing", name);
+            throw new ServiceMayNotContinueException(
+                String.join("\n", Arrays.asList(
+                    "This project has not yet been moved into the new version",
+                    "of Overleaf. You will need to move it in order to continue working on it.",
+                    "Please visit this project online on www.overleaf.com to do this.",
+                    "",
+                    "You can find the new git remote url by selecting \"Git\" from",
+                    "the left sidebar in the project view.",
+                    "",
+                    "If this is unexpected, please contact us at support@overleaf.com, or",
+                    "see https://www.overleaf.com/help/342 for more information."
+                ))
+            );
+        }
         Optional<Credential> oauth2 = Optional.ofNullable(
         Optional<Credential> oauth2 = Optional.ofNullable(
                 (Credential) httpServletRequest.getAttribute(
                 (Credential) httpServletRequest.getAttribute(
                         Oauth2Filter.ATTRIBUTE_KEY));
                         Oauth2Filter.ATTRIBUTE_KEY));

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

@@ -126,6 +126,9 @@ public class WLGitBridgeIntegrationTest {
         put("canCloneAMigratedRepositoryWithoutChanges", new HashMap<String, SnapshotAPIState>() {{
         put("canCloneAMigratedRepositoryWithoutChanges", new HashMap<String, SnapshotAPIState>() {{
             put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canCloneAMigratedRepositoryWithoutChanges/state/state.json")).build());
             put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/canCloneAMigratedRepositoryWithoutChanges/state/state.json")).build());
         }});
         }});
+        put("rejectV1Repository", new HashMap<String, SnapshotAPIState>() {{
+            put("state", new SnapshotAPIStateBuilder(getResourceAsStream("/rejectV1Repository/state/state.json")).build());
+        }});
     }};
     }};
 
 
     @Rule
     @Rule
@@ -849,6 +852,22 @@ public class WLGitBridgeIntegrationTest {
         assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneAMigratedRepositoryWithoutChanges/state/testproj_no_change"), testprojDir.toPath()));
         assertTrue(FileUtil.gitDirectoriesAreEqual(getResource("/canCloneAMigratedRepositoryWithoutChanges/state/testproj_no_change"), testprojDir.toPath()));
     }
     }
 
 
+    @Test
+    public void rejectV1Repository() throws IOException, GitAPIException, InterruptedException {
+        int gitBridgePort = 33884;
+        int mockServerPort = 3884;
+        MockSnapshotServer server = new MockSnapshotServer(mockServerPort, getResource("/rejectV1Repository").toFile());
+        server.start();
+        server.setState(states.get("rejectV1Repository").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 + "/1234bbccddff.git", null, dir);
+        wlgb.stop();
+        assertNotEquals(0, gitProcess.waitFor());
+    }
+
     private String makeConfigFile(
     private String makeConfigFile(
             int port,
             int port,
             int apiPort
             int apiPort

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/rejectV1Repository/state/1234bbccddff/foo/bar/test.tex

@@ -0,0 +1 @@
+This text is from another file.

+ 1 - 0
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/rejectV1Repository/state/1234bbccddff/main.tex

@@ -0,0 +1 @@
+content

BIN
services/git-bridge/src/test/resources/uk/ac/ic/wlgitbridge/WLGitBridgeIntegrationTest/rejectV1Repository/state/1234bbccddff/min_mean_wait_evm_7_eps_150dpi.png


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

@@ -0,0 +1,46 @@
+[
+	{
+		"project": "1234bbccddff",
+		"getDoc": {
+			"versionID": 1,
+			"createdAt": "2014-11-30T18:40:58.123Z",
+			"email": "jdleesmiller+1@gmail.com",
+			"name": "John+1"
+		},
+		"getSavedVers": [
+        	{
+        		"versionID": 1,
+        		"comment": "added more info on doc GET and error details",
+        		"email": "jdleesmiller+1@gmail.com",
+        		"name": "John+1",
+        		"createdAt": "2014-11-30T18:47:01.333Z"
+        	}
+		],
+		"getForVers": [
+			{
+				"versionID": 1,
+				"srcs": [
+                    {
+                    	"content": "content\n",
+                    	"path": "main.tex"
+                    },
+                    {
+                    	"content": "This text is from another file.",
+                    	"path": "foo/bar/test.tex"
+                    }
+	            ],
+	            "atts": [
+	            	{
+	            		"url": "http://127.0.0.1:3857/state/testproj/min_mean_wait_evm_7_eps_150dpi.png",
+	            		"path": "min_mean_wait_evm_7_eps_150dpi.png"
+	            	}
+	            ]
+	        }
+		],
+		"push": "success",
+		"postback": {
+			"type": "success",
+			"versionID": 2
+		}
+	}
+]