diff options
author | Sebastien Pouliot <sebastien@ximian.com> | 2006-04-21 16:47:45 +0400 |
---|---|---|
committer | Sebastien Pouliot <sebastien@ximian.com> | 2006-04-21 16:47:45 +0400 |
commit | a95c6cd076893438ec9ae527739c90bf487f8073 (patch) | |
tree | e79c7930a3ff7e9628deea3a07de2cd67d09ae81 | |
parent | 325ceb697aec1cbcdc2c875c7e8402b1c7f2898a (diff) |
2006-04-21 Sebastien Pouliot <sebastien@ximian.com>
* poll.cs: New test tool contributed by Simon Brys for bug #78085.
It's a good test for the abbreviated handshake.
* Makefile: Build/clean for poll.exe
svn path=/trunk/mcs/; revision=59744
-rw-r--r-- | mcs/class/Mono.Security/Test/tools/poll/ChangeLog | 5 | ||||
-rw-r--r-- | mcs/class/Mono.Security/Test/tools/poll/Makefile | 27 | ||||
-rw-r--r-- | mcs/class/Mono.Security/Test/tools/poll/poll.cs | 113 |
3 files changed, 145 insertions, 0 deletions
diff --git a/mcs/class/Mono.Security/Test/tools/poll/ChangeLog b/mcs/class/Mono.Security/Test/tools/poll/ChangeLog new file mode 100644 index 00000000000..507f65ba5cb --- /dev/null +++ b/mcs/class/Mono.Security/Test/tools/poll/ChangeLog @@ -0,0 +1,5 @@ +2006-04-21 Sebastien Pouliot <sebastien@ximian.com> + + * poll.cs: New test tool contributed by Simon Brys for bug #78085. + It's a good test for the abbreviated handshake. + * Makefile: Build/clean for poll.exe diff --git a/mcs/class/Mono.Security/Test/tools/poll/Makefile b/mcs/class/Mono.Security/Test/tools/poll/Makefile new file mode 100644 index 00000000000..02327488d37 --- /dev/null +++ b/mcs/class/Mono.Security/Test/tools/poll/Makefile @@ -0,0 +1,27 @@ +thisdir = class/Mono.Security/Test/tools/poll +SUBDIRS = +include ../../../../../build/rules.make + +LOCAL_MCS_FLAGS = /r:System.dll + +all-local install-local uninstall-local: + +test-local: + +# ??? What do we run here? + +run-test-local: + +clean-local: + rm -f *.exe *.pdb *.mdb + +sources = poll.cs + +DISTFILES = $(sources) + +dist-local: dist-default + +all: poll.exe + +poll.exe: poll.cs + $(CSCOMPILE) /target:exe /out:$@ $^ diff --git a/mcs/class/Mono.Security/Test/tools/poll/poll.cs b/mcs/class/Mono.Security/Test/tools/poll/poll.cs new file mode 100644 index 00000000000..9ed4f39a646 --- /dev/null +++ b/mcs/class/Mono.Security/Test/tools/poll/poll.cs @@ -0,0 +1,113 @@ +// Adapted from bug #78085 by Simon Brys + +using System; +using System.Collections; +using System.IO; +using System.Net; +using System.Security.Cryptography.X509Certificates; +using System.Threading; + +class Test { + + public static void Main (string[] args) + { + new Poller (args).PollingLoop (); + } +} + +class Poller : ICertificatePolicy { + + private const int DEFAULTPOLLRATE = 5*1000; + + private int _pollRate; + private ArrayList _polledObjects; + + public Poller (string[] args) + { + ServicePointManager.CertificatePolicy = this; + + _pollRate = DEFAULTPOLLRATE; + + _polledObjects = new ArrayList (); + if (args.Length > 0) { + // poll from user supplied list of web sites + for (int i = 0; i < args.Length; i++) { + + if (args [i].StartsWith ("--") && (i < args.Length - 1)) { + switch (args [i]) { + case "--rate": + _pollRate = Convert.ToInt32 (args [++i]); + break; + } + } else { + _polledObjects.Add (new PolledObject (args [i])); + } + } + } else { + // default sites to poll + _polledObjects.Add (new PolledObject ("https://www.google.com/")); + _polledObjects.Add (new PolledObject ("https://www.yahoo.com/")); + _polledObjects.Add (new PolledObject ("https://www.verisign.com/")); + _polledObjects.Add (new PolledObject ("https://www.thawte.com/")); + } + } + + public bool CheckValidationResult (ServicePoint servicePoint, X509Certificate certificate, + WebRequest webRequest, int certificateProblem) + { + return true; + } + + public void PollingLoop () + { + while (true) { + foreach (PolledObject polledObject in _polledObjects) { + polledObject.Poll (); + } + + Console.WriteLine ("Waiting {0} ms...", _pollRate); + Thread.Sleep (_pollRate); + } + } +} + +class PolledObject { + + private const int MAXRESULTLENGTH = 20; + private string _url; + + public PolledObject (string url) + { + _url = url; + } + + public void Poll () + { + try { + Uri uri = new Uri (_url); + HttpWebRequest httpWebRequest = (HttpWebRequest) WebRequest.Create (uri); + + WebResponse httpWebResponse = httpWebRequest.GetResponse (); + Stream responseStream = httpWebResponse.GetResponseStream (); + StreamReader responseStreamReader = new StreamReader (responseStream); + string response = responseStreamReader.ReadLine (); + responseStreamReader.Close (); + responseStream.Close (); + httpWebResponse.Close (); + + Console.WriteLine ("Response for {0}: {1}", _url, + response.Substring (0, response.Length > MAXRESULTLENGTH ? MAXRESULTLENGTH : response.Length)); + } + catch (WebException e) { + Console.WriteLine ("*** WebException raised in Poll() for {0}!", _url); + Console.WriteLine ("\tSource: {0}", e.Source); + Console.WriteLine ("\tMessage: {0}", e.Message); + Console.WriteLine ("\tStatus: {0}", e.Status); + } + catch (Exception e) { + Console.WriteLine ("*** Exception raised in Poll() for {0}!", _url); + Console.WriteLine ("\tSource: {0}", e.Source); + Console.WriteLine ("\tMessage: {0}", e.Message); + } + } +} |