Request body is not properly feined in loadtest - node.js

I was using loadtest for load tetsing of my node app. I had issue sending post requests via loadtest. The request is of the form:
loadtest http://localhost:7000/eth/checkEthBalance -T "application/x-www-form-urlencoded" -H "application/x-www-form-urlencoded" -m "POST" --data '{"accountAddress":"0x62720366ef403c9891e2bfbd5358ee3c8a57b113"}' -n 1
But in req.body, I am getting:
{ '{"accountAddress":"0x62720366ef403c9891e2bfbd5358ee3c8a57b113"}': '' }
instead of:
{"accountAddress":"0x62720366ef403c9891e2bfbd5358ee3c8a57b113"}
However a curl request workd fab:
curl -X POST \
http://localhost:7000/eth/checkEthBalance \
-H 'cache-control: no-cache' \
-H 'content-type: application/x-www-form-urlencoded' \
-H 'postman-token: 0bf637f7-2037-c4ca-29a7-cc2310786317' \
-d accountAddress=0x62720366ef403c9891e2bfbd5358ee3c8a57b113
DOn't know what's wrong with loadtest. Any help?

Here how I did it, you need to pass -T 'application/json'
Sample : loadtest -P '{"name" : "ashok dey", "email" : "ashokdey#gmail.com", "password" : "password123"}' -c 100 --rps 2000 http://localhost:3434/register -T 'application/json'
You have to pass the same when you are passing a file containing the post data.

Related

Error in Xray Rest API call for importing Test Execution Result

I know this query has been answered in so many post but those have not helped me. I did research, and tried, but still facing issue in making an API call to import test execution result.
Approach I took:
Created Test(Test Details: Cucumber), Test Precondition, Test Set, Test Plan and Test Execution
Exported Test using "Xray - Export to Cucumber" option
Added this in my BDD-Cucumber framework, executed and it has generated me cucumber.json file after execution
Trying API call using postman
/api/v1/import/execution/cucumber
curl --location --request POST 'https://xray.cloud.xpand-it.com/api/v1/import/execution/cucumber' \
--header 'Authorization: Bearer $token’ \
--header 'Content-Type: application/json' \
--data-binary '#/Users/aranjan/Downloads/cucumber.json'
Error:
{ "error": "Error creating Test Execution - Team is required."}
Now, this means it is trying to create new instead of update existing
Then, I used
/api/v1/import/execution/cucumber/multipart
curl --location --request POST 'https://xray.cloud.xpand-it.com/api/v1/import/execution/cucumber/multipart' \
--header 'Authorization: Bearer $token’ \
--form 'info=#/Users/aranjan/Downloads/xrayresultimport.json' \
--form 'result=#/Users/aranjan/Downloads/cucumber.json'
Error:
{ "error": "Unexpected field (result)"}
xrayresultimport.json
{
"fields": {
"project": {
"key": "HYP"
},
"customfield_10962": [
"Team","TeamQAAuto"
],
"issuetype": {
"id": "10722"
}
}
}
/api/v1/import/execution
curl --location --request POST 'https://xray.cloud.xpand-it.com/api/v1/import/execution' \
--header 'Authorization: Bearer $token’ \
--header 'Content-Type: application/json' \
--data-raw '{
"testExecutionKey": "HYP-3313",
"info" : {
"startDate" : "2020-09-25T11:47:35+01:00",
"finishDate" : "2020-09-25T11:53:00+01:00",
"testPlanKey" : "HYP-3341"
},
"tests" : [
{
"testKey" : "HYP-3330",
"start" : "2020-09-25T11:47:35+01:00",
"finish" : "2020-09-25T11:50:56+01:00",
"comment" : "Successful execution",
"status" : "PASSED"
}
]
}'
{ "error": "Error updating Test Execution - Issue update failed!"}
Agenda:
I want to import the execution result in my existing Test Execution.
I request you to guide me here.
Thanks in advance.
Currently, if you use the multipart endpoint it will always create new Test Executions.
The multipart request has a minor typo: you should have "results" instead of "result". An example would be something like this:
curl -H "Content-Type: multipart/form-data" -X POST -F info=#xrayresultimport.json -F results=#cucumber.json -H "Authorization: Bearer $token" https://xray.cloud.xpand-it.com/api/v2/import/execution/cucumber/multipart
That should make it work :)
Note: concerning the last example you gave, there could be several causes for it, including restrictions on Jira side. That would be analyzed by the Xray support team.

BASH CURL pass json data for POST request

im trying try to POST a request in a BASH script but somehow, my json data cant be find bellow is my code.
header=$(curl -sb -H "Accept: application/json" "http://localhost:4040/api/tunnels")
# this is json format
tunnels=`echo "$header"`
echo "{'token':'xoxp-token-key','channel':'hybridteam','appname':'Server Unit', 'data': ${tunnels}}"
header2=$(curl -H "Content-type: application/json" -H "Accept: application/json" -sb -d "{'token':'token-key-here','channel':'hybridteam-ngrok','appname':'This is testing PC', 'data': ${tunnels}}" -X POST "https://localhost:8080")
success=`echo "$header2"`
echo $success
And my Server gets the data like this
$data = json_decode(isset($_POST['data'])? $_POST['data'] : $_GET['data']);
$token = isset($_POST['token'])? $_POST['token'] : $_GET['token'];
$channel = isset($_POST['channel'])? $_POST['channel'] : $_GET['channel'];
BUT on my server I keep getting this response
<br /> <b>Notice</b>: Undefined index: data in <b>C://xampp/htdocs/server/index.php</b> on line <b>30</b><br /> <br /> <b>Notice</b>: Undefined index: token in <b>C://xampp/htdocs/server/index.php</b> on line <b>31</b><br /> <br /> <b>Notice</b>: Undefined index: channel in <b>C://xampp/htdocs/server/index.php</b> on line <b>32</b><br />
Pls Im new to bash scripting, need your help.
Thanks.
json supports double quotes
curl -H "Content-type: application/json" \
-H "Accept: application/json" -sb \
-d "{\"token\":\"token-key-here\",\"channel\":\"hybridteam-ngrok\",\"appname\":\"This is testing PC\", \"data\": ${tunnels}}" \
-X POST "https://localhost:8080"
and you need to read raw POST body and convert it either into object or to array.
$raw = file_get_contents("php://input");
$data = json_decode($raw,true);
$token = isset($data['token'])? $data['token'] : null;
$channel = isset($data['channel'])? $data['channel'] : null;

