How to implement stress test with NodeJS LoadTest - load-testing

I need to stress test a link that works with curl command below:
curl "http://192.168.1.191:7007/api/v1/users/login" -H "Accept-Encoding: gzip, deflate" -H "Accept-Language: en-US,en;q=0.8,vi;q=0.6" -H "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36" -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -H "Connection: keep-alive" --data "username=test&password=test" --compressed
How can I implement stress test with LoadTest

I found the solution.
I created a file test.txt with content:
username=test&password=test&
After that, run test command:
loadtest "http://192.168.1.191:7007/api/v1/users/login" -n 1000 -c 5 -p test.txt -T 'application/x-www-form-urlencoded'
Please make note that you have to add '&' in the end of test.txt file. This is a issue of LoadTest. I have had a pull request to fix it at https://github.com/alexfernandez/loadtest/pull/63

Related

Unable to add a group member using microsoft graph api in a bash script

If I run below http script from the graph.microsoft.com docs, it works fine.
POST https://graph.microsoft.com/v1.0/groups/9746dce-f530182/members/$ref
Content-type: application/json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6Il9Y-pCiTwLhttVX5wg
{
"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/e7cb-2f96bba6"
}
where:
9746dce-f530182 = group-id,
e7cb-2f96bba6 = user-id and
eyJ0eXAiOiJKV1QiLCJub25jZSI6Il9Y-pCiTwLhttVX5wg = auth-token
I would like to run this as a bash script, so that I can automate the token generation and the POST call. My script looks like so.
CLIENT_ID='283f4d25-87bde0ef'
TENANT_ID='2d987312-a4ff5ea0'
CLIENT_SECRET='XSY8Q~4Ls-ahi'
GROUP_ID="9746dc-00182"
USER_ID='e7cb46-bbbba6'
AT_URL="https://login.microsoftonline.com/${TENANT_ID}/oauth2/token"
auth_response=$(curl -X POST -d 'grant_type=client_credentials&client_id='${CLIENT_ID}'&client_secret='$CLIENT_SECRET'&resource=https://graph.microsoft.com' $AT_URL | jq .)
token="$(echo $auth_response | jq -r .token_type) $(echo $auth_response | jq -r .access_token)"
curl -H "Authorization: $token" -H "Content-type: application/json" -d '{"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/'$USER_ID'"}' "https://graph.microsoft.com/v1.0/groups/$GROUP_ID/members/$ref"
But this fails with the below error. What am I missing?
{"error":{"code":"Request_BadRequest","message":"Unsupported resource type 'DirectoryObject' for operation 'Create'.","innerError":{"date":"2022-05-25T11:24:21","request-id":"e189dc-063e","client-request-id":"e189d-2e42063e"}}}
I managed to fis the issue by changing the last line of the script to the following. The problem was that the $ref at the end of the URL was treated as a bash variable.
curl -H "Authorization: $token" -H "Content-Type: application/json" -d '{"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/'${USER_ID}'"}' 'https://graph.microsoft.com/v1.0/groups/'$GROUP_ID'/members/$ref'
Hope this helps someone else.
The final script looks like below
CLIENT_ID='283f4d25-87bde0ef'
TENANT_ID='2d987312-a4ff5ea0'
CLIENT_SECRET='XSY8Q~4Ls-ahi'
GROUP_ID="9746dc-00182"
USER_ID='e7cb46-bbbba6'
AT_URL="https://login.microsoftonline.com/${TENANT_ID}/oauth2/token"
auth_response=$(curl -X POST -d 'grant_type=client_credentials&client_id='${CLIENT_ID}'&client_secret='$CLIENT_SECRET'&resource=https://graph.microsoft.com' $AT_URL | jq .)
token="$(echo $auth_response | jq -r .token_type) $(echo $auth_response | jq -r .access_token)"
curl -H "Authorization: $token" -H "Content-Type: application/json" -d '{"#odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/'${USER_ID}'"}' 'https://graph.microsoft.com/v1.0/groups/'$GROUP_ID'/members/$ref'

Id attributes are missing in OneNote page content fetched via Microsoft Graph

