Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRolf Bjarne Kvinge <rolf@xamarin.com>2016-09-27 14:13:38 +0300
committerMarek Safar <marek.safar@gmail.com>2016-09-27 14:13:38 +0300
commite6536dd5e118a16cdca12840d6529ef9d01aaaad (patch)
treee998dac34514397f2f97beb16e1a2f10848c829d /mcs/class/System.Net.Http
parent59b6fde1b375e82de1a62ee772c1808cd379a53c (diff)
[System*] Throw a PlatformNotSupported exception when using the networking stack on watchOS. (#3606)
* [System] Fix line endings for a few files. Best reviewed by not showing whitespace changes (should be empty diff in that case). * [System] Fix potential crash in CookieParserTests. Socket.EndAccept can throw an exception, which will crash the process if it happens on a threadpool. So handle any exceptions when calling Socket.EndAccept, and propagate those exceptions out of any threadpool code. * [System.Net.Http] Throw a PlatformNotSupported exception when using HttpClientHandler on watchOS. * [System.Net.Http] Tweak tests after watchOS API change. Unfortunately the [ExpectedException] attribute can't be put on an entire class, so remove the [Category ("RequiresBSDSockets")] attribute on the class and instead decorate each test with an [ExpectedException] attribute. * [System] Extract the HttpListenerResponseHelper class to a separate file. Extract the HttpListenerResponseHelper class to a separate file so that it's easier to replace the HttpListenerResponse implementation by using a different file. * [System] Throw a PlatformNotSupported exception when using the networking stack on watchOS. * [System] Tweak tests after watchOS API changes. Unfortunately the [ExpectedException] attribute can't be put on an entire class, so remove the [Category ("RequiresBSDSockets")] attribute on the class and instead decorate each test with an [ExpectedException] attribute. * [System] Fix potential crash in SocketAcceptAsyncTest. Fix potential crash in SocketAcceptAsyncTest by catching any exceptions in code executed on the threadpool so that we never end up with unhandled exceptions (which may terminate the process). * [System] Avoid logic in SetUp attributes in tests. Any type of exception in [SetUp] attributes causes all tests to fail with that exception. This even happens for tests that do not need the logic in the [SetUp] attribute. So rewrite tests a bit to not use [SetUp] when we can reasonably avoid it, and instead instantiate class-level variables on first use. This ensures that any exceptions that occur when initializing those variables are attributed to the corresponding test, and not all of them. * [System] Make exception handler (for test) catch more exceptions to avoid unhandled exceptions causing process termination. * [System] Remove Obsolete attribute on API that throws PNSE.
Diffstat (limited to 'mcs/class/System.Net.Http')
-rw-r--r--mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.platformnotsupported.cs175
-rw-r--r--mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientHandlerTest.cs12
-rw-r--r--mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientTest.cs100
-rw-r--r--mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.exclude.sources1
-rw-r--r--mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.sources2
5 files changed, 267 insertions, 23 deletions
diff --git a/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.platformnotsupported.cs b/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.platformnotsupported.cs
new file mode 100644
index 00000000000..eb5b7ffa820
--- /dev/null
+++ b/mcs/class/System.Net.Http/System.Net.Http/HttpClientHandler.platformnotsupported.cs
@@ -0,0 +1,175 @@
+//
+// System.Net.Http/HttpClientHandler.cs
+//
+// Author:
+// Rolf Bjarne Kvinge <rolf@xamarin.com>
+//
+// Copyright (C) 2016 Xamarin Inc (http://www.xamarin.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System.Collections.Generic;
+using System.Net.Security;
+using System.Security.Authentication;
+using System.Security.Cryptography.X509Certificates;
+using System.Threading.Tasks;
+using System.Threading;
+
+namespace System.Net.Http
+{
+ public class HttpClientHandler : HttpMessageHandler
+ {
+ const string EXCEPTION_MESSAGE = "System.Net.Http.HttpClientHandler is not supported on the current platform.";
+
+ public HttpClientHandler ()
+ {
+ throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
+ }
+
+ public bool AllowAutoRedirect {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public DecompressionMethods AutomaticDecompression {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public ClientCertificateOption ClientCertificateOptions {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public CookieContainer CookieContainer {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public ICredentials Credentials {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public int MaxAutomaticRedirections {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public long MaxRequestContentBufferSize {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public bool PreAuthenticate {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public IWebProxy Proxy {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public virtual bool SupportsAutomaticDecompression {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public virtual bool SupportsProxy {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public virtual bool SupportsRedirectConfiguration {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public bool UseCookies {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public bool UseDefaultCredentials {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public bool UseProxy {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ protected override void Dispose (bool disposing)
+ {
+ throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
+ }
+
+ HttpResponseMessage CreateResponseMessage (HttpWebResponse wr, HttpRequestMessage requestMessage, CancellationToken cancellationToken)
+ {
+ throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
+ }
+
+ protected internal async override Task<HttpResponseMessage> SendAsync (HttpRequestMessage request, CancellationToken cancellationToken)
+ {
+ throw new PlatformNotSupportedException (EXCEPTION_MESSAGE);
+ }
+
+#if NETSTANDARD
+ public bool CheckCertificateRevocationList {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public X509CertificateCollection ClientCertificates {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public ICredentials DefaultProxyCredentials {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public int MaxConnectionsPerServer {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public int MaxResponseHeadersLength {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public IDictionary<string,object> Properties {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public Func<HttpRequestMessage,X509Certificate2,X509Chain,SslPolicyErrors,bool> ServerCertificateCustomValidationCallback {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+
+ public SslProtocols SslProtocols {
+ get { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ set { throw new PlatformNotSupportedException (EXCEPTION_MESSAGE); }
+ }
+#endif
+ }
+}
diff --git a/mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientHandlerTest.cs b/mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientHandlerTest.cs
index 78f8a0c225d..3f06e1c316d 100644
--- a/mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientHandlerTest.cs
+++ b/mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientHandlerTest.cs
@@ -61,6 +61,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Properties_Defaults ()
{
var h = new HttpClientHandler ();
@@ -83,6 +86,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Properties_Invalid ()
{
var h = new HttpClientHandler ();
@@ -107,6 +113,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Properties_AfterClientCreation ()
{
var h = new HttpClientHandler ();
@@ -119,6 +128,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Disposed ()
{
var h = new HttpClientHandler ();
diff --git a/mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientTest.cs b/mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientTest.cs
index f1af864e214..d9aab417dfa 100644
--- a/mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientTest.cs
+++ b/mcs/class/System.Net.Http/Test/System.Net.Http/HttpClientTest.cs
@@ -263,6 +263,10 @@ namespace MonoTests.System.Net.Http
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ // Using HttpClientHandler, which indirectly requires BSD sockets.
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void CancelRequestViaProxy ()
{
var handler = new HttpClientHandler {
@@ -321,7 +325,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Proxy_Disabled ()
{
var pp = WebRequest.DefaultWebProxy;
@@ -398,7 +404,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Complete_Default ()
{
bool? failed = null;
@@ -443,7 +451,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Complete_Version_1_0 ()
{
bool? failed = null;
@@ -491,7 +501,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Complete_ClientHandlerSettings ()
{
bool? failed = null;
@@ -556,7 +568,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Complete_CustomHeaders ()
{
bool? failed = null;
@@ -621,7 +635,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Complete_CustomHeaders_SpecialSeparators ()
{
bool? failed = null;
@@ -656,7 +672,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Complete_CustomHeaders_Host ()
{
bool? failed = null;
@@ -690,7 +708,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Transfer_Encoding_Chunked ()
{
bool? failed = null;
@@ -720,7 +740,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Transfer_Encoding_Custom ()
{
bool? failed = null;
@@ -749,7 +771,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Complete_Content ()
{
var listener = CreateListener (l => {
@@ -777,7 +801,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Complete_Content_MaxResponseContentBufferSize ()
{
var listener = CreateListener (l => {
@@ -800,7 +826,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Complete_Content_MaxResponseContentBufferSize_Error ()
{
var listener = CreateListener (l => {
@@ -827,7 +855,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Complete_NoContent ()
{
foreach (var method in new HttpMethod[] { HttpMethod.Post, HttpMethod.Put, HttpMethod.Delete }) {
@@ -860,7 +890,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Complete_Error ()
{
var listener = CreateListener (l => {
@@ -881,7 +913,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Content_Get ()
{
var listener = CreateListener (l => {
@@ -901,7 +935,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Content_BomEncoding ()
{
var listener = CreateListener (l => {
@@ -926,7 +962,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Content_Put ()
{
bool passed = false;
@@ -952,7 +990,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Send_Content_Put_CustomStream ()
{
bool passed = false;
@@ -1055,7 +1095,9 @@ namespace MonoTests.System.Net.Http
[Test]
[Category ("MobileNotWorking")] // Missing encoding
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void GetString_Many ()
{
Action<HttpListenerContext> context = (HttpListenerContext l) => {
@@ -1085,7 +1127,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void GetByteArray_ServerError ()
{
var listener = CreateListener (l => {
@@ -1108,7 +1152,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void DisallowAutoRedirect ()
{
var listener = CreateListener (l => {
@@ -1137,7 +1183,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void RequestUriAfterRedirect ()
{
var listener = CreateListener (l => {
@@ -1178,7 +1226,9 @@ namespace MonoTests.System.Net.Http
}
[Test]
- [Category ("RequiresBSDSockets")]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
/*
* Properties may only be modified before sending the first request.
*/
@@ -1209,6 +1259,10 @@ namespace MonoTests.System.Net.Http
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ // Using HttpClientHandler, which indirectly requires BSD sockets.
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
/*
* However, this policy is not enforced for custom handlers and there
* is also no way a derived class could tell its HttpClientHandler parent
diff --git a/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.exclude.sources b/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.exclude.sources
new file mode 100644
index 00000000000..5c2ff8a54f8
--- /dev/null
+++ b/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.exclude.sources
@@ -0,0 +1 @@
+System.Net.Http/HttpClientHandler.cs
diff --git a/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.sources b/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.sources
new file mode 100644
index 00000000000..a9d766e5eda
--- /dev/null
+++ b/mcs/class/System.Net.Http/monotouch_watch_System.Net.Http.dll.sources
@@ -0,0 +1,2 @@
+#include System.Net.Http.dll.sources
+System.Net.Http/HttpClientHandler.platformnotsupported.cs