frisby
frisby copied to clipboard
Could not generate token using frisby v2
i am using frisby for apis automation and Jasmine for test. I am not able to generate simple token generation using basic Auth
this is how my curl call look like for token generation and same I am trying with Frisby.js.
$ curl -k https://URL -u username:password -H "header:value"
The output brings token like some value
TDIKhjglj7698ssjgljuypubvbi
Same I am doing with frisby to generate token so in this case I am not getting error and my spec is getting passed everytime. Even for negative expects conditions. here is my code
var frisby =require('frisby');
frisby.globalSetup({
request: {
headers: {
'Authorization': 'Basic ' + Buffer.from("username:password").toString('base64'),
'Content-Type': 'application/json+scim',
'header':'value'
}} });
//do setup for Authorization of the token for REST call
it ('uses globalSetup for every test after it is called', function () {
`return frisby
.get('URL')`
` .inspectResponse()`
.expect('status', 400),`
{ strictSSL: false }`
});`
can anyone just point out what exactly am I missing in code. I have tested with response 400 still test is getting passed and token not getting generated. I am using link Frisby Documentation
Also running test using -
#jasmine test_spec.js
Randomized with seed 54594
Started
1 spec, 0 failures
Finished in 0.049 seconds
Randomized with seed 54594 (jasmine --random=true --seed=54594)
Try using inspectRequest()
to ensure that the header values are getting passed correctly, and are the values that you expect.
Thanks @vlucas. If you have read my comment. My test is getting passed even when expect checks for status 200 and provided is 400. And my token is not getting generated in either case. I tried inspectBody(),inspectJson() also inspectrequest(). None worked. If you can tell is there anything else I need to change in my code. I am following this link: https://docs.frisbyjs.com/api-and-usage/setup
Your curl command disables HTTPS cert checking with the -k
flag.
So maybe you need to do the same in the frisby test.
Just guessing but maybe you should add the node-fetch
options to disable HTTPS cert checking.
Try this.
var frisby = require('frisby');
frisby.globalSetup({
request: {
headers: {
'Authorization': 'Basic ' + Buffer.from("username:password").toString('base64'),
'header':'value'
},
// It's one of these
strictSSL : false,
rejectUnauthorized: false
}
});
//do setup for Authorization of the token for REST call
it ('uses globalSetup for every test after it is called', function () {
return frisby.get('URL')
.inspectResponse()
.expect('status', 400);
});
@LarryBattleWork
Getting error when passing either of strictSSL : false, rejectUnauthorized: false in globalSetup()
Failures:
FetchError: request to http://URL/login failed, reason: socket hang up
Stack:
error properties: null({ type: 'system', errno: 'ECONNRESET', code: 'ECONNRESET', constructor: Function })
at <Jasmine>
at ClientRequest.
Thanks. It worked adding above globaSetup(). process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
So your solution looks like this?
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
frisby.globalSetup({
request: {
headers: {
'Authorization': 'Basic ' + Buffer.from("username:password").toString('base64'),
'header':'value'
}
}
});
NOTE: Don't use NODE_TLS_REJECT_UNAUTHORIZED
in production code.
Doc link: https://nodejs.org/api/cli.html#cli_node_tls_reject_unauthorized_value
@LarryBattleWork thanks for response. Can you suggest other property other than this which will work. I tried strictSSL : false, rejectUnauthorized: false Both seems to not work.
Also how can I get the response in variable. I tried .then(function (res) { let postId = res.json; Console.log(postId) } But this seems to give error. Any suggestions.
If curl -k
option is removed, does it give an error like frisby ?
@H1Gdev -k in curl is for verifying server legitimacy. so in that case it error me with ssl error.
@vlucas Can you please suggest which reporting goes with Jasmine-Frisby project. Or if any links yo can refer me too.
Thanks in advance.