Login - Body doesnt have correlated value instead it is passing param name of correlation

Hello All,

As part of application i correlated CSRF token. I passed it in the login request.

Correlation:
check(regex("""_csrf" value="([^"]*)"""")
.saveAs(“Corrcsrf”))

I passed those value like this : .formParam("_csrf", “${Corrcsrf}”)

When i execute, I got 403 forbidden error. Then i checked the log, I was surprised to see values were not replaced instead strings are replaced.

body:FormUrlEncodedRequestBody{contentType=‘application/x-www-form-urlencoded’, charset=UTF-8, content=_csrf=%24%7BCorrcsrf%7D&username=RESUNDA&pingRefId=true&pingResume=%24%7Bpingresume%7D%2Fresume%2Fas%2Fauthorization.ping&instance=default&password=123123}

Can anyone please suggest me.

Regards
Rekha S

Hello,

Please follow the requirements listed here.

You don’t say that you have checked you’re using the latest version, if you’re using the Java or the Scala DSL, etc. As is, it’s impossible to help you.

Java Version : 11
Scala : 3.1.2
Gatling : 3.7.6
Maven : 3.8.5
IntelliJ Idea : IntelliJ IDEA 2022.1

Let me know if you need any more information.

Weird, I don’t think gatling is compatible with scala 3.

You didn’t tell if you use the Java or the Scala DSL (as we manage both now).

Did you try with the "#{Corrcsrf}" syntax? (See Gatling Expression Language), because $ is deprecated.

Have you messed up the imports?

You MUST have the same imports as in our documentation:

import io.gatling.core.Predef._
import io.gatling.http.Predef._

Typically, don’t let IntelliJ “optimize” your imports and actually break things.

Hello sbrevet,

I changed the scala version to 2.13. I changed to “#{Corrcsrf}” still no luck.

Yes I am using the same lib whatever you mentioned. (not allowing IDE to optimize)

I am using scala DSL

Here’s what I did:

  • git clone https://github.com/gatling/gatling-maven-plugin-demo-scala.git
  • uncommented TRACE logger in logback-test.xml
  • changed BasicSimulation to:
package computerdatabase

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._

class BasicSimulation extends Simulation {

  val httpProtocol = http
    .baseUrl("http://computer-database.gatling.io") // Here is the root for all relative URLs
    .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // Here are the common headers
    .acceptEncodingHeader("gzip, deflate")
    .acceptLanguageHeader("en-US,en;q=0.5")
    .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")

  val scn = scenario("Scenario Name")
      .exec(session => session.set("foo", "bar"))
      .exec(http("request_10")
        .post("/computers")
        .formParam("""name""", """#{foo}""") // EXPECT bar
        .formParam("""introduced""", """2012-05-30""")
        .formParam("""discontinued""", """""")
        .formParam("""company""", """37"""))

  setUp(scn.inject(atOnceUsers(1)).protocols(httpProtocol))
}
  • ran mvn clean gatling:test
  • observed that the substitution was properly triggered in the logs:
body:FormUrlEncodedRequestBody{contentType='application/x-www-form-urlencoded', charset=UTF-8, content=name=bar&introduced=2012-05-30&discontinued=&company=37}

So as far as I can tell, everything works as expected. As I already request in this thread, please provide a reproducer.

I deleted the simulation and recreated freshly because in IDE, scala 3.X version was configured. When I recreated, I could change to scala 2.X. It is mainly because of scala version.

Now it is working fine :slight_smile:

Great, thanks four your feedback!