2 // XmlDsigEnvelopedSignatureTransformTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2004 Novell Inc.
12 using System
.Security
.Cryptography
;
13 using System
.Security
.Cryptography
.Xml
;
18 using NUnit
.Framework
;
20 namespace MonoTests
.System
.Security
.Cryptography
.Xml
{
22 // Note: GetInnerXml is protected in XmlDsigEnvelopedSignatureTransform making it
23 // difficult to test properly. This class "open it up" :-)
24 public class UnprotectedXmlDsigEnvelopedSignatureTransform
: XmlDsigEnvelopedSignatureTransform
{
26 public XmlNodeList
UnprotectedGetInnerXml ()
28 return base.GetInnerXml ();
33 public class XmlDsigEnvelopedSignatureTransformTest
: Assertion
{
35 protected UnprotectedXmlDsigEnvelopedSignatureTransform transform
;
38 protected void SetUp ()
40 transform
= new UnprotectedXmlDsigEnvelopedSignatureTransform ();
44 public void Properties ()
46 AssertEquals ("Algorithm", "http://www.w3.org/2000/09/xmldsig#enveloped-signature", transform
.Algorithm
);
48 Type
[] input
= transform
.InputTypes
;
49 AssertEquals ("Input Length", 3, input
.Length
);
50 // check presence of every supported input types
54 foreach (Type t
in input
) {
55 if (t
.ToString () == "System.Xml.XmlDocument")
57 if (t
.ToString () == "System.Xml.XmlNodeList")
60 Assert ("No Input Stream", !istream
);
61 Assert ("Input XmlDocument", ixmldoc
);
62 Assert ("Input XmlNodeList", ixmlnl
);
64 Type
[] output
= transform
.OutputTypes
;
65 AssertEquals ("Output Length", 2, output
.Length
);
66 // check presence of every supported output types
69 foreach (Type t
in output
) {
71 throw new InvalidOperationException ();
72 if (t
.ToString () == "System.Xml.XmlNodeList")
74 if (t
.ToString () == "System.Xml.XmlDocument")
77 Assert ("Output XmlNodeList", oxmlnl
);
78 Assert ("Output XmlDocument", oxmldoc
);
81 protected void AssertEquals (string msg
, XmlNodeList expected
, XmlNodeList actual
)
83 for (int i
=0; i
< expected
.Count
; i
++) {
84 if (expected
[i
].OuterXml
!= actual
[i
].OuterXml
)
85 Fail (msg
+ " [" + i
+ "] expected " + expected
[i
].OuterXml
+ " bug got " + actual
[i
].OuterXml
);
90 public void GetInnerXml ()
92 // Always returns null
93 AssertNull (transform
.UnprotectedGetInnerXml ());
96 private XmlDocument
GetDoc ()
98 string dsig
= "<Signature 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#dsa-sha1\" /><Reference URI=\"\"><Transforms><Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\" /></Transforms><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" /><DigestValue>fdy6S2NLpnT4fMdokUHSHsmpcvo=</DigestValue></Reference></Signature>";
99 string test
= "<Envelope> " + dsig
+ " </Envelope>";
100 XmlDocument doc
= new XmlDocument ();
106 public void LoadInputAsXmlDocument ()
108 XmlDocument doc
= GetDoc ();
109 transform
.LoadInput (doc
);
110 object o
= transform
.GetOutput ();
111 AssertEquals ("EnvelopedSignature result", doc
, o
);
115 public void LoadInputAsXmlNodeList ()
117 XmlDocument doc
= GetDoc ();
118 transform
.LoadInput (doc
.ChildNodes
);
119 XmlNodeList xnl
= (XmlNodeList
) transform
.GetOutput ();
120 AssertEquals ("EnvelopedSignature result", doc
.ChildNodes
, xnl
);