XmlDsigC14NTransformTest.cs 19 KB

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