2 // NonceTest.cs - NUnit Test Cases for Nonce
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
10 using NUnit.Framework;
11 using Microsoft.Web.Services.Security;
15 namespace MonoTests.MS.Web.Services.Security {
18 public class NonceTest : Assertion {
20 private const string Sample = "<wsse:Nonce xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/12/secext\">GWSRuy1IC4zb2jsA+Sz/rw==</wsse:Nonce>";
21 private const string Zero = "<wsse:Nonce xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/12/secext\"></wsse:Nonce>";
24 // NOTE: Nonce doesn't have a public constructor in WSE1 (*) so tests can only be runned with WSE2
25 // (*) this is bad because we can't reuse Nonce inside other security protocols
28 public void ConstructorInt ()
30 Nonce n = new Nonce (16);
34 public void ConstructorIntZero ()
36 Nonce n = new Nonce (0);
37 AssertEquals ("Nonce(0).Value", String.Empty, n.Value);
38 AssertNotNull ("Nonce(0).GetValueBytes()", n.GetValueBytes ());
39 XmlDocument doc = new XmlDocument ();
40 XmlElement xel = n.GetXml (doc);
41 AssertEquals ("Nonce(0).GetXml", Zero, xel.OuterXml);
45 [ExpectedException (typeof (OverflowException))]
46 public void ConstructorNegativeInt ()
48 Nonce n = new Nonce (-1);
52 public void ConstructorXmlElement ()
54 XmlDocument doc = new XmlDocument ();
56 Nonce n = new Nonce (doc.DocumentElement);
58 XmlElement xel = n.GetXml (doc);
59 AssertEquals ("ConstructorXmlElement", Sample, xel.OuterXml);
63 [ExpectedException (typeof (ArgumentNullException))]
64 public void ConstructorXmlElementNull ()
66 Nonce n = new Nonce (null);
72 Nonce n = new Nonce (16);
73 AssertNotNull ("Value", n.Value);
74 byte[] v = n.GetValueBytes ();
75 AssertNotNull ("GetValueBytes", v);
76 AssertEquals ("Value==base64(GetValueBytes)", n.Value, Convert.ToBase64String (v));
82 Nonce n = new Nonce (16);
83 XmlDocument doc = new XmlDocument ();
84 XmlElement xel = n.GetXml (doc);
85 Assert ("GetXml.StartsWith", xel.OuterXml.StartsWith ("<wsse:Nonce xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/12/secext\">"));
86 Assert ("GetXml.EndsWith", xel.OuterXml.EndsWith ("==</wsse:Nonce>"));
90 [ExpectedException (typeof (ArgumentNullException))]
91 public void GetXmlNull ()
93 Nonce n = new Nonce (16);
98 public void LoadXml ()
100 Nonce n = new Nonce (16);
101 XmlDocument doc = new XmlDocument ();
102 doc.LoadXml (Sample);
103 n.LoadXml (doc.DocumentElement);
105 XmlElement xel = n.GetXml (doc);
106 AssertEquals ("LoadXml", Sample, xel.OuterXml);
110 [ExpectedException (typeof (ArgumentException))]
111 public void LoadXml_BadLocalName ()
113 Nonce n = new Nonce (16);
114 XmlDocument doc = new XmlDocument ();
115 doc.LoadXml ("<wsse:SecurityTokenRef xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/07/secext\" />");
116 n.LoadXml (doc.DocumentElement);
120 [ExpectedException (typeof (ArgumentException))]
121 public void LoadXml_BadNamespace ()
123 Nonce n = new Nonce (16);
124 XmlDocument doc = new XmlDocument ();
125 doc.LoadXml ("<wsse:SecurityTokenRef xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2202/07/secext\" />");
126 n.LoadXml (doc.DocumentElement);
130 [ExpectedException (typeof (ArgumentNullException))]
131 public void LoadXmlNull ()
133 Nonce n = new Nonce (16);