Getting Gatling To Work Out Some Hack

August 13, 2013 | Bounteous x Accolite

Besides benchmarking and stress testing, Gatling still has more to it. It has the potential to be turned into a spam engine!

What Is Gatling?

Gatling is actually a benchmark stress test tool that gives you an idea of how your site and server are performing.  It measures things like how many user requests can be processed before the server runs out of memory and causes errors.

Getting Gatling Started

Go to gatling-tool.org and download the gatling-charts-highcharts-1.5.2-bundle.tar.gz

Extract gatling-charts-highcharts-1.5.2-bundle.tar.gz to any directory you want.

Setting Up Gatling Simulation Test

Gatling simulation scripts are Scala classes but don’t worry, we don’t need to write out the Scala class from scratch.  Usually, the quickest way to tweak a test is to record a Gatling scenario with the Gatling Recorder shell script. The scenario will then be recorded and generated as a Gatling simulation script. From there, we can edit the Gatling simulation script to run the tests we want.

Configuration For The Gatling Recorder

First, enable the proxy listening port in Firefox.  In FireFox, make sure you set up your HTTP proxy and SSL proxy. Go to FireFox preference -> Advanced -> Network -> Connection, click on Settings, then you will see the following screen:

screenshot of how to configure the gatling recorder

For an easy configuration, you can use the default 8000 and 8001 port for HTTP proxy and SSL proxy respectively.

Using The Gatling Recorder

image of Gatling Recorder

 

Now that the settings have been configured, we can proceed to use the Gatling recorder. Run the recorder.sh in {Gatling_Root}/bin. The Gatling recorder interface will pop up like the screen above. Make sure the listening ports have the configured values (8000 and 8001 for HTTP proxy and SSL proxy respectively) in the FireFox configuration. The Package and Class Name are just there for setting up the folder path and file structure after the Output Folder.  There we will use “packageTest” and “simulationTest”.  Press “start” to start recording. In our recording example, we are registering a test customer in a stock Magento Community Edition, v.1.7.0.2 with sample data installed.

The Gatling recorder is recording our HTTP requests of the registration process

image of recorded with sample data installed

Here is the FireFox view of the registration process recording.

FireFox view of the registration process recording

Here Is The Simulation Scala Class That We Generated From The Recorder:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package packageTest
 
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import com.excilys.ebi.gatling.http.Headers.Names._
import akka.util.duration._
import bootstrap._
import assertions._
 
class simulationTest extends Simulation {
 
  val httpConf = httpConfig
      .baseURL("http://www.magento1702vanilla.com")
      .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
      .acceptEncodingHeader("gzip, deflate")
      .acceptLanguageHeader("en-US,en;q=0.5")
      .connection("keep-alive")
      .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:22.0) Gecko/20100101 Firefox/22.0")
 
 
  val headers_4 = Map(
      "Content-Type" -> """application/x-www-form-urlencoded"""
  )
 
 
  val scn = scenario("Scenario Name")
    .exec(http("request_1")
          .get("/")
      )
    .pause(4)
    .exec(http("request_2")
          .get("/customer/account/login/")
      )
    .pause(2)
    .exec(http("request_3")
          .get("/customer/account/create/")
      )
    .pause(30)
    .exec(http("request_4")
          .post("/customer/account/createpost/")
          .headers(headers_4)
            .param("""success_url""", """""")
            .param("""error_url""", """""")
            .param("""firstname""", """Simulation""")
            .param("""lastname""", """Test""")
            .param("""email""", """simulationtest@infielddesign.com""")
            .param("""password""", """password1""")
            .param("""confirmation""", """password1""")
      )
 
  setUp(scn.users(1).protocolConfig(httpConf))
}

Using this simulation Scala class, we can tweak our own version of the benchmark test. We can do things like adding multiple users, changing the rate of users entering the system, apply dynamic data for multiple users, etc. In this recorded script, we can clearly see that none of the http request has any encrypted key as part of the url parameters. Here is a wild thought: we can do a little bit of hacking, like maybe register 25 test customers at once using a modified simulation Scala class.

Here Is The Modified Simulation Scala Class For Registering 25 Test Customers At Once:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package packageTest
 
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import com.excilys.ebi.gatling.http.Headers.Names._
import akka.util.duration._
import bootstrap._
import assertions._
 
class simulationTest25 extends Simulation {
 
  val httpConf = httpConfig
      .baseURL("http://www.magento1702vanilla.com")
      .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
      .acceptEncodingHeader("gzip, deflate")
      .acceptLanguageHeader("en-US,en;q=0.5")
      .connection("keep-alive")
      .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:22.0) Gecko/20100101 Firefox/22.0")
 
 
  val headers_4 = Map(
      "Content-Type" -> """application/x-www-form-urlencoded"""
  )
 
 
  val scn = scenario("Scenario Name")
    .feed(csv("buyers25.csv").queue)
    .exec(http("request_1")
          .get("/")
      )
    .pause(4)
    .exec(http("request_2")
          .get("/customer/account/login/")
      )
    .pause(2)
    .exec(http("request_3")
          .get("/customer/account/create/")
      )
    .pause(30)
    .exec(http("request_4")
          .post("/customer/account/createpost/")
          .headers(headers_4)
            .param("""success_url""", """""")
            .param("""error_url""", """""")
            .param("""firstname""", "${Firstname}")
            .param("""lastname""", "${Lastname}")
            .param("""email""", "${Email}")
            .param("""password""", """password1""")
            .param("""confirmation""", """password1""")
      )
 
  setUp(scn.users(25).protocolConfig(httpConf))
}

Here Is The Buyers25.Csv, The CSV File That Contains Dynamic Test Users Data:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Firstname,Lastname,Email
Test,User1,test1@example.com
Test,User2,test2@example.com
Test,User3,test3@example.com
Test,User4,test4@example.com
Test,User5,test5@example.com
Test,User6,test6@example.com
Test,User7,test7@example.com
Test,User8,test8@example.com
Test,User9,test9@example.com
Test,User10,test10@example.com
Test,User11,test11@example.com
Test,User12,test12@example.com
Test,User13,test13@example.com
Test,User1Heading 24,test14@example.com
Test,User15,test15@example.com
Test,User16,test16@example.com
Test,User17,test17@example.com
Test,User18,test18@example.com
Test,User19,test19@example.com
Test,User20,test20@example.com
Test,User21,test21@example.com
Test,User22,test22@example.com
Test,User23,test23@example.com
Test,User24,test24@example.com
Test,User25,test25@example.com

Running The Gatling Simulation

Now we will run the Gatling Simulation by running the gatling.sh in {Gatling_Root}/bin

The terminal is showing the process of the Gatling simulation test.

terminal showing the process of the Gatling simulation test

The is how the customer_entity table looks before the 25 test users simulation.

customer_entity table before the 25 test users simulation

The is how the customer_entity table looks after the 25 test users simulation. Note that not the test users are not saved in order because Gatling fires all 25 sessions at the same time.

customer_entity table look after the 25 test users simulation.

Final Thought

Gatling can certainly do some cool tricks! Gatling does not replace a “spam engine”, but this “hacking” feature allows for light data import in some web applications. What are your thoughts?