Author: spouliot
Date: 2005-04-07 08:00:34 -0400 (Thu, 07 Apr 2005)
New Revision: 42634

Added:
   trunk/mcs/class/Mono.Security/Test/tools/postecho/postmulti.cs
Modified:
   trunk/mcs/class/Mono.Security/Test/tools/postecho/ChangeLog
   trunk/mcs/class/Mono.Security/Test/tools/postecho/Makefile
   trunk/mcs/class/Mono.Security/Test/tools/postecho/README
Log:
2005-04-07  Sebastien Pouliot  <[EMAIL PROTECTED]> 

        * postmulti.cs: New. Async POST tests using HttpWebRequest.
        * Makefile: Build postmulti tool.
        * README: updated instructions with the new postmulti tool.



Modified: trunk/mcs/class/Mono.Security/Test/tools/postecho/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Security/Test/tools/postecho/ChangeLog 2005-04-07 
11:49:23 UTC (rev 42633)
+++ trunk/mcs/class/Mono.Security/Test/tools/postecho/ChangeLog 2005-04-07 
12:00:34 UTC (rev 42634)
@@ -1,3 +1,9 @@
+2005-04-07  Sebastien Pouliot  <[EMAIL PROTECTED]> 
+
+       * postmulti.cs: New. Async POST tests using HttpWebRequest.
+       * Makefile: Build postmulti tool.
+       * README: updated instructions with the new postmulti tool.
+
 2005-04-06  Sebastien Pouliot  <[EMAIL PROTECTED]> 
  
        * postecho.cs: Added an ICertificatePolicy to ease testing with 

Modified: trunk/mcs/class/Mono.Security/Test/tools/postecho/Makefile
===================================================================
--- trunk/mcs/class/Mono.Security/Test/tools/postecho/Makefile  2005-04-07 
11:49:23 UTC (rev 42633)
+++ trunk/mcs/class/Mono.Security/Test/tools/postecho/Makefile  2005-04-07 
12:00:34 UTC (rev 42634)
@@ -15,13 +15,16 @@
 clean-local:
        rm -f *.exe *.mdb *.pdb
 
-sources = postecho.cs
+sources = postecho.cs postmulti.cs
 
 DISTFILES = $(sources)
 
 dist-local: dist-default
 
-all: postecho.exe
+all: postecho.exe postmulti.exe
 
-postecho.exe: $(sources)
-       $(CSCOMPILE) /target:exe /out:$@ $(sources)
+postecho.exe: postecho.cs
+       $(CSCOMPILE) /target:exe /out:$@ $^
+
+postmulti.exe: postmulti.cs
+       $(CSCOMPILE) /target:exe /out:$@ $^

Modified: trunk/mcs/class/Mono.Security/Test/tools/postecho/README
===================================================================
--- trunk/mcs/class/Mono.Security/Test/tools/postecho/README    2005-04-07 
11:49:23 UTC (rev 42633)
+++ trunk/mcs/class/Mono.Security/Test/tools/postecho/README    2005-04-07 
12:00:34 UTC (rev 42634)
@@ -8,6 +8,21 @@
 wise not result wise) if you test with the MS runtime.
 
 
+POSTMULTI
+
+To run the postmulti tool your web server(s) must have a script present to 
+return the TEST variable value to the tool.
+
+The tool use async HttpWebRequest|Response to send and receive a fixed (in
+source code, default is 1 megabytes) length buffer from all URLs specified 
+on the command line. 
+
+The WaitHandle class has a limit of 64 handles. Supplying more than 64 URLs
+on the command-line will result in a NotSupportedException exception.
+
+
+NOTES
+
 Available server-side scripts
 
 1.     sendback.asp

