Ejemplo n.º 1
0
        private bool VerifyAddHeaderIsIllegal(WebHeaderCollection wrc, string header, string content, Type exceptionType)
        {
            bool res = true;

            try
            {
                Log.Comment("Set Headers Properties for header: '" + header + "', with value: '" + content + "'");

                if (null == content)
                {
                    wrc.Add(header);
                }
                else
                {
                    wrc.Add(header, content);
                }

                Log.Comment("Illegal header was set:  Failed.");
                res = false;
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, exceptionType))
                {
                    res = false;
                }
            }

            return(res);
        }
Ejemplo n.º 2
0
        private MFTestResults SetCommonHttpResponseHeaders_1_0(ref System.Net.WebHeaderCollection wrs)
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("Set Response Headers Properties");
                wrs.Set(HttpKnownHeaderNames.Allow.ToString(), "GET");
                wrs.Set(HttpKnownHeaderNames.ContentEncoding.ToString(), "gzip");
                wrs.Set(HttpKnownHeaderNames.ContentLength.ToString(), "26012");
                wrs.Set(HttpKnownHeaderNames.ContentType.ToString(), "text/plain, image/gif");
                wrs.Set(HttpKnownHeaderNames.Expires.ToString(), "Thu, 01 Dec 1994 16:00:00 GMT");  //always force client cache validate on the request
                wrs.Set(HttpKnownHeaderNames.KeepAlive.ToString(), "");
                wrs.Set(HttpKnownHeaderNames.LastModified.ToString(), "Fri, 22 May 2009 12:43:31 GMT");
                wrs.Set(HttpKnownHeaderNames.Location.ToString(), "http://www.w3.org/pub/WWW/People.html");
                wrs.Set(HttpKnownHeaderNames.WWWAuthenticate.ToString(), "BASIC realm=\"executives\"");
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                {
                    result = MFTestResults.Fail;
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        private MFTestResults VerifyHttpResponseHeaders(System.Net.WebHeaderCollection wrc, System.Net.WebHeaderCollection wrs)
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                string[] headers = wrc.AllKeys;
                string   sValue  = String.Empty;

                for (int i = 0; i < wrc.Count; i++)
                {
                    sValue = wrc[headers[i]];
                    if (sValue != wrs[headers[i]])
                    {
                        Log.Exception(headers[i] + "property value is incorrect.");
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                {
                    result = MFTestResults.Fail;
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        public MFTestResults ConstructorTestsEmptyArgs()
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("Create string request");
                string URL = "";
                try
                {
                    HttpWebRequest strRequest = (HttpWebRequest)HttpWebRequest.Create(URL);
                    Log.Exception("Expected ArgumentException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    /* pass case */
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.KnownFailure;
            }
            return(result);
        }
Ejemplo n.º 5
0
        public MFTestResults ProtocolVersion()
        {
            MFTestResults  result = MFTestResults.Pass;
            HttpWebRequest wr     = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);

            try
            {
                Log.Comment("Initial version: " + wr.ProtocolVersion);

                Log.Comment("Set Version 1.0");
                wr.ProtocolVersion = new Version(1, 0);
                if (wr.ProtocolVersion.Major != 1 && wr.ProtocolVersion.Minor != 0)
                {
                    Log.Exception("Expected version 1.0, but got " + wr.ProtocolVersion.ToString());
                    result = MFTestResults.Fail;
                }

                Log.Comment("Set Version 1.1");
                wr.ProtocolVersion = new Version(1, 1);
                if (wr.ProtocolVersion.Major != 1 && wr.ProtocolVersion.Minor != 1)
                {
                    Log.Exception("Expected version 1.0, but got " + wr.ProtocolVersion.ToString());
                    result = MFTestResults.Fail;
                }

                Log.Comment("Set Invalid Version 3.7");
                try
                {
                    wr.ProtocolVersion = new Version(3, 7);
                    Log.Exception("Expected Argument Exception");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return(result);
        }
Ejemplo n.º 6
0
        private MFTestResults SetCommonHttpResponseHeaders(ref System.Net.WebHeaderCollection wrs)
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("Set Response Headers Properties");
                wrs.Set(HttpKnownHeaderNames.AcceptRanges.ToString(), "bytes");
                wrs.Set(HttpKnownHeaderNames.Age.ToString(), "0");
                wrs.Set(HttpKnownHeaderNames.Allow.ToString(), "GET, PUT");
                wrs.Set(HttpKnownHeaderNames.CacheControl.ToString(), "no-cache"); //Force intermediate caches to validate their copies directly with the origin server.
                wrs.Set(HttpKnownHeaderNames.Connection.ToString(), "close");
                wrs.Set(HttpKnownHeaderNames.ContentEncoding.ToString(), "gzip");
                wrs.Set(HttpKnownHeaderNames.ContentLanguage.ToString(), "mi, en");
                wrs.Set(HttpKnownHeaderNames.ContentLength.ToString(), "26012");
                wrs.Set(HttpKnownHeaderNames.ContentLocation.ToString(), "");
                wrs.Set(HttpKnownHeaderNames.ContentMD5.ToString(), "60e985979f1d55ab7542440fbb9659e5");
                wrs.Set(HttpKnownHeaderNames.ContentRange.ToString(), "bytes 21010-47021/47022");
                wrs.Set(HttpKnownHeaderNames.ContentType.ToString(), "text/plain, image/gif");
                wrs.Set(HttpKnownHeaderNames.Date.ToString(), System.DateTime.Today.ToString());
                wrs.Set(HttpKnownHeaderNames.ETag.ToString(), "W/");
                wrs.Set(HttpKnownHeaderNames.Expires.ToString(), "Thu, 01 Dec 1994 16:00:00 GMT");  //always force client cache validate on the request
                wrs.Set(HttpKnownHeaderNames.KeepAlive.ToString(), "");
                wrs.Set(HttpKnownHeaderNames.LastModified.ToString(), "Fri, 22 May 2009 12:43:31 GMT");
                wrs.Set(HttpKnownHeaderNames.Location.ToString(), "http://www.w3.org/pub/WWW/People.html");
                wrs.Set(HttpKnownHeaderNames.Pragma.ToString(), "no-cache");
                wrs.Set(HttpKnownHeaderNames.ProxyAuthenticate.ToString(), "NNNNNNNNNNNNNNNNN==");
                wrs.Set(HttpKnownHeaderNames.RetryAfter.ToString(), "120");
                wrs.Set(HttpKnownHeaderNames.SetCookie.ToString(), "http://www.w3.org/hypertext/DataSources/Overview.html");
                wrs.Set(HttpKnownHeaderNames.Trailer.ToString(), "Test Code");
                wrs.Set(HttpKnownHeaderNames.TransferEncoding.ToString(), "8BIT");
                wrs.Set(HttpKnownHeaderNames.Upgrade.ToString(), "HTTP/2.0, SHTTP/1.3");
                wrs.Set(HttpKnownHeaderNames.Vary.ToString(), "TestVary");
                wrs.Set(HttpKnownHeaderNames.Via.ToString(), "1.0 fred, 1.1 nowhere.com (Apache/1.1)");
                wrs.Set(HttpKnownHeaderNames.Warning.ToString(), "TestWarning");
                wrs.Set(HttpKnownHeaderNames.WWWAuthenticate.ToString(), "BASIC realm=\"executives\"");
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                {
                    result = MFTestResults.Fail;
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
        public MFTestResults InvalidConstructorTests()
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("null string");
                string nullString = null;
                try { WebRequest nsWR = WebRequest.Create(nullString); }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("null uri");
                Uri nullUri = null;
                try { WebRequest nuWr = WebRequest.Create(nullUri); }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("invalud URI type");
                try { WebRequest inWr = WebRequest.Create("ftp://ftp.microsoft.com"); }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(NotSupportedException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return(result);
        }
Ejemplo n.º 8
0
        private bool TestCheckBadHeaders(string value)
        {
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);;

            try
            {
                wr.Headers.Add("Test", value);
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        private MFTestResults Verify(System.Net.WebHeaderCollection wrc, System.Net.WebHeaderCollection RequestHeaders)
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("Get Headers - User-Agent");
                if (wrc["User-Agent"] != RequestHeaders["User-Agent"])
                {
                    Log.Exception("User-Agent property value is incorrect.");
                    result = MFTestResults.Fail;
                }

                Log.Comment("Get Headers - Connection");
                if (wrc["Connection"] != RequestHeaders["Connection"])
                {
                    Log.Exception("Connection property value is incorrect.");
                    result = MFTestResults.Fail;
                }

                Log.Comment("Get Headers - Host");
                if (wrc["Host"] != RequestHeaders["Host"])
                {
                    Log.Exception("Host property value is incorrect.");
                    result = MFTestResults.Fail;
                }
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                {
                    result = MFTestResults.Fail;
                }
            }

            return(result);
        }
Ejemplo n.º 11
0
        public MFTestResults ContentLengthHeader()
        {
            MFTestResults  result = MFTestResults.Pass;
            HttpWebRequest wr     = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);;

            try
            {
                Log.Comment("negative value should throw");
                try
                {
                    wr.ContentLength = -1;
                }
                catch (Exception ex)
                {
                    /* pass case */
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentOutOfRangeException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                wr.ContentLength = 1234567;
                if (wr.ContentLength != 1234567)
                {
                    Log.Exception("Expected ContentLength 1234567, but got " + wr.ContentLength);
                    result = MFTestResults.Fail;
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return(result);
        }
Ejemplo n.º 12
0
        public MFTestResults SetHeadersAfterRequest()
        {
            MFTestResults  result = MFTestResults.Pass;
            HttpWebRequest wr     = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpTestServer.s_CurrentPort.ToString() + "/");

            wr.UserAgent = ".Net Micro Framwork Device/4.0";
            HttpTestServer server = new HttpTestServer("http", ref result)
            {
                RequestUri     = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>SetHeadersAfterRequest</body></html>"
            };

            try
            {
                // Setup server
                server.StartServer();
                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

                // Tests
                try
                {
                    Log.Comment("ReadWriteTimeout");
                    wr.ReadWriteTimeout = 10;
                    Log.Exception("[Client] Expected InvalidOperationException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                try
                {
                    Log.Comment("ContentLength");
                    wr.ContentLength = 10;
                    Log.Exception("[Client] Expected InvalidOperationException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                try
                {
                    Log.Comment("Headers");
                    wr.Headers = new WebHeaderCollection();
                    Log.Exception("[Client] Expected InvalidOperationException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                try
                {
                    Log.Comment("Proxy");
                    wr.Proxy = null;
                    Log.Exception("[Client] Expected InvalidOperationException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                try
                {
                    Log.Comment("SendChunked");
                    wr.SendChunked = true;
                    Log.Exception("[Client] Expected InvalidOperationException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                // Stop server
                server.StopServer();
            }

            return(result);
        }
Ejemplo n.º 13
0
        public MFTestResults AddRangeInvalidTests()
        {
            MFTestResults  result = MFTestResults.Pass;
            HttpWebRequest wr;

            try
            {
                Log.Comment("invalid from - AddRange(-1, 500)");
                wr = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);
                try
                {
                    wr.AddRange(-1, 500);
                    Log.Exception("Expected ArgumentOutOfRangeException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    /* pass case */
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentOutOfRangeException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("invalid from - AddRange(1, -500)");
                wr = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);
                try
                {
                    wr.AddRange(1, -500);
                    Log.Exception("Expected ArgumentOutOfRangeException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    /* pass case */
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentOutOfRangeException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("invalid specifier - AddRange(null, 500)");
                wr = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);
                try
                {
                    wr.AddRange(null, 500);
                    Log.Exception("Expected ArgumentNullException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    /* pass case */
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("invalid specifier - AddRange(null, 1, 500)");
                wr = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);
                try
                {
                    wr.AddRange(null, 1, 500);
                    Log.Exception("Expected ArgumentNullException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    /* pass case */
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return(result);
        }
Ejemplo n.º 14
0
        public MFTestResults InvalidConstructorTests()
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("null string constructor");
                try { uri = new Uri(null); }
                catch (ArgumentNullException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("no uri string");
                try { uri = new Uri("foo"); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("uri, no address");
                try { uri = new Uri("http:"); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("uri, starts with non-alpha");
                try { uri = new Uri("1ttp://foo.com"); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("uri, includes numeric");
                try { uri = new Uri("h1tp://foo.com"); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("uri, includes non-alpha");
                try { uri = new Uri("h@tp://foo.com"); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("No ABSPath port URI");
                try { uri = new Uri(HttpTests.MSUrl + ":80"); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("Empty string constructor");
                try { uri = new Uri(""); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return(result);
        }