diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/GitControllerCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/GitControllerCE.java index 34fb2edcb8..33f6528af8 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/GitControllerCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/ce/GitControllerCE.java @@ -196,8 +196,8 @@ public class GitControllerCE { } @GetMapping("/import/keys") - public Mono> generateKeyForGitImport() { - return service.generateSSHKey() + public Mono> generateKeyForGitImport(@RequestParam(required = false) String keyType) { + return service.generateSSHKey(keyType) .map(result -> new ResponseDTO<>(HttpStatus.OK.value(), result, null)); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCE.java index e94bc84d22..7bea9e8246 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCE.java @@ -64,7 +64,7 @@ public interface GitServiceCE { Mono importApplicationFromGit(String organisationId, GitConnectDTO gitConnectDTO); - Mono generateSSHKey(); + Mono generateSSHKey(String keyType); Mono testConnection(String defaultApplicationId); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java index 99587fa568..7c61da4660 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java @@ -2017,8 +2017,8 @@ public class GitServiceCEImpl implements GitServiceCE { } @Override - public Mono generateSSHKey() { - GitAuth gitAuth = GitDeployKeyGenerator.generateSSHKey(null); + public Mono generateSSHKey(String keyType) { + GitAuth gitAuth = GitDeployKeyGenerator.generateSSHKey(keyType); GitDeployKeys gitDeployKeys = new GitDeployKeys(); gitDeployKeys.setGitAuth(gitAuth); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/GitServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/GitServiceTest.java index fe812c535f..9689e45129 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/GitServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/GitServiceTest.java @@ -2285,30 +2285,66 @@ public class GitServiceTest { @Test @WithUserDetails(value = "api_user") - public void generateSSHKey_DataNotExistsInCollection_Success() { - Mono publicKey = gitService.generateSSHKey(); + public void generateSSHKeyDefaultType_DataNotExistsInCollection_Success() { + Mono publicKey = gitService.generateSSHKey(null); StepVerifier .create(publicKey) .assertNext(s -> { assertThat(s).isNotNull(); assertThat(s.getPublicKey()).contains("appsmith"); + assertThat(s.getPublicKey()).startsWith("ecdsa-sha2-nistp256"); }) .verifyComplete(); } @Test @WithUserDetails(value = "api_user") - public void generateSSHKey_KeyExistsInCollection_Success() { - GitAuth publicKey = gitService.generateSSHKey().block(); + public void generateSSHKeyRSAType_DataNotExistsInCollection_Success() { + Mono publicKey = gitService.generateSSHKey("RSA"); - Mono newKey = gitService.generateSSHKey(); + StepVerifier + .create(publicKey) + .assertNext(s -> { + assertThat(s).isNotNull(); + assertThat(s.getPublicKey()).contains("appsmith"); + assertThat(s.getPublicKey()).startsWith("ssh-rsa"); + }) + .verifyComplete(); + } + + @Test + @WithUserDetails(value = "api_user") + public void generateSSHKeyDefaultType_KeyExistsInCollection_Success() { + GitAuth publicKey = gitService.generateSSHKey(null).block(); + + Mono newKey = gitService.generateSSHKey(null); StepVerifier .create(newKey) .assertNext(s -> { assertThat(s).isNotNull(); assertThat(s.getPublicKey()).contains("appsmith"); + assertThat(s.getPublicKey()).startsWith("ecdsa-sha2-nistp256"); + assertThat(s.getPublicKey()).isNotEqualTo(publicKey.getPublicKey()); + assertThat(s.getPrivateKey()).isNotEmpty(); + }) + .verifyComplete(); + } + + @Test + @WithUserDetails(value = "api_user") + public void generateSSHKeyRSA_KeyExistsInCollection_Success() { + GitAuth publicKey = gitService.generateSSHKey(null).block(); + + Mono newKey = gitService.generateSSHKey("RSA"); + + StepVerifier + .create(newKey) + .assertNext(s -> { + assertThat(s).isNotNull(); + assertThat(s.getPublicKey()).contains("appsmith"); + assertThat(s.getPublicKey()).startsWith("ssh-rsa"); assertThat(s.getPublicKey()).isNotEqualTo(publicKey.getPublicKey()); assertThat(s.getPrivateKey()).isNotEmpty(); }) @@ -2345,7 +2381,7 @@ public class GitServiceTest { @WithUserDetails(value = "api_user") public void importApplicationFromGit_privateRepoLimitReached_ThrowApplicationLimitError() { GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testRepo.git", testUserProfile); - gitService.generateSSHKey().block(); + gitService.generateSSHKey(null).block(); Mockito .when(gitCloudServicesUtils.getPrivateRepoLimitForOrg(Mockito.any(), Mockito.anyBoolean())) .thenReturn(Mono.just(0)); @@ -2363,7 +2399,7 @@ public class GitServiceTest { @WithUserDetails(value = "api_user") public void importApplicationFromGit_emptyRepo_ThrowError() { GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testRepo.git", testUserProfile); - GitAuth gitAuth = gitService.generateSSHKey().block(); + GitAuth gitAuth = gitService.generateSSHKey(null).block(); ApplicationJson applicationJson = createAppJson(filePath).block(); applicationJson.setExportedApplication(null); @@ -2389,7 +2425,7 @@ public class GitServiceTest { @WithUserDetails(value = "api_user") public void importApplicationFromGit_validRequest_Success() { GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testRepo.git", testUserProfile); - GitAuth gitAuth = gitService.generateSSHKey().block(); + GitAuth gitAuth = gitService.generateSSHKey(null).block(); ApplicationJson applicationJson = createAppJson(filePath).block(); applicationJson.getExportedApplication().setName("testRepo"); @@ -2422,7 +2458,7 @@ public class GitServiceTest { @WithUserDetails(value = "api_user") public void importApplicationFromGit_validRequestWithDuplicateApplicationName_Success() { GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testGitRepo.git", testUserProfile); - GitAuth gitAuth = gitService.generateSSHKey().block(); + GitAuth gitAuth = gitService.generateSSHKey(null).block(); ApplicationJson applicationJson = createAppJson(filePath).block(); applicationJson.getExportedApplication().setName("testGitRepo (1)"); @@ -2466,7 +2502,7 @@ public class GitServiceTest { .block(); GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testGitImportRepo.git", testUserProfile); - GitAuth gitAuth = gitService.generateSSHKey().block(); + GitAuth gitAuth = gitService.generateSSHKey(null).block(); ApplicationJson applicationJson = createAppJson(filePath).block(); applicationJson.getExportedApplication().setName("testGitImportRepo"); @@ -2513,7 +2549,7 @@ public class GitServiceTest { .block(); GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testGitImportRepoCancelledMidway.git", testUserProfile); - GitAuth gitAuth = gitService.generateSSHKey().block(); + GitAuth gitAuth = gitService.generateSSHKey(null).block(); ApplicationJson applicationJson = createAppJson(filePath).block(); applicationJson.getExportedApplication().setName(null); @@ -2573,7 +2609,7 @@ public class GitServiceTest { @WithUserDetails(value = "api_user") public void importApplicationFromGit_validRequestWithDuplicateDatasourceOfDifferentType_ThrowError() { GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testGitImportRepo1.git", testUserProfile); - gitService.generateSSHKey().block(); + gitService.generateSSHKey(null).block(); ApplicationJson applicationJson = createAppJson(filePath).block(); applicationJson.getExportedApplication().setName("testGitImportRepo1"); applicationJson.getDatasourceList().get(0).setName("db-auth-1"); @@ -2605,7 +2641,7 @@ public class GitServiceTest { @WithUserDetails(value = "api_user") public void importApplicationFromGit_validRequestWithEmptyRepo_ThrowError() { GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/emptyRepo.git", testUserProfile); - GitAuth gitAuth = gitService.generateSSHKey().block(); + GitAuth gitAuth = gitService.generateSSHKey(null).block(); ApplicationJson applicationJson =new ApplicationJson(); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ReleaseNotesServiceTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ReleaseNotesServiceTest.java index 51097f1a05..519145290f 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ReleaseNotesServiceTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ReleaseNotesServiceTest.java @@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import java.util.ArrayList; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -20,7 +21,7 @@ public class ReleaseNotesServiceTest { @Test public void testComputeNewReleases() { - List releaseNodes = releaseNotesService.getReleaseNodesCache(); + List releaseNodes = new ArrayList<>(); releaseNodes.addAll(List.of( new ReleaseNode("v3"), new ReleaseNode("v2"),