Coder
Coder

Reputation: 79

JWT headers with Gatling Post Request

I want to include a JWT header with my Gatling POST request.

I am doing something like this:

val R1= scenario("Scenario")
.feed(idFeeder)
.header("", "",
Jwt.sha256(requestBody), "", "", "")))
   .body(
    StringBody(session => requestBody.replace(
      "0000000000",
      session("id").as[String]
    ))
  ).asJSON   

Where "id" is a session attribute which contains a randomly generated id to be added to the requestBody. How can I obtain the id substituted request body in Jwt.sha256(requestBody) which send the request body to the JWT class to get the hash of it (Which should be included in the JWT header)

Jwt.sha256() requires a String and returns a URL encode of the string

Upvotes: 0

Views: 267

Answers (1)

Mateusz Gruszczynski
Mateusz Gruszczynski

Reputation: 1510

Assuming Jwt.sha256() takes a string body and returns some String token then its just like with body:

.header(
  "HeaderName",
  session => Jwt.sha256(requestBody.replace("0000000000", session("id").as[String]))
)

Upvotes: 0

Related Questions