Testing for HTTP 401 Errors in JMeter

UPDATE:

Thanks for tip. However as per JMeter 2.11 it’s quite enough to use just one Response Assertion, erroneous HTTP status code is being ignored, but the assertion checks the response for any patterns defined and if some condition is not met the sampler is being marked as failed. See How to Use JMeter Assertions in 3 Easy Steps guide for more details.

I recently picked up jmeter and writing a test looking for 401 errors produced from the server.  In my particular case I wanted jmeter to recognize that as a specific error that is valid.  The problem is that by default any 4xx or 5xx error is noted as a problem right off the bat.  Due to this we need to a bit of extra work in order for jmeter to tell me that 401 is a valid response for my test.  To make this work, one needs to add TWO Response Assertations.

The first Assertation you need to configure the ‘Ignore Status’ to true.  This might seem convoluted because you need to look for the 401, but we’ll tackle that in the next Response Assertation.   We ignore the status because jmeter processes responses in a specific order, the first assertation would be ignored because jmeter sensed the error.  If we were to put the pattern of 401 in this one, it would never be tested for.

The second assertation is then configured to test the ‘Response Code’ containing a 401.  This assertation will look at the response code and return an OK status for this test like we expect.

Results from this test are exactly what I needed to prove the 401 from the server was being triggered appropriately.

John T Skarbek

John T Skarbek
Im an Infrastructure Engineer at CA Technologies in the Agile Business Unit. Reading and using the latest and greatest of technology is what I want to be doing. Blogging is not something I do on any regular basis (and it shows).

Demonstrating Memory Behavior for AWS Lambda Function Freezing

AWS indicates that when a function is executed, there are some things that getleftover between runs. The execution environment, which AW...… Continue reading

Openshift v3 Deployment Strategy

Published on April 23, 2016

Haproxy URL Rewrite Logging Double Take

Published on May 29, 2015