We are creating a OneNote page using the below Graph endpoint. Several id attributes are present in the HTML content of this page.
POST .. groups/{group-id}/onenote/sections/{section-id}/pages
To get the OneNote page content again, we are using the below graph end point.
GET ..groups/{group-id}/onenote/pages/{page-id}/content?includeIds=true
In the case of one of our customers, when we get the page content, we don't see those id attributes that we added when creating the page. Other customers do not experience this problem.
We checked that we did not PATCH anything on that page before it started returning page content without id attributes.
In debugging, we noticed that if we create a OneNote page and get the page content immediately, we get the IDs back, but if we do it later, we don't.
Here are the details of the latest get request for that page content.
curl $'https://graph.microsoft.com/v1.0/groups/e07ccbcc-3464-4777-aa3a-466cc0db328c/onenote/pages/1-1ea50c06f867479a84ffa6a1f3710e0d\u002157-7b03c43d-87ff-4692-8664-d3a42822b7ed/content?includeIds=true' \
-H 'Connection: keep-alive' \
-H 'Cache-Control: no-cache' \
-H 'sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Microsoft Edge";v="92"' \
-H 'Pragma: no-cache' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'Authorization: Bearer
-H 'client-request-id: 95a44839-0407-4fe7-b497-294c9375ea1f' \
-H 'Accept: application/json, text/plain, */*' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36 Edg/92.0.902.84' \
-H 'If-Modified-Since: Mon: 26 Jul 1997 05:00:00 GMT' \
-H 'Origin: https://app.boarddecisions.com' \
-H 'Sec-Fetch-Site: cross-site' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Referer: https://app.boarddecisions.com/' \
-H 'Accept-Language: en-GB,en;q=0.9,en-US;q=0.8' \
--compressed
Additional Details about ids -
In OneNote page content, for different table elements, we have id attributes.
Example -
<table border="1" data-type="tasks" id="meetingDecisionsTable" style="width:1080px">
......
</table>
We usually get these IDs back in the data-id attribute like below.
For one specific customer, we are not getting any data-id attribute in the page content. We are unable to reproduce this issue outside of the customer's environment. Therefore, it should be tracked with the request id provided above.

Unable to get refresh_token from vimeo ouath

As per a standard ouath2.0 Authorization grant code glow. The code received in query can be used to get an access_token as well a refresh_token.
But I am not able to get refresh_token from vimeo. Just the access_token is being provided with the below curl
curl 'https://api.vimeo.com/oauth/access_token' \
-H 'Accept: application/json, text/plain, */*' \
-H 'Referer: http://localhost:4200/vimeoCallback?code=0772xxxxsomeCode0003f7d818e207b' \
-H 'Authorization: Basic YTMtxxxbasicbase64(KEY:ID)XXXXUg==' \
-H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36' \
-H 'Content-Type: application/json' \
--data-binary '{"grant_type":"authorization_code","code":"0772xxxxsomeCode0003f7d818e207b","redirect_uri":"http://localhost:4200/vimeoCallback"}' \
Please suggest me what I need to get the refresh_token
Your message parameters look good - you just need to send them as form encoded data rather than as JSON - see this link for the syntax.

How do I delete a docker image from docker hub via command line?

