Message Signing and digest calculation


I am very new to gatling(about 2 days old) and I have a task in hand. I need to write a test for a Secure POST request which needs to contain

  1. Digest of the payload in the header
  2. Signature in the header which has digest and date as two of the 4 fields.

I first tried to use my customSignature to sign the request and calculate the digest

val scn = scenario("HelloWorldTest")
    .body(StringBody(baseClass.generateBody("${DEBITIBAN}", "${CREDITIBAN}"))).asJSON
    .signatureCalculator(new MessageSignature())
    .header("Authorization", "${ACCESSTOKEN}")
    .header("Date", myHeaderDateString)
    .header("Digest", baseClass.generateDigest(baseClass.myFinalMessage))
    .header("Signature", baseClass.generateSignature(myHeaderDateString,
    .header("host", baseClass.eAppHost))

This was giving wrong digest value and after reading through the logs and blogs I found that this was due the fact that the feeder replace the values in the request only at the last minute before sending the request to server.

There are a lot of forums which are suggesting to implement the SignatureCalculator interface. But I am not able to find a working example which caters to

  • How this method is integrated with the scenario
  • How the value of the request object is passed from the scenario to implemented method.

Is it possible to provide a sample code snippet which can help me understand how it is integrated and what needs to be done to make this work for me



I found the solution for my problem.
Below is the snippet of the fixed code

val scn = scenario("HelloWorldTest")
    .body(StringBody(baseClass.generateBody("${DEBITIBAN}", "${CREDITIBAN}"))).asJSON
      .header("CLIENTID", "${CLIENTID}")
    .signatureCalculator( calculateAndAddSignature(_, _) )

Then I added the below method in the same class

def calculateAndAddSignature(request: Request, requestBuilder: RequestBuilderBase[_]): Unit = {
       println("request = " + request)