key authorisation test case by JSON.strongify in JMEter - json

I testing authorisation in JMeter.
Authorisation is by key, who is send in JSON.stringify.
first is open connected by web socket,
next send is key in json format.
how is the best way to testing is? what test case could be?
i think set happy path, and next authentication failed and in this give
1. missing key - what testing/ set this in jmeter ?
2.bad key - not exist - what set this in jmeter?
what could be addicted test case/?
what testing authentication in jmeter?

You can use JMeter WebSocket Samplers in order to open the WebSocket connection and send your request payload. Note that WebSocket Samplers are not a part of official JMeter distribution, you will need to install them using JMeter Plugins Manager. You need WebSocket Samplers by Peter Doornbosch
You can use Response Assertion to add a conditional check to server response and change expected result according to your test case.
With regards to possible test cases - you should stick to the functional requirements and make sure that all of them are covered. If you don't have explicit requirements you're limited only by your fantasy and the time you have to implement your test, several possible use cases could be: something very big, null, numeric, boolean, another JSON object, JSON array, malformed JSON, not sending anything (session timeout), etc.

Related

Extracting value from Json response of POST request in Jmeter using Json Extractor

Post request Json Extractor Get request debug sampler error message I'm using Jmeter for stress testing of my application. Test plan that I'm building has a POST request which creates a user and the next PATCH request updates it. Basically I want to extract user_id from Json response received after POST request and add that id in the body of the next request. For that I use Json extractor in my POST request and when I check Debug Sampler the value is successfully stored. But when I try to use extracted user_id in any subsequent requests of the same thread it is not recognized. However when I tried to extract user_id of already created user with GET request then this user_id is normally recognized by other requests. I'm not sure whether Json extractor is not normally used with POST requests or I'm doing something wrong.
It's impossible to provide an answer without seeing the screenshot of your Test Plan or even better Schematic View (the option is available under "Tools" main menu entry since JMeter 5.1)
Given you're able to see the extracted value in the debug sampler I can think of 2 possible options:
Your syntax of referring the user_id variable is wrong, in JMeter the Variables are accessed like ${user_id}
Placement of your JSON Extractor is wrong, i.e. instead of putting it as a child of a specific sampler you have it at the same level as all Samplers therefore it's getting applied to the Debug Sampler as well and the extracted value gets overwritten. See Scoping Rules user manual section for more information

Nifi RestLookupService in LookupRecord gives JsonParseException

