Validate 'Could not resolve host' use case in Postman - postman

I need to delete a tenant and make sure that the tenant is not accessible anymore. Is there a way to validate 'Could not resolve host' i.e. 'Error: getaddrinfo' in Postman as this error is the expected behavior?
When below curl command is executed in a terminal
curl https://invaliddomain1281738012732.com -v
Proper error message is displayed
curl: (6) Could not resolve host: invaliddomain1281738012732.com
But in postman, is there a way to add a test to validate this behavior?

You won't be able to test the validity of the URL by calling it directly and writing a test on the result, from Postman's Learning Center:
Tests will execute after the response is received, so when you click
Send, Postman will run your test script when the response data returns
from the API.
A workaround to that is to query that URL directly from the Tests tab and assert the response there, e.g.:
pm.test("address doesn't exist", function(){
pm.sendRequest('https://invaliddomain1281738012732.com', (error, response) => {
pm.expect(error.errno).to.eql("ENOTFOUND");
});
})

Related

503 error when fetching an internal NextJS api with query parameters on AWS Amplify

I am trying to fetch data from a JSON file through NextJS internal API on the client side. But it is always throwing 503 error:
The Lambda function associated with the CloudFront distribution is invalid or doesn't have the required permissions.
We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.
I tried to use the GET method with query params in the URL, but it didn't work, then I try the POST method with the query in the body(just to test out), but it also didn't work either.
Here is the code:
const response = await fetch(`/api/search?q=${query}`, {
method: "GET",
headers: {
'Content-Type': 'application/json',
},
})
const res = await response.json()
I have another component that sends some user inputs to save in my DB, and it is working perfectly. (I am really confused why one works but not other given both are equivalent request)
Also, the same app deployed on Vercel is working perfectly. So I think the issue is with Amplify.
Anyone had similar issues with the Next app on Amplify? please help.
most likely you are sending a GET request but you have something in the body. e.g. form-data. this is example in postman.

How to return dynamic response from postman mock server?

I want to return the dynamic response from the postman mock server.
When mock URL hits in the postman, we get request body and from request body I want to fetch the field value and return the value to response.
mock URL : {{url}}/customer
RequestBody:
{
"Id": 47896,
"name": userName
}
I want to send the Id value in the Response Body:
{
"Id":47896
}
We are creating the random Id value in our project and we hit mock URL with that value in request body.
Every time the id value will be different after calling the mock URL. we are processing on the Id value if it mismatch then we throw an error.
Anyway to process the request body?
In the postman documentation, I didn't find any conclusive solution.
There is a limitation you can use dynamic value only in postman app not in newman .
https://github.com/postmanlabs/newman/issues/2565
In postman app you can :
Set response in mock server as :
{
"id":{{id}}
}
Choose environment for mock server :
click edit and choose and environment.
Enable persist variable value settings
Note that this will update both initial and current value with the value you will set as pm.environment.set("name",valu") in your script.
Now set environment variable id through pre-reuest script:
pm.environment.set("id",5)
output
Note:
You should send request two times, first time for the environment to sync with cloud
and second to get updated response , so try to send a dummy request before the actual request .
IN old app it was working fine now it looks like you need two request.

Receive Callback request inside Postman automated test

I am trying to write automated tests with Postman. I am new to postman automation world so sorry if the question will seem dumb.
In the api that I need to test when I send a request I immediately receive a response with a transactionID, no matter transaction succeeded or not. Along with my request I send a CallbackURL to the server where I expect the actual transaction result to be called back. The server will do a PUT request back to the CallbackURL that I have provided with the transactionID and the actual response or error.
So the question is, can I have such kind of scenarios in my postman tests?
I guess I should run a web server and expose an endpoint which will expect a PUT request and I should get the body of this PUT request in my tests to check it, and respond back to it with success.
In other words, within my script I need to perform the following actions:
Do a request to the server passing a callback URL
check the immediate response from the server and keep the returned transactionID
Have a webserver run with an endpoint that I passed as a callback URL
Expect a request to that endpoint with transactionID and actual response
Check that the response is what I actually expected
Respond to the request with success
I was thinking about Postman Mock server, but seems it is not designed for such usage.
I also think may be I can run some JS Webserver (may be nodeJS) inside the postman Sandbox...
Actually I am very new to postman testing and I am really confused about this kind of issue. Is it even possible to do this with postman or I need something else?
There are some features provided by POSTMAN which can help you to resolve your problem
When you do request to server passing callback URL it gives you transactionID in response. Save that transactionID in environment variable or global variable. Same you can do it for callbackURL.
Eg. pm.environment.set("transactionID", transactionID);
Then you can do the second request where you passed callback URL and transactionID which you have already.
In short in POSTMAN there are features like
Set global and environment variable which helps to pass some values fetched from response to another request.
call other request on success of first request
eg. postman.setnextRequest({{requestname}});
If you can mentioned your problem statement little bit in details it will be easy to answer in better way.
Hope This Will Help You

Why is res.cookie() not working in my sails.js app?

Acording to sails.js docs, it is only needed to use req.cookie('name', 'value') in order to make it work, however I can't make it work.
error: Sending 500 ("Server Error") response:
TypeError: res.cookie is not a function
at Object.login [as acounts/login] (/home/emirc/Escritorio/projects/letrica-vB0.1/letrica-beta/api/controllers/AcountsController.js:154:9)

How do you add JSON data to an HTML AWS lambda response body?

I've run into some trouble with a site I am building. It used AWS lambda functions. I am building and deploying on AWS CodeStar.
The site strips the URL parameter (e.g. /BTC), sends that to external API endpoint, which returns some JSON data. I can display the entire JSON response using body: JSON.stringify(response), so it is definitely coming through from the API. However, I would like to the JSON values to HTML markup before sending back to the client. Yet, when I do something like var html = '<h1>JSON.stringify(response['DISPLAY']['BTC']['USD']['MARKET'])</h1>';. I receive an Internal Server Error - Malformed Request.
I can't figure this out. I'm fairly new to the world of AWS, so may be overlooking something, I've looked around in the docs and can't seem to find anything related to this.
Also, when I had the JSON.stringify output displaying on the webpage. If I re-parsed this in the browser console, response['DISPLAY']['BTC']['USD']['MARKET'] returned a value - so I am fairly sure the syntax for the payload data is correct.
exports.get = function(event, context) {
var ticker = event.pathParameters.currency;
rp(`https://min-api.cryptocompare.com/data/pricemultifull?fsyms=${ticker}&tsyms=USD`)
.then(function (response) {
var html = `<h1>${JSON.stringify(response['DISPLAY']['BTC']['USD']['MARKET'])}</h1>`;
context.succeed({
statusCode: 200,
body: html,
headers: {'Content-Type': 'text/html'}
});
})
.catch(function (err) {
console.log('error: ', err);
});
};
Any help would be appreciated! Happy to provide more info if required.
This is caused by a combination of a couple of things, as far as I can tell:
Within your .catch block you are not calling context.error. In other words, if there's an error in your lambda function, the lambda function never signals that it's finished executing properly to the invoker. API gateway throws up its hands in despair and spits out a 502 error.
response is a string, so when you try to access its properties, you cause an exception and end up in your .catch block. First you need to JSON.parse(response)
Here's a helpful note: whenever you call console.log, the log output can be found in CloudWatch > Logs > /aws/lambda/<your-lambda-name>. This can be useful for figuring out why/where things are breaking.