Jmeter - Cannot generate token - jmeter

Could you please help me ?
I want to create a token folow algorithm on Jmeter:
hash := sha256.Sum256([]byte(orderKey + apiKey))
return hex.EncodeToString(hash[:32])
Thank you so much!

Use __digest function, first argument SHA-256 and second argument string to encode
${__digest(SHA-256,Felix qui potuit rerum cognoscere causas,mysalt,,)}
returns a3bc6900fe2b2fc5fa8a601a4a84e27a079bf2c581d485009bc5c00516729ac7

Related

How can be remove a value from jmeter response using regular expression

Response is {"d":"14049,171681785,347225778"} and I want to extract the value 171681785 from response
Can somebody help me how to write regular expression to extract 171681785 from the above response?
Since 14049 can change, i can advise you to use JSON Extractor indeed. After getting the value of d with $.d, you can use this code in JSR223 Post Proccesor to get the value in the middle.
String[] array = vars.get("yourVariableName").split(",");
vars.put("theValueYouWant", array[1]);

Jmeter values mapping

How to achieve a kind of mapping between string and numeric values that can be used for comparison in assertion? Example:
MAP "DELIVERED"=0
"PENDING"=1
"WAITING"=2
sampler1 - extracted numeric_value=0
sampler2 - assert string value="DELIVERED" is equal to its numeric value
Please check the below test plan:-
I have used variable name from regular expression of 1st sampler in the switch controller like ${regVar}..Then used the second request 3 times i.e. 0,1,2 and used response assertion with the desired value like "DELIVERED"=0 for first sampler under switch i.e "0" then in second "PENDING"=1 i.e "1"..so on.
With this, based on the regEx value from 1st http sample, only one http request will be send for 2nd sampler and that request have it own assertion. I have tried with both positive and negative cases. Please change the assertion value based on your requirements.
Please check if it helps.
Be aware of JSR223 Assertion which allows you to use arbitrary Groovy code to define pass/fail criteria.
You can access the numeric_value using vars shorthand for JMeterVariables class like:
def numericValue = vars.get('numeric_value')
Example code:
def myMap = ['0':'DELIVERED', '1':'PENDING', '2':'WAITING']
def numericValue = vars.get('numeric_value')
log.info('Numeric value is: ' + numericValue)
log.info('Status is: ' + myMap.get(numericValue))
Demo:
More information: Scripting JMeter Assertions in Groovy - A Tutorial
Thanks Dmitri, implemented solution based on your suggestion and it suites fine.

postman - how to generate random number in specific range?

I need to generate random number in specific range for postman.
I wonder if there is possible to generate it and to use it in variable in postman, from what I saw at postman site is:
{{$randomint }}
will give random number between 1-1000
and I already tried to do something like this:
{{$randomint(1,5)}}
to get number between 1-5 but postman didn't get this kind of option, so how to specify range for the random in postman?
You can just use Lodash for this as it's a built-in module:
pm.environment.set("random_number", _.random(1, 5))
Or just add the number 5 to the _.random() function and this will be a number from 0 to 5.
This worked for me:
In your Pre-request script define your variable with:
pm.globals.set('randomNumber', Math.floor(Math.random() * 5));
Then in your URL call your variable in the URL like so:
{{randomNumber}}
Hope this works for you.
A little late.
But none of the above answers worked for me.
I solved it by setting a variable in pre-request tab.
Example:
pm.collectionVariables.set ("randomNum", _.random (20,100));
Then use the variable name in the body of my request (like any other variable)
{
"number": {{randomNum}}
}
Finally, this generates a new number between the desired values in each request
Just use the modulo operation:
const num = pm.variables.replaceIn('{{$randomInt}}') % 5 + 1;
pm.environment.set("random_number", num);
// test
console.log(pm.variables.get('random_number'));

How to decrypt POST request body in golang

I am getting my request body value in encrypted form as below:
9oF0LS0aY0RGGfUEGoT%2FHSdqypxXKh7lmaTawlekrxw%3D
But the actual value I send is:
9oF0LS0aY0RGGfUEGoT/HSdqypxXKh7lmaTawlekrxw=
Any suggestion How I can get correct value.
Your text has been url encoded. Probably because it was a query parameter ?
What you can do is use the url.QueryUnescape function to decode the value.
str := "9oF0LS0aY0RGGfUEGoT%2FHSdqypxXKh7lmaTawlekrxw%3D"
str, _ = url.QueryUnescape(str)

Trying to extract key value from parsed JSON in ruby

I’m trying to parse some JSON from the twitter API and extract the value of a key (“media_url”), which is a sub-key of the key (“entities”)
so far I have:
url = 'https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&screen_name=print_broadcast&count=1'
response = RestClient.get(url)
data=response.body
result = JSON.parse(data)
How would I extract a key value from the parsed JSON?
I’ve tried
result[“entities”]
etc, but I get en error when trying to convert a string to integer... the result of my parsed JSON is an array - shouldn't this be a hash?
Sorry for the dumb questions.
Any help would be appreciated.
The JSON output is actually a list. Granted, it only has one element, but it's still a list.
First get result[0], then you can access ['entries'].

Resources