public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "HTTP response valid", Status = TestResult.INCONCLUSIVE }; try { var c = new WebClient(); byte[] data = c.DownloadData(o.Url + RelativeUrl); if (HttpValidationTests.IsValidJson(c.ResponseHeaders) && HttpValidationTests.IsValidCharsetUtf8(c.ResponseHeaders)) res.Status = TestResult.OK; else { res.Status = TestResult.FAIL; res.ExtraInformation = "No response header Content-Type. Invalid HTTP"; } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return res; }
public TestResultBase Test(Options o) { var p = new Uri(o.Url); var res = new GenericTestResult { ShortDescription = "TCP connection port " + p.Port, Status = TestResult.OK }; try { var client = new TcpClient(); client.Connect(p.DnsSafeHost, p.Port); res.Status = TestResult.OK; client.Close(); } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return res; }
public GenericTestResult RequestVerificationCode(string emailAddress) { GenericTestResult httpResponse = new GenericTestResult(); httpResponse.Date = DateTime.Now; int statusCode = (int)HttpStatusCode.OK; httpResponse.Operation = "Client request for a verifaction code."; if (!GenericHelpers.IsEmailAddressValid(emailAddress)) { httpResponse.Message = "Illegal email address: " + emailAddress; } else { bool test = SessionHelpers.RequestVerificationCode(emailAddress); if (!test) { statusCode = (int)HttpStatusCode.InternalServerError; httpResponse.Message = "Something bad happened..."; } else { httpResponse.Message = "Ok"; } httpResponse.BoolResult = test; } this.HttpContext.Response.StatusCode = statusCode; httpResponse.StatusCode = statusCode; return(httpResponse); }
private static void RunTest(Options o, string subTest, Action <string> logger, ITest test, int i) { TestResultBase result = null; try { result = test.Test(o); result.StepNr = i; result.SubTest = subTest; } catch (Exception ex) { if (result == null) { result = new GenericTestResult(); } result.StepNr = i; result.SubTest = subTest; result.Status = TestResult.FAIL; result.CauseOfFailure = ex.Message; result.ExtraInformation = ex.StackTrace; } if (logger != null) { logger(result.ToString()); } }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = string.Format("Calling {0} with {1} credentials", RelativeUrl, UseCredentials == AuthenticationMode.UseInvalidCredentials ? "invalid" : "no"), Status = TestResult.INCONCLUSIVE }; try { WebClient c = SetupWebClient(o, UseCredentials); string data = Encoding.UTF8.GetString(c.DownloadData(o.Url + RelativeUrl)); res.Status = TestResult.FAIL; res.CauseOfFailure = "HTTP OK where it should be 401."; } catch (WebException wex) { var response = (HttpWebResponse)wex.Response; if (response.StatusCode == HttpStatusCode.Unauthorized) { res.Status = TestResult.OK; res.ExtraInformation = "Ok - received " + response.StatusCode + " (expected behaviour)"; } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return(res); }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "HTTP response valid", Status = TestResult.INCONCLUSIVE }; try { var c = new WebClient(); byte[] data = c.DownloadData(o.Url + RelativeUrl); if (HttpValidationTests.IsValidJson(c.ResponseHeaders) && HttpValidationTests.IsValidCharsetUtf8(c.ResponseHeaders)) { res.Status = TestResult.OK; } else { res.Status = TestResult.FAIL; res.ExtraInformation = "No response header Content-Type. Invalid HTTP"; } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return(res); }
public TestResultBase Test(Options o) { var p = new Uri(o.Url); var res = new GenericTestResult { ShortDescription = "TCP connection port " + p.Port, Status = TestResult.OK }; try { var client = new TcpClient(); client.Connect(p.DnsSafeHost, p.Port); res.Status = TestResult.OK; client.Close(); } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return(res); }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "Sanity light check", Status = TestResult.INCONCLUSIVE }; try { WebClientEx webClient = SetupWebClient(o); string responseData = Encoding.UTF8.GetString(webClient.DownloadData(o.Url + RelativeUrl)); if (responseData == "[]" || webClient.StatusCode == HttpStatusCode.NoContent) { res.Status = TestResult.INCONCLUSIVE; res.ExtraInformation = "NO DATA at " + RelativeUrl; return res; } var responseObj = ServiceStack.Text.JsonSerializer.DeserializeFromString(responseData, TypeToDeserialize); // check if response is ok according to the handler res.Status = CheckValidDataInsideFunctionHandler(responseObj) ? TestResult.OK : TestResult.FAIL; } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } finally { res.ExtraInformation += " Url: " + RelativeUrl; } return res; }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = string.Format("Calling {0} with {1} credentials", RelativeUrl, UseCredentials == AuthenticationMode.UseInvalidCredentials ? "invalid" : "no"), Status = TestResult.INCONCLUSIVE }; try { WebClient c = SetupWebClient(o, UseCredentials); string data = Encoding.UTF8.GetString(c.DownloadData(o.Url + RelativeUrl)); res.Status = TestResult.FAIL; res.CauseOfFailure = "HTTP OK where it should be 401."; } catch (WebException wex) { var response = (HttpWebResponse) wex.Response; if (response.StatusCode == HttpStatusCode.Unauthorized) { res.Status = TestResult.OK; res.ExtraInformation = "Ok - received " + response.StatusCode + " (expected behaviour)"; } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return res; }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "Sanity light check", Status = TestResult.INCONCLUSIVE }; try { WebClientEx webClient = SetupWebClient(o); string responseData = Encoding.UTF8.GetString(webClient.DownloadData(o.Url + RelativeUrl)); if (responseData == "[]" || webClient.StatusCode == HttpStatusCode.NoContent) { res.Status = TestResult.INCONCLUSIVE; res.ExtraInformation = "NO DATA at " + RelativeUrl; return(res); } var responseObj = ServiceStack.Text.JsonSerializer.DeserializeFromString(responseData, TypeToDeserialize); // check if response is ok according to the handler res.Status = CheckValidDataInsideFunctionHandler(responseObj) ? TestResult.OK : TestResult.FAIL; } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } finally { res.ExtraInformation += " Url: " + RelativeUrl; } return(res); }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "Check completeness response", Status = TestResult.INCONCLUSIVE }; try { var c = SetupWebClient(o); if (OnSetupWebClient != null) OnSetupWebClient(c); var watch = new Stopwatch(); watch.Start(); string data = Encoding.UTF8.GetString(c.DownloadData(o.Url + RelativeUrl)); if (data == "[]" || c.StatusCode == HttpStatusCode.NoContent) { res.Status = TestResultWhenNoData.HasValue ? TestResultWhenNoData.Value : TestResult.INCONCLUSIVE; res.ExtraInformation = "NO DATA at " + RelativeUrl; return res; } watch.Stop(); ResponseData = data; RequestDuration = watch.ElapsedMilliseconds; if (HttpValidationTests.IsValidJson(c.ResponseHeaders) && HttpValidationTests.IsValidCharsetUtf8(c.ResponseHeaders)) { if (FieldsThatShouldBePresent.All(data.Contains)) res.Status = TestResult.OK; else { res.Status = TestResult.FAIL; res.ExtraInformation = "Response DTO did not contain all the required fields"; } } else { res.Status = TestResult.FAIL; res.ExtraInformation = "No response header Content-Type. Invalid HTTP"; } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } finally { res.ExtraInformation += " Url: " + RelativeUrl; } return res; }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "Calling HTTP (no SSL)", Status = TestResult.INCONCLUSIVE }; try { WebClient c = SetupWebClient(o); string data = Encoding.UTF8.GetString(c.DownloadData((o.Url + RelativeUrl).Replace("https", "http"))); if (c.ResponseHeaders["Location"] != null && c.ResponseHeaders["Location"].Contains("https")) { res.Status = TestResult.OK; res.ExtraInformation = "Using redirect"; } if (HttpValidationTests.IsValidJson(c.ResponseHeaders) && HttpValidationTests.IsValidCharsetUtf8(c.ResponseHeaders)) { if (data.Contains("generation_time") && data.Contains("ref_position_lon") && data.Contains("ref_position_lat") && data.Contains("speed") && data.Contains("heading") && data.Contains("provider_id") && data.Contains("user_id_anonymous")) { res.Status = TestResult.FAIL; res.ExtraInformation = "Received http 200 ok with all data fields present."; } else { res.Status = TestResult.FAIL; res.ExtraInformation = "Received http 200 ok, but required data fields were not present."; } } else { res.Status = TestResult.OK; res.ExtraInformation = "No json data received. "; } } catch (WebException wex) { var response = (HttpWebResponse)wex.Response; if (response.StatusCode != HttpStatusCode.Accepted && response.StatusCode != HttpStatusCode.NotModified) { res.Status = TestResult.OK; res.ExtraInformation = "Ok - received " + response.StatusCode + " (expected behaviour)"; } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return(res); }
public TestResultBase Test(Options o) { var testResult = new GenericTestResult { ShortDescription = "Performance (uptime) " + RelativeUrl, Status = TestResult.INCONCLUSIVE }; DateTime current = DateTime.Now; // to check if we elapsed total seconds. var results = new List <Tuple <long, TestResult> >(); //long lastMessageTime = 0; while (true) { var test = new CheckCompletenessResponseTest { RelativeUrl = RelativeUrl, //string.Format(RelativeUrl, lastMessageTime) FieldsThatShouldBePresent = FieldsThatShouldBePresent }; TestResultBase res = test.Test(o); results.Add(new Tuple <long, TestResult>(test.RequestDuration, res.Status)); //if (test.ResponseData != null) //{ // // now store the last updated time from the previous // string data = test.ResponseData; //} Thread.Sleep(IntervalTime); if (DateTime.Now.Subtract(current).TotalSeconds >= TestDuration) { break; } } IEnumerable <Tuple <long, TestResult> > succesCount = results.Where(t => t.Item2 == TestResult.OK).ToList(); var totalResultCount = results.Count; double percentageSuccess = totalResultCount == 0 ? 0 : succesCount.Count() / (double)totalResultCount; double avgTime = succesCount.Any() ? succesCount.Select(t => t.Item1).Average() : -1; testResult.ExtraInformation = Math.Round(avgTime, 0) + " ms average time"; if (percentageSuccess >= 0.95) { testResult.Status = TestResult.OK; } else { testResult.Status = TestResult.FAIL; testResult.CauseOfFailure = "Percentage success: " + Math.Round(percentageSuccess * 100) + "%"; } return(testResult); }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "Calling HTTP (no SSL)", Status = TestResult.INCONCLUSIVE }; try { WebClient c = SetupWebClient(o); string data = Encoding.UTF8.GetString(c.DownloadData((o.Url + RelativeUrl).Replace("https", "http"))); if (c.ResponseHeaders["Location"] != null && c.ResponseHeaders["Location"].Contains("https")) { res.Status = TestResult.OK; res.ExtraInformation = "Using redirect"; } if (HttpValidationTests.IsValidJson(c.ResponseHeaders) && HttpValidationTests.IsValidCharsetUtf8(c.ResponseHeaders)) { if (data.Contains("generation_time") && data.Contains("ref_position_lon") && data.Contains("ref_position_lat") && data.Contains("speed") && data.Contains("heading") && data.Contains("provider_id") && data.Contains("user_id_anonymous")) { res.Status = TestResult.FAIL; res.ExtraInformation = "Received http 200 ok with all data fields present."; } else { res.Status = TestResult.FAIL; res.ExtraInformation = "Received http 200 ok, but required data fields were not present."; } } else { res.Status = TestResult.OK; res.ExtraInformation = "No json data received. "; } } catch (WebException wex) { var response = (HttpWebResponse) wex.Response; if (response.StatusCode != HttpStatusCode.Accepted && response.StatusCode != HttpStatusCode.NotModified) { res.Status = TestResult.OK; res.ExtraInformation = "Ok - received " + response.StatusCode + " (expected behaviour)"; } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return res; }
public TestResultBase Test(Options o) { var testResult = new GenericTestResult { ShortDescription = "Performance (uptime) " + RelativeUrl, Status = TestResult.INCONCLUSIVE }; DateTime current = DateTime.Now; // to check if we elapsed total seconds. var results = new List<Tuple<long, TestResult>>(); //long lastMessageTime = 0; while (true) { var test = new CheckCompletenessResponseTest { RelativeUrl = RelativeUrl, //string.Format(RelativeUrl, lastMessageTime) FieldsThatShouldBePresent = FieldsThatShouldBePresent }; TestResultBase res = test.Test(o); results.Add(new Tuple<long, TestResult>(test.RequestDuration, res.Status)); //if (test.ResponseData != null) //{ // // now store the last updated time from the previous // string data = test.ResponseData; //} Thread.Sleep(IntervalTime); if (DateTime.Now.Subtract(current).TotalSeconds >= TestDuration) break; } IEnumerable<Tuple<long, TestResult>> succesCount = results.Where(t => t.Item2 == TestResult.OK).ToList(); var totalResultCount = results.Count; double percentageSuccess = totalResultCount == 0 ? 0 : succesCount.Count() / (double)totalResultCount; double avgTime = succesCount.Any() ? succesCount.Select(t => t.Item1).Average() : -1; testResult.ExtraInformation = Math.Round(avgTime, 0) + " ms average time"; if (percentageSuccess >= 0.95) { testResult.Status = TestResult.OK; } else { testResult.Status = TestResult.FAIL; testResult.CauseOfFailure = "Percentage success: " + Math.Round(percentageSuccess * 100) + "%"; } return testResult; }
public GenericTestResult TestPassword(string passwdToTest) { GenericTestResult httpResponse = new GenericTestResult(); httpResponse.Date = DateTime.Now; httpResponse.Tester = passwdToTest; int statusCode = (int)HttpStatusCode.OK; bool result = GenericHelpers.CheckPasswordStrength(passwdToTest); httpResponse.BoolResult = result; httpResponse.Message = "good password strength"; if (result == false) { httpResponse.Message = "bad password strength"; } this.HttpContext.Response.StatusCode = statusCode; httpResponse.StatusCode = statusCode; return(httpResponse); }
/// <summary> /// Test ICMP/ PING Connectivity /// </summary> /// <param name="o"></param> public TestResultBase Test(Options o) { string domain = new Uri(o.Url).DnsSafeHost; var res = new GenericTestResult { ShortDescription = "Ping", Status = TestResult.OK }; long rtt = 0; int nrSuccess = 0; try { for (int i = 0; i < NrOfPingChecks; i++) { PingReply pingReply = new Ping().Send(domain); if (pingReply.Status == IPStatus.Success) { long replyTimes = pingReply.RoundtripTime; // successd rtt += pingReply.RoundtripTime; nrSuccess++; } else { // fail res.Status = TestResult.FAIL; res.CauseOfFailure = pingReply.Status.ToString(); } } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } res.ExtraInformation = rtt != 0 ? (rtt / nrSuccess) + " ms avg RTT" : "0"; return(res); }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "HTTP service running", Status = TestResult.INCONCLUSIVE }; try { var c = new WebClient(); byte[] data = c.DownloadData(o.Url); if (c.ResponseHeaders.AllKeys.Contains("Content-Type")) { res.Status = TestResult.OK; } else { res.Status = TestResult.FAIL; res.ExtraInformation = "No response header Content-Type. Invalid HTTP"; } } catch (WebException wex) { var response = (HttpWebResponse)wex.Response; //if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.ServiceUnavailable || response.StatusCode == HttpStatusCode.NotFound) //{ res.Status = TestResult.OK; res.ExtraInformation = "Ok - HTTP confirmed. Received " + response.StatusCode; //} } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return(res); }
/// <summary> /// Test ICMP/ PING Connectivity /// </summary> /// <param name="o"></param> public TestResultBase Test(Options o) { string domain = new Uri(o.Url).DnsSafeHost; var res = new GenericTestResult { ShortDescription = "Ping", Status = TestResult.OK }; long rtt = 0; int nrSuccess = 0; try { for (int i = 0; i < NrOfPingChecks; i++) { PingReply pingReply = new Ping().Send(domain); if (pingReply.Status == IPStatus.Success) { long replyTimes = pingReply.RoundtripTime; // successd rtt += pingReply.RoundtripTime; nrSuccess++; } else { // fail res.Status = TestResult.FAIL; res.CauseOfFailure = pingReply.Status.ToString(); } } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } res.ExtraInformation = rtt != 0 ? (rtt/nrSuccess) + " ms avg RTT" : "0"; return res; }
public GenericTestResult CompareVerificationCode(string emailAddress, int verificationCodeToCheck) { GenericTestResult httpResponse = new GenericTestResult(); httpResponse.Date = DateTime.Now; int statusCode = (int)HttpStatusCode.OK; httpResponse.Operation = "Client request for a verification code check"; bool test = SessionHelpers.CompareVerificationCode(emailAddress, verificationCodeToCheck); if (!test) { httpResponse.Message = "The code is wrong."; } else { httpResponse.Message = "The code is ok."; } httpResponse.BoolResult = test; this.HttpContext.Response.StatusCode = statusCode; httpResponse.StatusCode = statusCode; return(httpResponse); }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "HTTP service running", Status = TestResult.INCONCLUSIVE }; try { var c = new WebClient(); byte[] data = c.DownloadData(o.Url); if (c.ResponseHeaders.AllKeys.Contains("Content-Type")) res.Status = TestResult.OK; else { res.Status = TestResult.FAIL; res.ExtraInformation = "No response header Content-Type. Invalid HTTP"; } } catch (WebException wex) { var response = (HttpWebResponse) wex.Response; //if (response.StatusCode == HttpStatusCode.Unauthorized || response.StatusCode == HttpStatusCode.ServiceUnavailable || response.StatusCode == HttpStatusCode.NotFound) //{ res.Status = TestResult.OK; res.ExtraInformation = "Ok - HTTP confirmed. Received " + response.StatusCode; //} } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return res; }
private static void RunTest(Options o, string subTest, Action<string> logger, ITest test, int i) { TestResultBase result = null; try { result = test.Test(o); result.StepNr = i; result.SubTest = subTest; } catch (Exception ex) { if (result == null) { result = new GenericTestResult(); } result.StepNr = i; result.SubTest = subTest; result.Status = TestResult.FAIL; result.CauseOfFailure = ex.Message; result.ExtraInformation = ex.StackTrace; } if (logger != null) logger(result.ToString()); }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "Validity server-side certificate", Status = TestResult.OK }; try { ServicePointManager.MaxServicePoints = 0; ServicePointManager.MaxServicePointIdleTime = 0; ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => { res.ExtraInformation = certificate.ToString(); // CHECK CERTIFICATE // If the certificate is a valid, signed certificate, return true. if (sslPolicyErrors == SslPolicyErrors.None) { res.Status = TestResult.OK; return(true); } // If there are errors in the certificate chain, look at each error to determine the cause. if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) != 0) { if (chain != null && chain.ChainStatus != null) { foreach ( X509ChainStatus status in chain.ChainStatus) { if ((certificate.Subject == certificate.Issuer) && (status.Status == X509ChainStatusFlags .UntrustedRoot)) { // Self-signed certificates with an untrusted root are valid. if (Options.AllowValidSelfSignedCertificates) { continue; } res.Status = TestResult.FAIL; res.CauseOfFailure = "Self signed certificate. While valid - is not approved."; return(false); } if (status.Status != X509ChainStatusFlags.NoError) { // If there are any other errors in the certificate chain, the certificate is invalid, // so the method returns false. res.Status = TestResult.FAIL; res.CauseOfFailure = status.StatusInformation; return(false); } } } // When processing reaches this line, the only errors in the certificate chain are // untrusted root errors for self-signed certificates. These certificates are valid // for default Exchange server installations, so return true. if (Options.AllowValidSelfSignedCertificates) { res.Status = TestResult.OK; return(true); } res.Status = TestResult.FAIL; res.CauseOfFailure = "Self signed certificate. While valid - is not approved."; return(false); } res.Status = TestResult.FAIL; res.CauseOfFailure = "Invalid certificate"; return(false); }; HttpWebRequest req = SetupWebRequest(o, o.Url + RelativeUrl); var response = (HttpWebResponse)req.GetResponse(); } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return(res); }
public TestResultBase Test(Options o) { var testResult = new GenericTestResult { ShortDescription = "Performance (uptime) " + RelativeUrl, Status = TestResult.INCONCLUSIVE }; DateTime current = DateTime.Now; // to check if we elapsed total seconds. var results = new List <Tuple <long, TestResult> >(); long lastMessageTime = 0; while (true) { var test = new CheckCompletenessResponseTest { RelativeUrl = string.Format("/fcd?last_message_time={0}", lastMessageTime), FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInFCD(), TestResultWhenNoData = TestResult.OK }; TestResultBase res = test.Test(o); results.Add(new Tuple <long, TestResult>(test.RequestDuration, res.Status)); if (test.ResponseData != null) { // now store the last updated time from the previous string data = test.ResponseData; // deserialize var fcdMsg = JsonConvert.DeserializeObject <FcdMessage>(data); if (lastMessageTime == fcdMsg.message_time) { GenerationTimeValid = false; } else { if (!GenerationTimeValid.HasValue) { GenerationTimeValid = true; } } lastMessageTime = fcdMsg.message_time; } else { GenerationTimeValid = false; } Thread.Sleep(IntervalTime); if (DateTime.Now.Subtract(current).TotalSeconds >= TestDuration) { break; } } IEnumerable <Tuple <long, TestResult> > succesCount = results.Where(t => t.Item2 == TestResult.OK); double percentageSuccess = succesCount.Count() / (double)results.Count; double avgTime = results.Select(t => t.Item1).Average(); testResult.ExtraInformation = Math.Round(avgTime, 0) + " ms average time"; if (percentageSuccess >= 0.95) { testResult.Status = TestResult.OK; } else { testResult.Status = TestResult.FAIL; testResult.CauseOfFailure = "Percentage success: " + Math.Round(percentageSuccess * 100, 0) + " %"; } return(testResult); }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "Check completeness response", Status = TestResult.INCONCLUSIVE }; try { var c = SetupWebClient(o); if (OnSetupWebClient != null) { OnSetupWebClient(c); } var watch = new Stopwatch(); watch.Start(); string data = Encoding.UTF8.GetString(c.DownloadData(o.Url + RelativeUrl)); if (data == "[]" || c.StatusCode == HttpStatusCode.NoContent) { res.Status = TestResultWhenNoData.HasValue ? TestResultWhenNoData.Value : TestResult.INCONCLUSIVE; res.ExtraInformation = "NO DATA at " + RelativeUrl; return(res); } watch.Stop(); ResponseData = data; RequestDuration = watch.ElapsedMilliseconds; if (HttpValidationTests.IsValidJson(c.ResponseHeaders) && HttpValidationTests.IsValidCharsetUtf8(c.ResponseHeaders)) { if (FieldsThatShouldBePresent.All(data.Contains)) { res.Status = TestResult.OK; } else { res.Status = TestResult.FAIL; res.ExtraInformation = "Response DTO did not contain all the required fields"; } } else { res.Status = TestResult.FAIL; res.ExtraInformation = "No response header Content-Type. Invalid HTTP"; } } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } finally { res.ExtraInformation += " Url: " + RelativeUrl; } return(res); }
public TestResultBase Test(Options o) { var testResult = new GenericTestResult { ShortDescription = "Performance (uptime) " + RelativeUrl, Status = TestResult.INCONCLUSIVE }; DateTime current = DateTime.Now; // to check if we elapsed total seconds. var results = new List<Tuple<long, TestResult>>(); long lastMessageTime = 0; while (true) { var test = new CheckCompletenessResponseTest { RelativeUrl = string.Format("/fcd?last_message_time={0}", lastMessageTime), FieldsThatShouldBePresent = FieldTester.FieldsThatShouldBePresentInFCD(), TestResultWhenNoData = TestResult.OK }; TestResultBase res = test.Test(o); results.Add(new Tuple<long, TestResult>(test.RequestDuration, res.Status)); if (test.ResponseData != null) { // now store the last updated time from the previous string data = test.ResponseData; // deserialize var fcdMsg = JsonConvert.DeserializeObject<FcdMessage>(data); if (lastMessageTime == fcdMsg.message_time) { GenerationTimeValid = false; } else { if (!GenerationTimeValid.HasValue) GenerationTimeValid = true; } lastMessageTime = fcdMsg.message_time; } else { GenerationTimeValid = false; } Thread.Sleep(IntervalTime); if (DateTime.Now.Subtract(current).TotalSeconds >= TestDuration) break; } IEnumerable<Tuple<long, TestResult>> succesCount = results.Where(t => t.Item2 == TestResult.OK); double percentageSuccess = succesCount.Count()/(double) results.Count; double avgTime = results.Select(t => t.Item1).Average(); testResult.ExtraInformation = Math.Round(avgTime, 0) + " ms average time"; if (percentageSuccess >= 0.95) { testResult.Status = TestResult.OK; } else { testResult.Status = TestResult.FAIL; testResult.CauseOfFailure = "Percentage success: " + Math.Round(percentageSuccess * 100, 0) + " %"; } return testResult; }
public TestResultBase Test(Options o) { var res = new GenericTestResult { ShortDescription = "Validity server-side certificate", Status = TestResult.OK }; try { ServicePointManager.MaxServicePoints = 0; ServicePointManager.MaxServicePointIdleTime = 0; ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => { res.ExtraInformation = certificate.ToString(); // CHECK CERTIFICATE // If the certificate is a valid, signed certificate, return true. if (sslPolicyErrors == SslPolicyErrors.None) { res.Status = TestResult.OK; return true; } // If there are errors in the certificate chain, look at each error to determine the cause. if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) != 0) { if (chain != null && chain.ChainStatus != null) { foreach ( X509ChainStatus status in chain.ChainStatus) { if ((certificate.Subject == certificate.Issuer) && (status.Status == X509ChainStatusFlags .UntrustedRoot)) { // Self-signed certificates with an untrusted root are valid. if (Options.AllowValidSelfSignedCertificates) continue; res.Status = TestResult.FAIL; res.CauseOfFailure = "Self signed certificate. While valid - is not approved."; return false; } if (status.Status != X509ChainStatusFlags.NoError) { // If there are any other errors in the certificate chain, the certificate is invalid, // so the method returns false. res.Status = TestResult.FAIL; res.CauseOfFailure = status.StatusInformation; return false; } } } // When processing reaches this line, the only errors in the certificate chain are // untrusted root errors for self-signed certificates. These certificates are valid // for default Exchange server installations, so return true. if (Options.AllowValidSelfSignedCertificates) { res.Status = TestResult.OK; return true; } res.Status = TestResult.FAIL; res.CauseOfFailure = "Self signed certificate. While valid - is not approved."; return false; } res.Status = TestResult.FAIL; res.CauseOfFailure = "Invalid certificate"; return false; }; HttpWebRequest req = SetupWebRequest(o, o.Url + RelativeUrl); var response = (HttpWebResponse) req.GetResponse(); } catch (Exception ex) { res.Status = TestResult.FAIL; res.CauseOfFailure = ex.Message; } return res; }