Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not generate token using frisby v2 #561

Open
G4gan opened this issue May 21, 2020 · 10 comments
Open

Could not generate token using frisby v2 #561

G4gan opened this issue May 21, 2020 · 10 comments

Comments

@G4gan
Copy link

G4gan commented May 21, 2020

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)

@vlucas
Copy link
Owner

vlucas commented May 21, 2020

Try using inspectRequest() to ensure that the header values are getting passed correctly, and are the values that you expect.

@G4gan
Copy link
Author

G4gan commented May 21, 2020

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

@LarryBattleWork
Copy link

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);
});

@G4gan
Copy link
Author

G4gan commented May 22, 2020

@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
at ClientRequest. (dir\node_modules\node-fetch\lib\index.js:1455:11)
at ClientRequest.emit (events.js:310:20)

@G4gan
Copy link
Author

G4gan commented May 22, 2020

Thanks.
It worked adding above globaSetup().
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

@LarryBattleWork
Copy link

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

@G4gan
Copy link
Author

G4gan commented May 24, 2020

@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.

@H1Gdev
Copy link
Collaborator

H1Gdev commented May 24, 2020

If curl -k option is removed, does it give an error like frisby ?

@G4gan
Copy link
Author

G4gan commented May 25, 2020

@H1Gdev
-k in curl is for verifying server legitimacy.
so in that case it error me with ssl error.

@G4gan
Copy link
Author

G4gan commented Jun 7, 2020

@vlucas Can you please suggest which reporting goes with Jasmine-Frisby project.
Or if any links yo can refer me too.

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants