Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a random User/Pass (for Basic Authentication) with JMeter?

I'm using JMeter to stress test an API. I've got Basic Authentication set up - seems to be working great.

Now, i'm trying to randomize the credentials that JMeter passes across the wire. So, there's two ways I know I can do this.

  1. Add a custom HTTP Header (via an HTTP Header Manager Element) and set then value to the random fields (ie. something I've read in from a csv file)
  2. Use the HTTP Authorization Manager Element and pass in the username and password there.

Now, if I try and use method (1) above, I need to create the following header/data :-

Authorization: Basic <some Base64 encoded string in the format username:password>

eg.
Authorization: Basic OnVzZXIxOnBhc3Mx

Kewl. simple. BUT that header value is not getting passed across the wire :( I can add any other header type and it's passed across the wire..

hmm .. ok then .. lets try method (2).

Now that works .. but I can only hardcode in the username & password. I can't see how I can pass in a username VARIABLE (ie. ${usernmae} ) or a password VARIABLE (ie. ${password} ).... If it's hardcoded, then the server correctly replies with the correct page/data.

so .. can someone please help?

like image 632
Pure.Krome Avatar asked Jun 15 '10 05:06

Pure.Krome


1 Answers

I would recommend trying the following:

  1. Create a HTTP Authorization Manager Element
  2. Setup the username and password to be variables, ${username} , ${password}
  3. Create a CSV file with your usernames and passwords (do not use a header row)
  4. create a CSV Data Set Config Element, with the variable names set to "username,password" (no quotes, and no space after the comma)
  5. Each thread/loop will read a different value from the CSV file.

Alternately, if you want the value to be truely random for the login, there are some functions you can use to generate random numbers or send in the time of execution.

like image 176
BlackGaff Avatar answered Oct 18 '22 18:10

BlackGaff