I have a basic NIFI flow with one GenerateFlowFile processor and one LookupRecord processor with RestLookupService.
I need to do a rest lookup and enrich the incoming flow file with rest response.
I am getting errors that the lookup service is unable to lookup coordinates with the value I am extracting from the incoming flow file.
GenerateFlowFile is configured with simple JSON
LookupRecord is configured to extract the key from the JSON and populate it to the RestLookupService. Also, JsonReader and JsonSetWriter is configured to read the incoming flow file and to write the response back to the flow file
The RestLookupService itself exits with JsonParseException about unexpected character '<'
RestLookupService is configured with my API running in the cloud in which I am trying to use the extracted KEY from the incoming flow file.
The most interesting bug is that when I configure the URL to point for example to mocky.io everything works correctly so it means that the issue itself is tight with the API URL I am using (http://iotosk.ddns.net:3006/devices/${key}/getParsingData). I have tried also removing the $key, using the exact URL, using different URLs..
Of course the API is working OK over postman/curl anything else. I have checked the logs on the container that the API is running on and there is no requests in the logs what means that nifi is failing even before reaching the API. At least on application level...
I am absolutely out of options without any clue how to solve this. And with nifi also google is not helpful.
Does anybody see any issue in the configuration or can point me in some direction what can cause this issue?
After some additional digging. The issue was connected with authentication logic even
before the API receives it and that criples the request and and returned XML as Bryan Bende suggested in the comment.
But definitely better logging in nifi will help to solve this way faster...

JMeter Beanshell adds backslash to cookies values

The application for which I am preparing performance script is implemented on Sails and uses cookies for validating authentication for API calls. Using the HTTP Cookie Manager from JMeter did not help as it did not record all the cookie values. I was able to add them manually using beanshell preprocessor
The snippet of beanshell code:
CookieManager manager = sampler.getCookieManager();
Cookie cookie1 = new Cookie("cookie1","someValue","localhost","/",false,0);
manager.add(cookie1);
This code successfully added cookie1 into cookies in JMeter.
I also need to add another cookie which has value similar to JSON.
CookieManager manager = sampler.getCookieManager();
Cookie jsonCookie = new Cookie("cookie1","{\"Element\":{\"child1\":\"child1value\",\"child2\":\"child2value\"}","localhost","/",false,0);
manager.add(jsonCookie);
The value of this new cookie (jsonCookie) looks fine in the Debug Sampler. When I look for this same cookie in the Request, the Cookie variable has additional escape characters added to the doublequote.
Http Request Cookie Data:
cookie1=somevalue;jsonCookie="{\"Element\":{\"child1\":\"child1value\",\"child2\":\"child2value\"}"
Debug Sampler value
COOKIE_cookie1=somevalue
COOKIE_jsonCookie="{\"Element\":{\"child1\":\"child1value\",\"child2\":\"child2value\"}"
The addition of extra escape characters in the cookie data caused the authentication to fail. How do I make sure that the cookie values do not have these additional escape characters?
I have tried fetching these json values from User defined variables as well as passing them directly in Beanshell preprocessor. In both approach the resulting cookie value is the same.
You can change "Cookie Policy" dropdown to netscape in order to remove these "extra slashes"
And actually I don't see any need for scripting here as you can add a custom cookie via User-Defined Cookies section like:
A couple more recommendations:
Don't run JMeter and application under test on the same machine as JMeter can be very resource intensive and you might get into situation when JMeter and application under test will be struggling for the OS resources
If you have to do scripting consider switching to JSR223 PreProcessor and Groovy language as when it comes to high loads Beanshell performance might be a big question mark

Jmeter and Json, extracting and using variables for another request

I'm new to JMeter and I'm probably missing something quite simple...
Note: I'm using a json add-on as well.
After making a request, I extract a value from the response. If I check the view results I'm able to see the correct value in the variable I created.
-Initial extraction of value-
-how I tried to use my new value for a new request-
If I try use the variable in another request, I receive an error because the variable is now the default value.
What am I doing incorrectly that makes the second post request to use the default value and not the value it captured (if I did that correctly).
Thanks
JSON Path Extractor is a Post Processor. It is not a Sampler. It should be the child element of the first request 'Create Order' in your test plan if you are going to extract from the 'Create Order' response. If it is in same level with other requests, the post processor will be executed for each and every samplers in the same level. That is why, You are able to see the value for the first time. Now Post processor tries to extract the value from the Debug Sampler as well. As Debug Sampler does not match your JSON extract condition, It sets the default value.
2 years later (March 2018), with Jmeter version 4.0, solution it's the same.
With the new interface, simply by dragging the json extractor on the http request, the json is limited to perform the extraction operation on it, maintaining the results.

REST Service testing - SOAP UI

I need to add JSON format parameters to request payload to do a POST request in restful service testing. How can I do that in SOAP UI?
You did not specify which version of SoapUI you are using. In version 4.x of SoapUI, they made the same assumption as what FrAn answered: you generally do not want to include a payload for a GET request. In later versions of SoapUI, they corrected this and you are able to do it.
Once you change the method type to POST, on the individual method call, you will see another panel where you are able to define the body. You can see this in the documentation. You will have to write out the entire body manually.
For REST services, the payload is not part of the WADL - which SoapUI uses internally to store the entire definition. You can create a sample Request in your REST service to make creating test cases easier. You can see this in the documentation.
Lastly, some additional information is available in the API Dojo.
HTTP GET request shouldn't contain payload. While you can do that, insofar as it isn't explicitly precluded by the HTTP specification, I would suggest avoiding it simply because people don't expect things to work that way.