Updating request body using a SignatureCalculator in Gatling 3

I’m migrating from gatling 2.3 to 3.2 and I have run into an issue with signing and updating a request with form params using a SignatureCalculator.

In gatling 2.3 I could calculate the signature and add a new form parameter with the signature. This form parameter does get added to the sent request.

exec(http("Form params with signature") .post("/with-signature") .headers(Map("Content-Type" -> "application/x-www-form-urlencoded")) .formParam("value", "some-value") .signatureCalculator((request: Request, value: RequestBuilderBase[_]) => { // calculate signature based on form params in the request value.addFormParam("signature", "calculated-signature") () }))

In gatling 3 this no longer seems to be possible. I’ve tried the following but the added form parameter doesn’t get applied to the sent request.

`
exec(http(“Form params with signature”)
.post("/with-signature")
.formParam(“value”, “some-value”)
.sign(new MySignatureCalculator()))

class MySignatureCalculator extends SignatureCalculator {
override def sign(request: Request): Unit = {
val body = request.getBody
val formParams: java.util.List[Param] = body.asInstanceOf[FormUrlEncodedRequestBody].getContent()
// calculate signature based on form params in the request
request.getBody.asInstanceOf[FormUrlEncodedRequestBody].getContent.add(new Param(“signature”, “calculated-signature”))
}
}
`

Has the possibility to update the request body using a signature calculator been intentionally removed from Gatling 3 or is there some other way to achieve this?

I’ve seen there are few posts about the same thing but I haven’t yet seen any clear answer on this question.

Any input on this will be much appreciated.

Thanks!

Has the possibility to update the request body using a signature calculator been intentionally removed from Gatling 3

Yes, this was intentional as all the standard scheme we’re aware of use HTTP headers and don’t edit the request body and this change let us simplify the code a lot.
What is this auth scheme you’re using? Something standard or home made?
Gatling 3 has been out for more than one year and we don’t get much complains about this change.

or is there some other way to achieve this?

Not I can think of.

Thanks for you response, Stéphane.

This use case is for the Shopify e-commerce platform which has its own home-made solution for signing requests. The signature is calculated based on all other Shopify form parameters in the request and signed using HMAC-SHA256 with a key. The signature is then added as a form parameter to the request.

Would you mind having the feature to allow request body updates using a SignatureCalculator added to Gatling 3? I’d be happy to raise a feature request ticket for this use case.

I am also having trouble with this when trying to test an API using Ethereum signatures. They “wraps” the body on a JSON blob containing the original data and the signature value.

May I need to change the approach from SignatureCalculator to use a body processor (https://gatling.io/docs/current/http/http_request#request-body-processor) instead.

Took a look on the GZIP body processor. Problem is that I know the body to be StringBody and want not to handle every single other type of Body to implement the signing scheme.

Any ideas?