Added: trunk/mcs/class/Mono.Security/Test/tools/postecho/postmulti.cs
===================================================================
--- trunk/mcs/class/Mono.Security/Test/tools/postecho/postmulti.cs      
2005-04-07 11:49:23 UTC (rev 42633)
+++ trunk/mcs/class/Mono.Security/Test/tools/postecho/postmulti.cs      
2005-04-07 12:00:34 UTC (rev 42634)
@@ -0,0 +1,135 @@
+//
+// postmulti.cs: Multi-sessions TLS/SSL Test Program
+//     based on tlstest.cs, tlsmulti.cs and postecho.cs
+//
+// Author:
+//     Sebastien Pouliot  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2004-2005 Novell (http://www.novell.com)
+//
+
+using System;
+using System.Collections;
+using System.Globalization;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+using System.Reflection;
+using System.Security.Cryptography.X509Certificates;
+using System.Text;
+using System.Threading;
+
+using Mono.Security.Protocol.Tls;
+
+public class State {
+
+       static ArrayList handleList = new ArrayList ();
+
+       private int id;
+       private HttpWebRequest request;
+       private ManualResetEvent handle;
+
+       public State (int id, HttpWebRequest req)
+       {
+               this.id = id;
+               request = req;
+               handle = new ManualResetEvent (false);
+               handleList.Add (handle);
+       }
+
+       public int Id {
+               get { return id; }
+       }
+
+       public HttpWebRequest Request {
+               get { return request; }
+       }
+
+       public void Complete ()
+       {
+               handle.Set ();
+       }
+
+       static public void WaitAll ()
+       {
+               if (handleList.Count > 0) {
+                       WaitHandle[] handles = (WaitHandle[]) 
handleList.ToArray (typeof (WaitHandle));
+                       WaitHandle.WaitAll (handles);
+                       handleList.Clear ();
+               }
+       }
+}
+
+public class MultiTest {
+
+       public const int buffersize = 1024 * 1024;
+
+       static byte[] data = new byte [buffersize];
+
+       public static void Main (string[] args) 
+       {
+               ServicePointManager.CertificatePolicy = new 
TestCertificatePolicy ();
+
+               string postdata = "TEST=";
+               byte[] bytes = Encoding.Default.GetBytes (postdata);
+
+               // prepare test buffer
+               for (int i = 0; i < buffersize; i++)
+                       data[i] = 65;
+
+               int id = 1;
+               foreach (string url in args) {
+                       Console.WriteLine ("POST #{0} at {1}", id, url);
+                       HttpWebRequest req = (HttpWebRequest) WebRequest.Create 
(url);
+                       req.Method = "POST";
+                       req.ContentType = "application/x-www-form-urlencoded";
+                       req.ContentLength = 5 + data.Length;
+
+                       Stream output = req.GetRequestStream ();
+                       output.Write (bytes, 0, bytes.Length);
+                       output.Write (data, 0, data.Length);
+                       output.Close ();
+
+                       State s = new State (id++, req);
+                       req.BeginGetResponse (new AsyncCallback 
(ResponseCallback), s);
+               }
+
+               State.WaitAll ();
+       }
+
+       private static void ResponseCallback (IAsyncResult result)
+       {
+               State state = ((State) result.AsyncState);
+               HttpWebResponse response = (HttpWebResponse) 
state.Request.EndGetResponse (result);
+
+               Stream stream = response.GetResponseStream ();
+               StreamReader sr = new StreamReader (stream, Encoding.UTF8);
+               string received = sr.ReadToEnd ();
+
+               if (data.Length != received.Length) {
+                       Console.WriteLine ("ECHO #{0} - Invalid length {1}. 
Expected {2}", state.Id, received.Length, data.Length);
+               } else {
+                       bool ok = true;
+                       for (int i = 0; i < received.Length; i++) {
+                               if (received[i] != 'A') {
+                                       ok = false;
+                                       Console.WriteLine ("ECHO #{0} - Error 
at position #{1} - received '{2}'", state.Id, i, received[i]);
+                                       break;
+                               }
+                       }
+                       if (ok)
+                               Console.WriteLine ("ECHO #{0} - Result OK 
(length: {1})", state.Id, received.Length);
+               }
+
+               state.Complete ();
+       }
+
+       public class TestCertificatePolicy : ICertificatePolicy {
+
+               public bool CheckValidationResult (ServicePoint sp, 
X509Certificate certificate, WebRequest request, int error)
+               {
+                       // whatever the reason we do not stop the SSL connection
+                       return true;
+               }
+       }
+}

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to