Bearer token header being dropped - any ideas?

Hi All,

I’m using gatling-charts-highcharts-bundle-3.2.0 and have a simple 2-stage scenario where I need to POST for a bearer token before using it in the next request in an authorization header. After some debugging I’ve found gatling is dropping the header when I set the ‘Authorization’ header value to ‘Bearer ${token}’. If for example I set the value to ‘foo ${token}’, I can see the token is captured correctly and added to the headers for the request.

Can anyone help point me in the right direction?

Thanks,

Tony

Here’s my scenario file:

import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

class NewSimulation extends Simulation {

val bearerHeader = Map(“Content-Type” → “application/x-www-form-urlencoded”)

val authURI = “https://someurl/v1/token
val endpoint = “https://someendpoint/api/test

val scn = scenario(“Testing”)
.exec(http(“Auth”)
.post(authURI)
.headers(headerAuth)
.formParam(“grant_type”, “client_credentials”)
.basicAuth(“user”,“PASS”)
.check(status.is(200))
.check(regex("“access_token”:"(.+?)"").find.saveAs(“token”)))
.exec(http(“Rate”)
.post(rateURI)
.header(“Authorization”, “Bearer ${token}”)
.check(status.is(307)))

setUp(scn.inject(atOnceUsers(1))).protocols()
}

Here’s the output with 'Bearer ${token}":

HTTP request:
POST https://someendpoint/api/test
headers=
accept: /
Referer: https://someendpoint/api/test
origin: https://someendpoint
host: someendpoint
content-length: 0

And here is with ‘foo ${token}’

HTTP request:
POST https://someendpoint/api/test
headers=
Authorization: foo $TOKEN_DATA_IS_HERE
accept: /
Referer: https://someendpoint/api/test
origin: https://someendpoint
host: someendpoint
content-length: 0

Hi Tony,

In your requests, both requests end points are same. “Authorization” header should be passed to first request not subsequent requests.

e.g.
Request 1
add “Authorization” header
Request 2

Please note Request 1 and Request 2 end points should be same, if you try to add in Request 2, it would not work.

Regards,
Mohana Reddy

Hi Mohana,

Thanks for the reply. Since the auth endpoint differs from the main test endpoint should I use two difference scenarios? I’ve actually tried this in other test but I still get the same problem (token is successfully passed between them but Auth header is dropped).

Cheers,

Tony