Skip to content

[Foundation] Enable HTTP digest auth in NSUrlSessionHandler#25179

Closed
mandel-macaque wants to merge 1 commit intodotnet:mainfrom
mandel-macaque:dev/manuel/add-digest-auth-nsurlhandler
Closed

[Foundation] Enable HTTP digest auth in NSUrlSessionHandler#25179
mandel-macaque wants to merge 1 commit intodotnet:mainfrom
mandel-macaque:dev/manuel/add-digest-auth-nsurlhandler

Conversation

@mandel-macaque
Copy link
Copy Markdown
Contributor

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.

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.
@mandel-capuchin
Copy link
Copy Markdown

@rolfbjarne I don't longer have sudo, you might need to create a branch for this to be able to run the CI.

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

This PR updates NSUrlSessionHandler to support HTTP Digest authentication challenges (instead of explicitly rejecting them), and adds a regression test that validates Digest auth success/failure against httpbin.

Changes:

  • Map NSURLAuthenticationMethodHTTPDigest to a credential-backed auth type so Credentials.GetCredential can provide a NetworkCredential.
  • Add an httpbin URL helper for the Digest auth endpoint.
  • Add a System.Net.Http test covering successful and unsuccessful Digest authentication.

Reviewed changes

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

File Description
src/Foundation/NSUrlSessionHandler.cs Stops rejecting Digest challenges and treats them like other credential-backed schemes.
tests/monotouch-test/System.Net.Http/NetworkResources.cs Adds GetDigestAuthUrl for httpbin’s digest-auth endpoint.
tests/monotouch-test/System.Net.Http/MessageHandlers.cs Adds a regression test that exercises Digest authentication using NSUrlSessionHandler.Credentials.

Comment on lines +917 to +926
var handler = new NSUrlSessionHandler () {
Credentials = new NetworkCredential (username, password, "")
};

var client = new HttpClient (handler);

HttpStatusCode httpStatus = HttpStatusCode.NotFound;
var done = TestRuntime.TryRunAsync (TimeSpan.FromSeconds (30), async () => {
var result = await client.GetAsync (NetworkResources.Httpbin.GetDigestAuthUrl (validUsername, validPassword));
httpStatus = result.StatusCode;
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

The test allocates NSUrlSessionHandler/HttpClient (and the HttpResponseMessage from GetAsync) without disposing them. In this test suite there are other tests that use using var for these types; not disposing can keep sockets/connections open longer than necessary and can lead to intermittent failures when many network tests run.

Copilot uses AI. Check for mistakes.
Comment on lines +929 to +934
if (!done) {
Assert.Inconclusive ("Request timedout.");
} else {
TestRuntime.IgnoreInCIIfBadNetwork (httpStatus);
Assert.IsNull (ex, "Exception not null");
Assert.AreEqual (expectedStatus, httpStatus, "Status not ok");
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

This test only calls TestRuntime.IgnoreInCIIfBadNetwork (httpStatus). If the request fails with an exception (DNS, timeout, connection reset, etc), httpStatus may remain the default and the exception won't be considered for CI ignore logic, making the new test unnecessarily flaky. Consider calling TestRuntime.IgnoreInCIIfBadNetwork (ex) (or using it in addition to the status-based overload) before asserting ex is null.

Copilot uses AI. Check for mistakes.
}, out var ex);

if (!done) {
Assert.Inconclusive ("Request timedout.");
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

Typo/grammar: "timedout" should be "timed out" in the inconclusive message.

Copilot uses AI. Check for mistakes.
@rolfbjarne
Copy link
Copy Markdown
Member

Recreated: #25180.

@rolfbjarne rolfbjarne closed this Apr 17, 2026
rolfbjarne added a commit that referenced this pull request Apr 22, 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.

---------

Co-authored-by: Manuel de la Pena <mandel@themacaque.com>
Co-authored-by: Manuel de la Pena <mandel@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants