XmlDsigExcC14NTransformTest.cs 22 KB

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