2 // XmlDsigEnvelopedSignatureTransformTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2004 Novell Inc.
13 using System
.Security
.Cryptography
;
14 using System
.Security
.Cryptography
.Xml
;
19 using NUnit
.Framework
;
21 namespace MonoTests
.System
.Security
.Cryptography
.Xml
{
23 // Note: GetInnerXml is protected in XmlDsigEnvelopedSignatureTransform making it
24 // difficult to test properly. This class "open it up" :-)
25 public class UnprotectedXmlDsigEnvelopedSignatureTransform
: XmlDsigEnvelopedSignatureTransform
{
26 public UnprotectedXmlDsigEnvelopedSignatureTransform ()
30 public UnprotectedXmlDsigEnvelopedSignatureTransform (bool includeComments
)
31 : base (includeComments
)
35 public XmlNodeList
UnprotectedGetInnerXml ()
37 return base.GetInnerXml ();
42 public class XmlDsigEnvelopedSignatureTransformTest
{
43 private UnprotectedXmlDsigEnvelopedSignatureTransform transform
;
48 transform
= new UnprotectedXmlDsigEnvelopedSignatureTransform ();
52 public void Constructor1 ()
54 CheckProperties (transform
);
57 [Test
] // ctor (Boolean)
58 public void Constructor2 ()
60 transform
= new UnprotectedXmlDsigEnvelopedSignatureTransform (true);
61 CheckProperties (transform
);
62 transform
= new UnprotectedXmlDsigEnvelopedSignatureTransform (false);
63 CheckProperties (transform
);
66 void CheckProperties (XmlDsigEnvelopedSignatureTransform transform
)
68 Assert
.AreEqual ("http://www.w3.org/2000/09/xmldsig#enveloped-signature",
69 transform
.Algorithm
, "Algorithm");
71 Type
[] input
= transform
.InputTypes
;
72 Assert
.AreEqual (3, input
.Length
, "Input Length");
73 // check presence of every supported input types
77 foreach (Type t
in input
) {
78 if (t
== typeof (XmlDocument
))
80 if (t
== typeof (XmlNodeList
))
82 if (t
== typeof (Stream
))
85 Assert
.IsTrue (istream
, "Input Stream");
86 Assert
.IsTrue (ixmldoc
, "Input XmlDocument");
87 Assert
.IsTrue (ixmlnl
, "Input XmlNodeList");
89 Type
[] output
= transform
.OutputTypes
;
90 Assert
.AreEqual (2, output
.Length
, "Output Length");
91 // check presence of every supported output types
94 foreach (Type t
in output
) {
95 if (t
== typeof (XmlNodeList
))
97 if (t
== typeof (XmlDocument
))
100 Assert
.IsTrue (oxmlnl
, "Output XmlNodeList");
101 Assert
.IsTrue (oxmldoc
, "Output XmlDocument");
104 void AssertEquals (XmlNodeList expected
, XmlNodeList actual
, string msg
)
106 for (int i
= 0; i
< expected
.Count
; i
++) {
107 if (expected
[i
].OuterXml
!= actual
[i
].OuterXml
)
108 Assert
.Fail (msg
+ " [" + i
+ "] expected " + expected
[i
].OuterXml
+ " bug got " + actual
[i
].OuterXml
);
113 public void GetInnerXml ()
115 // Always returns null
116 Assert
.IsNull (transform
.UnprotectedGetInnerXml ());
119 private XmlDocument
GetDoc ()
121 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>";
122 string test
= "<Envelope> " + dsig
+ " </Envelope>";
123 XmlDocument doc
= new XmlDocument ();
129 public void LoadInputAsXmlDocument ()
131 XmlDocument doc
= GetDoc ();
132 transform
.LoadInput (doc
);
133 object o
= transform
.GetOutput ();
134 Assert
.AreEqual (doc
, o
, "EnvelopedSignature result");
138 public void LoadInputAsXmlNodeList ()
140 XmlDocument doc
= GetDoc ();
141 transform
.LoadInput (doc
.ChildNodes
);
142 XmlNodeList xnl
= (XmlNodeList
) transform
.GetOutput ();
143 AssertEquals (doc
.ChildNodes
, xnl
, "EnvelopedSignature result");