I create docker image for testing in my Jenkins pipeline, uploading this to Docker hub and deploy those to Kubernetes. At the end of the testing process, I want to delete the test image from Docker hub (not from test machine). How do I delete docker hub image from command line?
Use the Docker Hub API as documented in:
https://docs.docker.com/v1.7/reference/api/docker-io_api/#delete-a-user-repository
I've just tested a delete of a test image with curl:
curl -X DELETE -u "$user:$pass" https://index.docker.io/v1/repositories/$namespace/$reponame/
Replace $user and $pass with your user and password on the Docker Hub, respectively; and replace $namespace (in my case it's the same as the $user) and $reponame with the image name (in my case was test).
You can delete any <TAG> from your Docker Hub <REPO> by using curl and REST API to the Docker Hub website (at https://hub.docker.com/v2/) rather that to the Docker Hub registry (at docker.io). So if you are not afraid of using an undocumented API, this currently works:
curl -i -X DELETE \
-H "Accept: application/json" \
-H "Authorization: JWT $HUB_TOKEN" \
https://hub.docker.com/v2/repositories/<HUB_USERNAME>/<REPO>/tags/<TAG>/
The HUB_TOKEN is a JSON Web Token passed using Authorization HTTP header, and it can be obtained by posting your credendials in JSON format to the /v2/users/login/ Docker Hub endpoint:
HUB_TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"$HUB_USERNAME\", \"password\": \"$HUB_PASSWORD\"}" https://hub.docker.com/v2/users/login/ | jq -r .token)
2FA => Personal Access Token
Note than when you have 2FA enabled, you’ll need a personal access token (the only password accepted by the API when using 2FA).
Dockerhub has a REST backEnd, then you can use it... it is just skipping the FE...
For example:
export USERNAME=myuser
export PASSWORD=mypass
export ORGANIZATION=myorg (if it's personal, then it's your username)
export REPOSITORY=myrepo
export TAG=latest
curl -u $USERNAME:$PASSWORD -X "DELETE" https://cloud.docker.com/v2/repositories/$ORGANIZATION/$REPOSITORY/tags/$TAG/
This will delete one tag...
In my case, I have microservices, then the REPOSITORY = the Microservice Name...
If I want to delete all the older images, I can iterate on this....
For any PowerShell friends.
$params = #{username='mickey';password='minnie'}
$response = Invoke-RestMethod -Uri https://hub.docker.com/v2/users/login/ -Method POST -Body $params
$token = $response.token;
$orgName = "mickey" #organization or user name
$repoName = "disney"
$Uri = $("https://hub.docker.com/v2/repositories/$orgName/$repoName/")
Invoke-WebRequest -Method Delete -Uri $Uri -Headers #{Authorization="JWT " + $token; Accept= 'application/json' }
It is possible. For a shortcut, Open dev tools in Chrome, go to the network tab. Delete a tag manually from Docker Hub. You will see a request on the network tab in dev tools that goes to https://cloud.docker.com/v2/repositories//tags/. Just right click on that request, Copy, Copy as Curl. It should look something like this...
curl "https://cloud.docker.com/v2/repositories//tags//" -X DELETE -H 'Pragma: no-cache' -H 'Origin: https://cloud.docker.com' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36' -H 'Accept: application/json' -H 'Cache-Control: no-cache' -H 'Referer: https://cloud.docker.com/user/repository/registry-1.docker.io/reponame/tags' -H 'Cookie: ' --compressed
You can now use the new BETA (as of 2022-01) Docker Hub API
https://docs.docker.com/docker-hub/api/latest/
and the docker-hub CLI tool among a few other options.
hub-tool login
hub-tool tag rm myrepo/myimage:mytag

Dart pub publish gives error after authentication

I wanted to put a small library code to pub.dartlang.org
After calling pub publish, it asked me to Allow accessing my google account for sending files. After I allowed by going to the given browser link, it gave me this error in the command line:
Waiting for your authorization...
Authorization received, processing...
ProcessException: No such file or directory
Command: curl --dump-header /tmp/temp_dir1_CzMqQG/curl-headers --cacert /home/afsina/apps/dart/dart-sdk/util/pub/curl/ca-certificates.crt --request POST --location --max-redirs 5 --data-binary #- --header accept: --header user-agent: --header Content-Type: application/x-www-form-urlencoded; charset=UTF-8 --header content-length: 265 https://accounts.google.com/o/oauth2/token
here is the --verbose output
Looks great! Are you ready to upload your package (y/n)? y
IO : Read line: y
FINE: Loading OAuth2 credentials.
IO : Seeing if file /home/afsina/.pub-cache/credentials.json exists.
IO : File /home/afsina/.pub-cache/credentials.json does not exist.
FINE: No credentials found at /home/afsina/.pub-cache/credentials.json.
MSG : Pub needs your authorization to upload packages on your behalf.
| In a web browser, go to https://accounts.google.com/o/oauth2/auth?access_type=offline&approval_prompt=force&response_type=code&client_id=818368855108-8grd2eg9tj9f38os6f1urbcvsq399u8n.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A59097&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email
| Then click "Allow access".
|
| Waiting for your authorization...
MSG : Authorization received, processing...
FINE: Sending Curl request POST https://accounts.google.com/o/oauth2/token
IO : Begin create temp directory .
IO : End create temp directory .
IO : Spawning curl --dump-header /tmp/temp_dir1_RpLNu6/curl-headers --cacert /home/afsina/apps/dart/dart-sdk/util/pub/curl/ca-certificates.crt --request POST --location --max-redirs 5 --data-binary #- --header accept: --header user-agent: --header Content-Type: application/x-www-form-urlencoded; charset=UTF-8 --header content-length: 265 https://accounts.google.com/o/oauth2/token
IO : Spawning curl --dump-header /tmp/temp_dir1_RpLNu6/curl-headers --cacert /home/afsina/apps/dart/dart-sdk/util/pub/curl/ca-certificates.crt --request POST --location --max-redirs 5 --data-binary #- --header accept: --header user-agent: --header Content-Type: application/x-www-form-urlencoded; charset=UTF-8 --header content-length: 265 https://accounts.google.com/o/oauth2/token
ERR : ProcessException: No such file or directory
| Command: curl --dump-header /tmp/temp_dir1_RpLNu6/curl-headers --cacert /home/afsina/apps/dart/dart-sdk/util/pub/curl/ca-certificates.crt --request POST --location --max-redirs 5 --data-binary #- --header accept: --header user-agent: --header Content-Type: application/x-www-form-urlencoded; charset=UTF-8 --header content-length: 265 https://accounts.google.com/o/oauth2/token
I am guessing it cannot find the ca-certificates.crt file but not sure why.
Version Info: Dart SDK version 0.2.10.1_r16761
ubuntu linux 12.10 64 bit
My bad, this was because pub has "curl" dependency. After installing curl I could publish the lib.
If you run pub on Linux or Mac, it will assume curl is in your PATH and try to spawn it without an explicit path. On Windows, it will use the included curl binary. Our assumption here was that most *NIX users would have curl installed already.
This curl dependency should be going away soon anyway, but I'm glad you found the solution.

Resources