I have a Collection that has POST requests in it.
This collections needs bearer token for auth.
The Pre-request script and Tests assertion is written at Collection level.
Problem: The collection works fine when ran in Postman, but when I run it in Azure… it throws “Syntax Error Unexpected token at test-script inside…”. And none of the assertions written at collection level is validated as indicated by 0 in report.
How can I resolve Unexpected token issue and have the assertions run. Thanks.
PRE-Request Script:
postman.setEnvironmentVariable("guid", genHexString(32));
const parse =require('csv-parse/lib/sync');
const holiday = parse(pm.environment.get("holiday"),{
});
Tests:
const responseData = pm.response.json();
const csv_data = pm.environment.get("test_data");
const parse = require('csv-parse/lib/sync');
const csv_parsed_json_data = parse(csv_data, {
});
pm.test("Response has a body", () => {
pm.response.to.be.withBody;
});
pm.test("response body is json", () => {
pm.response.to.have.jsonBody()
});
Error message in Azure
# failure detail
01. SyntaxError
Unexpected token .
at test-script
inside "Set library"
02. SyntaxError
Unexpected token .
at test-script
inside "Obtain Token"
03. SyntaxError
Unexpected token .
at test-script
inside "Introspection"
04. SyntaxError
Unexpected token .
at test-script
inside "test case for so and so "
Related
I am using Hapi-auth-jwt2 and facing an issue after my JWT expire, instead of getting a 401 error I am getting 500 server error,
Here is my code:
const prepare = async () => {
if(prepared){
return;
}
await server.register(documentor as any);
server.auth.strategy('token','jwt',{
key:JWT_TOKEN,
validate: AuthService.verify,
verifyOptions:{
algorithms:['HS256']
}
});
server.auth.default('token');
server.validator(Joi);
server.route(routes);
prepared = true;}
it is working fine if token is valid, but in case of invalid token it suppose to return 401, but i am getting 500, if i am using ignoreExpiration: true in verifyOptions it is again working.
this is related to #328, since i am using v10.2.0 it is suppose to be fixed, still not working in my case.
Also in case of invalid token or expired token validate: AuthService.verify is not getting called.
I don't know what is wrong with it. Please help.
Here is a debug error message if that helps
Debug: auth, unauthenticated, error, token
Error: Expired token
at Object.raiseError (/Users/tinkeshwar/Sites/proj/tool/node_modules/hapi-auth-jwt2/lib/index.js:302:45)
at Object.internals.authenticate (/Users/tinkeshwar/Sites/proj/tool/node_modules/hapi-auth-jwt2/lib/index.js:171:26)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at Object.authenticate (/Users/tinkeshwar/Sites/proj/tool/node_modules/hapi-auth-jwt2/lib/index.js:353:22)
at exports.Manager.execute (/Users/tinkeshwar/Sites/proj/tool/node_modules/#hapi/hapi/lib/toolkit.js:60:28)
at module.exports.internals.Auth._authenticate (/Users/tinkeshwar/Sites/proj/tool/node_modules/#hapi/hapi/lib/auth.js:258:30)
at Request._lifecycle (/Users/tinkeshwar/Sites/proj/tool/node_modules/#hapi/hapi/lib/request.js:372:32)
at Request._execute (/Users/tinkeshwar/Sites/proj/tool/node_modules/#hapi/hapi/lib/request.js:280:9)
Debug: internal, error
ValidationError: "attributes" is not allowed
statusCode: Joi.any().optional().example(401),
error: Joi.any().example("Unauthorized"),
message: Joi.any().example("Missing authentication"),
attributes: {error: "Expired token"}
}).label("Unauthorized Error");
you should probably compare your schema for the unauthorized responses.
My React Native 0.62.3 app receives a string value returned from nodejs 12.16.x. Here is the function on nodejs server:
return res.status(200).send(who); //<<==who is string "seller"
At front end, the returned value is received in res:
let res = await helper.getAPI(url, _result, "GET");
let res1 = await res.json(); //<<== here throw error
However the above code throws error:
isWho : [SyntaxError: JSON Parse error: Unexpected identifier "seller"]
I don't quite understand why the value "seller" is treated as Unexpected identifier. What is the right way to parse return from nodejs sever for string value?
I try to make an API call with Node Js.
My Goal is to get the current state of my Phillips hue light.
But i always get an error message: SyntaxError: Unexpected token u in JSON at position 0
I searched the web but couldn't find a solution to solve the problem and i don't understand what this error message means.
here is the code i use to make the call( don't worry "username" is just a place holder).
const request = require('request');
request('https://192.168.1.10/api/<username>/lights/', function (error, response, body) {
var huelights = JSON.parse(body)
console.log(huelieghts);
});
I am trying to set up Spotify authorization using Authorization Code Flow ( as from https://developer.spotify.com/documentation/general/guides/authorization-guide/#authorization-code-flow ) and got stuck receiving the tokens from the Spotify server.
When I make the POST request, I log the response body and set two variables: access and refresh tokens. The response body indeed contains these tokens, the variables are, however, are undefined (see logs).
console.log("Response.body: ")
console.log(response.body);
var access_token = response.body['access_token'],
refresh_token = response.body['refresh_token'];
console.log("Access: " + access_token);
console.log("Refresh: " + refresh_token);
I've tried both body.access_token and response.body.access_token as well.
A 2019-09-03T09:13:03.184411Z Response.body:
A 2019-09-03T09:13:03.184575Z {"scope":"playlist-modify-private","access_token":"BQAjB5eurOdl3oM2j-8db4pKi-...","token_type":"Bearer","refresh_token":"AQDtEcfw…
A 2019-09-03T09:13:03.184607Z Access: undefined
A 2019-09-03T09:13:03.184618Z Refresh: undefined
Make sure to convert the body to a proper object before trying to access properties.
Try the following:
const body = JSON.parse(response.body);
I'm trying to store a postman collection variable for a JWT token after a user logins. I am getting this error:
SyntaxError | Invalid or unexpected token
For reference this is what I've been using for the tests
var data = pm.response.json();
pm.environment.set(“token”, data.token);
response from POST on user login
{
"success": true,
"token": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjYjRhN2E0Njg5MzBiN2FkOTI0MzUwZCIsIm5hbWUiOiJWaW5jZW50IFRhbmciLCJpYXQiOjE1NTUzNzEzMDYsImV4cCI6MTU1NTM3NDkwNn0.P3V2YRcAAkZugJnCZ-GYFcCqFHDn4ei45kh5MgO2r0s"
}
Picture of POST request for user to login
Okay I figured out the solution.
I copied the snippet from a blog but the blog rendered the quotations as Unicode characters instead of just regular quotes.
Original statement:
pm.environment.set(“token", data.token);
Revised:
pm.environment.set(“token", data.token);