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

Disable/Enable SSL certificate verification #370

Closed
ruslK opened this issue Aug 9, 2024 · 9 comments
Closed

Disable/Enable SSL certificate verification #370

ruslK opened this issue Aug 9, 2024 · 9 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@ruslK
Copy link

ruslK commented Aug 9, 2024

Is your feature request related to a problem? Please describe.
We are required to hit our endpoint which is HTTPS with SSL, and we are getting error: Error: unable to verify the first certificate

Describe the solution you'd like
Able to Disable and Enable SSL certificate verification

Describe alternatives you've considered
N/A

Additional context
N/A

@ruslK
Copy link
Author

ruslK commented Aug 9, 2024

I was able to disable with hardcode: process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

@leelaprasadv
Copy link
Member

leelaprasadv commented Aug 9, 2024

@ruslK This has been answered here

Are these self signed certificates or private network API call or behind a proxy ?

A working example that might be of help #293

Note: You will have to ignore parts that doesn't relate to your case in the above example

Additionally, if you have the cert/key pair you can provide it the agent in withCore() and you should be able to make https requests.

@ruslK
Copy link
Author

ruslK commented Aug 9, 2024

@leelaprasadv

Are these self signed certificates or private network API call or behind a proxy ?

  • we don't use proxy.

Additionally, if you have the cert/key pair you can provide it the agent in withCore() and you should be able to make https requests.

  • we don't mock data, we do E2E, we are hitting actual endpoint in environment.

We would be happy disable SSL with pactum, not with process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

@ruslK
Copy link
Author

ruslK commented Aug 9, 2024

@leelaprasadv
Can I ask another question about Redirection?
we have endpoint, which finish with 302 and should be redirected to another endpoint.
When I execute that endpoint in postman, I see in logs that postman makes 5 another call with redirection.
is possible to do with pactum?

@leelaprasadv
Copy link
Member

@ruslK

we don't mock data, we do E2E, we are hitting actual endpoint in environment.

Yes, the example provides you with details on how to use an agent, the suggestion was to pick the block of code related to the agent from the example.

const https = require('https');

// If you have the cert/key pair
const key = fs.readFileSync("server.key")
const cert = fs.readFileSync("server.crt")

const agent = new https.Agent({
  cert: cert, // Optional - add if cert available 
  key: key, // Optional - add if key is available 
  rejectUnauthorized: false // Ignore  certificate errors
});

pactum.spec()
    .get('<https url>')
    .withCore({agent: agent })
    .expectStatus(200)

For follow Redirects, refer to the documention https://pactumjs.github.io/api/requests/withFollowRedirects.html#withfollowredirects

@ruslK
Copy link
Author

ruslK commented Aug 13, 2024

@leelaprasadv
about Redirect

For follow Redirects, refer to the documention https://pactumjs.github.io/api/requests/withFollowRedirects.html#withfollowredirects

what is deep of Redirect? one redirect or not?
and how to config redirections?
and how to see logs for redirections?

@leelaprasadv
Copy link
Member

leelaprasadv commented Aug 13, 2024

PactumJS relies on phin.js for http/https requests and it has a default follow redirect count of 20. Changes to support configuring redirect count in PactumJS can be expected in the next couple of releases.

As for debug logs for redirects, phin under the hood uses follow-redirects, one option I see is to set an environment variable suggested in their readme doc
https://github.com/follow-redirects/follow-redirects/tree/main?tab=readme-ov-file#debug-logging

@ruslK
Copy link
Author

ruslK commented Aug 14, 2024

@leelaprasadv
thank for this tip:

PactumJS relies on phin.js for http/https requests and it has a default follow redirect count of 20. Changes to support configuring redirect count in PactumJS can be expected in the next couple of releases.

As for debug logs for redirects, phin under the hood uses follow-redirects, one option I see is to set an environment variable suggested in their readme doc https://github.com/follow-redirects/follow-redirects/tree/main?tab=readme-ov-file#debug-logging

It is working, but I have issue with cookies, cookies are not passing for next redirected call.
In postman there is config calls Disable cookie jar - if I disable in postman, i'm getting same problem with pactum.
image

So it possible to Enable Cookies Jar with PactumJS?

looks like someone else looking for same: #112

@leelaprasadv
Copy link
Member

PactumJS relies on phin.js for http/https requests and it has a default follow redirect count of 20. Changes to support configuring redirect count in PactumJS can be expected in the next couple of releases.
The above will be handled in #372

Closing the issue as the original question is answered. Please follow up rest of the queries in existing discussions or start a new one if required.

@leelaprasadv leelaprasadv self-assigned this Aug 16, 2024
@leelaprasadv leelaprasadv added the documentation Improvements or additions to documentation label Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants