[release/6.0] Fix SendAsync from impersonated context with default credentials #59155
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.
Backport of #58922 to release/6.0
Fixes #58033
As @geoffkizer suggested, this fails because the connection setting is updated only in constructor. Even if options are passed to
HttpHandler
constructor, we actually createHttpConnectionSettings
first and then we updated it.I was originally thinking about updating relevant setters in
HttpHandler
but I end up updating theCloneAndNormalize
and that seems sufficient. That has benefit that all the logic is still encapsulated inHttpConnectionSettings
.This is pretty trivial two line change.
Now, the trouble is testing. Some existing NTLM tests use
HttpListener
and that is problematic because of lack of fine control and general reliance. And we do not have any impersonation tests for HTTP.To solve the first issue, I used NTLM code from
Common
and I added (duplicate?) NTLM/Negotiate test using standard Loopback pattern. If that proves to be stable and working we can possibly remove relianceHttpListener
and clean up rest of the tests. (and get some more coverage for code Kestrel use via reflection (or make that finally public)).To solve the second problem, I moved existing
WindowsIdentityFixture
toTestUtilities
. That essentially creates ad hoc account and use that for testing. That seems to require some level of privilege. The existing tests inSystem.Security
did not have any guard and they seems to run fine in CI. We can possibly updateCanRunImpersonatedTests
if this becomes nuisance. Certainly running tests from elevated shell seems to work fine but I don't know if that is really needed.With that, I added new test to verify that
HttpClient
will open new connection for the impersonated context.And it also verifies that the authenticated identity is different.
/cc @danmoseley @wfurt
Customer Impact
Testing
Risk