public SslClient(IPAddress ipAddress, String targetHost, X509Certificate cert, X509Certificate [] ca, SslVerification verify, SslProtocols[] sslProtocols, bool expectedException) { // Initialize the Socket messageSent = MFUtilities.GetRandomSafeString(2000) + TERMINATOR; // Initialize the port that communication is using port = 11111; this.ipAddress = ipAddress; this.messageSent = "hello" + TERMINATOR; this.targetHost = targetHost; this.cert = cert; this.ca = ca; this.verify = verify; this.sslProtocols = sslProtocols; this.expectedException = expectedException; }
public MFTestResults LargeSendBuffer() { if (!IsLoopback) { return(MFTestResults.Skip); } result = MFTestResults.Pass; try { using (TestSerialPort serialPort = new TestSerialPort(Serial.COM1)) { serialPort.Handshake = Handshake.RequestToSend; serialPort.Open(); serialPort.AsyncRead = true; string start = MFUtilities.GetRandomSafeString(10000); byte[] buff = Encoding.UTF8.GetBytes(start); serialPort.Write(buff, 0, buff.Length); // wait for data to drain while (serialPort.AsyncResult.Length < start.Length && (serialPort.BytesToWrite > 0 || serialPort.BytesToRead > 0)) { Thread.Sleep(100); } if (serialPort.AsyncResult != start) { Log.Exception("Failed: " + serialPort.AsyncResult + " != " + start); result = MFTestResults.Fail; } // wait to make sure AsyncReader is closed; serialPort.AsyncRead = false; while (serialPort.IsAsyncReading) { Thread.Sleep(100); } } } catch (Exception ex) { result = MFTestResults.Fail; Log.Exception(ex.Message); } return(result); }
public MFTestResults Ssid() { int MAX_SSID_LENGTH = 31; char[] specialChars = { '~', '/', '`', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '-', '+', '=', '{', '[', '}', ']', '|', '\\', ':', ';', '"', '\'', }; char[] specialChars2 = { '<', ',', '>', '.', '?', '/' }; string[] testStrings = { " ", MFUtilities.GetRandomSafeString(1), MFUtilities.GetRandomSafeString(MAX_SSID_LENGTH), MFUtilities.GetRandomString(1), MFUtilities.GetRandomString(MAX_SSID_LENGTH), MFUtilities.GetRandomHighByteString(1), MFUtilities.GetRandomHighByteString(8), "?˜???", "??????", "0x0001fd94", new string(specialChars), new string(specialChars2), }; string[] invalidStrings = { MFUtilities.GetRandomSafeString(MAX_SSID_LENGTH + 1), MFUtilities.GetRandomString(MAX_SSID_LENGTH + 1), MFUtilities.GetRandomString(MAX_SSID_LENGTH + 1 + new Random().Next(100)), }; foreach (string testString in testStrings) { try { SetSsid(testString); // Verify. if (MFTestResults.Fail == VerifySsid(testString)) { return(MFTestResults.Fail); } } catch (Exception ex) { Log.Exception(ex.Message); return(MFTestResults.Fail); } } foreach (string invalidString in invalidStrings) { try { SetSsid(invalidString); Log.Comment("Setting ssid to " + invalidString + " succeeded. " + " Expected an exception to be thrown. Returning a failure."); return(MFTestResults.Fail); } catch (Exception ex) { Log.Comment("Test passed - A valid exception was thrown: " + ex.Message); } } SetSsid("SSID_1"); // Return test result. return(MFTestResults.Pass); }
public MFTestResults FunctionalChunkTests() { 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"; wr.KeepAlive = true; HttpTestServer server = new HttpTestServer("http", ref result) { RequestUri = wr.RequestUri, RequestHeaders = wr.Headers, ResponseString = MFUtilities.GetRandomSafeString(5000), }; try { // Setup server server.StartServer(); Log.Comment("Send UnChunked"); wr.SendChunked = false; HttpWebResponse response = (HttpWebResponse)wr.GetResponse(); HttpTests.PrintHeaders("Client", response.Headers); using (Stream responseStream = response.GetResponseStream()) { if (responseStream != null) { string page = HttpTests.ReadStream("Client", responseStream); if (page != server.ResponseString) { result = MFTestResults.Fail; Log.Exception("[Client] Send UnChunked - Corrupt Page!"); Log.Exception("[Client] Expected: " + server.ResponseString); Log.Exception("[Client] Received: " + page); } } else { result = MFTestResults.Fail; Log.Exception("[Client] Expected stream, but got null"); } } Log.Comment("Send Chunked"); wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpTestServer.s_CurrentPort.ToString() + "/"); wr.UserAgent = ".Net Micro Framwork Device/4.0"; wr.SendChunked = true; server.SendChunked = true; server.RequestHeaders = wr.Headers; response = (HttpWebResponse)wr.GetResponse(); HttpTests.PrintHeaders("Client", response.Headers); using (Stream responseStream = response.GetResponseStream()) { if (responseStream != null) { string page = HttpTests.ReadStream("Client", responseStream); if (page != server.ResponseString) { result = MFTestResults.Fail; Log.Exception("[Client] Send Chunked - Corrupt Page!"); Log.Exception("[Client] Expected: " + server.ResponseString); Log.Exception("[Client] Received: " + page); } } else { result = MFTestResults.Fail; Log.Exception("[Client] Expected stream, but got null"); } } } catch (Exception ex) { Log.Exception("[Client] Unexpected Exception", ex); result = MFTestResults.Fail; } finally { // Stop server server.StopServer(); } return(result); }