diff options
author | Gert Driesen <drieseng@users.sourceforge.net> | 2009-06-06 03:20:31 +0400 |
---|---|---|
committer | Gert Driesen <drieseng@users.sourceforge.net> | 2009-06-06 03:20:31 +0400 |
commit | 6c3fbf55b91662af290a3c73fc004717ab2da449 (patch) | |
tree | 9df06f046aae1d6d9030a80c7a52ead43e58cad4 /mcs/class/System/Test | |
parent | c88bd5348b5712c9e9fe26444e379742df05099c (diff) |
* HttpWebRequestTest.cs: Added tests for bugs #465613, #510661,
#510642 and #508027.
svn path=/trunk/mcs/; revision=135573
Diffstat (limited to 'mcs/class/System/Test')
-rw-r--r-- | mcs/class/System/Test/System.Net/ChangeLog | 5 | ||||
-rw-r--r-- | mcs/class/System/Test/System.Net/HttpWebRequestTest.cs | 340 |
2 files changed, 343 insertions, 2 deletions
diff --git a/mcs/class/System/Test/System.Net/ChangeLog b/mcs/class/System/Test/System.Net/ChangeLog index fe1ab1f713f..9188cfe5bea 100644 --- a/mcs/class/System/Test/System.Net/ChangeLog +++ b/mcs/class/System/Test/System.Net/ChangeLog @@ -1,3 +1,8 @@ +2009-06-06 Gert Driesen <drieseng@users.sourceforge.net> + + * HttpWebRequestTest.cs: Added tests for bugs #465613, #510661, + #510642 and #508027. + 2009-05-17 Gert Driesen <drieseng@users.sourceforge.net> * CookieTest.cs: Added test for Path. diff --git a/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs b/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs index b5a13f241b8..a3060eb7cab 100644 --- a/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs +++ b/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs @@ -128,7 +128,7 @@ namespace MonoTests.System.Net } [Test] - [Category("InetAccess")] + [Category("InetAccess")] public void Cookies1 () { // The purpose of this test is to ensure that the cookies we get from a request @@ -286,6 +286,241 @@ namespace MonoTests.System.Net } } + [Test] + public void BeginGetRequestStream_Body_NotAllowed () + { + IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000); + string url = "http://" + IPAddress.Loopback.ToString () + ":8000/test/"; + + using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (EchoRequestHandler))) { + responder.Start (); + + HttpWebRequest request; + + request = (HttpWebRequest) WebRequest.Create (url); + request.Method = "GET"; + + try { + request.BeginGetRequestStream (null, null); + Assert.Fail ("#A1"); + } catch (ProtocolViolationException ex) { + // Cannot send a content-body with this + // verb-type + Assert.IsNull (ex.InnerException, "#A2"); + Assert.IsNotNull (ex.Message, "#A3"); + } + + request = (HttpWebRequest) WebRequest.Create (url); + request.Method = "HEAD"; + + try { + request.BeginGetRequestStream (null, null); + Assert.Fail ("#B1"); + } catch (ProtocolViolationException ex) { + // Cannot send a content-body with this + // verb-type + Assert.IsNull (ex.InnerException, "#B2"); + Assert.IsNotNull (ex.Message, "#B3"); + } + } + } + + [Test] // bug #465613 + [Category ("NotWorking")] + public void BeginGetRequestStream_NoBuffering () + { + IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8002); + string url = "http://" + IPAddress.Loopback.ToString () + ":8002/test/"; + + using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (EchoRequestHandler))) { + responder.Start (); + + HttpWebRequest req; + Stream rs; + IAsyncResult ar; + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "POST"; + req.SendChunked = false; + req.KeepAlive = false; + req.AllowWriteStreamBuffering = false; + + ar = req.BeginGetRequestStream (null, null); + rs = req.EndGetRequestStream (ar); + rs.Close (); + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "POST"; + req.SendChunked = false; + req.KeepAlive = true; + req.AllowWriteStreamBuffering = false; + + try { + req.BeginGetRequestStream (null, null); + Assert.Fail ("#A1"); + } catch (ProtocolViolationException ex) { + // When performing a write operation with + // AllowWriteStreamBuffering set to false, + // you must either set ContentLength to a + // non-negative number or set SendChunked + // to true + Assert.IsNull (ex.InnerException, "#A2"); + Assert.IsNotNull (ex.Message, "#A3"); + } + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "POST"; + req.SendChunked = false; + req.KeepAlive = true; + req.AllowWriteStreamBuffering = false; + req.ContentLength = 0; + + ar = req.BeginGetRequestStream (null, null); + rs = req.EndGetRequestStream (ar); + rs.Close (); + } + } + + [Test] // bug #508027 + [Category ("NotWorking")] + public void BeginGetResponse () + { + IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8003); + string url = "http://" + IPAddress.Loopback.ToString () + ":8003/test/"; + + using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (EchoRequestHandler))) { + responder.Start (); + + HttpWebRequest req; + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "POST"; + req.SendChunked = false; + req.KeepAlive = false; + req.AllowWriteStreamBuffering = false; + req.BeginGetResponse (null, null); + req.Abort (); + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "POST"; + req.SendChunked = true; + req.KeepAlive = false; + req.AllowWriteStreamBuffering = false; + req.BeginGetResponse (null, null); + req.Abort (); + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "POST"; + req.ContentLength = 5; + req.SendChunked = false; + req.KeepAlive = false; + req.AllowWriteStreamBuffering = false; + req.BeginGetResponse (null, null); + req.Abort (); + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "POST"; + req.SendChunked = false; + req.KeepAlive = true; + req.AllowWriteStreamBuffering = false; +#if NET_2_0 + req.BeginGetResponse (null, null); + req.Abort (); +#else + try { + req.BeginGetResponse (null, null); + } catch (ProtocolViolationException ex) { + // Either ContentLength must be set to a non-negative + // number, or SendChunked set to true in order to perform + // the write operation when AllowWriteStreamBuffering + // is disabled + Assert.IsNull (ex.InnerException, "#A2"); + Assert.IsNotNull (ex.Message, "#A3"); + } finally { + req.Abort (); + } +#endif + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "POST"; + req.SendChunked = false; + req.KeepAlive = false; + req.AllowWriteStreamBuffering = false; + req.ContentLength = 5; + req.BeginGetResponse (null, null); + req.Abort (); + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "POST"; + req.SendChunked = false; + req.KeepAlive = true; + req.AllowWriteStreamBuffering = false; + req.ContentLength = 5; + req.BeginGetResponse (null, null); + req.Abort (); + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "GET"; + req.SendChunked = true; +#if NET_2_0 + req.BeginGetResponse (null, null); + req.Abort (); +#else + try { + req.BeginGetResponse (null, null); + Assert.Fail ("#B1"); + } catch (ProtocolViolationException ex) { + // Content-Length cannot be set for a + // non-write operation + Assert.IsNull (ex.InnerException, "#B2"); + Assert.IsNotNull (ex.Message, "#B3"); + } finally { + req.Abort (); + } +#endif + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "GET"; + req.ContentLength = 5; +#if NET_2_0 + req.BeginGetResponse (null, null); + req.Abort (); +#else + try { + req.BeginGetResponse (null, null); + Assert.Fail ("#C1"); + } catch (ProtocolViolationException ex) { + // Content-Length cannot be set for a + // non-write operation + Assert.IsNull (ex.InnerException, "#C2"); + Assert.IsNotNull (ex.Message, "#C3"); + } finally { + req.Abort (); + } +#endif + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "GET"; + req.ContentLength = 0; +#if NET_2_0 + req.BeginGetResponse (null, null); + req.Abort (); +#else + try { + req.BeginGetResponse (null, null); + Assert.Fail ("#D1"); + } catch (ProtocolViolationException ex) { + // Content-Length cannot be set for a + // non-write operation + Assert.IsNull (ex.InnerException, "#D2"); + Assert.IsNotNull (ex.Message, "#D3"); + } finally { + req.Abort (); + } +#endif + } + } + [Test] // bug #429200 public void GetRequestStream () { @@ -307,7 +542,108 @@ namespace MonoTests.System.Net Assert.AreSame (rs1, rs2, "#2"); rs1.Close (); - responder.Stop (); + } + } + + [Test] // bug #510661 + [Category ("NotWorking")] + public void GetRequestStream_Close_NotAllBytesWritten () + { + IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000); + string url = "http://" + IPAddress.Loopback.ToString () + ":8000/test/"; + + using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (EchoRequestHandler))) { + responder.Start (); + + HttpWebRequest req; + Stream rs; + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "POST"; + req.ContentLength = 2; + rs = req.GetRequestStream (); + try { + rs.Close (); + Assert.Fail ("#A1"); + } catch (WebException ex) { + // The request was aborted: The request was canceled + Assert.AreEqual (typeof (WebException), ex.GetType (), "#A2"); + Assert.IsNotNull (ex.Message, "#A3"); + Assert.IsNull (ex.Response, "#A4"); + Assert.AreEqual (WebExceptionStatus.RequestCanceled, ex.Status, "#A5"); + + // Cannot close stream until all bytes are written + Exception inner = ex.InnerException; + Assert.IsNotNull (inner, "#A6"); + Assert.AreEqual (typeof (IOException), inner.GetType (), "#A7"); + Assert.IsNull (inner.InnerException, "#A8"); + Assert.IsNotNull (inner.Message, "#A9"); + } + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "POST"; + req.ContentLength = 2; + rs = req.GetRequestStream (); + rs.WriteByte (0x0d); + try { + rs.Close (); + Assert.Fail ("#B1"); + } catch (WebException ex) { + // The request was aborted: The request was canceled + Assert.AreEqual (typeof (WebException), ex.GetType (), "#B2"); + Assert.IsNotNull (ex.Message, "#B3"); + Assert.IsNull (ex.Response, "#B4"); + Assert.AreEqual (WebExceptionStatus.RequestCanceled, ex.Status, "#B5"); + + // Cannot close stream until all bytes are written + Exception inner = ex.InnerException; + Assert.IsNotNull (inner, "#B6"); + Assert.AreEqual (typeof (IOException), inner.GetType (), "#B7"); + Assert.IsNull (inner.InnerException, "#B8"); + Assert.IsNotNull (inner.Message, "#B9"); + } + + req = (HttpWebRequest) WebRequest.Create (url); + req.Method = "POST"; + req.ContentLength = 2; + rs = req.GetRequestStream (); + rs.WriteByte (0x0d); + rs.WriteByte (0x0d); + rs.Close (); + } + } + + [Test] // bug #510642 + [Category ("NotWorking")] + public void GetRequestStream_Write_Overflow () + { + IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8001); + string url = "http://" + IPAddress.Loopback.ToString () + ":8001/test/"; + + using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (EchoRequestHandler))) { + responder.Start (); + + HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url); + req.ProtocolVersion = HttpVersion.Version11; + req.Method = "POST"; + req.Timeout = 200; + req.ReadWriteTimeout = 100; + req.ContentLength = 2; + + Stream rs = req.GetRequestStream (); + + byte [] buffer = new byte [] { 0x2a, 0x2c, 0x1d }; + try { + rs.Write (buffer, 0, 3); + Assert.Fail ("#1"); + } catch (ProtocolViolationException ex) { + // Bytes to be written to the stream exceed + // Content-Length bytes size specified + Assert.IsNull (ex.InnerException, "#2"); + Assert.IsNotNull (ex.Message, "#3"); + } finally { + req.Abort (); + } } } |