shekharpro / mb-unit

Automatically exported from code.google.com/p/mb-unit
0 stars 0 forks source link

Prefilter test log messages to ensure non-printable characters are stripped and conformant XML can be produced. #411

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Compile assembly with code provided below.
2. Run it with Gallio.Echo with report-type HTML

What is the expected output? What do you see instead?

-------------------------------------
C:> Gallio.Echo.exe TestAssembly.dll /report-type:html

Gallio Echo - Version 3.0.6 build 749
Get the latest version at http://www.gallio.org/

Start time: 12:35 PM
Verifying assembly names.
Initializing the runtime and loading plugins.
Initializing the test runner.
Running the tests.
Generating reports.
Disposing the test runner.
Stop time: 12:35 PM (Total execution time: 5.893 seconds)
Error: A fatal exception occurred.
System.Xml.XmlException: '.', hexadecimal value 0x00, is an invalid
character. Line 5, position 17.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
   at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args)
   at System.Xml.XmlTextReaderImpl.ThrowInvalidChar(Int32 pos, Char invChar)
   at System.Xml.XmlTextReaderImpl.ParseCDataOrComment(XmlNodeType type,
Int32& outStartPos, Int32& outEndPos)
   at System.Xml.XmlTextReaderImpl.ParseCDataOrComment(XmlNodeType type)
   at System.Xml.XmlTextReaderImpl.ParseElementContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XPath.XPathDocument.LoadFromReader(XmlReader reader,
XmlSpace space)
   at System.Xml.XPath.XPathDocument..ctor(XmlReader reader, XmlSpace space)
   at System.Xml.XPath.XPathDocument..ctor(XmlReader reader)
   at
