-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Add support for Trusted connections for MSSQL #57
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
Draft
Artmann
wants to merge
1
commit into
main
Choose a base branch
from
chris/trusted-connections
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+118
−0
Draft
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -940,3 +940,88 @@ def test_federated_auth_params_bigquery_missing_params( | |
|
|
||
| # Verify the dict was not modified | ||
| self.assertEqual(sql_alchemy_dict, original_dict) | ||
|
|
||
|
|
||
| class TestMssqlTrustedConnection(unittest.TestCase): | ||
| """Tests for MS SQL Server Windows Authentication (trusted connections).""" | ||
|
|
||
| def test_trusted_connection_removes_credentials(self): | ||
| """Test that mssql_trusted_connection removes username and password from URL.""" | ||
| from deepnote_toolkit.sql.sql_execution import _handle_mssql_trusted_connection | ||
|
|
||
| sql_alchemy_dict = { | ||
| "url": "mssql+pymssql://user:password@myserver:1433/mydb", | ||
| "params": {"mssql_trusted_connection": True}, | ||
| } | ||
|
|
||
| _handle_mssql_trusted_connection(sql_alchemy_dict) | ||
|
|
||
| # Verify credentials were removed from URL | ||
| self.assertIn("mssql+pymssql://", sql_alchemy_dict["url"]) | ||
| self.assertIn("myserver", sql_alchemy_dict["url"]) | ||
| self.assertIn("mydb", sql_alchemy_dict["url"]) | ||
| self.assertNotIn("user", sql_alchemy_dict["url"]) | ||
| self.assertNotIn("password", sql_alchemy_dict["url"]) | ||
|
|
||
| # Verify the flag was removed from params | ||
| self.assertNotIn("mssql_trusted_connection", sql_alchemy_dict["params"]) | ||
|
|
||
| def test_trusted_connection_preserves_query_params(self): | ||
| """Test that existing query parameters are preserved.""" | ||
| from deepnote_toolkit.sql.sql_execution import _handle_mssql_trusted_connection | ||
|
|
||
| sql_alchemy_dict = { | ||
| "url": "mssql+pymssql://user:password@myserver/mydb?charset=utf8", | ||
| "params": {"mssql_trusted_connection": True}, | ||
| } | ||
|
|
||
| _handle_mssql_trusted_connection(sql_alchemy_dict) | ||
|
|
||
| # Verify query params are preserved | ||
| self.assertIn("charset=utf8", sql_alchemy_dict["url"]) | ||
|
|
||
| def test_trusted_connection_not_enabled(self): | ||
| """Test that no action is taken when mssql_trusted_connection is not set.""" | ||
| from deepnote_toolkit.sql.sql_execution import _handle_mssql_trusted_connection | ||
|
|
||
| sql_alchemy_dict = { | ||
| "url": "mssql+pymssql://user:password@myserver/mydb", | ||
| "params": {}, | ||
| } | ||
| original_url = sql_alchemy_dict["url"] | ||
|
|
||
| _handle_mssql_trusted_connection(sql_alchemy_dict) | ||
|
|
||
| self.assertEqual(sql_alchemy_dict["url"], original_url) | ||
|
|
||
| def test_trusted_connection_false(self): | ||
| """Test that no action is taken when mssql_trusted_connection is False.""" | ||
| from deepnote_toolkit.sql.sql_execution import _handle_mssql_trusted_connection | ||
|
|
||
| sql_alchemy_dict = { | ||
| "url": "mssql+pymssql://user:password@myserver/mydb", | ||
| "params": {"mssql_trusted_connection": False}, | ||
| } | ||
| original_url = sql_alchemy_dict["url"] | ||
|
|
||
| _handle_mssql_trusted_connection(sql_alchemy_dict) | ||
|
|
||
| self.assertEqual(sql_alchemy_dict["url"], original_url) | ||
|
|
||
| @mock.patch("deepnote_toolkit.sql.sql_execution.logger") | ||
| def test_trusted_connection_non_mssql_url_warns(self, mock_logger): | ||
| """Test that a warning is logged for non-mssql URLs.""" | ||
| from deepnote_toolkit.sql.sql_execution import _handle_mssql_trusted_connection | ||
|
|
||
| sql_alchemy_dict = { | ||
| "url": "postgresql://user:password@localhost/db", | ||
| "params": {"mssql_trusted_connection": True}, | ||
| } | ||
| original_url = sql_alchemy_dict["url"] | ||
|
|
||
| _handle_mssql_trusted_connection(sql_alchemy_dict) | ||
|
|
||
| mock_logger.warning.assert_called_once_with( | ||
| "mssql_trusted_connection is only supported for MS SQL Server connections" | ||
| ) | ||
| self.assertEqual(sql_alchemy_dict["url"], original_url) | ||
|
Comment on lines
+1011
to
+1027
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Missing assertion for flag retention. When warning triggers, flag should remain in params. Add: self.assertIn("mssql_trusted_connection", sql_alchemy_dict["params"])🧰 Tools🪛 Ruff (0.14.11)1027-1027: Use a regular Replace (PT009) 🤖 Prompt for AI Agents |
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Verify flag retention.
When
mssql_trusted_connectionisFalse, the flag remains in params. Add assertion to confirm:🧰 Tools
🪛 Ruff (0.14.11)
1009-1009: Use a regular
assertinstead of unittest-styleassertEqualReplace
assertEqual(...)withassert ...(PT009)
🤖 Prompt for AI Agents