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