Skip to content

[Foundation] Enable HTTP digest auth in NSUrlSessionHandler#25180

Merged
rolfbjarne merged 3 commits intomainfrom
dev/manuel/add-digest-auth-nsurlhandler
Apr 22, 2026
Merged

[Foundation] Enable HTTP digest auth in NSUrlSessionHandler#25180
rolfbjarne merged 3 commits intomainfrom
dev/manuel/add-digest-auth-nsurlhandler

Conversation

@rolfbjarne
Copy link
Copy Markdown
Member

@rolfbjarne rolfbjarne commented Apr 17, 2026

NSUrlSessionHandler was explicitly rejecting HTTP digest challenges by mapping NSURLAuthenticationMethodHTTPDigest to the internal reject sentinel. That meant iOS never answered digest auth challenges with configured credentials, while other supported auth schemes did.

Handle digest challenges like other credential-backed auth methods so Credentials.GetCredential can return a NetworkCredential and the handler can respond with an NSUrlCredential.

Add a System.Net.Http regression test covering successful and failed digest authentication, and add a shared httpbin helper for the digest auth endpoint.

Recreated from #25179 (by @mandel-macaque) to not use a fork.

NSUrlSessionHandler was explicitly rejecting HTTP digest challenges by
mapping NSURLAuthenticationMethodHTTPDigest to the internal reject
sentinel. That meant iOS never answered digest auth challenges with
configured credentials, while other supported auth schemes did.

Handle digest challenges like other credential-backed auth methods so
Credentials.GetCredential can return a NetworkCredential and the handler
can respond with an NSUrlCredential.

Add a System.Net.Http regression test covering successful and failed
digest authentication, and add a shared httpbin helper for the digest
auth endpoint.

Local monotouch-test build validation was attempted, but this checkout
is currently blocked by the expected Xcode installation and local build
environment configuration.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables HTTP Digest authentication in NSUrlSessionHandler by treating digest challenges as credential-backed auth (instead of explicitly rejecting them), and adds a regression test to validate digest auth behavior against httpbin.

Changes:

  • Map NSURLAuthenticationMethodHTTPDigest to a non-reject auth type so Credentials.GetCredential can supply credentials.
  • Add an httpbin URL helper for the digest auth endpoint.
  • Add a System.Net.Http test covering successful and failed digest authentication scenarios.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/Foundation/NSUrlSessionHandler.cs Stops rejecting digest challenges; allows credential lookup/response for digest auth.
tests/monotouch-test/System.Net.Http/NetworkResources.cs Adds httpbin digest-auth endpoint URL helper used by tests.
tests/monotouch-test/System.Net.Http/MessageHandlers.cs Adds regression test verifying digest auth works (success + failure cases).

Comment thread tests/monotouch-test/System.Net.Http/MessageHandlers.cs
Comment thread tests/monotouch-test/System.Net.Http/MessageHandlers.cs
Comment thread tests/monotouch-test/System.Net.Http/NetworkResources.cs
Comment thread tests/monotouch-test/System.Net.Http/MessageHandlers.cs
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
Copy link
Copy Markdown
Member Author

@mandel-macaque there are some test failures:

MonoTests.System.Net.Http.MessageHandlerTest.SupportsDigestAuthentication : 2314.5388 ms
	[PASS] TestNSUrlSessionDefaultDisableCookiesWithManagedContainer
	[PASS] TestNSUrlSessionDefaultDisabledCookies
	[PASS] TestNSUrlSessionEphemeralDisabledCookies
	[FAIL] TestNSUrlSessionEphemeralHandlerCookieContainer :   Cookies
       Expected string length 54 but was 165. Strings differ at index 47.
       Expected: "...    "cookie": "chocolate-chip"\n  }\n}\n"
       But was:  "...    "cookie": "chocolate-chip", \n    "fake": "fake_value",..."
  --------------------------------------------^
		   at MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionHandlerCookieContainerImpl(NSUrlSessionHandler nativeHandler) in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 177
		   at MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionEphemeralHandlerCookieContainer() in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 133
	[FAIL] TestNSUrlSessionEphemeralHandlerCookies :   Managed Cookie Count
       Expected: 1
       But was:  4
		   at MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionHandlerCookiesImpl(NSUrlSessionHandler nativeHandler) in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 116
		   at MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionEphemeralHandlerCookies() in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 83
	[FAIL] TestNSUrlSessionHandlerCookieContainer :   Cookies
       Expected string length 54 but was 165. Strings differ at index 47.
       Expected: "...    "cookie": "chocolate-chip"\n  }\n}\n"
       But was:  "...    "cookie": "chocolate-chip", \n    "fake": "fake_value",..."
  --------------------------------------------^
		   at MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionHandlerCookieContainerImpl(NSUrlSessionHandler nativeHandler) in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 177
		   at MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionHandlerCookieContainer() in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 126
	[IGNORED] TestNSurlSessionHandlerCookieContainerSetCookie : Unexpected network failure in CI
Ignoring test, because not running in CI: Unexpected network failure in CI
		   at TestRuntime.IgnoreInCI(String message) in /Users/builder/azdo/_work/1/s/macios/tests/common/TestRuntime.cs:line 196
		   at MonoTests.System.Net.Http.MessageHandlerTest.TestNSurlSessionHandlerCookieContainerSetCookie() in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 206
	[FAIL] TestNSUrlSessionHandlerCookies :   Managed Cookie Count
       Expected: 1
       But was:  4
		   at MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionHandlerCookiesImpl(NSUrlSessionHandler nativeHandler) in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 116
		   at MonoTests.System.Net.Http.MessageHandlerTest.TestNSUrlSessionHandlerCookies() in /Users/builder/azdo/_work/1/s/macios/tests/monotouch-test/System.Net.Http/MessageHandlers.cs:line 75
	[PASS] TestNSUrlSessionHandlerDetectMissingClientCertificate
	[PASS] TestNSUrlSessionHandlerDetectMissingClientCertificateOptOut
	[PASS] TestNSUrlSessionHandlerOptionalClientCertificate
	[PASS] TestNSUrlSessionHandlerSendClientCertificate
	[PASS] TestNSUrlSessionTimeoutExceptionWhileStreamingContent

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #463be1c] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 463be1ca767f4725ab0a12279d32de82a9bab4f1 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [PR Build #463be1c] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 463be1ca767f4725ab0a12279d32de82a9bab4f1 [PR build]

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 463be1ca767f4725ab0a12279d32de82a9bab4f1 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

✅ [CI Build #463be1c] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 463be1ca767f4725ab0a12279d32de82a9bab4f1 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Copy Markdown
Collaborator

🚀 [CI Build #463be1c] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 156 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker: All 44 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 15 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 12 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: 463be1ca767f4725ab0a12279d32de82a9bab4f1 [PR build]

Copy link
Copy Markdown
Member

@dalexsoto dalexsoto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@rolfbjarne rolfbjarne merged commit 727a5e4 into main Apr 22, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Community contribution ❤

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants