Hi all,
I’m trying to use Gatling to test a site that has basicAuth configured for all access (testing environment). I can successfully make a request using the http.basicAuth call, but when I try a request that results in a re-direct, Gatling automatically follows it, and I get a 401 error page in the log. Looking at the server logs, it seems as though on the second request (the redirect follow), Gatling is not providing the username/password that it used for the first request. Is there any way to control this that I’m missing?
`
val httpProtocol = http
.baseURL(“http://mysite.com”)
.inferHtmlResources()
.acceptHeader(""“text/css,/;q=0.1"”")
.acceptEncodingHeader(""“gzip, deflate”"")
.acceptLanguageHeader(""“en-US,en;q=0.5"”")
.connection(""“keep-alive”"")
.userAgentHeader(""“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Firefox/31.0"”")
val headers_0 = Map(""“Accept”"" → “”“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8"”")
val scn = scenario(“BasicSimulation”)
.exec(http(“Landing Page”)
// Generates a 302 redirect
.get("""/""")
.headers(headers_0)
.basicAuth(""“username”"",""“password”"")
.check(regex(""“input name=“authenticity_token” type=“hidden” value=”(.*)">""").saveAs(“auth_token”)))
`
Thanks!
-Ben
Hi Ben,
If you’re using basicAuth at the request level, only the request on which you used it will be authentified.
What you need is specifying basicAuth at the protocol level, so that all requests will be authentified.
Just move basicAuth so that it set on your httpProtocol rather than on the Landing Page request and it’ll work
Cheers,
Pierre
Hi Pierre,
Thanks for the quick response. I had that thought, and tried moving the basicAuth call - but it doesn’t seem to fix things? It works on the first call (the request to “/“), but then I still get a 401 on the redirect.
Updated code:
val httpProtocol = http
.baseURL(“http://demo.subtext.org”)
.inferHtmlResources()
.acceptHeader(""“text/css,/;q=0.1"”")
.acceptEncodingHeader(""“gzip, deflate”"")
.acceptLanguageHeader(""“en-US,en;q=0.5"”")
.connection(""“keep-alive”"")
.userAgentHeader(""“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Firefox/31.0"”")
.basicAuth(“"“username”"",”"“password””")
That’s strange…
Could you share your simulation ?
Sure. I’ve attached the .scala file with password/usernames cleaned.
Here’s the output log:
`
Select simulation id (default is ‘basicsimulation’). Accepted characters are a-z, A-Z, 0-9, - and _
Select run description (optional)
Simulation consumer.BasicSimulation started…
09:20:42.774 [INFO ] i.g.h.c.HttpProtocol - Start warm up
09:20:43.095 [INFO ] i.g.h.c.HttpProtocol - Warm up done
09:20:43.231 [INFO ] i.g.h.a.HttpRequestAction$ - Sending request=Landing Page uri=http://mysite.com/: scenario=BasicSimulation, userId=1429584253802008026-0
BasicSimulation.scala (3.98 KB)
Hi Ben,
After some investigation, I found that Gatling didn’t propagate the Authorization header on redirects, which caused your bug.
It has been fixed on master : https://github.com/gatling/gatling/issues/2116
Could you grab the latest snapshot on Sonatype (should be available in a few minutes) and check that it has been fixed ?
Cheers,
Pierre
Is this in the latest snapshot build yet? I just downloaded the snaptshot, and it doesn’t seem to be working. (I don’t have a gatling build environment set up)
-ben
Could you provide debug logs, please?
`
Select simulation id (default is ‘basicsimulation’). Accepted characters are a-z, A-Z, 0-9, - and _
Select run description (optional)
Simulation subtextconsumer.BasicSimulation started…
08:19:13.809 [INFO ] i.g.h.c.HttpProtocol - Start warm up
08:19:14.177 [INFO ] i.g.h.c.HttpProtocol - Warm up done
08:19:14.286 [INFO ] i.g.h.a.HttpRequestAction$ - Sending request=Landing Page uri=http://mysite.com/: scenario=BasicSimulation, userId=3435566742843572270-0
Weird.
Are your sure you grabbed the latest snapshot?
I just added some debug info, please grab a fresh snapshot in a few minutes.