Skip to content

Commit 2531454

Browse files
committed
fix: [CI-5235]: added validation for ssh url
1 parent bf50359 commit 2531454

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

960-api-services/src/main/java/io/harness/git/GitClientHelper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,13 @@ public static void validateURL(@NotNull String url) {
510510
throw new InvalidRequestException(
511511
format("Invalid repo url %s,should start with either http:// , https:// , ssh:// or git@", url));
512512
}
513+
if (url.startsWith("git@") && !url.contains(":")) {
514+
throw new InvalidRequestException(
515+
format("Invalid repo url %s, valid ssh url formats are git@provider.com:username/repo, "
516+
+ "ssh://provider.com/username/repo, "
517+
+ "ssh://git@provider.com/username/repo",
518+
url));
519+
}
513520
}
514521

515522
public static String getCompleteUrlForProjectLevelAzureConnector(String url, String repoName) {

960-api-services/src/test/java/io/harness/git/GitClientHelperTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,10 @@ public void testValidateURL() {
528528
assertThatCode(() -> GitClientHelper.validateURL("ssh://github.com/smjt-h")).doesNotThrowAnyException();
529529
assertThatCode(() -> GitClientHelper.validateURL("git@github.com:smjt-h/goHelloWorldServer.git"))
530530
.doesNotThrowAnyException();
531+
assertThatThrownBy(() -> GitClientHelper.validateURL("git@github.com/smjt-h/goHelloWorldServer.git"))
532+
.isExactlyInstanceOf(InvalidRequestException.class);
533+
assertThatCode(() -> GitClientHelper.validateURL("ssh://git@github.com/smjt-h/goHelloWorldServer.git"))
534+
.doesNotThrowAnyException();
531535
assertThatCode(() -> GitClientHelper.validateURL("https://github.com/smjt-h/goHelloWorldServer.git"))
532536
.doesNotThrowAnyException();
533537
}

0 commit comments

Comments
 (0)