OAuth in Gatling

Recently got a chance to do some load testing of our endpoints. At first I’ve started with ab. However I came to the problems very soon. We have OAuth and it became a sort of stopper. All of the oauth proxies did not work for me. So I started looking at alternative solutions.

Gatling was already on the horizon however I had hard times making it work with OAuth. Once it became the last chance – I just had to make it work for us with OAuth.

The main problem I had with Gatling was how to regenerate oath_signature for each request.

So we have the following code in Scala

def buildParams(user : User) : String = {
  val parameters = new OAuthParameters
  parameters.consumerKey = Configuration.consumerKey;
  parameters.token = user.token;
  parameters.signatureMethod = "HMAC-SHA1";
  parameters.version = "1.0";

  val signer = new OAuthHmacSigner
  signer.clientSharedSecret = Configuration.consumerSecret;
  signer.tokenSharedSecret = user.secretToken;

  parameters.signer = signer;
  parameters.computeSignature(method, new GenericUrl(url));
  return (parameters.getAuthorizationHeader())

No we need somehow invoke this call for each request. It appears this can be done via feed. We can create an infinite Iterator like:

Iterator.continually(Map("auth" -> buildParams(user))

and use Gatling EL to pass the header

request.header("Authorization", "${auth}".

The full scenario code looks like:

val scn = scenario(name)
   .feed(Iterator.continually(Map("auth" -> buildParams(user)))
   .exec(request.header("Authorization", "${auth}"));

As a result we have an infinite loop of signatures and Gatling uses bound parameter name for each request.

UPDATE: It appears that this approach is not optimal. Actually Gatling already has Signature Calculator.

This entry was posted in Development, Tips and tagged , , . Bookmark the permalink.

1 Response to OAuth in Gatling

  1. Pingback: Interesting stuff. Week 50-53 | My Technical Life

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s