Can't send a Jmeter request with graphql, 400 response using valid URL - jmeter

From what I've read on https://graphql.org/learn/serving-over-http/ and Performance test for graphQL API, I can send a graphQL request over jmeter.
In the stack overflow example, a graphQL server was built with Apollo and then queried via Jmeter. I am just trying to do load testing and not build schemas or data sets, so I don't have Apollo on my local machine, and I'm also not sure that I would be testing the QA environment if I did try to do this all locally.
I can access our graphQL at https://proprietary-website/graphql/gql and if I run the following query, it returns the expected results:
query currentUserProfile {
currentUserProfile {
id
}
}
Now, I try to apply that to jmeter
I create a HTTP Request in my thread group with protocol: https, server name: proprietary-website, method: GET, path: /graphql/gql
I create an HTTP Header Manager and include the required Bearer Token and Content-Type headers
I create a listener to View Results Tree
Then I run a jmeter load test with 500 threads
I see the valid URL passed in the request body:
GET https://proprietary-website/graphql/gql
GET data:
{"query":{"currentUserProfile {id}"}}
[no cookies]
but I get back:
HTTP/1.0 400 Bad Request
Content-Type: text/html; charset=UTF-8
Referrer-Policy: no-referrer
Content-Length: 1555
Date: Thu, 12 Dec 2019 16:40:26 GMT
I am new to graphql, am I not allowed to send Jmeter requests to the URL my dev gave me and do I have to use the apollo server? If so, can someone point me to some examples?
I am on Windows 10
I also tried:
k6, but this requires docker and i have no admin rights on my computer
easygraphql-lt but when I ran a test script with #easygraphql-lt, I got dependency errors that I don't quite understand how to fix
I looked at easygraphql-load-tester, but this would require me to have access to the project but all i have is the website. I don't have a graphQL.js or an index.js to reference
UPDATE: I just saw that I can copy the query as a curl request so I pasted that request in command line and it gave me extra headers that I put in my jmeter HTTP Header manager:
$ curl 'https://proprietary-website/graphql/gql' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Origin: https://proprietary-website' -H 'Authorization: Bearer redacted' --data-binary '{"query":" query currentUserProfile { currentUserProfile { id }}"}'
But I still get a 400 back, so I think I need to send the query differently as it is showing appended as a --data-binary (not sure what that means). I tried some other SO suggestions, no luck so far
I also tried against an app out of the O'Reilly graphql book, snowtooth.herokuapp.com. This was simpler, so the curl request was simpler, and the information I pasted into jmeter was less, but I still got the error: GET query missing using Protocol: HTTP, server name: snowtooth.herokuapp.com, method: GET and Body Data: {"query":"query { allLifts { name}}"}, plus all the requisite headers in the Header Manager

Not sure what your proprietary website implementation is, however this http://snowtooth.herokuapp.com/ can be tested like:
HTTP GET request:
HTTP POST request:
Also be aware that since JMeter 5.1 it's possible to create a JMeter test plan from CURL command, this http://snowtooth.herokuapp.com/ gives me the following CURL command:
curl 'http://snowtooth.herokuapp.com/' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Origin: http://snowtooth.herokuapp.com' --data-binary '{"query":"{allLifts{name}}"}' --compressed
And when I import it to JMeter I can execute the requests successfully:

Related

postman binary data-type detect and save in laravel request

In postman there is an option to send binary datatype in a api.
I am sending that in a api where but i am unable to detect that binary file in laravel request method.
curl --location --request POST 'http://192.168.*.*/api/v1/contact_us/save' \
--header 'Authorization: Bearer some_key' \
--header 'Content-Type: image/jpeg' \
--data-binary '#/Users/username/Desktop/filename.jpeg'
Above is my curl code generated in postman.
Although i am successfully getting this file when i request in multipart/form-data
I did see a question related to it but it is not the exact case
related question
If the HTTP request payload is purely a file (ie. not from a HTML form) then you can access it in Laravel using:
$request->getContent()

Microsoft Bot Framework (WebChat) - 500 Internal Server Error

