Test | Fix Kerberos SSPI authentication failure when using TCP proxy in manual tests#4146
Open
ShreyaLaxminarayan wants to merge 1 commit intodotnet:mainfrom
Open
Test | Fix Kerberos SSPI authentication failure when using TCP proxy in manual tests#4146ShreyaLaxminarayan wants to merge 1 commit intodotnet:mainfrom
ShreyaLaxminarayan wants to merge 1 commit intodotnet:mainfrom
Conversation
…al tests Problem: CreateAndStartProxy used in manual tests rewrites the connection string address to 127.0.0.1, causing kerberos to construct the wrong SPN (MSSQLSvc/localhost) instead of the real server name. Since localhost is not registered in Active Directory, SSPI authentication fails with Microsoft.Data.SqlClient.SqlException: The target principal name is incorrect. Cannot generate SSPI context. Fix: Capture the original server name before the proxy rewrites the address. After rewriting, explicitly set ServerSPN in the connection string to the real server's SPN using DataTestUtility.GetMachineFQDN, but only if ServerSPN is not already set by the caller. Tests Affected: SqlCommandCancelTest.TimeOutDuringRead_Tcp— previously failing with SSPI error, now passing
paulmedynski
approved these changes
Apr 7, 2026
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #4146 +/- ##
==========================================
- Coverage 73.22% 66.32% -6.91%
==========================================
Files 280 274 -6
Lines 43000 65782 +22782
==========================================
+ Hits 31486 43628 +12142
- Misses 11514 22154 +10640
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cheenamalhotra
approved these changes
Apr 8, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem:
CreateAndStartProxy used in manual tests rewrites the connection string address to 127.0.0.1, causing kerberos to construct the wrong SPN (MSSQLSvc/localhost) instead of the real server name. Since localhost is not registered in Active Directory, SSPI authentication fails with
Microsoft.Data.SqlClient.SqlException: The target principal name is incorrect. Cannot generate SSPI context.Kerberos builds the SPN from the resolved connection address. When the proxy rewrites the address to 127.0.0.1, the SPN is constructed from localhost instead of the actual server hostname, breaking AD lookup.
Fix:
Capture the original server name before the proxy rewrites the address. After rewriting, explicitly set ServerSPN in the connection string to the real server's SPN using DataTestUtility.GetMachineFQDN, but only if ServerSPN is not already set by the caller.
This fix only applies if ServerSPN is not set already.
Tests Affected:
SqlCommandCancelTest.TimeOutDuringRead_Tcp— previously failing with SSPI error, now passing