I'm attempting to test an HTTP service with JMeter. The HTTP service requires authentication through a simple bearer token mechanism. I'm trying to proceed as follows:
- POST authentication request
- Store token as a variable
- Set Authorization HTTP header to stored variable
- Request protected resource(s)
- Evaluate performance
So far I've been able to post the request, get the token, extract it with regex, save it to a variable, and assert that the variable is appropriately set.
The problem is getting the variable into the HTTP header. In the "Header Manager" the value is set like this:
Unfortunately when the next requests are issued their authorization header has the value "Bearer ". Searching around the internet led me to believe that headers are configured before the thread starts, which would explain the "Bearer "
My sampling/grouping/nesting is as follows:
All the tests pass up to get restricted resource, which fails with a 400, since the authorization header is malformed.
I feel like I'm missing something really obvious, and/or approaching this problem the wrong way.
See Question&Answers more detail:os