how to use the simple-oauth2 library to make request application/x-www-form-urlencoded?

i have some code which perfectly work through mac terminal and giving me token from website
curl -XPOST "https://link.com/oauth/access_token" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: 1.0" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_id=myawesomeapp" \
--data-urlencode "client_secret=abc123" \
--data-urlencode "scope=read write"
I want to do request through nodejs without curl request. website giving link on npm library simple-oauth2, but my code does not work.
my not working version of this
const credentials = {
client: {
id: 'myawesomeapp',
secret: 'abc123'
},
auth: {
tokenHost: 'https://link.com',
tokenPath: '/oauth/access_token'
},
http: {
'headers.authorization': 'headers.Accept = application/x-www-form-urlencoded'
}
};
oauth2 = oauth2.create(credentials);
oauth2.accessToken.create()
If it's an x-www-form-urlencoded content type, you'll probably need to also update the authorisation method in your options to form (its default is header). I.e.
const credentials = {
/*
your existing config
*/
options: {
authorizationMethod: 'body'
}
}
Hopefully that should do the trick...

POST request containing CSR fails in Bash

I've written a bash script that sends a POST request to a server. The request contains a certificate signing request and the server signs it and returns a certificate.
When I copy and paste the CSR text in the POST's body, then the POST request is successful. But when I read the CSR from a variable, then the POST request fails. I've attached a snippet of the program below.
PROGRAM - Bash
openssl req -new -newkey rsa:2048 -nodes -out cert.csr -keyout priv.key -subj "/C=MyCountry/ST=MyState/L=MyCity/O=MyCompany/OU=MyDept/CN=MyComp"
if [ $? == 0 ]; then
csr=$(<cert.csr)
fi
response=$(curl -o - -s -w "%{http_code}\n" -X POST \
https://xxx.xxx.com/URI-END-POINT \
-H "authorization: $token" \
-H "content-type: application/json" \
-d '{
"digicert": {
"csr": "'$csr'",
"profileName": "pn123",
"signatureHash": "sh123",
"userPrincipalName": "pn123",
"validationScopeId": "vsi123"
},
"IccId": "sim123",
"MacAddress": "mac123"
}')
if [ $?==0 ]; then
status=$(echo $response | tail -c 4)
if [ "$status" == "$http_success" ]; then
echo -e "Request for certificate SUCCESS"
else
echo -e "Request for certificate FAILED with return code $status"
fi
else
echo -e "Request for certificate FAILED"
fi
OUTPUT - Bash
curl: option -----END: is unknown
curl: try 'curl --help' or 'curl --manual' for more information
In the above script, if I replace the line "csr": "'$csr'", with "csr": "----BEGIN CERTIFICATE REQUEST---- XXXXXXX ----END CERTIFICATE REQUEST----", then this will work fine.
Can you help me debug this?
Thanks!
Maybe the string in $csr is being evaluated, like if put in double quotes and the resulting string is something different than expected.
For start, try to see if $csr is same as "$csr".
To post the contents of a file, use jq to generate the JSON blob for you: this will take care of any necessary quoting automatically. The output of jq is pipe directly to curl by using the #- argument for the -d option. (A #-prefixed string indicates the name of a file curl should read from; - is the alias for standard input.)
response=$(jq -n --arg csr "$(<csr)" '{
digicert: {
csr: $csr,
profileName: "pn123",
signatureHash : "sh123",
userPrincipalName: "pn123",
validationScopeId: "vsi123"
},
IccId: "sim123",
MacAddress: "mac123"
}' |
curl -o - -s -w "%{http_code}\n" -X POST \
https://xxx.xxx.com/URI-END-POINT \
-H "authorization: $token" \
-H "content-type: application/json" \
-d #-
)

Windows curl string formatting

I am trying to use curl to make an HTTP POST request.
The request contains some environment variables. Here is the command:
curl -X POST -u username:pass -H "Content-Type: application/json" -d "{ \"fields\": { \"project\": { \"key\": \"myproject\" }, \"summary\": \"${var1.name} - ${var2.name}\", \"description\": \"Testing testing!:\n${url}\", \"issuetype\": { \"name\": \"Task\" }}}" http://myurl.com/rest
The information is sent, but the ${var1.name} and ${var2.name} are being sent as literal strings and not as their actual values.
The command is run on windows so that is why I am escaping the quotes. Could that be a problem as to why they're being sent as strings?
Windows environment variables are deferenced as %var1% and %var2%. This works:
C:\>set var1.name=test1
C:\>set var2.name=test2
C:\>set var
var1.name=test1
var2.name=test2
curl.exe -X POST -u username:pass -H "Content-Type: application/json" -d "{ \"fields\": { \"project\": { \"key\": \"myproject\" }, \"summary\": \"%var1.name% - %var2.name%\", \"description\": \"Testing testing!:\n${url}\", \"issuetype\": { \"name\": \"Task\" }}}" http://myurl.com/rest

Resources