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

fix: allow set rejectUnauthorized = true on urllib.request options #561

Merged
merged 3 commits into from
Dec 7, 2024

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Dec 7, 2024

closes #531

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced HTTP client configuration with options for handling HTTP/2 and unauthorized requests.
    • Introduced new tests for validating behavior with rejectUnauthorized set to false.
  • Bug Fixes

    • Improved error handling and address validation in HTTP client tests.
  • Documentation

    • Updated comments for clarity and consistency in the HttpClient class.
  • Chores

    • Updated dependency management for improved security and functionality.

Copy link

coderabbitai bot commented Dec 7, 2024

Warning

Rate limit exceeded

@fengmk2 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 37 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between dc478f0 and cca519c.

Walkthrough

The pull request includes updates to the package.json file, specifically changing the version of the selfsigned dependency and removing the https-pem dependency. Additionally, it modifies the HttpClient class to improve the handling of HTTP client options, particularly around the rejectUnauthorized setting. New test cases are added to validate these changes, ensuring that the HTTP client behaves correctly when configured for secure connections and HTTP/2 support.

Changes

File Change Summary
package.json Updated selfsigned dependency from ^2.0.1 to ^2.4.1; removed https-pem from devDependencies.
src/HttpClient.ts Reformatted comments in ClientOptions; no functional changes.
src/index.ts Added variables for HTTP client configurations; updated getDefaultHttpClient and request method signatures to include new options.
test/HttpClient.test.ts Replaced pem with selfsigned; updated server creation logic; added tests for HTTP/2 support.
test/fixtures/server.ts Renamed variable from pems to pem for consistency in self-signed certificate generation.
test/options.rejectUnauthorized-false.test.ts Introduced tests for rejectUnauthorized: false behavior with HTTP/2.
test/options.timeout.test.ts Replaced pem with selfsigned for server setup; focused on timeout error handling.

Assessment against linked issues

Objective Addressed Explanation
Ensure rejectUnauthorized works as expected (#531)

Possibly related PRs

Suggested labels

bug

Poem

🐇 In the meadow where bunnies play,
The code has danced a bright new way.
With selfsigned now in tow,
Secure connections start to flow.
HTTP/2 hops with glee,
A happy client, just like me! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

pkg-pr-new bot commented Dec 7, 2024

Open in Stackblitz

npm i https://pkg.pr.new/node-modules/urllib@561

commit: cca519c

Copy link

codecov bot commented Dec 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.79%. Comparing base (8cf5c3b) to head (cca519c).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #561      +/-   ##
==========================================
+ Coverage   93.27%   94.79%   +1.51%     
==========================================
  Files          11       11              
  Lines        1235     1267      +32     
  Branches      286      305      +19     
==========================================
+ Hits         1152     1201      +49     
+ Misses         79       62      -17     
  Partials        4        4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
test/HttpClient.test.ts (1)

463-469: Verify the usage of the hostname variable

The variable hostname is initialized and assigned within the checkAddress callback. Ensure that this variable is used later in the test to validate the hostname check functionality.

If hostname is intended for assertion purposes, consider adding assertions to utilize this variable effectively.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9dde585 and dc478f0.

📒 Files selected for processing (7)
  • package.json (1 hunks)
  • src/HttpClient.ts (1 hunks)
  • src/index.ts (2 hunks)
  • test/HttpClient.test.ts (4 hunks)
  • test/fixtures/server.ts (1 hunks)
  • test/options.rejectUnauthorized-false.test.ts (1 hunks)
  • test/options.timeout.test.ts (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/HttpClient.ts
  • test/fixtures/server.ts
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/index.ts

[warning] 40-46: src/index.ts#L40-L46
Added lines #L40 - L46 were not covered by tests

🔇 Additional comments (6)
src/index.ts (1)

39-46: Lines 39-46 are not covered by tests

According to static analysis, the branch handling allowH2 when rejectUnauthorized is not false lacks test coverage. This may lead to untested behaviors in production.

Consider adding unit tests to cover these lines to ensure that the allowH2 logic functions correctly when rejectUnauthorized is true or undefined. This will increase confidence in the functionality and prevent potential issues.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 40-46: src/index.ts#L40-L46
Added lines #L40 - L46 were not covered by tests

test/HttpClient.test.ts (2)

121-125: Updated to use selfsigned library for certificate generation

The change from pem to selfsigned for generating self-signed certificates seems appropriate and aligns with the updated dependencies.


179-183: Consistent use of selfsigned in tests

The test setup now consistently uses selfsigned to generate SSL certificates. This ensures uniformity across tests.

test/options.rejectUnauthorized-false.test.ts (1)

1-70: Added tests for rejectUnauthorized: false

The new test cases effectively verify that setting rejectUnauthorized to false allows connections to servers with self-signed certificates, both in HTTP/1.1 and HTTP/2.

package.json (1)

75-75: Updated selfsigned dependency version and removed https-pem

The selfsigned library has been updated to ^2.4.1, and https-pem has been removed from devDependencies.

Please verify that the new version of selfsigned is compatible and does not introduce any breaking changes that could affect certificate generation in tests. Reviewing the changelog for selfsigned is recommended.

test/options.timeout.test.ts (1)

4-4: Replaced pem with selfsigned for SSL certificates in tests

The tests now use selfsigned to generate SSL certificates, ensuring consistency across the test suite.

Also applies to: 49-53

@fengmk2 fengmk2 merged commit 88785e1 into master Dec 7, 2024
24 checks passed
@fengmk2 fengmk2 deleted the support-request-rejectUnauthorized branch December 7, 2024 11:46
fengmk2 pushed a commit that referenced this pull request Dec 7, 2024
[skip ci]

## [4.6.6](v4.6.5...v4.6.6) (2024-12-07)

### Bug Fixes

* allow set rejectUnauthorized = true on urllib.request options ([#561](#561)) ([88785e1](88785e1))
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

Successfully merging this pull request may close these issues.

rejectUnauthorized not work for me
1 participant