Mike Wilett
Mike Wilett

Reputation: 21

Implementing HMAC authentication

The application I am performance testing, in jMeter, passes two authentication parameters in the HTTP Header request. The authentication method used is HMAC authentication in JavaScript using jQuery SHA256.

Does anyone have experience / knowledge implementing this in jMeter, or other performance testing tools ?.

Upvotes: 0

Views: 1604

Answers (1)

Dmitri T
Dmitri T

Reputation: 168002

Given you need to send HTTP Request having HMAC-encoded header:

  1. Add Beanshell PreProcessor as a child of the HTTP Request sampler
  2. Put the following code into the PreProcessor's "Script" area

    import org.apache.commons.codec.digest.HmacUtils;
    
    String key = vars.get("key");
    String value = vars.get("value");
    String headerValue = HmacUtils.hmacSha256Hex(key, value);
    
    vars.put("headerValue", headerValue); 
    
  3. Add HTTP Header Manager as a child of HTTP Request sampler and after the Beanshell PreProcessor
  4. Configure it to send required header name and use ${headerValue} as value

    • I cannot guarantee that above code will suit for your application, it may expect slightly different implementation, however it should be enough for you to get the idea. See HmacUtils class JavaDoc for all the available methods.
    • Check out How to Use BeanShell: JMeter's Favorite Built-in Component to get initial knowledge on Beanshell scripting in JMeter, in particular to learn what vars shorthand stands for

Upvotes: 1

Related Questions