XmlDsigC14NTransformTest.cs 20 KB

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