-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Add option to enable encryption on MSSQL Server db #4134
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
Merged
timothycarambat
merged 3 commits into
master
from
4073-feat-mssqlconnector-support-additonal-provider-config-for-optionsencrypt
Jul 15, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
server/__tests__/utils/SQLConnectors/connectionParser.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| /* eslint-env jest */ | ||
| const { ConnectionStringParser } = require("../../../utils/agents/aibitat/plugins/sql-agent/SQLConnectors/utils"); | ||
|
|
||
| describe("ConnectionStringParser", () => { | ||
| describe("Basic Parsing", () => { | ||
| test("should parse a basic connection string without options", () => { | ||
| const parser = new ConnectionStringParser({ scheme: "mssql" }); | ||
| const result = parser.parse("mssql://user:pass@localhost:1433/mydb"); | ||
|
|
||
| expect(result).toEqual({ | ||
| scheme: "mssql", | ||
| username: "user", | ||
| password: "pass", | ||
| hosts: [{ host: "localhost", port: 1433 }], | ||
| endpoint: "mydb", | ||
| options: undefined | ||
| }); | ||
| }); | ||
|
|
||
| test("should parse a connection string with options", () => { | ||
| const parser = new ConnectionStringParser({ scheme: "mssql" }); | ||
| const result = parser.parse("mssql://user:pass@localhost:1433/mydb?encrypt=true&trustServerCertificate=true"); | ||
|
|
||
| expect(result).toEqual({ | ||
| scheme: "mssql", | ||
| username: "user", | ||
| password: "pass", | ||
| hosts: [{ host: "localhost", port: 1433 }], | ||
| endpoint: "mydb", | ||
| options: { | ||
| encrypt: "true", | ||
| trustServerCertificate: "true" | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| test("should handle empty passwords", () => { | ||
| const parser = new ConnectionStringParser({ scheme: "mssql" }); | ||
| const result = parser.parse("mssql://user@localhost:1433/mydb"); | ||
|
|
||
| expect(result).toEqual({ | ||
| scheme: "mssql", | ||
| username: "user", | ||
| password: undefined, | ||
| hosts: [{ host: "localhost", port: 1433 }], | ||
| endpoint: "mydb", | ||
| options: undefined | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Error Handling", () => { | ||
| test("should throw error for invalid scheme", () => { | ||
| const parser = new ConnectionStringParser({ scheme: "mssql" }); | ||
| expect(() => parser.parse("mysql://user:pass@localhost:3306/mydb")) | ||
| .toThrow("URI must start with 'mssql://'"); | ||
| }); | ||
|
|
||
| test("should throw error for missing scheme", () => { | ||
| const parser = new ConnectionStringParser({ scheme: "mssql" }); | ||
| expect(() => parser.parse("user:pass@localhost:1433/mydb")) | ||
| .toThrow("No scheme found in URI"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Special Characters", () => { | ||
| test("should handle special characters in username and password", () => { | ||
| const parser = new ConnectionStringParser({ scheme: "mssql" }); | ||
| const result = parser.parse("mssql://user%40domain:p%40ssw%3Ard@localhost:1433/mydb"); | ||
|
|
||
| expect(result).toEqual({ | ||
| scheme: "mssql", | ||
| username: "user@domain", | ||
| password: "p@ssw:rd", | ||
| hosts: [{ host: "localhost", port: 1433 }], | ||
| endpoint: "mydb", | ||
| options: undefined | ||
| }); | ||
| }); | ||
|
|
||
| test("should handle special characters in database name", () => { | ||
| const parser = new ConnectionStringParser({ scheme: "mssql" }); | ||
| const result = parser.parse("mssql://user:pass@localhost:1433/my%20db"); | ||
|
|
||
| expect(result).toEqual({ | ||
| scheme: "mssql", | ||
| username: "user", | ||
| password: "pass", | ||
| hosts: [{ host: "localhost", port: 1433 }], | ||
| endpoint: "my db", | ||
| options: undefined | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Multiple Hosts", () => { | ||
| test("should parse multiple hosts", () => { | ||
| const parser = new ConnectionStringParser({ scheme: "mssql" }); | ||
| const result = parser.parse("mssql://user:pass@host1:1433,host2:1434/mydb"); | ||
|
|
||
| expect(result).toEqual({ | ||
| scheme: "mssql", | ||
| username: "user", | ||
| password: "pass", | ||
| hosts: [ | ||
| { host: "host1", port: 1433 }, | ||
| { host: "host2", port: 1434 } | ||
| ], | ||
| endpoint: "mydb", | ||
| options: undefined | ||
| }); | ||
| }); | ||
|
|
||
| test("should handle hosts without ports", () => { | ||
| const parser = new ConnectionStringParser({ scheme: "mssql" }); | ||
| const result = parser.parse("mssql://user:pass@host1,host2/mydb"); | ||
|
|
||
| expect(result).toEqual({ | ||
| scheme: "mssql", | ||
| username: "user", | ||
| password: "pass", | ||
| hosts: [ | ||
| { host: "host1" }, | ||
| { host: "host2" } | ||
| ], | ||
| endpoint: "mydb", | ||
| options: undefined | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("Provider-Specific Tests", () => { | ||
| test("should parse MySQL connection string", () => { | ||
| const parser = new ConnectionStringParser({ scheme: "mysql" }); | ||
| const result = parser.parse("mysql://user:pass@localhost:3306/mydb?ssl=true"); | ||
|
|
||
| expect(result).toEqual({ | ||
| scheme: "mysql", | ||
| username: "user", | ||
| password: "pass", | ||
| hosts: [{ host: "localhost", port: 3306 }], | ||
| endpoint: "mydb", | ||
| options: { ssl: "true" } | ||
| }); | ||
| }); | ||
|
|
||
| test("should parse PostgreSQL connection string", () => { | ||
| const parser = new ConnectionStringParser({ scheme: "postgresql" }); | ||
| const result = parser.parse("postgresql://user:pass@localhost:5432/mydb?sslmode=require"); | ||
|
|
||
| expect(result).toEqual({ | ||
| scheme: "postgresql", | ||
| username: "user", | ||
| password: "pass", | ||
| hosts: [{ host: "localhost", port: 5432 }], | ||
| endpoint: "mydb", | ||
| options: { sslmode: "require" } | ||
| }); | ||
| }); | ||
|
|
||
| test("should parse MSSQL connection string with encryption options", () => { | ||
| const parser = new ConnectionStringParser({ scheme: "mssql" }); | ||
| const result = parser.parse("mssql://user:pass@localhost:1433/mydb?encrypt=true&trustServerCertificate=true"); | ||
|
|
||
| expect(result).toEqual({ | ||
| scheme: "mssql", | ||
| username: "user", | ||
| password: "pass", | ||
| hosts: [{ host: "localhost", port: 1433 }], | ||
| endpoint: "mydb", | ||
| options: { | ||
| encrypt: "true", | ||
| trustServerCertificate: "true" | ||
| } | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.