SignedInfoTest.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // SignedInfoTest.cs - NUnit Test Cases for SignedInfo
  3. //
  4. // Author:
  5. // Sebastien Pouliot ([email protected])
  6. //
  7. // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
  8. //
  9. using System;
  10. using System.Security.Cryptography;
  11. using System.Security.Cryptography.Xml;
  12. using System.Xml;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.Security.Cryptography.Xml {
  15. [TestFixture]
  16. public class SignedInfoTest : Assertion {
  17. protected SignedInfo info;
  18. [SetUp]
  19. protected void SetUp ()
  20. {
  21. info = new SignedInfo ();
  22. }
  23. [Test]
  24. public void Empty ()
  25. {
  26. AssertEquals ("CanonicalizationMethod", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", info.CanonicalizationMethod);
  27. AssertNull ("Id", info.Id);
  28. AssertNotNull ("References", info.References);
  29. AssertEquals ("References.Count", 0, info.References.Count);
  30. AssertNull ("SignatureLength", info.SignatureLength);
  31. AssertNull ("SignatureMethod", info.SignatureMethod);
  32. AssertEquals ("ToString()", "System.Security.Cryptography.Xml.SignedInfo", info.ToString ());
  33. }
  34. [Test]
  35. [ExpectedException (typeof (CryptographicException))]
  36. public void EmptyException ()
  37. {
  38. string xml = info.GetXml ().OuterXml;
  39. }
  40. [Test]
  41. public void Properties ()
  42. {
  43. info.CanonicalizationMethod = "http://www.go-mono.com/";
  44. AssertEquals ("CanonicalizationMethod", "http://www.go-mono.com/", info.CanonicalizationMethod);
  45. info.Id = "Mono::";
  46. AssertEquals ("Id", "Mono::", info.Id);
  47. }
  48. [Test]
  49. public void References ()
  50. {
  51. Reference r1 = new Reference ();
  52. r1.Uri = "http://www.go-mono.com/";
  53. r1.AddTransform (new XmlDsigBase64Transform ());
  54. info.AddReference (r1);
  55. AssertEquals ("References.Count 1", 1, info.References.Count);
  56. Reference r2 = new Reference ("http://www.motus.com/");
  57. r2.AddTransform (new XmlDsigBase64Transform ());
  58. info.AddReference (r2);
  59. AssertEquals ("References.Count 2", 2, info.References.Count);
  60. info.SignatureMethod = "http://www.w3.org/2000/09/xmldsig#dsa-sha1";
  61. }
  62. [Test]
  63. public void Load ()
  64. {
  65. string xml = "<SignedInfo xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\" /><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\" /><Reference URI=\"#MyObjectId\"><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>/Vvq6sXEVbtZC8GwNtLQnGOy/VI=</DigestValue></Reference></SignedInfo>";
  66. XmlDocument doc = new XmlDocument ();
  67. doc.LoadXml (xml);
  68. info.LoadXml (doc.DocumentElement);
  69. AssertEquals ("LoadXml", xml, (info.GetXml ().OuterXml));
  70. AssertEquals ("LoadXml-C14N", "http://www.w3.org/TR/2001/REC-xml-c14n-20010315", info.CanonicalizationMethod);
  71. AssertEquals ("LoadXml-Algo", "http://www.w3.org/2000/09/xmldsig#rsa-sha1", info.SignatureMethod);
  72. AssertEquals ("LoadXml-Ref1", 1, info.References.Count);
  73. }
  74. // there are many (documented) not supported methods in SignedInfo
  75. [Test]
  76. [ExpectedException (typeof (NotSupportedException))]
  77. public void NotSupportedCount ()
  78. {
  79. int n = info.Count;
  80. }
  81. [Test]
  82. [ExpectedException (typeof (NotSupportedException))]
  83. public void NotSupportedIsReadOnly ()
  84. {
  85. bool b = info.IsReadOnly;
  86. }
  87. [Test]
  88. [ExpectedException (typeof (NotSupportedException))]
  89. public void NotSupportedIsSynchronized ()
  90. {
  91. bool b = info.IsSynchronized;
  92. }
  93. [Test]
  94. [ExpectedException (typeof (NotSupportedException))]
  95. public void NotSupportedSyncRoot ()
  96. {
  97. object o = info.SyncRoot;
  98. }
  99. [Test]
  100. [ExpectedException (typeof (NotSupportedException))]
  101. public void NotSupportedCopyTo ()
  102. {
  103. info.CopyTo (null, 0);
  104. }
  105. }
  106. }