Post Request with JWT

Hi

I have this Scenario

class IssueWebhook extends Simulation {

//val session : Session

val httpProtocol = http.baseURL(CONNECT_APP)

val paramsMutableMapHack = collection.mutable.MapString, Array[String]

val fireIssueWebhookScenario = scenario(s"Register ${NUM_TENANTS} Tenants")
.feed(tenantKeyFeeder.random)
.feed(userKeyFeeder.random)
.feed(issueKeyFeeder.random)
.exec(http(“update-issue-webhook-request”)
.post("/jira-issue_updated")
.body(ELFileBody(“webhook-template.json”)).asJSON
.queryParam(“jwt”,JwtSigner.generateSignature(“POST”,"/jira-issue_updated", paramsMutableMapHack.toMap,"${tenant}","${user}",“mock-tenant-shared-secret”))
.check(status.is(200)))
.pause(1 second)

setUp(fireIssueWebhookScenario.inject(ramp(NUM_TENANTS users) over (10 seconds)))
.protocols(httpProtocol)
.assertions(global.successfulRequests.percent.is(100))

}

I need to do Post Request with JWT. Gatling-jwt only supports GET. So what I try to do is call to JwtSigner.generateSignature (from Gatling-jwt) to Generate the JWT token and pass it as parameter. The problem is that JwtSigner.generateSignature is generating the Token with exactly “${tenant}” and “${user}”. I though both “${tenant}” and “${user}” are replaced by the current tentant an user of session. Obviusly I am doing something wrong. Pls Help me.

This is the code of JWTSigner.generateSignature

https://bitbucket.org/atlassianlabs/gatling-jwt/src/37984665d5feb177ea5b4047deb68a8f9f226944/src/main/scala/com/atlassian/gatling/jwt/JwtSigner.scala?at=master

This is an example of what is generating:

Header
{ “alg”: “HS256”, “typ”: “JWT” }
Claims
{ “iss”: “${tenant}”, “iat”: 1423749763, “qsh”: “17cf901e7574ec13905582237c2741dece664398dcb6fdc32384b25d4a8fcfa9”, “sub”: “${user}”, “exp”: 1423749943 }
Signature (encoded)
BAGCDK0uHXvS_Ijv3JEsl5fQXCLNKvI61NOqAItXCmU

Thanks a lot!

You have to pass a function to queryParam, not a value.
http://gatling.io/docs/2.1.4/session/expression_el.html#expression

Hi,
thanks for the quickly answer.

I think i get it. There is no possible to get the current value of ${tenant} and ${user} and pass it to JwtSigner.generateSignature to build with the JWT to current tenant and user?.

You can’t use Gatling EL inside custom code.