Gallio.Reports.XsltReportFormatter.SerializeReportToXPathDocument(IReportWriter
reportWriter, AttachmentContentDisposition attachmentContentDisposition) in
c:\RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio.Reports\XsltReportFormatter.cs:line 225
   at Gallio.Reports.XsltReportFormatter.ApplyTransform(IReportWriter
reportWriter, AttachmentContentDisposition attachmentContentDisposition,
ReportFormatterOptions options) in c:\RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio.Reports\XsltReportFormatter.cs:line 146
   at Gallio.Reports.XsltReportFormatter.Format(IReportWriter reportWriter,
ReportFormatterOptions options, IProgressMonitor progressMonitor) in
c:\RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio.Reports\XsltReportFormatter.cs:line 107
   at Gallio.Runner.Reports.DefaultReportManager.Format(IReportWriter
reportWriter, String formatterName, ReportFormatterOptions
formatterOptions, IProgressMonitor progressMonitor) in
c:\RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio\Runner\Reports\DefaultReportManager.cs:line 66
   at Gallio.Runner.TestLauncherResult.GenerateReports(String
reportDirectory, String reportName, IList`1 reportFormats,
ReportFormatterOptions reportFormatOptions, IReportManager reportManager,
IProgressMonitor progressMonitor) in c:\RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio\Runner\TestLauncherResult.cs:line 164
   at
Gallio.Runner.TestLauncher.<>c__DisplayClass4.<GenerateReports>b__3(IProgressMon
itor
progressMonitor) in c:\RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio\Runner\TestLauncher.cs:line 630
   at
Gallio.Runner.TestLauncher.<>c__DisplayClass11.<RunWithProgress>b__10(IProgressM
onitor
progressMonitor) in c:\RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio\Runner\TestLauncher.cs:line 805
   at
Gallio.Runtime.ProgressMonitoring.BaseProgressMonitorProvider.Run(TaskWithProgre
ss
task) in c:\RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio\Runtime\ProgressMonitoring\BaseProgressMonitorProvider
.cs:line
34
   at Gallio.Runner.TestLauncher.RunWithProgress(TaskWithProgress task) in
c:\RelEng\Projects\MbUnitv3\Work\src\Gallio\Gallio\Runner\TestLauncher.cs:line
788
   at Gallio.Runner.TestLauncher.GenerateReports(TestLauncherResult result,
IReportManager reportManager) in c:\RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio\Runner\TestLauncher.cs:line 628
   at Gallio.Runner.TestLauncher.RunWithInitializedRunner(ITestRunner
runner, IReportManager reportManager) in c:\RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio\Runner\TestLauncher.cs:line 586
   at Gallio.Runner.TestLauncher.RunWithRuntime() in
c:\RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio\Runner\TestLauncher.cs:line 545
   at Gallio.Runner.TestLauncher.Run() in c:\RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio\Runner\TestLauncher.cs:line 491
   at Gallio.Echo.EchoProgram.RunTests(ILogger logger)
   at Gallio.Echo.EchoProgram.RunImpl(String[] args)
   at Gallio.Runtime.ConsoleSupport.ConsoleProgram`1.Run(IRichConsole
console, String[] args) in c:\
RelEng\Projects\MbUnit
v3\Work\src\Gallio\Gallio\Runtime\ConsoleSupport\ConsoleProgram.cs:line 187
-------------------------------------

The string that it was supposed to put into the report looks like this:

<?xml version="1.0"?>
<TestSomething xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ID>abc</ID>
  <Address>10.11.12.13</Address>
</TestSomething>

The above string was take from Gallio.Icarus's report view. 

What version of the product are you using? On what operating system?

Gallio Echo - Version 3.0.6 build 749

Windows XP SP3

Please provide any additional information below.

It only throw this when you create an report (I tested only with HTML type)
The test works fine in Gallio.Icarus.

The code to reproduce the error is as follows:

namespace CheckSerialization
{
    using System.Diagnostics;
    using System.IO;
    using System.Text;
    using System.Xml.Serialization;
    using NUnit.Framework;

    [TestFixture]
    public class BugReportTests
    {
        [Test]
        public void TestBugInGallio()
        {
            var obj = new TestSomething() { ID = "abc", Address =
"10.11.12.13" };

            using (MemoryStream stream = new MemoryStream())
            {
                XmlSerializer serializer = new
XmlSerializer(typeof(TestSomething));
                serializer.Serialize(stream, obj);
                var pkt = Encoding.UTF8.GetString(stream.GetBuffer());

                Debug.Write(pkt);
            }
        }
    }

    [Serializable]
    public class TestSomething
    {
        public string ID { get; set; }
        public string Address { get; set; }
    }
}

Original issue reported on code.google.com by fgret...@gmail.com on 26 Mar 2009 at 10:55

GoogleCodeExporter commented 8 years ago

Original comment by fgret...@gmail.com on 26 Mar 2009 at 10:55

GoogleCodeExporter commented 8 years ago

Original comment by fgret...@gmail.com on 26 Mar 2009 at 10:56

GoogleCodeExporter commented 8 years ago
Did this work pre-v3.0.6?

I think the issue is that the XML serialized stream contains a BOM.  This is 
getting
pulled into the string and is copied into the report.  However, a BOM should not
appear in the middle of a document.

What surprises me is that I have CheckCharacters = false in the affected code 
so I
wouldn't expect it to throw even if a BOM appeared in there.  I guess it's just 
time
I started performing early pre-filtering of report content to ensure that 
characters
not valid in XML are stripped or replaced early.

Original comment by jeff.br...@gmail.com on 27 Mar 2009 at 2:05

GoogleCodeExporter commented 8 years ago
Here's the actual string in "pkt".  Not a BOM but a whole mess of null padding!

"<?xml version=\"1.0\"?>\r\n<TestSomething
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n  <ID>abc</ID>\r\n 
<Address>10.11.12.13</Address>\r\n</TestSomething>\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"

You probably want to be using ToArray() instead of GetBuffer().

Original comment by jeff.br...@gmail.com on 30 Mar 2009 at 11:22

GoogleCodeExporter commented 8 years ago
Alternately use the variant of Encoding.UTF8.GetString() that takes a buffer, 
start
position and count to extract just the part of the MEmoryStream that was 
written to.

Or even better, tell the XmlSerializer to writer to an XmlWriter backed by a
StringWriter.

However, I still intend to provide a workaround for this problem in Gallio so at
least it doesn't crash.

Original comment by jeff.br...@gmail.com on 30 Mar 2009 at 11:28

GoogleCodeExporter commented 8 years ago
Ahh, yes, the GetBuffer() slipped by me. I will notify the author of the unit 
test
and suggest the fix.  

My original intent was to help strengthen Gallio so that it did not crash, but
instead show the unit test author that his was doing something very silly. ;-)  
The
fact that Gallio crashed caused our CI builds to fail, but the output did not 
show
which test was the culprit.  Thanks.

Original comment by fgret...@gmail.com on 30 Mar 2009 at 12:31

GoogleCodeExporter commented 8 years ago
I'm going to hold off on adding the workaround until v3.0.7.  Basically we will 
just
need to prefilter the messages to ensure that the user doesn't try to write 
crazy
binary content to the log.

Original comment by jeff.br...@gmail.com on 31 Mar 2009 at 3:55

GoogleCodeExporter commented 8 years ago

Original comment by jeff.br...@gmail.com on 28 Apr 2009 at 7:24

GoogleCodeExporter commented 8 years ago

Original comment by jeff.br...@gmail.com on 29 Jun 2009 at 8:33

GoogleCodeExporter commented 8 years ago
Issue 465 has been merged into this issue.

Original comment by jeff.br...@gmail.com on 18 Jul 2009 at 5:12

GoogleCodeExporter commented 8 years ago
Fixed in v3.1 by normalizing messages 

Original comment by jeff.br...@gmail.com on 19 Jul 2009 at 12:59