From 9bcec069b9a42dcdefa2ad9e2e76440d30b8ba3a Mon Sep 17 00:00:00 2001 From: Manish Kumar <107841575+sondermanish@users.noreply.github.com> Date: Wed, 15 May 2024 11:04:32 +0530 Subject: [PATCH] fix: added regex (#33426) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description > Added regex for supporting custom usernames in ssh Fixes #19881 ## Automation /ok-to-test tags="@tag.Git" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 05f2b6f8e6bbbbd6f05e70d9fa9194a07c89d86d > Cypress dashboard url: Click here! ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No --- .../com/appsmith/server/helpers/GitUtils.java | 7 +++++++ .../com/appsmith/server/helpers/GitUtilsTest.java | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java index 0387e059bd..f8d6b03f84 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java @@ -26,6 +26,9 @@ public class GitUtils { public static final Pattern URL_PATTERN_WITHOUT_SCHEME = Pattern.compile("^git@(?.+?):/*(?.+?)(\\.git)?$"); + public static final Pattern URL_PATTERN_WITH_CUSTOM_USERNAME = + Pattern.compile("^(ssh://)?[a-zA-Z0-9]+@(?.+?):/*(?.+?)(\\\\.git)?$"); + /** * Sample repo urls : * git@example.com:user/repoName.git @@ -45,6 +48,10 @@ public class GitUtils { match = URL_PATTERN_WITHOUT_SCHEME.matcher(sshUrl); } + if (!match.matches()) { + match = URL_PATTERN_WITH_CUSTOM_USERNAME.matcher(sshUrl); + } + if (!match.matches()) { throw new AppsmithException( AppsmithError.INVALID_GIT_CONFIGURATION, diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitUtilsTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitUtilsTest.java index 0409ec3152..f388da74cf 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitUtilsTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/GitUtilsTest.java @@ -60,6 +60,14 @@ public class GitUtilsTest { assertThat(GitUtils.convertSshUrlToBrowserSupportedUrl( "ssh://git@tim.tam.example.com:9876/v3/sladeping/pyhe/SpaceJunk")) .isEqualTo("https://tim.tam.example.com/v3/sladeping/pyhe/SpaceJunk"); + + // custom ssh username: + assertThat(GitUtils.convertSshUrlToBrowserSupportedUrl("custom@vs-ssh.visualstudio.com:v3/newJet/ai/zilla")) + .isEqualTo("https://vs-ssh.visualstudio.com/v3/newJet/ai/zilla"); + + assertThat(GitUtils.convertSshUrlToBrowserSupportedUrl( + "ssh://custom@vs-ssh.visualstudio.com:v3/newJet/ai/zilla")) + .isEqualTo("https://vs-ssh.visualstudio.com/v3/newJet/ai/zilla"); } @Test @@ -131,6 +139,13 @@ public class GitUtilsTest { assertThat(GitUtils.getRepoName("user@host.xz:path/to/repo.git")).isEqualTo("repo"); assertThat(GitUtils.getRepoName("org-987654321@github.com:org_name/repository_name.git")) .isEqualTo("repository_name"); + + // custom ssh username: + assertThat(GitUtils.getRepoName("custom@vs-ssh.visualstudio.com:v3/newJet/ai/zilla")) + .isEqualTo("zilla"); + + assertThat(GitUtils.getRepoName("ssh://custom@vs-ssh.visualstudio.com:v3/newJet/ai/zilla")) + .isEqualTo("zilla"); } @Test