// // SignatureTest.cs - NUnit Test Cases for SignedXml // // Author: // Sebastien Pouliot (spouliot@motus.com) // // (C) 2002 Motus Technologies Inc. (http://www.motus.com) // using NUnit.Framework; using System; using System.Security.Cryptography; using System.Security.Cryptography.Xml; using System.Xml; namespace MonoTests.System.Security.Cryptography.Xml { public class SignatureTest : TestCase { public SignatureTest () : base ("System.Security.Cryptography.Xml.Signature testsuite") {} public SignatureTest (string name) : base (name) {} protected Signature signature; protected override void SetUp () { signature = new Signature (); } protected override void TearDown () {} public static ITest Suite { get { return new TestSuite (typeof (SignatureTest)); } } public void TestSignature () { XmlElement xel = null; // empty - missing SignedInfo try { xel = signature.GetXml (); Fail ("Expected CryptographicException but got none"); } catch (CryptographicException) { // this is expected } catch (Exception e) { Fail ("Expected CryptographicException but got :" + e.ToString ()); } SignedInfo info = new SignedInfo (); signature.SignedInfo = info; info.SignatureMethod = "http://www.w3.org/2000/09/xmldsig#dsa-sha1"; signature.SignatureValue = new byte [128]; try { xel = signature.GetXml (); } catch (Exception e) { Fail ("Expected ... but got :" + e.ToString ()); } } public void TestLoad () { string value = "/Vvq6sXEVbtZC8GwNtLQnGOy/VI=A6XuE8Cy9iOffRXaW9b0+dUcMUJQnlmwLsiqtQnADbCtZXnXAaeJ6nGnQ4Mm0IGi0AJc7/2CoJReXl7iW4hltmFguG1e3nl0VxCyCTHKGOCo1u8R3K+B1rTaenFbSxs42EM7/D9KETsPlzfYfis36yM3PqatiCUOsoMsAiMGzlc=tI8QYIpbG/m6JLyvP+S3X8mzcaAIayxomyTimSh9UCpEucRnGvLw0P73uStNpiF7wltTZA1HEsv+Ha39dY/0j/Wiy3RAodGDRNuKQao1wu34aNybZ673brbsbHFUfw/o7nlKD2xO84fbajBZmKtBBDy63NHt+QL+grSrREPfCTM=AQABThis is some text"; XmlDocument doc = new XmlDocument (); doc.LoadXml (value); signature.LoadXml (doc.DocumentElement); string s = signature.GetXml ().OuterXml; AssertEquals ("Load", value, s); } } }