Test | Fix Kerberos SSPI authentication failure when using TCP proxy in manual tests - #4146
Merged
Conversation
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 65.92% 64.39% -1.53%
==========================================
Files 276 272 -4
Lines 42962 65784 +22822
==========================================
+ Hits 28322 42363 +14041
- Misses 14640 23421 +8781
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
cheenamalhotra
enabled auto-merge (squash)
April 8, 2026 00:45
Contributor
Author
|
Can this be merged? |
Member
|
There are failures preventing this merge, it's strange why they are happening only on this branch. Can you update this branch with changes from 'main'? |
…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
Contributor
Author
|
@cheenamalhotra I have updated the branch |
Contributor
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Contributor
Author
|
@cheenamalhotra Can this be merged? |
cheenamalhotra
enabled auto-merge (squash)
May 5, 2026 05:07
paulmedynski
pushed a commit
that referenced
this pull request
May 7, 2026
…al tests (#4146) 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
cheenamalhotra
pushed a commit
that referenced
this pull request
Jul 14, 2026
…al tests (#4146) 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
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