From "Test in Web Chat" window in Azure Dashboard, I entered "hello" which is correctly received in my backend, but I'm still figuring out how to reply.
Note: WORDS IN CAPS means variable.
curl -d "grant_type=client_credentials&client_id=CLI-ENT-ID&client_secret=SECRET&scope=https%3A%2F%2Fapi.botframework.com%2F.default" -X POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
Response: {"token_type":"Bearer","expires_in":3600,"ext_expires_in":0,"access_token":"VERY_LONG_STRING"}
curl -d '{"type":"message","from":{"id":"mybot#SOME_ID","name":"mybot"},"conversation":{"id":"CONVERSATION_ID"},"recipient":{"id":"RECIPIENT_ID","name":"You"},"locale":"en","text":"hello too","replyToId":"CONVERSATION_ID|0000008"}' -H "Content-Type: application/json" -H "Authorization: Bearer VERY_LONG_STRING" -X POST https://api.botframework.com/v3/conversations/CONVERSATION_ID/activities/CONVERSATION_ID%7C0000008
Response: The page cannot be displayed because an internal server error has occurred.
Request from my app (also same error):
POST /v3/conversations/CONVERSATION_ID/activities/CONVERSATION_ID%7C0000008 HTTP/1.1
Accept: application/json
Content-Type: application/json
Authorization: Bearer VERY_LONG_STRING
User-Agent: Java-SDK
Content-Length: 273
Host: api.botframework.com
Connection: Keep-Alive
Accept-Encoding: gzip,deflate
{"type":"message","from":{"id":"mybot#SOME_ID","name":"mybot"},"conversation":{"id":"CONVERSATION_ID"},"recipient":{"id":"RECIPIENT_ID","name":"You"},"locale":"en","text":"hello too","replyToId":"CONVERSATION_ID|0000008"}
What do I miss?
Thanks to comment from Eric Dahlvang, I figure it out.
By default, ApiClient generated from swagger will have its basePath hardcoded to https://api.botframework.com.
Before replying, take the serviceUrl from incoming Activity and use it to change the basePath.

How do I pull some information from a website via bash?

I would like to get the specific information from this site BTC value:
foxbit.com.br
I would just like to take the value of the BTC , but with WGET and CURL can not , because the value of the page is not static .
Do this is possible?
Here's how you can go about doing such things:
Load the page and see that the values load shorly after the page. This indicates that it's updated by a separate ajax request.
Open the Chrome developer console and look through the small handful of requested xhr resources to see which document it comes from.
Right click the request and copy as cURL.
You get some monstrosity like this:
curl 'http://www.foxbit.com.br/cdn-cgi/pe/bag2?r\[\]=https%3A%2F%2Fapi.blinktrade.com%2Fapi%2Fv1%2FBRL%2Fticker%3Fcallback%3DjQuery21109214518333319575_1448214593730%26crypto_currency%3DBTC%26_%3D1448214593731' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'PE-Token: 136c4c7c7a1e6a4bea75c61a93655067d5752459-1448214593-1800' -H 'Accept-Language: en-US,en;q=0.8,no;q=0.6,nb;q=0.4' -H 'User-Agent: Mozilla/5.0 (X11; CrOS x86_64) AppleWebKit/530.00 (KHTML, like Gecko) Chrome/45.0.0.0 Safari/530.00' -H 'Accept: */*' -H 'Referer: http://www.foxbit.com.br/' -H 'Cookie: __cfduid=d069fe8cecbd20bd0d09a5c04fbc398601448214586; _gat=1; _ga=GA1.3.1862709458.1448214588' -H 'Connection: keep-alive' --compressed
However, the URL clearly indicates that it just fetches from some other API, so we decode that URL and get:
https://api.blinktrade.com/api/v1/BRL/ticker?callback=jQuery21109214518333319575_1448214593730&crypto_currency=BTC&_=1448214593731
And we can drop the parameters that seem irrelevant and see what we get now:
$ curl 'https://api.blinktrade.com/api/v1/BRL/ticker?crypto_currency=BTC'
{"high": 1272.5, "vol": 50.77552492, "buy": 1238.51, "last": 1244.0, "low": 1238.13, "pair": "BTCBRL", "sell": 1243.99, "vol_brl": 63522.33386051}
Nice clean JSON. We can now easily make a command fetching and picking out the value we're interested in with the json tool jq:
$ curl -s 'https://api.blinktrade.com/api/v1/BRL/ticker?crypto_currency=BTC' |
jq '.last'
1244

Ruby cURL POST Request not going through

