Question

I have an interrogation regarding a Gatling simulation that involved signin to a java webapp.

I set up the following simulation and I was surprised to notice that it worked even though I did not explicitely retrieved and set the JSESSIONID cookie between the requests.

I would have expected the get commented with //AUTHENTICATED REQUEST HERE to fail....

Can someone please provide insight?

class SigninAndAct extends Simulation {

    val baseURL = "http://localhost:8080"
    val httpConf = httpConfig
            .baseURL(baseURL)
            .acceptHeader("*/*")
            .acceptEncodingHeader("gzip, deflate")
            .acceptLanguageHeader("fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3")
            .connection("keep-alive")
            .userAgentHeader("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0")


    val headers_1 = Map(
            "Accept" -> """text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"""
    )

    val headers_2 = Map(
            "Accept" -> """text/css,*/*;q=0.1"""
    )

    val headers_31 = Map(
            "Accept" -> """text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8""",
            "Content-Type" -> """application/x-www-form-urlencoded"""
    )


    val scn = scenario("Signin-scn")
                .exec(http("open-signin-page")
                    .get("/bignibou/signin")
                    .headers(headers_1)
                    .check(regex("""<input type="hidden" name="_csrf" value="(.*)" />""")
                    .saveAs("_csrf")))
                .exec(http("signin")
                    .post("/bignibou/signin")
                    .headers(headers_1)
                    .param("_csrf", "${_csrf}")
                    .param("username","balteo@yahoo.fr")
                    .param("password","------")
                    .check(currentLocation.is(baseURL+"/bignibou/dashboard")))
                .exec(http("open-edit-add-page")
                     .get("/bignibou/advertisement/childminder/edit/32768")//AUTHENTICATED REQUEST HERE
                     .headers(headers_1)
                     .check(currentLocation.is(baseURL+"/bignibou/advertisement/childminder/edit/32768")))

    setUp(scn.users(1).protocolConfig(httpConf))
}
Was it helpful?

Solution

That's because Gatling takes care of this for you. It stores them automatically in the user's session and pass them onto the next request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top