XMLDSIG transforms from .NET Core.
[mono.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Xml / XmlDsigExcC14NTransformTest.cs
1 //
2 // XmlDsigExcC14NTransformTest.cs - NUnit Test Cases for XmlDsigExcC14NTransform
3 //
4 // Author:
5 //  original:
6 //      Sebastien Pouliot <sebastien@ximian.com>
7 //      Aleksey Sanin (aleksey@aleksey.com)
8 //  this file:
9 //      Atsushi Enomoto <atsushi@ximian.com>
10 //
11 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
12 // (C) 2003 Aleksey Sanin (aleksey@aleksey.com)
13 // (C) 2004 Novell (http://www.novell.com)
14 //
15
16 //
17 // WARNING!!
18 //      This file is simply replaced C14N->ExcC14N, and then replaced expected
19 //      output XML. So, they are *not* from c14n specification.
20 //
21
22
23 using System;
24 using System.IO;
25 using System.Security.Cryptography.Xml;
26 using System.Text;
27 using System.Xml;
28
29 using NUnit.Framework;
30
31 namespace MonoTests.System.Security.Cryptography.Xml {
32
33         // Note: GetInnerXml is protected in XmlDsigExcC14NTransform making it
34         // difficult to test properly. This class "open it up" :-)
35         public class UnprotectedXmlDsigExcC14NTransform : XmlDsigExcC14NTransform {
36                 public UnprotectedXmlDsigExcC14NTransform ()
37                 {
38                 }
39
40                 public UnprotectedXmlDsigExcC14NTransform (bool includeComments)
41                         : base (includeComments)
42                 {
43                 }
44
45                 public UnprotectedXmlDsigExcC14NTransform (string inclusiveNamespacesPrefixList)
46                         : base (inclusiveNamespacesPrefixList)
47                 {
48                 }
49
50                 public UnprotectedXmlDsigExcC14NTransform (bool includeComments, string inclusiveNamespacesPrefixList)
51                         : base (includeComments, inclusiveNamespacesPrefixList)
52                 {
53                 }
54
55                 public XmlNodeList UnprotectedGetInnerXml () {
56                         return base.GetInnerXml ();
57                 }
58         }
59
60         [TestFixture]
61         public class XmlDsigExcC14NTransformTest {
62
63                 protected UnprotectedXmlDsigExcC14NTransform transform;
64
65                 [SetUp]
66                 protected void SetUp () 
67                 {
68                         transform = new UnprotectedXmlDsigExcC14NTransform ();
69                 }
70
71                 [TearDown]
72                 protected void CleanUp () 
73                 {
74                         try {
75                                 if (File.Exists ("doc.dtd"))
76                                         File.Delete ("doc.dtd");
77                                 if (File.Exists ("world.txt"))
78                                         File.Delete ("world.txt");
79                         }
80                         catch {}
81                 }
82
83                 [Test] // ctor ()
84                 public void Constructor1 ()
85                 {
86                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
87                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
88                         CheckProperties (transform);
89                 }
90
91                 [Test] // ctor (Boolean)
92                 public void Constructor2 ()
93                 {
94                         transform = new UnprotectedXmlDsigExcC14NTransform (true);
95                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
96                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
97                         CheckProperties (transform);
98
99                         transform = new UnprotectedXmlDsigExcC14NTransform (false);
100                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
101                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
102                         CheckProperties (transform);
103                 }
104
105                 [Test] // ctor (String)
106                 public void Constructor3 ()
107                 {
108                         transform = new UnprotectedXmlDsigExcC14NTransform (null);
109                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
110                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
111                         CheckProperties (transform);
112
113                         transform = new UnprotectedXmlDsigExcC14NTransform (string.Empty);
114                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
115                         Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
116                         CheckProperties (transform);
117
118                         transform = new UnprotectedXmlDsigExcC14NTransform ("#default xsd");
119                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
120                         Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
121                         CheckProperties (transform);
122                 }
123
124                 [Test] // ctor (Boolean, String)
125                 public void Constructor4 ()
126                 {
127                         transform = new UnprotectedXmlDsigExcC14NTransform (true, null);
128                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
129                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
130                         CheckProperties (transform);
131
132                         transform = new UnprotectedXmlDsigExcC14NTransform (true, string.Empty);
133                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
134                         Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
135                         CheckProperties (transform);
136
137                         transform = new UnprotectedXmlDsigExcC14NTransform (true, "#default xsd");
138                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#WithComments", transform.Algorithm, "Algorithm");
139                         Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
140                         CheckProperties (transform);
141
142                         transform = new UnprotectedXmlDsigExcC14NTransform (false, null);
143                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
144                         Assert.IsNull (transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
145                         CheckProperties (transform);
146
147                         transform = new UnprotectedXmlDsigExcC14NTransform (false, string.Empty);
148                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
149                         Assert.AreEqual (string.Empty, transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
150                         CheckProperties (transform);
151
152                         transform = new UnprotectedXmlDsigExcC14NTransform (false, "#default xsd");
153                         Assert.AreEqual ("http://www.w3.org/2001/10/xml-exc-c14n#", transform.Algorithm, "Algorithm");
154                         Assert.AreEqual ("#default xsd", transform.InclusiveNamespacesPrefixList, "InclusiveNamespacesPrefixList");
155                         CheckProperties (transform);
156                 }
157
158                 void CheckProperties (XmlDsigExcC14NTransform transform)
159                 {
160                         Type[] input = transform.InputTypes;
161                         Assert.IsTrue ((input.Length == 3), "Input #");
162                         // check presence of every supported input types
163                         bool istream = false;
164                         bool ixmldoc = false;
165                         bool ixmlnl = false;
166                         foreach (Type t in input) {
167                                 if (t.ToString () == "System.IO.Stream")
168                                         istream = true;
169                                 if (t.ToString () == "System.Xml.XmlDocument")
170                                         ixmldoc = true;
171                                 if (t.ToString () == "System.Xml.XmlNodeList")
172                                         ixmlnl = true;
173                         }
174                         Assert.IsTrue (istream, "Input Stream");
175                         Assert.IsTrue (ixmldoc, "Input XmlDocument");
176                         Assert.IsTrue (ixmlnl, "Input XmlNodeList");
177
178                         Type[] output = transform.OutputTypes;
179                         Assert.IsTrue ((output.Length == 1), "Output #");
180                         // check presence of every supported output types
181                         bool ostream = false;
182                         foreach (Type t in output) {
183                                 if (t.ToString () == "System.IO.Stream")
184                                         ostream = true;
185                         }
186                         Assert.IsTrue (ostream, "Output Stream");
187                 }
188
189                 [Test]
190                 public void Types ()
191                 {
192                         Type [] input = transform.InputTypes;
193                         input [0] = null;
194                         input [1] = null;
195                         input [2] = null;
196                         // property does not return a clone
197                         foreach (Type t in transform.InputTypes) {
198                                 Assert.IsNull (t);
199                         }
200                         // it's not a static array
201                         XmlDsigExcC14NTransform t2 = new XmlDsigExcC14NTransform ();
202                         foreach (Type t in t2.InputTypes) {
203                                 Assert.IsNotNull (t);
204                         }
205                 }
206
207                 [Test]
208                 public void GetInnerXml () 
209                 {
210                         XmlNodeList xnl = transform.UnprotectedGetInnerXml ();
211                         Assert.IsNull (xnl, "Default InnerXml");
212                 }
213
214                 private string Stream2String (Stream s) 
215                 {
216                         StringBuilder sb = new StringBuilder ();
217                         int b = s.ReadByte ();
218                         while (b != -1) {
219                                 sb.Append (Convert.ToChar (b));
220                                 b = s.ReadByte ();
221                         }
222                         return sb.ToString ();
223                 }
224
225                 static string xml = "<Test  attrib='at ' xmlns=\"http://www.go-mono.com/\" > \r\n &#xD; <Toto/> text &amp; </Test   >";
226                 // BAD for XmlDocument input (framework 1.0 result)
227                 static string c14xml1 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> \r\n \r <Toto></Toto> text &amp; </Test>";
228                 // GOOD for Stream input
229                 static string c14xml2 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> \n &#xD; <Toto></Toto> text &amp; </Test>";
230                 // GOOD for XmlDocument input. The difference is because once
231                 // xml string is loaded to XmlDocument, there is no difference
232                 // between \r and &#xD;, so every \r must be handled as &#xD;.
233                 static string c14xml3 = "<Test xmlns=\"http://www.go-mono.com/\" attrib=\"at \"> &#xD;\n &#xD; <Toto></Toto> text &amp; </Test>";
234
235                 private XmlDocument GetDoc () 
236                 {
237                         XmlDocument doc = new XmlDocument ();
238                         doc.PreserveWhitespace = true;
239                         doc.LoadXml (xml);
240                         return doc;
241                 }
242
243                 [Test]
244                 public void LoadInputAsXmlDocument () 
245                 {
246                         XmlDocument doc = GetDoc ();
247                         transform.LoadInput (doc);
248                         Stream s = (Stream) transform.GetOutput ();
249                         string output = Stream2String (s);
250                         Assert.AreEqual (c14xml3, output, "XmlDocument");
251                 }
252
253                 [Test]
254                 // see LoadInputAsXmlNodeList2 description
255                 public void LoadInputAsXmlNodeList () 
256                 {
257                         XmlDocument doc = GetDoc ();
258                         // Argument list just contains element Test.
259                         transform.LoadInput (doc.ChildNodes);
260                         Stream s = (Stream) transform.GetOutput ();
261                         string output = Stream2String (s);
262                         Assert.AreEqual ("<Test xmlns=\"http://www.go-mono.com/\"></Test>", output, "XmlChildNodes");
263                 }
264
265                 [Test]
266                 // MS has a bug that those namespace declaration nodes in
267                 // the node-set are written to output. Related spec section is:
268                 // http://www.w3.org/TR/2001/REC-xml-c14n-20010315#ProcessingModel
269                 public void LoadInputAsXmlNodeList2 () 
270                 {
271                         XmlDocument doc = GetDoc ();
272                         transform.LoadInput (doc.SelectNodes ("//*"));
273                         Stream s = (Stream) transform.GetOutput ();
274                         string output = Stream2String (s);
275                         string expected = "<Test xmlns=\"http://www.go-mono.com/\"><Toto></Toto></Test>";
276                         Assert.AreEqual (expected, output, "XmlChildNodes");
277                 }
278
279                 [Test]
280                 public void LoadInputAsStream () 
281                 {
282                         MemoryStream ms = new MemoryStream ();
283                         byte[] x = Encoding.ASCII.GetBytes (xml);
284                         ms.Write (x, 0, x.Length);
285                         ms.Position = 0;
286                         transform.LoadInput (ms);
287                         Stream s = (Stream) transform.GetOutput ();
288                         string output = Stream2String (s);
289                         Assert.AreEqual (c14xml2, output, "MemoryStream");
290                 }
291
292                 [Test]
293                 [Ignore ("LAMESPEC: input MUST be one of InputType - but no exception is thrown (not documented)")]
294                 public void LoadInputWithUnsupportedType () 
295                 {
296                         byte[] bad = { 0xBA, 0xD };
297                         transform.LoadInput (bad);
298                 }
299
300                 [Test]
301                 [ExpectedException (typeof (ArgumentException))]
302                 public void UnsupportedOutput () 
303                 {
304                         XmlDocument doc = new XmlDocument();
305                         object o = transform.GetOutput (doc.GetType ());
306                 }
307
308                 [Test]
309                 public void ExcC14NSpecExample1 ()
310                 {
311                         using (StreamWriter sw = new StreamWriter ("doc.dtd", false, Encoding.ASCII)) {
312                                 sw.Write ("<!-- presence, not content, required -->");
313                                 sw.Close ();
314                         }
315                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample1Input);
316                         Assert.AreEqual (ExcC14NSpecExample1Output, res, "Example 1 from c14n spec - PIs, Comments, and Outside of Document Element (without comments)");
317                 }
318
319                 [Test]
320                 public void ExcC14NSpecExample2 ()
321                 {
322                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample2Input);
323                         Assert.AreEqual (ExcC14NSpecExample2Output, res, "Example 2 from c14n spec - Whitespace in Document Content (without comments)");
324                 }
325
326                 [Test]
327                 public void ExcC14NSpecExample3 ()
328                 {
329                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample3Input);
330                         Assert.AreEqual (ExcC14NSpecExample3Output, res, "Example 3 from c14n spec - Start and End Tags (without comments)");
331                 }
332             
333                 [Test]
334 //              [Ignore ("This test should be fine, but it does not pass under MS.NET")]
335                 public void ExcC14NSpecExample4 ()
336                 {
337                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample4Input);
338                         Assert.AreEqual (ExcC14NSpecExample4Output, res, "Example 4 from c14n spec - Character Modifications and Character References (without comments)");
339                 }
340             
341                 [Test]
342                 public void ExcC14NSpecExample5 ()
343                 {
344                         using (StreamWriter sw = new StreamWriter ("world.txt", false, Encoding.ASCII)) {
345                                 sw.Write ("world");
346                                 sw.Close ();
347                         }
348                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample5Input);
349                         Assert.AreEqual (ExcC14NSpecExample5Output, res, "Example 5 from c14n spec - Entity References (without comments)");
350                 }
351     
352                 [Test]
353                 public void ExcC14NSpecExample6 ()
354                 {
355                         string res = ExecuteXmlDSigExcC14NTransform (ExcC14NSpecExample6Input);
356                         Assert.AreEqual (ExcC14NSpecExample6Output, res, "Example 6 from c14n spec - UTF-8 Encoding (without comments)");
357                 }
358
359                 private string ExecuteXmlDSigExcC14NTransform (string InputXml)
360                 {
361                         XmlDocument doc = new XmlDocument ();
362                         doc.PreserveWhitespace = true;
363                         doc.LoadXml (InputXml);
364                 
365                         // Testing default attribute support with
366                         // vreader.ValidationType = ValidationType.None.
367                         //
368                         UTF8Encoding utf8 = new UTF8Encoding ();
369                         byte[] data = utf8.GetBytes (InputXml.ToString ());
370                         Stream stream = new MemoryStream (data);
371                         XmlTextReader reader = new XmlTextReader (stream);
372                         XmlValidatingReader vreader = new XmlValidatingReader (reader);
373                         vreader.ValidationType = ValidationType.None;
374                         vreader.EntityHandling = EntityHandling.ExpandCharEntities;
375                         doc.Load (vreader);
376
377                         transform.LoadInput (doc);
378                         return Stream2String ((Stream)transform.GetOutput ());
379                 }
380
381                 //
382                 // Example 1 from ExcC14N spec - PIs, Comments, and Outside of Document Element: 
383                 // http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
384                 // 
385                 // Aleksey: 
386                 // removed reference to an empty external DTD
387                 //
388                 static string ExcC14NSpecExample1Input =  
389                         "<?xml version=\"1.0\"?>\n" +
390                         "\n" +
391                         "<?xml-stylesheet   href=\"doc.xsl\"\n" +
392                         "   type=\"text/xsl\"   ?>\n" +
393                         "\n" +
394                         // "<!DOCTYPE doc SYSTEM \"doc.dtd\">\n" +
395                         "\n" +
396                         "<doc>Hello, world!<!-- Comment 1 --></doc>\n" +
397                         "\n" +
398                         "<?pi-without-data     ?>\n\n" +
399                         "<!-- Comment 2 -->\n\n" +
400                         "<!-- Comment 3 -->\n";
401                 static string ExcC14NSpecExample1Output =   
402                         "<?xml-stylesheet href=\"doc.xsl\"\n" +
403                         "   type=\"text/xsl\"   ?>\n" +
404                         "<doc>Hello, world!</doc>\n" +
405                         "<?pi-without-data?>";
406                 
407                 //
408                 // Example 2 from ExcC14N spec - Whitespace in Document Content: 
409                 // http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent
410                 // 
411                 static string ExcC14NSpecExample2Input =  
412                         "<doc>\n" +
413                         "  <clean>   </clean>\n" +
414                         "   <dirty>   A   B   </dirty>\n" +
415                         "   <mixed>\n" +
416                         "      A\n" +
417                         "      <clean>   </clean>\n" +
418                         "      B\n" +
419                         "      <dirty>   A   B   </dirty>\n" +
420                         "      C\n" +
421                         "   </mixed>\n" +
422                         "</doc>\n";
423                 static string ExcC14NSpecExample2Output =   
424                         "<doc>\n" +
425                         "  <clean>   </clean>\n" +
426                         "   <dirty>   A   B   </dirty>\n" +
427                         "   <mixed>\n" +
428                         "      A\n" +
429                         "      <clean>   </clean>\n" +
430                         "      B\n" +
431                         "      <dirty>   A   B   </dirty>\n" +
432                         "      C\n" +
433                         "   </mixed>\n" +
434                         "</doc>";
435             
436                 //
437                 // Example 3 from ExcC14N spec - Start and End Tags: 
438                 // http://www.w3.org/TR/xml-c14n#Example-SETags
439                 //
440                 static string ExcC14NSpecExample3Input =  
441                         "<!DOCTYPE doc [<!ATTLIST e9 attr CDATA \"default\">]>\n" +
442                         "<doc>\n" +
443                         "   <e1   />\n" +
444                         "   <e2   ></e2>\n" +
445                         "   <e3    name = \"elem3\"   id=\"elem3\"    />\n" +
446                         "   <e4    name=\"elem4\"   id=\"elem4\"    ></e4>\n" +
447                         "   <e5 a:attr=\"out\" b:attr=\"sorted\" attr2=\"all\" attr=\"I\'m\"\n" +
448                         "       xmlns:b=\"http://www.ietf.org\" \n" +
449                         "       xmlns:a=\"http://www.w3.org\"\n" +
450                         "       xmlns=\"http://www.uvic.ca\"/>\n" +
451                         "   <e6 xmlns=\"\" xmlns:a=\"http://www.w3.org\">\n" +
452                         "       <e7 xmlns=\"http://www.ietf.org\">\n" +
453                         "           <e8 xmlns=\"\" xmlns:a=\"http://www.w3.org\">\n" +
454                         "               <e9 xmlns=\"\" xmlns:a=\"http://www.ietf.org\"/>\n" +
455                         "           </e8>\n" +
456                         "       </e7>\n" +
457                         "   </e6>\n" +
458                         "</doc>\n";
459                 static string ExcC14NSpecExample3Output =   
460                         "<doc>\n" +
461                         "   <e1></e1>\n" +
462                         "   <e2></e2>\n" +
463                         "   <e3 id=\"elem3\" name=\"elem3\"></e3>\n" +
464                         "   <e4 id=\"elem4\" name=\"elem4\"></e4>\n" +
465                         "   <e5 xmlns=\"http://www.uvic.ca\" xmlns:a=\"http://www.w3.org\" xmlns:b=\"http://www.ietf.org\" attr=\"I\'m\" attr2=\"all\" b:attr=\"sorted\" a:attr=\"out\"></e5>\n" +
466                         "   <e6>\n" +
467                         "       <e7 xmlns=\"http://www.ietf.org\">\n" +
468                         "           <e8 xmlns=\"\">\n" +
469                         "               <e9 attr=\"default\"></e9>\n" +
470 //                      "               <e9 xmlns:a=\"http://www.ietf.org\"></e9>\n" +
471                         "           </e8>\n" +
472                         "       </e7>\n" +
473                         "   </e6>\n" +
474                         "</doc>";
475             
476             
477                 //
478                 // Example 4 from ExcC14N spec - Character Modifications and Character References: 
479                 // http://www.w3.org/TR/xml-c14n#Example-Chars
480                 //
481                 // Aleksey: 
482                 // This test does not include "normId" element
483                 // because it has an invalid ID attribute "id" which
484                 // should be normalized by XML parser. Currently Mono
485                 // does not support this (see comment after this example
486                 // in the spec).
487                 static string ExcC14NSpecExample4Input =  
488                         "<!DOCTYPE doc [<!ATTLIST normId id ID #IMPLIED>]>\n" +
489                         "<doc>\n" +
490                         "   <text>First line&#x0d;&#10;Second line</text>\n" +
491                         "   <value>&#x32;</value>\n" +
492                         "   <compute><![CDATA[value>\"0\" && value<\"10\" ?\"valid\":\"error\"]]></compute>\n" +
493                         "   <compute expr=\'value>\"0\" &amp;&amp; value&lt;\"10\" ?\"valid\":\"error\"\'>valid</compute>\n" +
494                         "   <norm attr=\' &apos;   &#x20;&#13;&#xa;&#9;   &apos; \'/>\n" +
495                         // "   <normId id=\' &apos;   &#x20;&#13;&#xa;&#9;   &apos; \'/>\n" +
496                         "</doc>\n";
497                 static string ExcC14NSpecExample4Output =   
498                         "<doc>\n" +
499                         "   <text>First line&#xD;\n" +
500                         "Second line</text>\n" +
501                         "   <value>2</value>\n" +
502                         "   <compute>value&gt;\"0\" &amp;&amp; value&lt;\"10\" ?\"valid\":\"error\"</compute>\n" +
503                         "   <compute expr=\"value>&quot;0&quot; &amp;&amp; value&lt;&quot;10&quot; ?&quot;valid&quot;:&quot;error&quot;\">valid</compute>\n" +
504                         "   <norm attr=\" \'    &#xD;&#xA;&#x9;   \' \"></norm>\n" +
505                         // "   <normId id=\"\' &#xD;&#xA;&#x9; \'\"></normId>\n" +
506                         "</doc>";
507             
508                 //
509                 // Example 5 from ExcC14N spec - Entity References: 
510                 // http://www.w3.org/TR/xml-c14n#Example-Entities
511                 //
512                 static string ExcC14NSpecExample5Input =  
513                         "<!DOCTYPE doc [\n" +
514                         "<!ATTLIST doc attrExtEnt ENTITY #IMPLIED>\n" +
515                         "<!ENTITY ent1 \"Hello\">\n" +
516                         "<!ENTITY ent2 SYSTEM \"world.txt\">\n" +
517                         "<!ENTITY entExt SYSTEM \"earth.gif\" NDATA gif>\n" +
518                         "<!NOTATION gif SYSTEM \"viewgif.exe\">\n" +
519                         "]>\n" +
520                         "<doc attrExtEnt=\"entExt\">\n" +
521                         "   &ent1;, &ent2;!\n" +
522                         "</doc>\n" +
523                         "\n" +
524                         "<!-- Let world.txt contain \"world\" (excluding the quotes) -->\n";
525                 static string ExcC14NSpecExample5Output =  
526                         "<doc attrExtEnt=\"entExt\">\n" +
527                         "   Hello, world!\n" +
528                         "</doc>";           
529     
530                 //
531                 // Example 6 from ExcC14N spec - UTF-8 Encoding: 
532                 // http://www.w3.org/TR/xml-c14n#Example-UTF8
533                 // 
534                 static string ExcC14NSpecExample6Input =  
535                         "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
536                         "<doc>&#169;</doc>\n";
537                 static string ExcC14NSpecExample6Output =  
538                         "<doc>\xC2\xA9</doc>";
539             
540
541                 //
542                 // Example 7 from ExcC14N spec - Document Subsets: 
543                 // http://www.w3.org/TR/xml-c14n#Example-DocSubsets
544                 // 
545                 // Aleksey:
546                 // Well, XPath support in Mono is far from complete....
547                 // I was not able to simplify the xpath expression from this test
548                 // so it runs on Mono and still makes sense for testing this feature.
549                 // Thus this test is not included in the suite now.
550                 static string ExcC14NSpecExample7Input =  
551                         "<!DOCTYPE doc [\n" +
552                         "<!ATTLIST e2 xml:space (default|preserve) \'preserve\'>\n" +
553                         "<!ATTLIST e3 id ID #IMPLIED>\n" +
554                         "]>\n" +
555                         "<doc xmlns=\"http://www.ietf.org\" xmlns:w3c=\"http://www.w3.org\">\n" +
556                         "   <e1>\n" +
557                         "      <e2 xmlns=\"\">\n" +
558                         "         <e3 id=\"E3\"/>\n" +
559                         "      </e2>\n" +
560                         "   </e1>\n" +
561                         "</doc>\n";
562
563                 static string ExcC14NSpecExample7Xpath =  
564                         "(//.|//@*|//namespace::*)\n" +
565                         "[\n" +
566                         "self::ietf:e1\n" +
567                         "    or\n" +
568                         "(parent::ietf:e1 and not(self::text() or self::e2))\n" +
569                         "    or\n" +
570                         "count(id(\"E3\")|ancestor-or-self::node()) = count(ancestor-or-self::node())\n" +
571                         "]";
572                 static string ExcC14NSpecExample7Output =  
573                         "<e1 xmlns=\"http://www.ietf.org\" xmlns:w3c=\"http://www.w3.org\"><e3 xmlns=\"\" id=\"E3\" xml:space=\"preserve\"></e3></e1>";
574
575                 [Test]
576                 public void SimpleNamespacePrefixes ()
577                 {
578                         string input = "<a:Action xmlns:a='urn:foo'>http://tempuri.org/IFoo/Echo</a:Action>";
579                         string expected = @"<a:Action xmlns:a=""urn:foo"">http://tempuri.org/IFoo/Echo</a:Action>";
580
581                         XmlDocument doc = new XmlDocument ();
582                         doc.LoadXml (input);
583                         XmlDsigExcC14NTransform t = new XmlDsigExcC14NTransform ();
584                         t.LoadInput (doc);
585                         Stream s = t.GetOutput () as Stream;
586                         Assert.AreEqual (new StreamReader (s, Encoding.UTF8).ReadToEnd (), expected);
587                 }
588
589                 [Test]
590                 [ExpectedException (typeof (NullReferenceException))]
591                 public void GetDigestedOutput_Null ()
592                 {
593                         new XmlDsigExcC14NTransform ().GetDigestedOutput (null);
594                 }
595         }    
596 }
597