Search in sources :

Example 6 with BasicCurlParser

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

the class ParseCurlCommandActionTest method testCanAddAuthManagerInHttpRequest.

@Test
public void testCanAddAuthManagerInHttpRequest() throws Exception {
    ParseCurlCommandAction p = new ParseCurlCommandAction();
    AuthManager authManager = new AuthManager();
    Authorization authorization = new Authorization();
    authorization.setPass("passwd");
    authorization.setUser("user");
    authorization.setURL("http://jmeter.apache.org/");
    authorization.setMechanism(Mechanism.BASIC);
    authManager.addAuth(authorization);
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    Request request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -u 'user:passwd'");
    Method method = getMethodFor("canAddAuthManagerInHttpRequest", Request.class, AuthManager.class);
    assertFalse((boolean) method.invoke(p, request, authManager), "When AuthManager contains this authorization, shouldn't add a AuthManager in Http Request");
    request = basicCurlParser.parse("curl 'http://jmeter.apache.org/' -u 'user1:passwd1'");
    assertTrue((boolean) method.invoke(p, request, authManager), "When AuthManager contains this url, but the username or password isn't the same," + "should add a AuthManager in Http Request");
}
Also used : Authorization(org.apache.jmeter.protocol.http.control.Authorization) BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) AuthManager(org.apache.jmeter.protocol.http.control.AuthManager) Request(org.apache.jmeter.protocol.http.curl.BasicCurlParser.Request) ParseCurlCommandAction(org.apache.jmeter.protocol.http.gui.action.ParseCurlCommandAction) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 7 with BasicCurlParser

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

the class BasicCurlParserTest method testDnsServer.

@Test
public void testDnsServer() {
    String cmdLine = "curl -X POST  \"https://api.imgur.com/3/upload\" " + " -H 'Authorization: Client-ID fb52f2bfa714a36' --dns-servers '0.0.0.0,1.1.1.1'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertTrue(request.getDnsServers().contains("0.0.0.0"), "With method 'parser', the Dns Server 0.0.0.0 should exist");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 8 with BasicCurlParser

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

the class BasicCurlParserTest method testBug65270SingleEqualsWithDataUrlEncodeOptions.

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

Example 9 with BasicCurlParser

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

the class BasicCurlParserTest method testDataUrlEncodeMoreThanOneParameters.

@Test
public void testDataUrlEncodeMoreThanOneParameters() {
    String cmdLine = "curl -v 'https://postman-echo.com/post' -H 'Content-Type: application/x-www-form-urlencoded'" + " -H 'cache-control: no-cache' --data-urlencode 'foo1=!!!&foo2=???'";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    assertEquals("foo1=%21%21%21%26foo2%3D%3F%3F%3F", request.getPostData(), "With method 'parser',the parameters need to be encoded' ");
}
Also used : BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) Test(org.junit.jupiter.api.Test)

Example 10 with BasicCurlParser

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

the class BasicCurlParserTest method testCookieInHeader.

@Test
public void testCookieInHeader() {
    String cmdLine = "curl 'http://jmeter.apache.org/' -H 'cookie: PHPSESSID=testphpsessid;a=b' --compressed";
    BasicCurlParser basicCurlParser = new BasicCurlParser();
    BasicCurlParser.Request request = basicCurlParser.parse(cmdLine);
    List<Cookie> cookies = request.getCookieInHeaders("http://jmeter.apache.org/");
    Cookie c1 = new Cookie();
    c1.setDomain("jmeter.apache.org");
    c1.setName("a");
    c1.setValue("b");
    c1.setPath("/");
    assertEquals(c1, cookies.get(0), "Just static cookie in header can be added in CookieManager");
    assertEquals(1, cookies.size(), "Just static cookie in header can be added in CookieManager");
}
Also used : Cookie(org.apache.jmeter.protocol.http.control.Cookie) BasicCurlParser(org.apache.jmeter.protocol.http.curl.BasicCurlParser) 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