jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fschumac...@apache.org
Subject [jmeter] branch master updated: POST application/x-www-form-urlencoded cURL code generated from Postman is not imported correctly
Date Tue, 27 Apr 2021 18:59:57 GMT
This is an automated email from the ASF dual-hosted git repository.

fschumacher pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jmeter.git


The following commit(s) were added to refs/heads/master by this push:
     new 5f5b816  POST application/x-www-form-urlencoded cURL code generated from Postman
is not imported correctly
5f5b816 is described below

commit 5f5b8166402fbe66ba2aadc51ccdc284d9c8c030
Author: Felix Schumacher <felix.schumacher@internetallee.de>
AuthorDate: Tue Apr 27 20:57:27 2021 +0200

    POST application/x-www-form-urlencoded cURL code generated from Postman is not imported
correctly
    
    Allow multiple occurrences of --data-urlencode options and empty key and value on that
option.
    The data will be added as post data and not as form data, which is a bit inconvenient
and asked for
    in the same issue entry.
    
    Bugzilla Id: 65270
---
 .../jmeter/protocol/http/curl/BasicCurlParser.java |  5 +++-
 .../apache/jmeter/curl/BasicCurlParserTest.java    | 34 ++++++++++++++++++++++
 xdocs/changes.xml                                  |  1 +
 3 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
index 3533576..ca869b9 100644
--- a/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
+++ b/src/protocol/http/src/main/java/org/apache/jmeter/protocol/http/curl/BasicCurlParser.java
@@ -561,7 +561,7 @@ public class BasicCurlParser {
     private static final CLOptionDescriptor D_DATA_BINARY_OPT = new CLOptionDescriptor("data-binary",
             CLOptionDescriptor.ARGUMENT_REQUIRED, DATA_BINARY_OPT, "HTTP POST binary data
");
     private static final CLOptionDescriptor D_DATA_URLENCODE_OPT = new CLOptionDescriptor("data-urlencode",
-            CLOptionDescriptor.ARGUMENT_REQUIRED, DATA_URLENCODE_OPT, "HTTP POST url encoding
data ");
+            CLOptionDescriptor.ARGUMENT_REQUIRED | CLOptionDescriptor.DUPLICATES_ALLOWED,
DATA_URLENCODE_OPT, "HTTP POST url encoding data ");
     private static final CLOptionDescriptor D_DATA_RAW_OPT = new CLOptionDescriptor("data-raw",
             CLOptionDescriptor.ARGUMENT_REQUIRED, DATA_RAW_OPT, "HTTP POST url allowed '@'
");
     private static final CLOptionDescriptor D_FORM_OPT = new CLOptionDescriptor("form",
@@ -718,6 +718,9 @@ public class BasicCurlParser {
                 } else if (DATAS_OPT.contains(option.getDescriptor().getId())) {
                     String value = option.getArgument(0);
                     String dataOptionName = option.getDescriptor().getName();
+                    if (value == null) {
+                        value = "";
+                    }
                     value = getPostDataByDifferentOption(value.trim(), dataOptionName);
                     if ("GET".equals(request.getMethod())) {
                         request.setMethod("POST");
diff --git a/src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java
b/src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java
index 83a4ad7..53ade9f 100644
--- a/src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java
+++ b/src/protocol/http/src/test/java/org/apache/jmeter/curl/BasicCurlParserTest.java
@@ -26,6 +26,7 @@ import java.io.File;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Path;
+import java.util.Arrays;
 import java.util.List;
 
 import org.apache.commons.io.FileUtils;
@@ -49,6 +50,39 @@ public class BasicCurlParserTest {
     }
 
     @Test
+    public void testBug65270SingleEqualsWithDataUrlEncodeOptions() {
+        String cmdLine = String.join(" \\\n",
+        Arrays.asList("curl --location --request POST 'https://example.invalid/access/token'",
+        "--header 'HTTP_X_FORWARDED_FOR: 127.0.0.1'",
+        "--header 'Accept-Language: it-IT'",
+        "--header 'Content-Type: application/x-www-form-urlencoded'",
+        "--data-urlencode '='"));
+        BasicCurlParser basicCurlParser = new BasicCurlParser();
+        BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
+        assertEquals("https://example.invalid/access/token", request.getUrl());
+        assertEquals(3, request.getHeaders().size());
+        assertEquals("", request.getPostData());
+    }
+
+    @Test
+    public void testBug65270DuplicateDataUrlEncodeOptions() {
+        String cmdLine = String.join(" \\\n",
+                Arrays.asList("curl --location --request POST 'http://example.invalid/access/token'",
+                        "--header 'HTTP_X_FORWARDED_FOR: 127.0.0'", "--header 'Accept-Language:
it-IT'",
+                        "--header 'Content-Type: application/x-www-form-urlencoded'",
+                        "--data-urlencode 'client_id=someID'", "--data-urlencode 'client_secret=someSecret'",
+                        "--data-urlencode 'grant_type=password'", "--data-urlencode 'username=test'",
+                        "--data-urlencode 'password=Password1234'"));
+        BasicCurlParser basicCurlParser = new BasicCurlParser();
+        BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
+        assertEquals("http://example.invalid/access/token", request.getUrl());
+        assertEquals(3, request.getHeaders().size());
+        assertEquals(
+                "client_id=someID&client_secret=someSecret&grant_type=password&username=test&password=Password1234",
+                request.getPostData());
+    }
+
+    @Test
     public void testFFParsing() {
         String cmdLine = "curl 'http://jmeter.apache.org/' -H 'User-Agent: Mozilla/5.0 (Macintosh;
Intel Mac OS X 10.11; rv:63.0) Gecko/20100101 Firefox/63.0' "
                 + "-H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
"
diff --git a/xdocs/changes.xml b/xdocs/changes.xml
index 9d00536..14a6e5d 100644
--- a/xdocs/changes.xml
+++ b/xdocs/changes.xml
@@ -189,6 +189,7 @@ Summary
   <li><pr>658</pr>Improve javadoc. Contributed by Ori Marko (orimarko at
gmail.com)</li>
   <li><pr>661</pr>Fix wording in doc. Contributed by BugKing (wangzhen
at fit2cloud.com)</li>
   <li><pr>664</pr>Allow whitespace in path. Contributed by Till Neunast
(github.com/tilln)</li>
+  <li><bug>65270</bug>POST application/x-www-form-urlencoded cURL code
generated from Postman is not imported correctly</li>
 </ul>
 
  <!--  =================== Thanks =================== -->

Mime
View raw message