Merge branch 'bug/curl-import-with-url-argument' into 'release'
Fix cURL import when using `--url` argument See merge request theappsmith/internal-tools-server!386
This commit is contained in:
commit
e27af0f525
|
|
@ -190,7 +190,9 @@ public class CurlImporterService extends BaseApiImporter {
|
|||
} else if (token.startsWith("-d")) {
|
||||
// `-dstuff` -> `--data stuff`
|
||||
normalizedTokens.add(ARG_DATA);
|
||||
normalizedTokens.add(token.substring(2));
|
||||
if (token.length() > 2) {
|
||||
normalizedTokens.add(token.substring(2));
|
||||
}
|
||||
|
||||
} else if ("-H".equals(token)) {
|
||||
normalizedTokens.add(ARG_HEADER);
|
||||
|
|
@ -198,7 +200,9 @@ public class CurlImporterService extends BaseApiImporter {
|
|||
} else if (token.startsWith("-H")) {
|
||||
// `-HContent-Type:application/json` -> `--header Content-Type:application/json`
|
||||
normalizedTokens.add(ARG_HEADER);
|
||||
normalizedTokens.add(token.substring(2));
|
||||
if (token.length() > 2) {
|
||||
normalizedTokens.add(token.substring(2));
|
||||
}
|
||||
|
||||
} else if ("-X".equals(token)) {
|
||||
normalizedTokens.add(ARG_REQUEST);
|
||||
|
|
@ -206,7 +210,9 @@ public class CurlImporterService extends BaseApiImporter {
|
|||
} else if (token.startsWith("-X")) {
|
||||
// `-XGET` -> `--request GET`
|
||||
normalizedTokens.add(ARG_REQUEST);
|
||||
normalizedTokens.add(token.substring(2).toUpperCase());
|
||||
if (token.length() > 2) {
|
||||
normalizedTokens.add(token.substring(2).toUpperCase());
|
||||
}
|
||||
|
||||
} else if ("-b".equals(token)) {
|
||||
normalizedTokens.add(ARG_COOKIE);
|
||||
|
|
@ -217,7 +223,9 @@ public class CurlImporterService extends BaseApiImporter {
|
|||
} else if ("-A".equals(token)) {
|
||||
normalizedTokens.add(ARG_USER_AGENT);
|
||||
|
||||
} else {
|
||||
} else if (!"--url".equals(token)) {
|
||||
// We skip the `--url` argument since it's superfluous and URLs are directly sniffed out of the argument
|
||||
// list. The `--url` argument holds no special significance in cURL.
|
||||
normalizedTokens.add(token);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -518,6 +518,26 @@ public class CurlImporterServiceTest {
|
|||
assertEmptyBody(action);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseWithDashedUrlArgument() {
|
||||
Action action = curlImporterService.curlToAction("curl --url http://api.sloths.com");
|
||||
assertMethod(action, HttpMethod.GET);
|
||||
assertUrl(action, "http://api.sloths.com");
|
||||
assertEmptyPath(action);
|
||||
assertEmptyHeaders(action);
|
||||
assertEmptyBody(action);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseWithDashedUrlArgument2() {
|
||||
Action action = curlImporterService.curlToAction("curl -X POST -d '{\"name\":\"test\",\"salary\":\"123\",\"age\":\"23\"}' --url http://dummy.restapiexample.com/api/v1/create");
|
||||
assertMethod(action, HttpMethod.POST);
|
||||
assertUrl(action, "http://dummy.restapiexample.com");
|
||||
assertPath(action, "/api/v1/create");
|
||||
assertHeaders(action, new Property("Content-Type", "application/x-www-form-urlencoded"));
|
||||
assertBody(action, "{\"name\":\"test\",\"salary\":\"123\",\"age\":\"23\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@WithUserDetails(value = "api_user")
|
||||
public void importInvalidCurlCommand() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user