Search in sources :

Example 36 with BasicCurlParser

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser in project jmeter by apache.

the class BasicCurlParserTest method testBug65270DuplicateDataUrlEncodeOptions.

@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());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 37 with BasicCurlParser

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser in project jmeter by apache.

the class BasicCurlParserTest method testFormWithQuotedValue.

@Test
public void testFormWithQuotedValue() {
    String cmdLine = "curl 'https://www.exaple.invalid/' " + "--form 'test=\"something quoted\"'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    List<Pair<String, ArgumentHolder>> res = request.getFormData();
    assertTrue(res.contains(Pair.of("test", StringArgumentHolder.of("something quoted"))), "With method 'form', we should post form data");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test)

Example 38 with BasicCurlParser

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser in project jmeter by apache.

the class BasicCurlParserTest method testInterface.

@Test
public void testInterface() {
    String cmdLine = "curl 'http://jmeter.apache.org/'   --interface 'etho'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("etho", request.getInterfaceName());
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 39 with BasicCurlParser

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser in project jmeter by apache.

the class BasicCurlParserTest method testCookieFromFile.

@Test
public void testCookieFromFile() throws IOException {
    String pathname = tempFile.getAbsolutePath();
    String cmdLine = "curl -X POST  \"https://api.imgur.com/3/upload\" -b '" + pathname + "'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals(pathname, request.getFilepathCookie(), "With method 'parser', the file of cookie should be uploaded in CookieManager");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 40 with BasicCurlParser

use of org.apache.jmeter.protocol.http.curl.BasicCurlParser in project jmeter by apache.

the class BasicCurlParserTest method testForm.

@Test
public void testForm() {
    String cmdLine = "curl 'https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_submit/action_page.php' " + "-H 'cache-control: no-cache' -F 'test=name' -F 'test1=name1' ";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    List<Pair<String, ArgumentHolder>> res = request.getFormData();
    assertTrue(res.contains(Pair.of("test1", StringArgumentHolder.of("name1"))), "With method 'parser', we should post form data");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.jupiter.api.Test)

Aggregations

BasicCurlParser (org.apache.jmeter.protocol.http.curl.BasicCurlParser)84 Test (org.junit.jupiter.api.Test)81 Request (org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request)20 ParseCurlCommandAction (org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction)19 Method (java.lang.reflect.Method)16 Pair (org.apache.commons.lang3.tuple.Pair)8 HTTPSamplerProxy (org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy)6 DNSCacheManager (org.apache.jmeter.protocol.http.control.DNSCacheManager)4 AuthManager (org.apache.jmeter.protocol.http.control.AuthManager)3 HttpTestSampleGui (org.apache.jmeter.protocol.http.control.gui.HttpTestSampleGui)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Authorization (org.apache.jmeter.protocol.http.control.Authorization)2 Cookie (org.apache.jmeter.protocol.http.control.Cookie)2 CookieManager (org.apache.jmeter.protocol.http.control.CookieManager)2 TestPlan (org.apache.jmeter.testelement.TestPlan)2 ThreadGroup (org.apache.jmeter.threads.ThreadGroup)2 HashTree (org.apache.jorphan.collections.HashTree)2 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1