public MFTestResults TestWebProxyConstructor5() { MFTestResults result = MFTestResults.Pass; Log.Comment("Set proxy using WebProxy(System.Uri)"); UriProperties props = new UriProperties("http", "www.microsoft.com"); Uri uri = new Uri(props.OriginalUri); WebProxy proxyObject = new WebProxy(uri); if (proxyObject.BypassProxyOnLocal) { result = MFTestResults.Fail; } WebRequest wr = WebRequest.Create(uri); wr.Proxy = proxyObject; Uri wrUri = wr.Proxy.GetProxy(uri); if (wrUri != uri) { result = MFTestResults.Fail; } return(result); }
public MFTestResults TestWebProxyInvalidserverAddress() { MFTestResults result = MFTestResults.Pass; Log.Comment("Set proxy using WebProxy(string, bool)"); UriProperties props = new UriProperties("http", "www.microsoft.com"); Uri uri = new Uri(props.OriginalUri); try { WebProxy proxyObject = new WebProxy("ht1p:itgproxy", true); result = MFTestResults.Fail; } catch (ArgumentException ex) { Log.Exception("Expect ArgumentException: ", ex); } try { WebProxy proxyObject = new WebProxy(string.Empty, true); result = MFTestResults.Fail; } catch (ArgumentOutOfRangeException ex) { Log.Exception("Expect ArgumentOutOfRangeException: ", ex); } return(result); }
public MFTestResults InvalidDefaultTestGetHTTPRequestHeaderAfterCreateHTTP1_1_FTP() { MFTestResults result = MFTestResults.Pass; UriProperties props = new UriProperties("ftp", "//ftp.microsoft.com"); Uri uri = new Uri(props.OriginalUri); Log.Comment("Negative Test case 2:"); Log.Comment("Create WebRequest with FTP uri"); try { HttpWebRequest wrftp = (HttpWebRequest)WebRequest.Create(uri); } catch (System.NotSupportedException) { Log.Comment("Create WebRequest with FTP uri - Expected System.NotSupportedException"); } HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://ftp.microsoft.com"); wr.UserAgent = ".Net Micro Framwork Device/4.0"; Log.Comment("Initial version: " + wr.ProtocolVersion); //Default version is 1.1 Log.Comment("Set Version 1.1"); wr.ProtocolVersion = new Version(1, 1); HttpServer server = new HttpServer("http", ref result) { RequestUri = wr.RequestUri, RequestHeaders = wr.Headers, }; try { // Setup server server.StartServer(); System.Net.WebHeaderCollection wrc = wr.Headers; // Tests Verify(wrc, server.RequestHeaders); } catch (Exception ex) { Log.Exception("[Client] Unexpected Exception", ex); result = MFTestResults.Fail; } finally { // Stop server server.StopServer(); } return(result); }
private bool ValidUri(Uri uri, UriProperties props) { bool result = true; // AbsolutePath if (props.Path != null && uri.AbsolutePath != props.Path) { Log.Exception("Expected AbsolutePath: " + props.Path + ", but got: " + uri.AbsolutePath); result = false; } // AbsoluteUri if (uri.AbsoluteUri != props.AbsoluteUri) { Log.Exception("Expected AbsoluteUri: " + props.AbsoluteUri + ", but got: " + uri.AbsoluteUri); result = false; } // HostNameType if (uri.HostNameType != props.Type) { Log.Exception("Expected HostNameType: " + props.Type + ", but got: " + uri.HostNameType); result = false; } switch (uri.Scheme.ToLower()) { case "http": case "https": if (uri.Port != props.Port) { Log.Exception("Expected Port: " + props.Port + ", but got: " + uri.Port); result = false; } // Host if (uri.Host != props.Host) { Log.Exception("Expected Host: " + props.Host + ", but got: " + uri.Host); result = false; } break; default: // no validation break; } // Scheme if (uri.Scheme != props.Scheme) { Log.Exception("Expected Scheme: " + props.Scheme + ", but got: " + uri.Scheme); result = false; } return(result); }
private bool ValidUri(Uri uri, UriProperties props) { bool result = true; // AbsolutePath if (props.Path != null && uri.AbsolutePath != props.Path) { Log.Exception("Expected AbsolutePath: " + props.Path + ", but got: " + uri.AbsolutePath); result = false; } // AbsoluteUri if (uri.AbsoluteUri != props.AbsoluteUri) { Log.Exception("Expected AbsoluteUri: " + props.AbsoluteUri + ", but got: " + uri.AbsoluteUri); result = false; } // HostNameType if (uri.HostNameType != props.Type) { Log.Exception("Expected HostNameType: " + props.Type + ", but got: " + uri.HostNameType); result = false; } switch (uri.Scheme.ToLower()) { case "http": case "https": if (uri.Port != props.Port) { Log.Exception("Expected Port: " + props.Port + ", but got: " + uri.Port); result = false; } // Host if (uri.Host != props.Host) { Log.Exception("Expected Host: " + props.Host + ", but got: " + uri.Host); result = false; } break; default: // no validation break; } // Scheme if (uri.Scheme != props.Scheme) { Log.Exception("Expected Scheme: " + props.Scheme + ", but got: " + uri.Scheme); result = false; } return result; }
public MFTestResults ValidUri() { MFTestResults result = MFTestResults.Pass; try { Log.Comment("Microsoft URL"); props = new UriProperties("http", "www.microsoft.com"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("Alternate http port URL"); props = new UriProperties("http", "www.microsoft.com") { Port = 1080, Path = "/" //Need to remove later. This seems like a bug to require it. }; uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("URL with content"); props = new UriProperties("http", "www.microsoft.com") { Path = "/en/us/default.aspx" }; uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected Exception", ex); result = MFTestResults.Fail; } return(result); }
public MFTestResults TestDefaultWebProxy() { MFTestResults result = MFTestResults.Pass; Log.Comment("Set proxy using WebProxy()"); UriProperties props = new UriProperties("http", "www.microsoft.com"); Uri uri = new Uri(props.OriginalUri); WebProxy proxyObject = new WebProxy(); WebRequest wr = WebRequest.Create(uri); wr.Proxy = proxyObject; Uri wrUri = wr.Proxy.GetProxy(uri); if (wrUri != uri) { result = MFTestResults.Fail; } return result; }
public MFTestResults RelativeURI() { MFTestResults result = MFTestResults.Pass; try { Log.Comment("relative url"); uri = new Uri("/doc/text.html", UriKind.Relative); Log.Comment("absolute url"); props = new UriProperties("https", "www.microsoft.com") { Path = "/doc/text.html", Port = 1443 }; uri = new Uri(props.OriginalUri, UriKind.Absolute); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("RelativeOrAbsolute"); try { uri = new Uri("/doc/text.html", UriKind.RelativeOrAbsolute); } catch (ArgumentException ex) { if (!HttpTests.ValidateException(ex, typeof(ArgumentException))) { result = MFTestResults.Fail; } } } catch (Exception ex) { Log.Exception("Unexpected Exception", ex); result = MFTestResults.Fail; } return(result); }
public MFTestResults TestWebProxyConstructor1() { MFTestResults result = MFTestResults.Pass; Log.Comment("Set proxy using WebProxy(string)"); UriProperties props = new UriProperties("http", "www.microsoft.com"); Uri uri = new Uri(props.OriginalUri); string proxy = "itgproxy.redmond.corp.microsoft.com"; WebProxy proxyObject = new WebProxy(proxy); WebRequest wr = WebRequest.Create(uri); wr.Proxy = proxyObject; Uri wrUri = wr.Proxy.GetProxy(uri); if (wrUri.Host != proxy) { result = MFTestResults.Fail; } return result; }
public MFTestResults TestWebProxyConstructor2() { MFTestResults result = MFTestResults.Pass; Log.Comment("Set proxy using WebProxy(string, bool)"); UriProperties props = new UriProperties("http", "www.microsoft.com"); Uri uri = new Uri(props.OriginalUri); string proxy = "itgproxy.redmond.corp.microsoft.com"; WebProxy proxyObject = new WebProxy(proxy, true); WebRequest wr = WebRequest.Create(uri); wr.Proxy = proxyObject; Uri wrUri = wr.Proxy.GetProxy(uri); if (wrUri.Host != proxy) { result = MFTestResults.Fail; } return(result); }
public MFTestResults AdditionalValidUri() { MFTestResults result = MFTestResults.Pass; try { Log.Comment("iris.beep"); props = new UriProperties("iris.beep", "bop") { Type = UriHostNameType.Unknown }; uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("Microsoft Secure URL"); props = new UriProperties("https", "www.microsoft.com"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("Alternate https port URL"); props = new UriProperties("https", "www.microsoft.com") { Port = 1443 }; uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("H323 uri"); props = new UriProperties("h323", "user@host:54"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("FTP URI"); uri = new Uri("ftp://ftp.microsoft.com/file.txt"); parsed = new ParsedUri("ftp", "ftp.microsoft.com", UriHostNameType.Dns, 21, "/file.txt", "ftp://ftp.microsoft.com/file.txt"); if (!parsed.ValidUri(uri)) result = MFTestResults.Fail; Log.Comment("Unix style file"); uri = new Uri("file:///etc/hosts"); parsed = new ParsedUri("file", string.Empty, UriHostNameType.Basic, -1, "/etc/hosts", "file:///etc/hosts"); if (!parsed.ValidUri(uri)) result = MFTestResults.Fail; Log.Comment("Windows share style file"); uri = new Uri("file:///\\\\server\\folder\\file.txt"); parsed = new ParsedUri("file", "server", UriHostNameType.Dns, -1, "/folder/file.txt", "file://server/folder/file.txt"); if (!parsed.ValidUri(uri)) result = MFTestResults.Fail; Log.Comment("Windows drive style file"); uri = new Uri("file:///c:\\rbllog"); parsed = new ParsedUri("file", string.Empty, UriHostNameType.Basic, -1, "c:/rbllog", "file:///c:/rbllog"); if (!parsed.ValidUri(uri)) result = MFTestResults.Fail; } catch (Exception ex) { Log.Exception("Unexpected Exception - these cases currently all fail", ex); result = MFTestResults.Fail; } return result; }
public MFTestResults ValidURN() { MFTestResults result = MFTestResults.Pass; try { Log.Comment("isbn"); props = new UriProperties("urn", "isbn:0451450523"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("isan"); props = new UriProperties("urn", "isan:0000-0000-9E59-0000-O-0000-0000-2"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("issn"); props = new UriProperties("urn", "issn:0167-6423"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("ietf"); props = new UriProperties("urn", "ietf:rfc:2648"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("mpeg"); props = new UriProperties("urn", "mpeg:mpeg7:schema:2001"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("oid"); props = new UriProperties("urn", "oid:2.216.840"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("urn:uuid"); props = new UriProperties("urn", "uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("uuid"); props = new UriProperties("uuid", "6e8bc430-9c3a-11d9-9669-0800200c9a66"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("uci"); props = new UriProperties("urn", "uci:I001+SBSi-B10000083052"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; } catch (Exception ex) { Log.Exception("Unexpected Exception", ex); result = MFTestResults.Fail; } return result; }
public MFTestResults ValidUri() { MFTestResults result = MFTestResults.Pass; try { Log.Comment("Microsoft URL"); props = new UriProperties("http", "www.microsoft.com"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("Alternate http port URL"); props = new UriProperties("http", "www.microsoft.com") { Port = 1080, Path = "/" //Need to remove later. This seems like a bug to require it. }; uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("URL with content"); props = new UriProperties("http", "www.microsoft.com") { Path = "/en/us/default.aspx" }; uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) result = MFTestResults.Fail; } catch (Exception ex) { Log.Exception("Unexpected Exception", ex); result = MFTestResults.Fail; } return result; }
public MFTestResults AdditionalValidUri() { MFTestResults result = MFTestResults.Pass; try { Log.Comment("iris.beep"); props = new UriProperties("iris.beep", "bop") { Type = UriHostNameType.Unknown }; uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("Microsoft Secure URL"); props = new UriProperties("https", "www.microsoft.com"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("Alternate https port URL"); props = new UriProperties("https", "www.microsoft.com") { Port = 1443 }; uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("H323 uri"); props = new UriProperties("h323", "user@host:54"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("FTP URI"); uri = new Uri("ftp://ftp.microsoft.com/file.txt"); parsed = new ParsedUri("ftp", "ftp.microsoft.com", UriHostNameType.Dns, 21, "/file.txt", "ftp://ftp.microsoft.com/file.txt"); if (!parsed.ValidUri(uri)) { result = MFTestResults.Fail; } Log.Comment("Unix style file"); uri = new Uri("file:///etc/hosts"); parsed = new ParsedUri("file", string.Empty, UriHostNameType.Basic, -1, "/etc/hosts", "file:///etc/hosts"); if (!parsed.ValidUri(uri)) { result = MFTestResults.Fail; } Log.Comment("Windows share style file"); uri = new Uri("file:///\\\\server\\folder\\file.txt"); parsed = new ParsedUri("file", "server", UriHostNameType.Dns, -1, "/folder/file.txt", "file://server/folder/file.txt"); if (!parsed.ValidUri(uri)) { result = MFTestResults.Fail; } Log.Comment("Windows drive style file"); uri = new Uri("file:///c:\\rbllog"); parsed = new ParsedUri("file", string.Empty, UriHostNameType.Basic, -1, "c:/rbllog", "file:///c:/rbllog"); if (!parsed.ValidUri(uri)) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected Exception - these cases currently all fail", ex); result = MFTestResults.Fail; } return(result); }
public MFTestResults ValidURN() { MFTestResults result = MFTestResults.Pass; try { Log.Comment("isbn"); props = new UriProperties("urn", "isbn:0451450523"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("isan"); props = new UriProperties("urn", "isan:0000-0000-9E59-0000-O-0000-0000-2"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("issn"); props = new UriProperties("urn", "issn:0167-6423"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("ietf"); props = new UriProperties("urn", "ietf:rfc:2648"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("mpeg"); props = new UriProperties("urn", "mpeg:mpeg7:schema:2001"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("oid"); props = new UriProperties("urn", "oid:2.216.840"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("urn:uuid"); props = new UriProperties("urn", "uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("uuid"); props = new UriProperties("uuid", "6e8bc430-9c3a-11d9-9669-0800200c9a66"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } Log.Comment("uci"); props = new UriProperties("urn", "uci:I001+SBSi-B10000083052"); uri = new Uri(props.OriginalUri); if (!ValidUri(uri, props)) { result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected Exception", ex); result = MFTestResults.Fail; } return(result); }
public MFTestResults RelativeURI() { MFTestResults result = MFTestResults.Pass; try { Log.Comment("relative url"); uri = new Uri("/doc/text.html", UriKind.Relative); Log.Comment("absolute url"); props = new UriProperties("https", "www.microsoft.com") { Path = "/doc/text.html", Port = 1443 }; uri = new Uri(props.OriginalUri, UriKind.Absolute); if (!ValidUri(uri, props)) result = MFTestResults.Fail; Log.Comment("RelativeOrAbsolute"); try { uri = new Uri("/doc/text.html", UriKind.RelativeOrAbsolute); } catch (ArgumentException ex) { if (!HttpTests.ValidateException(ex, typeof(ArgumentException))) result = MFTestResults.Fail; } } catch (Exception ex) { Log.Exception("Unexpected Exception", ex); result = MFTestResults.Fail; } return result; }
public MFTestResults InvalidDefaultTestGetHTTPRequestHeaderAfterCreateHTTP1_1_FTP() { MFTestResults result = MFTestResults.Pass; UriProperties props = new UriProperties("ftp", "//ftp.microsoft.com"); Uri uri = new Uri(props.OriginalUri); Log.Comment("Negative Test case 2:"); Log.Comment("Create WebRequest with FTP uri"); try { HttpWebRequest wrftp = (HttpWebRequest)WebRequest.Create(uri); } catch (System.NotSupportedException) { Log.Comment("Create WebRequest with FTP uri - Expected System.NotSupportedException"); } HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://ftp.microsoft.com"); wr.UserAgent = ".Net Micro Framwork Device/4.0"; Log.Comment("Initial version: " + wr.ProtocolVersion); //Default version is 1.1 Log.Comment("Set Version 1.1"); wr.ProtocolVersion = new Version(1, 1); HttpServer server = new HttpServer("http", ref result) { RequestUri = wr.RequestUri, RequestHeaders = wr.Headers, }; try { // Setup server server.StartServer(); System.Net.WebHeaderCollection wrc = wr.Headers; // Tests Verify(wrc, server.RequestHeaders); } catch (Exception ex) { Log.Exception("[Client] Unexpected Exception", ex); result = MFTestResults.Fail; } finally { // Stop server server.StopServer(); } return result; }
public MFTestResults TestWebProxyInvalidserverAddress() { MFTestResults result = MFTestResults.Pass; Log.Comment("Set proxy using WebProxy(string, bool)"); UriProperties props = new UriProperties("http", "www.microsoft.com"); Uri uri = new Uri(props.OriginalUri); try { WebProxy proxyObject = new WebProxy("ht1p:itgproxy", true); result = MFTestResults.Fail; } catch (ArgumentException ex) { Log.Exception("Expect ArgumentException: ", ex); } try { WebProxy proxyObject = new WebProxy(string.Empty, true); result = MFTestResults.Fail; } catch (ArgumentOutOfRangeException ex) { Log.Exception("Expect ArgumentOutOfRangeException: ", ex); } return result; }