Skip to content

Commit 35db356

Browse files
committed
fix: [CI-5235]: added validation for ssh url
1 parent ffd4244 commit 35db356

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
@@ -537,6 +537,13 @@ public static void validateURL(@NotNull String url) {
537537
throw new InvalidRequestException(
538538
format("Invalid repo url %s,should start with either http:// , https:// , ssh:// or git@", url));
539539
}
540+
if (url.startsWith("git@") && !url.contains(":")) {
541+
throw new InvalidRequestException(
542+
format("Invalid repo url %s, valid ssh url formats are git@provider.com:username/repo, "
543+
+ "ssh://provider.com/username/repo, "
544+
+ "ssh://git@provider.com/username/repo",
545+
url));
546+
}
540547
}
541548

542549
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
@@ -550,6 +550,10 @@ public void testValidateURL() {
550550
assertThatCode(() -> GitClientHelper.validateURL("ssh://github.com/smjt-h")).doesNotThrowAnyException();
551551
assertThatCode(() -> GitClientHelper.validateURL("git@github.com:smjt-h/goHelloWorldServer.git"))
552552
.doesNotThrowAnyException();
553+
assertThatThrownBy(() -> GitClientHelper.validateURL("git@github.com/smjt-h/goHelloWorldServer.git"))
554+
.isExactlyInstanceOf(InvalidRequestException.class);
555+
assertThatCode(() -> GitClientHelper.validateURL("ssh://git@github.com/smjt-h/goHelloWorldServer.git"))
556+
.doesNotThrowAnyException();
553557
assertThatCode(() -> GitClientHelper.validateURL("https://github.com/smjt-h/goHelloWorldServer.git"))
554558
.doesNotThrowAnyException();
555559
}

0 commit comments

Comments
 (0)