I am using Paw, an application to test REST requests. I have the follow request working using the application but need to change it to use cURL to use in my ruby on rails application.
POST /rest/api/latest/result/TRUNKDEVQAUNIT-TESTANDRGITBUILDDEV-12/comment HTTP/1.1
Content-type: application/json
Accept: application/json
Authorization: Basic dWkud29ya2JvdDpFVmgzUFQ0dEch
Cookie: JSESSIONID=C851F60AFB4A83F12753B9CCBC745093
Host: bamboo10.com
Connection: close
User-Agent: Paw/2.2.5 (Macintosh; OS X/10.10.5) GCDHTTPRequest
Content-Length: 32
{"content":"here is a comment, for testing purposes“}
I think it should look something like this but it is not working. I did not add the real username and password (or host) in for security reasons. Any help would be much appreciated. Thank you!
`curl -X POST -u username:password --data {"body": "This is a comment, for testing purposes"} -H "Accept: application/json" -H "Content-type: application/json" https://bamboo.com/rest/api/latest/result/TRUNKDEVQAUNIT-TESTANDRGITBUILDDEV-12/comment`
After a little time, I found the correct way to do it. It appears I was missing a ' before and after the data, as well as changing the json element to be content and not body
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -u username:password -d '{"content": "This is a comment, for testing purposes"}' https://bamboo10.com/rest/api/latest/result/TRUNKDEVQAUNIT-TESTANDRGITBUILDDEV-12/comment

How to update a TeamCity build parameter using REST+cURL

I have a configuration parameter called "testing" in one of my build configurations in TeamCity. After taking a look at the TeamCity REST API doc here I could get information about this parameter using the following cURL command line commands on Windows:
(1) curl -X GET -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters
(2) curl -X GET -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
Response:
(1) <?xml version="1.0" encoding="UTF-8" standalone="yes"?><property name="testing" value="11"/></properties>
(2) 11
But then, when I try to update this "testing" build parameter using the following command, I get an error message:
curl -X PUT -d "1" -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
Response:
Error has occurred during request processing (Unsupported Media Type).
Error: javax.ws.rs.WebApplicationException
Not supported request. Please check URL, HTTP method and transfered data are correct.
I already successfully use a similar command to update the buildNumberCounter setting of the same build configuration:
curl -X PUT -d "1" -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/settings/buildNumberCounter
That's why I thought I can do the same with a build parameter in a similar way. What am I missing here?
UPDATE:
I managed to update the "testing" build parameter with value "1" using Fiddler. The request I composed had the following content:
Request: PUT
URL: http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
Request headers: Authorization: Basic (...)
Request body: 1
So the problem with my cURL command above is probably somewhere around the -d "1" option. But where?
UPDATE 2:
I'm not sure if that makes any difference, but I use this cURL build on Windows 7.
Instead of fixing the failing cURL command, as a workaround, we use now Node.js to compose and send the REST request to TeamCity.
The script that needs to be fed to node.exe is as follows:
// Equivalent cURL command:
// curl -X PUT -d "1" -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
var http = require('http'),
options = {
hostname: 'teamcity',
port: 8080,
path: '/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing',
method: 'PUT',
headers: { 'Authorization': 'Basic (...)' }
},
req;
req = http.request(options, function(res) { });
// write data to request body
req.write('1');
req.end();
Although the workaround works perfectly, I would still like to know what's wrong with the above cURL command?
For parameters that are non-XML like the one you are asking about, just add:
--Header "Content-Type: text/plain"
For parameters that are XML then you'll want to switch that to:
--Header "Content-Type: application/xml"
I was having a hard time figuring this out too but I found the answer. Instead of using -d and -H at the front. Use --data and --header at the end as shown below . I found this in the TeamCity docs buried in a "click to expand" example.
Set build number counter:
curl -v --basic --user <username>:<password> --request PUT http://<teamcity.url>/app/rest/buildTypes/<buildTypeLocator>/settings/buildNumberCounter --data <new number> --header "Content-Type: text/plain"
Set build number format:
curl -v --basic --user <username>:<password> --request PUT http://<teamcity.url>/app/rest/buildTypes/<buildTypeLocator>/settings/buildNumberPattern --data <new format> --header "Content-Type: text/plain"
I guess the REST API expect XML as input, add
-H "Content-type:text/xml"
and put XML as input. If you have a XML file file.xml :
curl -d "#/path/to/file.xml" -H "Content-type:text/xml" (...)

Resources