未验证 提交 851a9362 编写于 作者: F Filip Navara 提交者: GitHub

Do not throw PNSE exception from NegotiateAuthentication constructor, report...

Do not throw PNSE exception from NegotiateAuthentication constructor, report Unsupported status instead (#91753)
Co-authored-by: NCarlos Sánchez López <1175054+carlossanlop@users.noreply.github.com>
上级 0189dc44
...@@ -139,5 +139,32 @@ public async Task DefaultHandler_FakeServer_Success(bool useNtlm) ...@@ -139,5 +139,32 @@ public async Task DefaultHandler_FakeServer_Success(bool useNtlm)
}).ConfigureAwait(false); }).ConfigureAwait(false);
}); });
} }
[Fact]
[SkipOnPlatform(TestPlatforms.Browser | TestPlatforms.Windows, "DefaultCredentials are unsupported for NTLM on Unix / Managed implementation")]
public async Task DefaultHandler_FakeServer_DefaultCredentials()
{
await LoopbackServer.CreateClientAndServerAsync(
async uri =>
{
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
requestMessage.Version = new Version(1, 1);
HttpMessageHandler handler = new HttpClientHandler() { Credentials = CredentialCache.DefaultCredentials };
using (var client = new HttpClient(handler))
{
HttpResponseMessage response = await client.SendAsync(requestMessage);
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}
},
async server =>
{
await server.AcceptConnectionAsync(async connection =>
{
var authHeader = "WWW-Authenticate: NTLM\r\n";
await connection.SendResponseAsync(HttpStatusCode.Unauthorized, authHeader).ConfigureAwait(false);
connection.CompleteRequestProcessing();
}).ConfigureAwait(false);
});
}
} }
} }
...@@ -9,16 +9,23 @@ internal abstract partial class NegotiateAuthenticationPal ...@@ -9,16 +9,23 @@ internal abstract partial class NegotiateAuthenticationPal
{ {
public static NegotiateAuthenticationPal Create(NegotiateAuthenticationClientOptions clientOptions) public static NegotiateAuthenticationPal Create(NegotiateAuthenticationClientOptions clientOptions)
{ {
switch (clientOptions.Package) try
{ {
case NegotiationInfoClass.NTLM: switch (clientOptions.Package)
return new ManagedNtlmNegotiateAuthenticationPal(clientOptions); {
case NegotiationInfoClass.NTLM:
return new ManagedNtlmNegotiateAuthenticationPal(clientOptions);
case NegotiationInfoClass.Negotiate: case NegotiationInfoClass.Negotiate:
return new ManagedSpnegoNegotiateAuthenticationPal(clientOptions); return new ManagedSpnegoNegotiateAuthenticationPal(clientOptions);
default: default:
return new UnsupportedNegotiateAuthenticationPal(clientOptions); return new UnsupportedNegotiateAuthenticationPal(clientOptions);
}
}
catch (PlatformNotSupportedException)
{
return new UnsupportedNegotiateAuthenticationPal(clientOptions);
} }
} }
......
...@@ -23,20 +23,20 @@ internal partial class NegotiateAuthenticationPal ...@@ -23,20 +23,20 @@ internal partial class NegotiateAuthenticationPal
public static NegotiateAuthenticationPal Create(NegotiateAuthenticationClientOptions clientOptions) public static NegotiateAuthenticationPal Create(NegotiateAuthenticationClientOptions clientOptions)
{ {
if (UseManagedNtlm) try
{ {
switch (clientOptions.Package) if (UseManagedNtlm)
{ {
case NegotiationInfoClass.NTLM: switch (clientOptions.Package)
return new ManagedNtlmNegotiateAuthenticationPal(clientOptions); {
case NegotiationInfoClass.NTLM:
return new ManagedNtlmNegotiateAuthenticationPal(clientOptions);
case NegotiationInfoClass.Negotiate: case NegotiationInfoClass.Negotiate:
return new ManagedSpnegoNegotiateAuthenticationPal(clientOptions, supportKerberos: true); return new ManagedSpnegoNegotiateAuthenticationPal(clientOptions, supportKerberos: true);
}
} }
}
try
{
return new UnixNegotiateAuthenticationPal(clientOptions); return new UnixNegotiateAuthenticationPal(clientOptions);
} }
catch (Win32Exception) catch (Win32Exception)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册