How to pass a random User/Pass (for Basic Authentication) with JMeter? - 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.
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)
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?

I would recommend trying the following:
Create a HTTP Authorization Manager Element
Setup the username and password to be variables, ${username} , ${password}
Create a CSV file with your usernames and passwords (do not use a header row)
create a CSV Data Set Config Element, with the variable names set to "username,password" (no quotes, and no space after the comma)
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.

Related

In JMeter how do I set multiple dynamic variables in User Parameters or CSV Data Set Config

Very new to JMeter (and a long time Stack Overflow listener but first time caller so take it easy on me) so any help would be appreciated.
I am trying to set up a JMeter test that uses multiple dynamically generated access tokens to run across scenarios. I currently have a set of data using the CSV Data Set Config containing login credentials of a user's email and password for example:
email1#email.com,password1
email2#email.com,password2
Next I send a HTTP POST request to the Login service which generates an accessToken. Then, I am using the JSON Extractor to grab the generated accessToken. After that I am using the BeanShell Assertion to store the accessToken property/variable.
My issue seems to lie here in this last step since it will only store the last generated variable instead of each of the generated accessTokens. I want to be able to store/overwrite the grabbed accessToken for each email password combination. I would like it to modify/populate the CSV file like this:
email1#email.com,password1,accessToken1
email2#email.com,password2,accessToken2
I have also tried using the Pre Processor > User Parameters
Screen shot of User Parameters
I would like to have the "userBearerToken" variable update/overwrite along with the tests, but I cannot find a way to do so or if this can even currently be done.
I'm finding it difficult to word what I am trying to ask, but basically I want to store multiple dynamically generated variables (accessTokens that change and time out) and use them in other tests. I don't care which component can handle this (either the CSV or User Parameter), but I need to be able to store these variables with their corresponding email password credentials.
If you want to store the accessToken value into a JMeter property for using in other Thread Group(s) be aware that properties are global for the whole JVM and remain until JMeter is restarted so if you define a single accessToken property - each JMeter Thread (or iteration) will overwrite the value.
The solution is to use current thread (or iteration) number as prefix or postfix, this can be done using either __${__threadNum} function or relevant JMeter Variable depending on how iteration is defined or both.
Example setup:
In first thread group: ${__setProperty(access_token_${__threadNum},bar,)}
In second thread group: ${__P(access_token_${__threadNum},)}
Demo:
If you want to save the values into a file writing into the current one is not the best idea as you can (and most probably will) get malformed file due to a form of a race condition. So I would recommend using Sample Variables property instead.
If you add the next line to user.properties file:
sample_variables=email,password,accessToken
JMeter will store the variables named ${email}, ${password}, and ${accessToken} along with their values in the .jtl results file which is basically CSV file which can be re-used anywhere else.
However if you have a requirement to store only the credentials and the token you can go for the Flexible File Writer plugin and configure it to save the aforementioned variables values into a separate file, the relevant configuration would be as simple as:
variable#0,variable#1,variable#2
You can install Flexible File Writer plugin using JMeter Plugins Manager

Jmeter is converting '#' in the Password into junk character

I am recording Login in Jmeter. Password has '#'. Jmeter recorded exact string but when i run the same, '#' is converted to '%40ss' and login is getting failed(login is failing even if i pass parameters through csv file). But if we pass parameters through jmeter Body Data, Login is successful. I dont want to pass through Body Data, i want to send parameters through CSV file. How to achieve this. Please find the attachments
Recorded and Response
My expectation is that it is only a matter of representation, i.e. when I run similar request using a sniffer tool like Wireshark I can see # sign as a part of form data.
Most probably your problem lies somewhere else, i.e. you haven't correlated this __RequestVerificationToken or haven't added HTTP Cookie Manager.
When it comes to load testing ASP.NET web applications you cannot just record and replay your test, you need to perform correlation of dynamic parameters, check out ASP.NET Login Testing with JMeter article for more details.
Lakshmikanth, when you are passing any special character in parameters values then JMeter converts that character into percent-encoding for eg. '#' converts to '%40', '!' converts to '%21'.
To overcome this issue you can pass your password as it is [say P#ssword] in the .csv file but in your request you need to uncheck the encode checkbox corresponding to your password parameter.

How to login multiple different auth0 users with jmeter?

What I am trying to do:
I want to simulate 100 different users (username+password combinations) into the same site (that uses an integrated Auth0 login), and each user clicks a button.
What I tried:
Using other questions from stackoverflow, I created:
- a login.txt file:
and a "CSV data set config":
and a "body data" on the login page, where I tried to take the USER and PASS from the text file:
The problem:
- when I check the Request in the result tree, I can only see the correct username being taken from the login.txt file, but the password field is just ${PASS} and not an actual password:
Questions:
What am I doing wrong, as the password is not loaded from the file?
I have a lot of errors in the result tree, and I think it's because of the Auth0... do you have any guidelines on using it with JMeter?
You variable name you define is PASSWORD and not PASS,
You can call it in your test ${PASSWORD} instead of ${PASS}
Or, in the guideline it states to use ${PASS} so you can change in CSV Data Set Config the Variable Names to USER,PASS

Jmeter doesn't resolve parameter (from CSV Data Set Config) into request

Is try to use the CSV Data Set Config to insert a different username password for each Thread.
When posting to a login page the value of the password variable isn't resolved. The username variable is no problem. The variable is correctly loaded into the Thread because the Debug Sampler is showing the correct value for the password. I already tried to change the name of the variable, perhaps it clashes with some other variable name, but that didn't work.
Perhaps it's because the password field is a different type of input field?
Please let me know if need to clarify this more.. :)
Screenshot to clarify the situation:
1 - CSV-File
2- CSV Data Set Config
3 - Result Debug Sampler
4 - HTTP Request of the login page
5 - Result of the send request to the login page
Because here the variable isn't translated to the value the login process fails.
In your CSV Data Set Config element, in Variable Names (comma-delimited) field you have usernamecsv, pwdcsv... You need to remove space after comma!
usernamecsv, pwdcsv ---> usernamecsv,pwdcsv
This will solve your problem.

jmeter dynamically sign / hash a url

I'd like to test a restful web service which requires a custom authentication scheme (MD5 of the URL with a recent timestamp).
e.g. URL http://test.com/secret/stuff/csv_val?uid=123&ts=1388695589&sig=e8dcf859a079e8670a5765e3eb0413e4
Where csv_val is a dynamic value coming from a CSV file, uid is my user ID, ts is the current timestamp and sig is the MD5 of MY_SECRET_KEYhttp://test.com/secret/stuff/csv_val?uid=123&ts=1388695589
From my research I think I should be using a JSR223 pre-processor to generate the timestamp and MD5 but it is not clear how I can get access to the full URL inside the script. I found an SO post (How to connect Jmeter to Java class?) which looked very promising but doesn't seem to work for me.
So my question is: how can I get access to the HTTP request parameters (host, port, path, protocol, etc...) inside a pre-processor?
You can use user defined variables to store needed values. After that you construct your request the next way:
where values in ${...} are user defined variables. Values for them can be created in BeanShell, BSF or RS2323 preprocessor. Here is some API to work with UDV. Here is pretty similar question jmeter var.putobject variable use in other jdbc request, but it is ignored. And here is a link so that you can read csv_val from CSV file.

Resources