/// <summary>
        /// converts all data from the test resutls in to the Junit xml format and writes the xml file to disk.
        /// </summary>
        /// <param name="results"></param>
        public void CreateXmlFromRunResults(TestSuiteRunResults results)
        {
            _testSuites = new testsuites();

            testsuite ts = new testsuite
            {
                errors = results.NumErrors.ToString(),
                tests = results.NumTests.ToString(),
                failures = results.NumFailures.ToString(),
                name = results.SuiteName,
                package = ClassName
            };
            foreach (TestRunResults testRes in results.TestRuns)
            {
                testcase tc;
                if (testRes.TestType == TestType.LoadRunner.ToString())
                {
                    tc = CreateXmlFromLRRunResults(testRes);
                }
                else
                {
                    tc = CreateXmlFromUFTRunResults(testRes);
                }
                ts.AddTestCase(tc);
            }
            _testSuites.AddTestsuite(ts);

            if (File.Exists(XmlName))
                File.Delete(XmlName);

            using (Stream s = File.OpenWrite(XmlName))
            {
                _serializer.Serialize(s, _testSuites);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// converts all data from the test results in to the Junit xml format and writes the xml file to disk.
        /// </summary>
        /// <param name="results"></param>
        public bool CreateXmlFromRunResults(TestSuiteRunResults results, out string error)
        {
            error = string.Empty;

            _testSuites = new testsuites();

            testsuite uftts = new testsuite
            {
                errors   = IntToString(results.NumErrors),
                tests    = IntToString(results.NumTests),
                failures = IntToString(results.NumFailures),
                name     = results.SuiteName,
                package  = ClassName,
                time     = DoubleToString(results.TotalRunTime.TotalSeconds)
            };

            foreach (TestRunResults testRes in results.TestRuns)
            {
                if (testRes.TestType == TestType.LoadRunner.ToString())
                {
                    testsuite lrts = CreateXmlFromLRRunResults(testRes);
                    _testSuites.AddTestsuite(lrts);
                }
                else
                {
                    testcase ufttc = CreateXmlFromUFTRunResults(testRes);
                    uftts.AddTestCase(ufttc);
                }
            }
            if (uftts.testcase.Length > 0)
            {
                _testSuites.AddTestsuite(uftts);
            }

            try
            {
                if (File.Exists(XmlName))
                {
                    File.Delete(XmlName);
                }

                using (Stream s = File.OpenWrite(XmlName))
                {
                    _serializer.Serialize(s, _testSuites);
                }

                return(File.Exists(XmlName));
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// converts all data from the test results in to the Junit xml format and writes the xml file to disk.
        /// </summary>
        /// <param name="results"></param>
        public void CreateXmlFromRunResults(TestSuiteRunResults results)
        {
            _testSuites = new testsuites();

            testsuite uftts = new testsuite
            {
                errors   = results.NumErrors.ToString(),
                tests    = results.NumTests.ToString(),
                failures = results.NumFailures.ToString(),
                name     = results.SuiteName,
                package  = ClassName
            };

            foreach (TestRunResults testRes in results.TestRuns)
            {
                if (testRes.TestType == TestType.LoadRunner.ToString())
                {
                    testsuite lrts = CreateXmlFromLRRunResults(testRes);
                    _testSuites.AddTestsuite(lrts);
                }
                else
                {
                    testcase ufttc = CreateXmlFromUFTRunResults(testRes);
                    uftts.AddTestCase(ufttc);
                }
            }
            if (uftts.testcase.Length > 0)
            {
                _testSuites.AddTestsuite(uftts);
            }


            if (File.Exists(XmlName))
            {
                File.Delete(XmlName);
            }


            using (Stream s = File.OpenWrite(XmlName))
            {
                _serializer.Serialize(s, _testSuites);
            }
        }
Ejemplo n.º 4
0
        public JUnitXmlSerializer(PackageSource source, string time, string outputFile)
        {
            var testSuites = new testsuites();
            var testSuite  = new testsuite();

            testSuite.name     = string.Format("DevAudit {0} package source audit.", source.PackageManagerLabel);
            testSuite.package  = "org.ossindex.devaudit";
            testSuite.time     = time;
            testSuite.tests    = source.Vulnerabilities.Count.ToString();
            testSuite.failures = source.Vulnerabilities.Where(v => v.Value.Count > 0).Count().ToString();
            testSuite.testcase = new testcase[source.Vulnerabilities.Count];
            int tcount = 0;

            foreach (var pv in source.Vulnerabilities.OrderByDescending(sv => sv.Value.Count(v => v.PackageVersionIsInRange)))
            {
                IPackage package = pv.Key;
                List <IVulnerability> package_vulnerabilities = pv.Value;
                var tc = new testcase();
                tc.name       = package.Name;
                tc.classname  = package.Name;
                tc.assertions = "1";
                if (package_vulnerabilities.Count() == 0)
                {
                    continue;
                }
                else if (package_vulnerabilities.Count(v => v.PackageVersionIsInRange) == 0)
                {
                    continue;
                }
                else
                {
                    var matched_vulnerabilities       = package_vulnerabilities.Where(v => v.PackageVersionIsInRange).ToList();
                    int matched_vulnerabilities_count = matched_vulnerabilities.Count;
                    tc.failure = new failure[matched_vulnerabilities_count];
                    int c = 0;
                    foreach (var v in matched_vulnerabilities)
                    {
                        failure f = new failure();
                        f.message = "Package vulnerable";
                        VulnText.AppendFormat("--[{0}/{1}] ", (c + 1), matched_vulnerabilities_count);
                        VulnText.AppendFormat("{0} ", v.Title.Trim());
                        PrintAuditResultMultiLineField(2, "Description", v.Description.Trim().Replace("\n", "").Replace(". ", "." + Environment.NewLine));
                        VulnText.AppendFormat("{0}", string.Join(", ", v.Versions.ToArray()));
                        if (v.CVE != null && v.CVE.Count() > 0)
                        {
                            VulnText.AppendFormat("  --CVE(s): {0}", string.Join(", ", v.CVE.ToArray()));
                        }
                        if (!string.IsNullOrEmpty(v.Reporter))
                        {
                            VulnText.AppendFormat("  --Reporter: {0} ", v.Reporter.Trim());
                        }
                        if (!string.IsNullOrEmpty(v.CVSS.Score))
                        {
                            VulnText.AppendFormat("  --CVSS Score: {0}. Vector: {1}", v.CVSS.Score, v.CVSS.Vector);
                        }
                        if (v.Published != DateTime.MinValue)
                        {
                            VulnText.AppendFormat("  --Date published: {0}", v.Published.ToShortDateString());
                        }
                        if (!string.IsNullOrEmpty(v.Id))
                        {
                            VulnText.AppendFormat("  --Id: {0}", v.Id);
                        }
                        if (v.References != null && v.References.Count() > 0)
                        {
                            if (v.References.Count() == 1)
                            {
                                VulnText.AppendFormat("  --Reference: {0}", v.References[0]);
                            }
                            else
                            {
                                VulnText.AppendFormat("  --References:");
                                for (int i = 0; i < v.References.Count(); i++)
                                {
                                    VulnText.AppendFormat("    - {0}", v.References[i]);
                                }
                            }
                        }
                        if (!string.IsNullOrEmpty(v.DataSource.Name))
                        {
                            VulnText.AppendFormat("  --Provided by: {0}", v.DataSource.Name);
                        }
                        f.Text          = VulnText.ToString().Split(Environment.NewLine.ToCharArray());
                        tc.failure[c++] = f;
                        VulnText.Clear();
                    }
                }
                testSuite.testcase[tcount++] = tc;
            }
            testSuites.testsuite = new testsuite[] { testSuite };

            XmlSerializer xs = new XmlSerializer(typeof(testsuites));

            xs.Serialize(File.CreateText(outputFile), testSuites);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// converts all data from the test results in to the Junit xml format and writes the xml file to disk.
        /// </summary>
        /// <param name="results"></param>
        public void CreateXmlFromRunResults(TestSuiteRunResults results)
        {
            _testSuites = new testsuites();

            testsuite uftts = new testsuite
            {
                errors   = results.NumErrors.ToString(),
                tests    = results.NumTests.ToString(),
                failures = results.NumFailures.ToString(),
                name     = results.SuiteName,
                package  = ClassName
            };

            foreach (TestRunResults testRes in results.TestRuns)
            {
                if (testRes.TestType == TestType.LoadRunner.ToString())
                {
                    testsuite lrts = CreateXmlFromLRRunResults(testRes);
                    _testSuites.AddTestsuite(lrts);
                }
                else
                {
                    //Console.WriteLine("CreateXmlFromRunResults, UFT test");
                    testcase ufttc = CreateXmlFromUFTRunResults(testRes);
                    uftts.AddTestCase(ufttc);
                }
            }
            if (uftts.testcase.Length > 0)
            {
                //Console.WriteLine("CreateXmlFromRunResults, add test case to test suite");
                _testSuites.AddTestsuite(uftts);
            }
            else
            {
                //Console.WriteLine("CreateXmlFromRunResults, no uft test case to write");
            }

            if (File.Exists(XmlName))
            {
                //Console.WriteLine("CreateXmlFromRunResults, file exist - delete file");
                File.Delete(XmlName);
            }
            // else
            //{
            //Console.WriteLine("CreateXmlFromRunResults, file does not exist");
            // }

            using (Stream s = File.OpenWrite(XmlName))
            {
                //Console.WriteLine("CreateXmlFromRunResults, write test results to xml file");
                //Console.WriteLine("_testSuites: " + _testSuites.name + " tests: " + _testSuites.tests);
                //Console.WriteLine("_testSuites: " + _testSuites.ToString());
                _serializer.Serialize(s, _testSuites);
            }

            //Console.WriteLine("CreateXmlFromRunResults, XmlName: " + XmlName);

            /*if (File.Exists(XmlName))
             * {
             *  Console.WriteLine("CreateXmlFromRunResults, results file was created");
             * } else
             * {
             *  Console.WriteLine("CreateXmlFromRunResults, results file was not created");
             * }*/
        }