One of my projects returns token codes using an HTTP query so users easily can get and renew them if desired. I found one article where the author uses CURL queries to my host.
For example:
curl -k -H 'Authorization: Bearer SQ43OPLR79BIQQFN50PA6KI8MVJ77JT685V0S9TTRNNA6RO41DTA6FK7NR1H466C' -H 'User-Agent: api-test-agent' https://api.hh.ru/employers/2062418
It works and returns a JSON object.
I need an OpenURI-based query. How can I change this CURL command to a simple OpenURI call?
The equivalent request through open-uri is:
require 'open-uri'
puts open('https://api.hh.ru/employers/2062418',
'Authorization' => 'Bearer SQ43OPLR79BIQQFN50PA6KI8MVJ77JT685V0S9TTRNNA6RO41DTA6FK7NR1H466C',
'User-Agent' => 'api-test-agent'
).read
Related
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:
How would I convert:
curl -X DELETE -H "Authorization: token sampleToken" https://api.github.com/repos/sampleUser/deletedRepos
into a command for HTTParty? I'm having trouble dealing with the header. I think the way I input the header currently doesn't work. Here's what I'm trying right now:
HTTParty.delete("https://api.github.com/repos/sampleUser/deletedRepos/", header: "Authorization: token sampleToken")
This is a cUrl command I want to do in Ruby
curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' --data 'screen_name=example' --header 'Authorization: OAuth oauth_consumer_key="example", oauth_version="1.0"' --verbose
So far I only know how to GET requests using Net::HTTP but these don't have headers and data like the cUrl command above.
It would be great if someone could tell me how to GET in Ruby with headers and data.
If you don't mind using additional GEMS, try UniRest
I'm trying to mimic the following curl command that works perfectly:
curl -k -i -d #content.json -H "Content-Type: application/json" -H "Accept: applicaztion/json" https://localhost:909/api/authenticateUser
I'm mimicking the curl command in Ruby/rails. I'm using the rest-client gem. The target is an API written in old-style Perl. The problem is that the API does NOT "see" the payload that is sent in the new ruby code:
pload = '<string>'.to_json
response = RestClient::Request.execute(url: 'https://localhost:909/api/authenticateUser', method: :post, payload: pload, accept: :json, content_type: :json, verify_ssl: false)
What is going wrong? Is my Ruby code bad or is the Perl code "too stupid/old" to pick up the payload from ruby. This is the Perl code:
my $data = $cgi->param('POSTDATA') || "";
I tend to think the problem is with my ruby code since the old Perl code receives the payload properly from the curl command above and from some other old Perl code.
Thanks for the help.
For POSTDATA to be populated,
The request must have a Content-Length header
The value of the request's Content-Length header must be non-zero.
The request method must be POST.
The request must have a Content-Type header.
The value of the request's Content-Type header must not include any of the following:
application/x-www-form-urlencoded
multipart/form-data
application/xml
multipart/related
I have been able to query rally analytics API using DHC(Dev HTTP Client) with the following POST request
http://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/1234/artifact/snapshot/query.js&API_Key=key123
and body
{
"find": {
"ObjectID": 4321
}
}
Is there any way I can do this from Ruby? I have using 'rest-client' but am only getting errors endlessly (400, 403, ....)
Has anyone been able to do this ?
Is this possible using curl?
It's possible using both curl and ruby. You need to set a ZSESSIONID header value equal to your API Key. Curl example here (randomized Workspace OID and API Key):
curl -X POST \
'https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/12345678910/artifact/snapshot/query' \
-H 'content-type: application/json' \
-H 'accept: application/json' \
-H 'ZSESSIONID: _m31qjdm43Ou74h0cACk28zgBUOPm50Xtna2PhQ2L22' \
--data '{"find":{"FormattedID": "DE9", "__At": "current"},"fields":true,"start":0,"pagesize":10,"removeUnauthorizedSnapshots":true}' \
--compressed
It is fairly straightforward to do in Ruby also. The following Gists:
Rally Lookback Connection Helper
Rally Lookback Query Example
Contain a Ruby connection helper for connecting to Rally's Lookback API. The second Gist contains an example of using the connection helper along with a hash representing a find query object. The Ruby example uses httpclient gem as opposed to rest-client gem, but the concept is the same.
Has this API changed ? We had a change in our username recently and since then, running the Query example returns {"_rallyAPIMajor":"2","_rallyAPIMinor":"0","Errors":["Not Found"],"Warnings":[]}
for all the queries.