public void SendAsync_NoAutomaticProxySupportAndUseWinInetSettingsWithEmptySettings_ExpectedWinHttpProxySettings() { TestControl.WinHttpAutomaticProxySupport = false; var handler = new WinHttpHandler(); SendRequestHelper.Send( handler, delegate { handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy; }); Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.SessionProxySettings.AccessType); Assert.Equal(false, APICallHistory.RequestProxySettings.AccessType.HasValue); }
public void SendAsync_AutomaticProxySupportAndUseDefaultWebProxy_ExpectedWinHttpSessionProxySettings() { TestControl.WinHttpAutomaticProxySupport = true; var handler = new WinHttpHandler(); SendRequestHelper.Send( handler, delegate { handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseCustomProxy; handler.Proxy = new FakeDefaultWebProxy(); }); Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, APICallHistory.SessionProxySettings.AccessType); }
public void SecureRequest_AddInvalidCertificate_NullCertificateContextSet(X509Certificate2 certificate) { using (var handler = new WinHttpHandler()) { handler.ClientCertificates.Add(certificate); using (HttpResponseMessage response = SendRequestHelper.Send( handler, () => { }, TestServer.FakeSecureServerEndpoint)) { Assert.Equal(1, APICallHistory.WinHttpOptionClientCertContext.Count); Assert.Equal(IntPtr.Zero, APICallHistory.WinHttpOptionClientCertContext[0]); } } }
public void SecureRequest_ClientCertificateOptionAutomatic_CertStoreEmpty_NullCertificateContextSet() { using (var handler = new WinHttpHandler()) { handler.ClientCertificateOption = ClientCertificateOption.Automatic; using (HttpResponseMessage response = SendRequestHelper.Send( handler, () => { }, TestServer.FakeSecureServerEndpoint)) { Assert.Equal(1, APICallHistory.WinHttpOptionClientCertContext.Count); Assert.Equal(IntPtr.Zero, APICallHistory.WinHttpOptionClientCertContext[0]); } } }
public void SendAsync_UseCustomProxyWithBypass_ExpectedWinHttpProxySettings() { var handler = new WinHttpHandler(); var customProxy = new CustomProxy(true); SendRequestHelper.Send( handler, delegate { handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseCustomProxy; handler.Proxy = customProxy; }); Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.SessionProxySettings.AccessType); Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.RequestProxySettings.AccessType); }
public void TcpKeepalive_InfiniteTimeSpan_TranslatesToUInt32MaxValue() { using var handler = new WinHttpHandler(); SendRequestHelper.Send(handler, () => { handler.TcpKeepAliveEnabled = true; handler.TcpKeepAliveTime = Timeout.InfiniteTimeSpan; handler.TcpKeepAliveInterval = Timeout.InfiniteTimeSpan; }); (uint onOff, uint keepAliveTime, uint keepAliveInterval) = APICallHistory.WinHttpOptionTcpKeepAlive.Value; Assert.True(onOff != 0); Assert.Equal(uint.MaxValue, keepAliveTime); Assert.Equal(uint.MaxValue, keepAliveInterval); }
public void TcpKeepalive_WhenEnabled_ForwardsCorrectNativeOptions() { using var handler = new WinHttpHandler(); SendRequestHelper.Send(handler, () => { handler.TcpKeepAliveEnabled = true; handler.TcpKeepAliveTime = TimeSpan.FromMinutes(13); handler.TcpKeepAliveInterval = TimeSpan.FromSeconds(42); }); (uint onOff, uint keepAliveTime, uint keepAliveInterval) = APICallHistory.WinHttpOptionTcpKeepAlive.Value; Assert.True(onOff != 0); Assert.Equal(13_000u * 60u, keepAliveTime); Assert.Equal(42_000u, keepAliveInterval); }
public void SendAsync_NoAutomaticProxySupportAndUseWinInetSettingsWithAutoDetectButPACFileNotDetectedOnNetwork_ExpectedWinHttpProxySettings() { TestControl.WinHttpAutomaticProxySupport = false; TestControl.PACFileNotDetectedOnNetwork = true; FakeRegistry.WinInetProxySettings.AutoDetect = true; var handler = new WinHttpHandler(); SendRequestHelper.Send( handler, delegate { handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy; }); Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.SessionProxySettings.AccessType); Assert.Null(APICallHistory.RequestProxySettings.AccessType); }
public async Task SendAsync_NoWinHttpDecompressionSupportAndResponseBodyIsNotCompressed_ExpectedResponse() { TestControl.WinHttpDecompressionSupport = false; var handler = new WinHttpHandler(); HttpResponseMessage response = SendRequestHelper.Send( handler, delegate { handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy; }); Assert.NotNull(response.Content.Headers.ContentLength); string responseBody = await response.Content.ReadAsStringAsync(); Assert.Equal(TestServer.ExpectedResponseBody, responseBody); }
public void SecureRequest_ClientCertificateOptionAutomatic_CertStoreHasValidAndInvalidCerts_ValidCertificateContextSet() { using (var handler = new WinHttpHandler()) { var helper = new ClientCertificateHelper(); TestControl.CurrentUserCertificateStore = helper.ValidAndInvalidClientCertificateCollection; handler.ClientCertificateOption = ClientCertificateOption.Automatic; using (HttpResponseMessage response = SendRequestHelper.Send( handler, () => { }, TestServer.FakeSecureServerEndpoint)) { Assert.Equal(1, APICallHistory.WinHttpOptionClientCertContext.Count); Assert.NotEqual(IntPtr.Zero, APICallHistory.WinHttpOptionClientCertContext[0]); } } }
public async Task SendAsync_NoWinHttpDecompressionSupportAndResponseBodyIsGZipCompressed_ExpectedResponse() { TestControl.WinHttpDecompressionSupport = false; var handler = new WinHttpHandler(); HttpResponseMessage response = SendRequestHelper.Send( handler, delegate { handler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; TestServer.SetResponse(DecompressionMethods.GZip, TestServer.ExpectedResponseBody); }); Assert.Null(response.Content.Headers.ContentLength); string responseBody = await response.Content.ReadAsStringAsync(); Assert.Equal(0, response.Content.Headers.ContentEncoding.Count); Assert.Equal(TestServer.ExpectedResponseBody, responseBody); }
public async Task SendAsync_NoWinHttpDecompressionSupportAndResponseBodyIsNotCompressed_ExpectedResponse() { TestControl.WinHttpDecompressionSupport = false; var handler = new WinHttpHandler(); using (HttpResponseMessage response = SendRequestHelper.Send( handler, delegate { handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy; })) { await VerifyResponseContent( TestServer.ExpectedResponseBodyBytes, response.Content, responseContentWasOriginallyCompressed : false, responseContentWasAutoDecompressed : false); } }
public async Task SendAsync_NoWinHttpDecompressionSupportAndResponseBodyIsGZipCompressed_ExpectedResponse() { TestControl.WinHttpDecompressionSupport = false; var handler = new WinHttpHandler(); using (HttpResponseMessage response = SendRequestHelper.Send( handler, delegate { handler.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip; TestServer.SetResponse(DecompressionMethods.GZip, TestServer.ExpectedResponseBody); })) { await VerifyResponseContent( TestServer.ExpectedResponseBodyBytes, response.Content, responseContentWasOriginallyCompressed : true, responseContentWasAutoDecompressed : true); } }
public void SslProtocols_SetUsingValidEnums_ExpectedWinHttpHandleSettings() { var handler = new WinHttpHandler(); SendRequestHelper.Send( handler, delegate { handler.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12; }); uint expectedProtocols = Interop.WinHttp.WINHTTP_FLAG_SECURE_PROTOCOL_TLS1 | Interop.WinHttp.WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_1 | Interop.WinHttp.WINHTTP_FLAG_SECURE_PROTOCOL_TLS1_2; Assert.Equal(expectedProtocols, APICallHistory.WinHttpOptionSecureProtocols); }
public void SendAsync_NoAutomaticProxySupportAndUseWinInetSettingsWithAutoDetectSettingAndManualSettingButPACFileNotFoundOnNetwork_ExpectedWinHttpProxySettings() { const string manualProxy = FakeProxy; TestControl.WinHttpAutomaticProxySupport = false; FakeRegistry.WinInetProxySettings.AutoDetect = true; FakeRegistry.WinInetProxySettings.Proxy = manualProxy; TestControl.PACFileNotDetectedOnNetwork = true; var handler = new WinHttpHandler(); SendRequestHelper.Send( handler, delegate { handler.WindowsProxyUsePolicy = WindowsProxyUsePolicy.UseWinInetProxy; }); // Both AutoDetect and manual proxy are specified. If AutoDetect fails to find // the PAC file on the network, then we should fall back to manual setting. Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NO_PROXY, APICallHistory.SessionProxySettings.AccessType); Assert.Equal(Interop.WinHttp.WINHTTP_ACCESS_TYPE_NAMED_PROXY, APICallHistory.RequestProxySettings.AccessType); Assert.Equal(manualProxy, APICallHistory.RequestProxySettings.Proxy); }
public async Task SendAsync_NoWinHttpDecompressionSupport_AutoDecompressionSettingDiffers_ResponseIsNotDecompressed(bool responseIsGZip) { DecompressionMethods decompressionMethods = responseIsGZip ? DecompressionMethods.Deflate : DecompressionMethods.GZip; _output.WriteLine("DecompressionMethods = {0}", decompressionMethods.ToString()); TestControl.WinHttpDecompressionSupport = false; var handler = new WinHttpHandler(); using (HttpResponseMessage response = SendRequestHelper.Send( handler, delegate { handler.AutomaticDecompression = decompressionMethods; TestServer.SetResponse(responseIsGZip ? DecompressionMethods.GZip : DecompressionMethods.Deflate, TestServer.ExpectedResponseBody); })) { await VerifyResponseContent( TestServer.CompressBytes(TestServer.ExpectedResponseBodyBytes, useGZip: responseIsGZip), response.Content, responseContentWasOriginallyCompressed : true, responseContentWasAutoDecompressed : false); } }