Skip to content

Conversation

@Kumar-Kishan
Copy link
Contributor

@Kumar-Kishan Kumar-Kishan commented Oct 20, 2025

Description of change

Add socks proxy configuration options

Pull-Request Checklist

  • Code is up-to-date with the master branch
  • This pull request links relevant issues as 10529
  • There are new or updated unit tests validating the change (N/A)
  • Documentation has been updated to reflect this change (N/A), Since MongoClient already has the options

Summary by CodeRabbit

  • New Features

    • Added SOCKS5 proxy configuration support for MongoDB connections with optional proxy host, port, username, and password settings, allowing connections to route through a SOCKS5 proxy.
  • Tests

    • Added functional tests to verify proxy options are passed through when establishing MongoDB connections.

Copilot AI review requested due to automatic review settings October 20, 2025 19:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds SOCKS5 proxy configuration support to the MongoDB driver, enabling TypeORM users to connect to MongoDB through a SOCKS5 proxy server.

Key Changes:

  • Added four new connection options for SOCKS5 proxy configuration: proxyHost, proxyPort, proxyUsername, and proxyPassword
  • Updated the MongoDB driver to recognize and pass through these proxy options to the underlying MongoDB client

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/driver/mongodb/MongoConnectionOptions.ts Defines the new SOCKS5 proxy configuration options as part of the MongoDB connection interface
src/driver/mongodb/MongoDriver.ts Registers the new proxy options in the allowed MongoDB options list for pass-through to MongoClient

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

Walkthrough

Adds four optional Socks5 proxy configuration fields to MongoDB connection options and accepts them in the driver's option validation; adds a test asserting the proxy fields are forwarded to MongoClient.connect.

Changes

Cohort / File(s) Summary
MongoDB Proxy Configuration Fields
src/driver/mongodb/MongoConnectionOptions.ts
Added four optional readonly fields to the connection options interface: proxyHost?: string, proxyPort?: number, proxyUsername?: string, and proxyPassword?: string.
MongoDB Driver Option Registration
src/driver/mongodb/MongoDriver.ts
Added the proxy option names (proxyHost, proxyPort, proxyUsername, proxyPassword) to the list of accepted/registered MongoDB connection options so they are passed through to the client.
Tests — Driver proxy forwarding
test/functional/driver/MongoDriver.ts
Added test group "proxy options" that fakes MongoClient.connect, calls driver.connect(), and asserts the second argument passed to connect contains the proxy configuration fields.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Test
    participant Driver as MongoDriver
    participant Client as MongoClient.connect

    Test->>Driver: create driver with options { ..., proxyHost, proxyPort, proxyUsername, proxyPassword }
    Test->>Client: (fake) replace MongoClient.connect -> Promise.resolve()
    Driver->>Client: connect(uri, options)
    note right of Client #E8F3FF: options include proxyHost,\nproxyPort, proxyUsername, proxyPassword
    Client-->>Driver: Promise resolves
    Driver-->>Test: connect() resolves
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 I sniff a new tunnel, soft and spry,
Four little keys to send bytes by,
Socks5 whiskers, quiet and bright,
Hop—connections tucked out of sight. 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "MongoDB connector now includes SOCKS5 proxy settings" is fully related to the changeset. All three files modified in this PR directly support this claim: MongoConnectionOptions.ts adds four new optional proxy configuration fields (proxyHost, proxyPort, proxyUsername, proxyPassword), MongoDriver.ts extends option validation to accept these proxy options, and the test file adds a test case group verifying proxy option handling. The title is clear, specific, concise, and avoids vague terminology, making it easy for teammates scanning the history to understand that this PR adds SOCKS5 proxy configuration support to the MongoDB connector.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 20, 2025

typeorm-sql-js-example

npm i https://pkg.pr.new/typeorm/typeorm@11731

commit: 36c57e1

Copy link
Collaborator

@gioboa gioboa left a comment

Choose a reason for hiding this comment

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

May I ask you to add a test to validate these new settings?

@Kumar-Kishan
Copy link
Contributor Author

@gioboa i am fine with adding tests. But one small problem. I wasn't able to find any tests for mongodb at all? Do you want me to add them as well?

@gioboa
Copy link
Collaborator

gioboa commented Oct 20, 2025

@gioboa i am fine with adding tests. But one small problem. I wasn't able to find any tests for mongodb at all? Do you want me to add them as well?

Here there are MondoDB tests.

@Kumar-Kishan
Copy link
Contributor Author

@gioboa added test cases. Weren't able to test them locally due to better-sqlite3 build issues on my machine. is there any active work on updating it or moving away from it? I saw some issues pointing to move away from it? Will wait for CI test runners, to see if all fine.

Copy link
Contributor

@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

🧹 Nitpick comments (1)
test/functional/driver/MongoDriver.ts (1)

62-98: Test correctly verifies proxy options are passed to MongoClient.

The test properly mocks MongoClient.connect, calls driver.connect(), and asserts that all four proxy configuration fields are present in the options passed to the underlying MongoDB driver. The use of sinon.fake.resolves({}) is appropriate for this async mock.

Consider adding edge-case tests to improve coverage:

  • Test with partial proxy configuration (e.g., only proxyHost and proxyPort)
  • Test that proxy options coexist correctly with other MongoDB connection options
  • Test behavior with missing optional proxy credentials (proxyUsername, proxyPassword)

These additions would strengthen the test suite but are not critical for the current implementation.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2dedf23 and 36c57e1.

📒 Files selected for processing (1)
  • test/functional/driver/MongoDriver.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
test/functional/driver/MongoDriver.ts (1)
src/driver/mongodb/MongoDriver.ts (2)
  • MongoDriver (32-575)
  • connect (246-258)

Copy link
Collaborator

@gioboa gioboa left a comment

Choose a reason for hiding this comment

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

Thanks @Kumar-Kishan for your help 👍

@gioboa gioboa linked an issue Oct 20, 2025 that may be closed by this pull request
18 tasks
@gioboa gioboa merged commit d7867eb into typeorm:master Oct 20, 2025
61 checks passed
ThbltLmr pushed a commit to ThbltLmr/typeorm that referenced this pull request Dec 2, 2025
mgohin pushed a commit to mgohin/typeorm that referenced this pull request Jan 15, 2026
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.

MongoDB connector ignores SOCKS5 proxy settings

3 participants