fix: CURL empty command error msg fix (#23119)

Changed the error message returned in case of empty input from the user for CURL import

Fixes #12008
This commit is contained in:
PiyushPushkar02 2023-05-11 17:09:05 +05:30 committed by GitHub
parent fa9eb6497a
commit 6060ade54f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 3 deletions

View File

@ -12,6 +12,7 @@ import java.text.MessageFormat;
public enum AppsmithError {
// Ref syntax for message templates: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/text/MessageFormat.html
INVALID_PARAMETER(400, AppsmithErrorCode.INVALID_PARAMETER.getCode(), "Please enter a valid parameter {0}.", AppsmithErrorAction.DEFAULT, "Invalid parameter", ErrorType.ARGUMENT_ERROR, null),
EMPTY_CURL_INPUT_STATEMENT(400, AppsmithErrorCode.EMPTY_CURL_INPUT_STATEMENT.getCode(), "Input CURL statement is empty / null. Please edit the input box to provide a valid CURL statement.", AppsmithErrorAction.DEFAULT, "Invalid parameter", ErrorType.ARGUMENT_ERROR, null),
PLUGIN_NOT_INSTALLED(400, AppsmithErrorCode.PLUGIN_NOT_INSTALLED.getCode(), "Plugin {0} not installed", AppsmithErrorAction.DEFAULT, "Plugin not installed", ErrorType.INTERNAL_ERROR, null),
PLUGIN_ID_NOT_GIVEN(400, AppsmithErrorCode.PLUGIN_ID_NOT_GIVEN.getCode(), "Missing plugin id. Please enter one.", AppsmithErrorAction.DEFAULT, "Missing plugin id", ErrorType.INTERNAL_ERROR, null),
DATASOURCE_NOT_GIVEN(400, AppsmithErrorCode.DATASOURCE_NOT_GIVEN.getCode(), "Missing datasource. Add/enter/connect a datasource to create a valid action.",

View File

@ -66,6 +66,7 @@ public enum AppsmithErrorCode {
GENERIC_BAD_REQUEST("AE-BAD-4000", "Generic bad request"),
GOOGLE_RECAPTCHA_FAILED("AE-CAP-4035", "Google recaptcha failed"),
INVALID_CRUD_PAGE_REQUEST("AE-CRD-4039", "Invalid crud page request"),
EMPTY_CURL_INPUT_STATEMENT("AE-CRL-4054","Invalid CURL input statement"),
INVALID_CURL_COMMAND("AE-CRL-4029", "Invalid curl command"),
INVALID_CURL_METHOD("AE-CRL-4032", "Invalid curl method"),
INVALID_CURL_HEADER("AE-CRL-4036", "Invalid curl header"),

View File

@ -37,6 +37,7 @@ import java.util.Base64;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import static org.apache.commons.lang3.StringUtils.isBlank;
@Slf4j
public class CurlImporterServiceCEImpl extends BaseApiImporter implements CurlImporterServiceCE {
@ -80,8 +81,8 @@ public class CurlImporterServiceCEImpl extends BaseApiImporter implements CurlIm
ActionDTO action;
try {
if (input == null) {
throw new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.CURL_CODE);
if (isBlank((String) input)) {
throw new AppsmithException(AppsmithError.EMPTY_CURL_INPUT_STATEMENT, FieldName.CURL_CODE);
}
action = curlToAction((String) input, name);
} catch (AppsmithException e) {

View File

@ -160,7 +160,7 @@ public class CurlImporterServiceTest {
@Test
@WithUserDetails(value = "api_user")
public void testImportAction_EmptyLex() {
public void testImportActionOnInvalidInput() {
setup();
// Set up the application & page for which this import curl action would be added
Application app = new Application();
@ -180,6 +180,50 @@ public class CurlImporterServiceTest {
.verify();
}
@Test
@WithUserDetails(value = "api_user")
public void testImportActionOnNullInput() {
setup();
// Set up the application & page for which this import curl action would be added
Application app = new Application();
app.setName("curlTest Incorrect Command");
Application application = applicationPageService.createApplication(app, workspaceId).block();
assert application != null;
PageDTO page = newPageService.findPageById(application.getPages().get(0).getId(), AclPermission.MANAGE_PAGES, false).block();
assert page != null;
Mono<ActionDTO> action = curlImporterService.importAction(null, page.getId(), "actionName", workspaceId, null);
StepVerifier
.create(action)
.expectErrorMatches(throwable -> throwable instanceof AppsmithException &&
throwable.getMessage().equals(AppsmithError.EMPTY_CURL_INPUT_STATEMENT.getMessage()))
.verify();
}
@Test
@WithUserDetails(value = "api_user")
public void testImportActionOnEmptyInput() {
setup();
// Set up the application & page for which this import curl action would be added
Application app = new Application();
app.setName("curlTest Incorrect Command");
Application application = applicationPageService.createApplication(app, workspaceId).block();
assert application != null;
PageDTO page = newPageService.findPageById(application.getPages().get(0).getId(), AclPermission.MANAGE_PAGES, false).block();
assert page != null;
Mono<ActionDTO> action = curlImporterService.importAction("", page.getId(), "actionName", workspaceId, null);
StepVerifier
.create(action)
.expectErrorMatches(throwable -> throwable instanceof AppsmithException &&
throwable.getMessage().equals(AppsmithError.EMPTY_CURL_INPUT_STATEMENT.getMessage()))
.verify();
}
@Test
@WithUserDetails(value = "api_user")
public void importValidCurlCommand() {