0,
state.ToIntPtr()))
{
- int lastError = Marshal.GetLastWin32Error();
- Debug.Assert((unchecked((int)lastError) != Interop.WinHttp.ERROR_INSUFFICIENT_BUFFER &&
- unchecked((int)lastError) != unchecked((int)0x80090321)), // SEC_E_BUFFER_TOO_SMALL
- $"Unexpected async error in WinHttpRequestCallback: {unchecked((int)lastError)}");
-
// Dispose (which will unpin) the state object. Since this failed, WinHTTP won't associate
// our context value (state object) to the request handle. And thus we won't get HANDLE_CLOSING
// notifications which would normally cause the state object to be unpinned and disposed.
state.Dispose();
- throw WinHttpException.CreateExceptionUsingError(lastError);
+ WinHttpException.ThrowExceptionUsingLastError();
}
}
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET Framework throws PNSE for ServerCertificateCustomValidationCallback")]
public partial class HttpClientHandler_ServerCertificates_Test : HttpClientTestBase
{
- // TODO: https://github.com/dotnet/corefx/issues/7812
private static bool ClientSupportsDHECipherSuites => (!PlatformDetection.IsWindows || PlatformDetection.IsWindows10Version1607OrGreater);
private bool BackendSupportsCustomCertificateHandlingAndClientSupportsDHECipherSuites =>
(BackendSupportsCustomCertificateHandling && ClientSupportsDHECipherSuites);
[MemberData(nameof(CertificateValidationServersAndExpectedPolicies))]
public async Task UseCallback_BadCertificate_ExpectedPolicyErrors(string url, SslPolicyErrors expectedErrors)
{
+ const int SEC_E_BUFFER_TOO_SMALL = unchecked((int)0x80090321);
+
if (!BackendSupportsCustomCertificateHandlingAndClientSupportsDHECipherSuites)
{
return;
}
- if (PlatformDetection.IsUap)
+ try
{
- // UAP HTTP stack caches connections per-process. This causes interference when these tests run in
- // the same process as the other tests. Each test needs to be isolated to its own process.
- // See dicussion: https://github.com/dotnet/corefx/issues/21945
- RemoteInvoke((remoteUrl, remoteExpectedErrors, useManagedHandlerString) =>
+ if (PlatformDetection.IsUap)
{
- UseCallback_BadCertificate_ExpectedPolicyErrors_Helper(
- remoteUrl,
- bool.Parse(useManagedHandlerString),
- (SslPolicyErrors)Enum.Parse(typeof(SslPolicyErrors), remoteExpectedErrors)).Wait();
+ // UAP HTTP stack caches connections per-process. This causes interference when these tests run in
+ // the same process as the other tests. Each test needs to be isolated to its own process.
+ // See dicussion: https://github.com/dotnet/corefx/issues/21945
+ RemoteInvoke((remoteUrl, remoteExpectedErrors, useManagedHandlerString) =>
+ {
+ UseCallback_BadCertificate_ExpectedPolicyErrors_Helper(
+ remoteUrl,
+ bool.Parse(useManagedHandlerString),
+ (SslPolicyErrors)Enum.Parse(typeof(SslPolicyErrors), remoteExpectedErrors)).Wait();
- return SuccessExitCode;
- }, url, expectedErrors.ToString(), UseManagedHandler.ToString()).Dispose();
+ return SuccessExitCode;
+ }, url, expectedErrors.ToString(), UseManagedHandler.ToString()).Dispose();
+ }
+ else
+ {
+ await UseCallback_BadCertificate_ExpectedPolicyErrors_Helper(url, UseManagedHandler, expectedErrors);
+ }
}
- else
+ catch (HttpRequestException e) when (e.InnerException?.GetType().Name == "WinHttpException" &&
+ e.InnerException.HResult == SEC_E_BUFFER_TOO_SMALL &&
+ !PlatformDetection.IsWindows10Version1607OrGreater)
{
- await UseCallback_BadCertificate_ExpectedPolicyErrors_Helper(url, UseManagedHandler, expectedErrors);
+ // Testing on old Windows versions can hit https://github.com/dotnet/corefx/issues/7812
+ // Ignore SEC_E_BUFFER_TOO_SMALL error on such cases.
}
}