From 8d6080cd9f483b90867f2ee746c4806528f95fb4 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Fri, 31 Mar 2023 21:12:44 +0100 Subject: [PATCH] [tests] Use msftconnecttest.com in QuoteInvalidQuoteUrlsShouldWork (#7919) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Context: 112c8328a61009962aa0321590d7937a0aa69dff Context: https://bugzilla.xamarin.com/show_bug.cgi?id=14968 Context: https://github.com/xamarin/monodroid/commit/5e923e369379508c7f1fd20307a0acb5fb29bdf8 Context: https://github.com/xamarin/monodroid/commit/2e5f7bb4f79bb79dadba5413ccafcaa6bda70b1a For historical purposes… is (was?) a bug wherein accessing an "invalid" URL such as would result in a `URISyntaxException` at runtime: Exception of type 'Java.Net.URISyntaxException' was thrown. at Android.Runtime.JNIEnv.NewObject (IntPtr jclass, IntPtr jmethod, Android.Runtime.JValue[] parms) at Java.Net.URI..ctor (System.String uri) at Android.Runtime.AndroidEnvironment+_Proxy.IsBypassed (System.Uri host) at System.Net.ServicePointManager.FindServicePoint (System.Uri address, IWebProxy proxy) at System.Net.HttpWebRequest.GetServicePoint () at System.Net.HttpWebRequest.BeginGetResponse (System.AsyncCallback callback, System.Object state) at System.Net.HttpWebRequest.GetResponse () at Xamarin.Android.RuntimeTests.ProxyTest.QuoteInvalidQuoteUrlsShouldWork () at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) --- End of managed exception stack trace --- java.net.URISyntaxException: Illegal character in query at index 29: http://example.com/?query&foo|bar at libcore.net.UriCodec.validate(UriCodec.java:63) at java.net.URI.parseURI(URI.java:406) at java.net.URI.(URI.java:204) at xamarin.android.nunitlite.TestSuiteInstrumentation.n_onStart(Native Method) at xamarin.android.nunitlite.TestSuiteInstrumentation.onStart(TestSuiteInstrumentation.java:39) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701) Index 29 is `|` (zero-based!). The "problem" here that using `|` within the query string is accepted under .NET & Mono, which resulted in a "breakage of expectations" for Xamarin.Android customers ("this URL works on .NET!"). The "fix" was to use [`Uri.AbsoluteUri`][5], which replaces `|` with `%7C`, hex-escaping the offending value and adding the `ProxyTest.QuoteInvalidQuoteUrlsShouldWork()` unit test. That background done, commit 112c8328 updated `ProxyTest.QuoteInvalidQuoteUrlsShouldWork()` to hit instead of , on the assumption that it would be "better" if we *didn't* use non-Microsoft URLs as part of our unit tests. The problem is that this didn't work (eep?! not sure how PR #7909 was green here!): System.Net.WebException : net_http_ssl_connection_failed ----> System.Net.Http.HttpRequestException : net_http_ssl_connection_failed ----> System.Security.Authentication.AuthenticationException : net_auth_SSPI ----> Interop+AndroidCrypto+SslException : Exception_WasThrown, Interop+AndroidCrypto+SslException Update `ProxyTest.QuoteInvalidQuoteUrlsShouldWork()` to instead hit , which is a Microsoft-owned server -- no possible DOS'ing of -- which *passes* for this particular test. [0]: https://developer.android.com/reference/java/net/URI#URI(java.lang.String) [1]: https://www.ietf.org/rfc/rfc2396.txt [2]: https://www.ietf.org/rfc/rfc3986.html#section-3.4 [3]: https://android.googlesource.com/platform/libcore/+/jb-mr2-release/luni/src/main/java/libcore/net/UriCodec.java#46 [4]: https://android.googlesource.com/platform/libcore/+/jb-mr2-release/luni/src/main/java/java/net/URI.java#349 [5]: https://learn.microsoft.com/en-us/dotnet/api/system.uri.absoluteuri?view=net-7.0 --- tests/Mono.Android-Tests/System.Net/ProxyTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Mono.Android-Tests/System.Net/ProxyTest.cs b/tests/Mono.Android-Tests/System.Net/ProxyTest.cs index a8149eccd3c..a46f56f70f0 100644 --- a/tests/Mono.Android-Tests/System.Net/ProxyTest.cs +++ b/tests/Mono.Android-Tests/System.Net/ProxyTest.cs @@ -13,7 +13,7 @@ public class ProxyTest { [Test] public void QuoteInvalidQuoteUrlsShouldWork () { - string url = "https://bing.com/?query&foo|bar"; + string url = "http://www.msftconnecttest.com/connecttest.txt?query&foo|bar"; var request = (HttpWebRequest) WebRequest.Create (url); request.Method = "GET"; var response = (HttpWebResponse) request.GetResponse ();