(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Microsoft.Web.Services / Test / Microsoft.Web.Services.Security / BinarySecurityTokenTest.cs
blob9da5c5a1f86d8208aec57ecb4805f85340f51c4e
1 //
2 // BinarySecurityTokenTest.cs
3 // - NUnit Test Cases for BinarySecurityToken
4 //
5 // Author:
6 // Sebastien Pouliot (spouliot@motus.com)
7 //
8 // (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
9 //
11 using NUnit.Framework;
12 using Microsoft.Web.Services.Security;
13 using System;
14 using System.Security.Cryptography;
15 using System.Xml;
16 using MWSS = Microsoft.Web.Services.Security;
18 namespace MonoTests.MS.Web.Services.Security {
20 // non-abstract BinarySecurityToken for test uses only
21 public class BinarySecurityToken : MWSS.BinarySecurityToken {
23 #if WSE1
24 public BinarySecurityToken (XmlElement element) : base (element) {}
25 #endif
26 public BinarySecurityToken (XmlQualifiedName valueType) : base (valueType) {}
28 public override AuthenticationKey AuthenticationKey {
29 get { return null; }
32 public override DecryptionKey DecryptionKey {
33 get { return null; }
36 public override EncryptionKey EncryptionKey {
37 get { return null; }
40 public override SignatureKey SignatureKey {
41 get { return null; }
44 public override bool SupportsDataEncryption {
45 get { return false; }
48 public override bool SupportsDigitalSignature {
49 get { return false; }
51 #if WSE1
52 public override void Verify() {}
53 #else
54 public override bool Equals (SecurityToken token)
56 return false;
59 public override int GetHashCode ()
61 return 0;
64 public override bool IsCurrent {
65 get { return false; }
67 #endif
70 [TestFixture]
71 public class BinarySecurityTokenTest : Assertion {
73 private static string name = "mono";
74 private static string ns = "http://www.go-mono.com/";
75 #if WSE1
76 [Test]
77 [ExpectedException (typeof (ArgumentNullException))]
78 public void ConstructorNullXmlElement ()
80 // we do not want to confuse the compiler about null ;-)
81 XmlElement xel = null;
82 BinarySecurityToken bst = new BinarySecurityToken (xel);
85 [Test]
86 public void ConstructorXmlElement ()
88 string xml = "<wsse:BinarySecurityToken xmlns:vt=\"http://www.go-mono.com/\" ValueType=\"vt:mono\" EncodingType=\"wsse:Base64Binary\" xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\" wsu:Id=\"SecurityToken-eb24c89d-012a-431e-af2d-db6a41f1b88e\" xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/07/secext\" />";
89 XmlDocument doc = new XmlDocument ();
90 doc.LoadXml (xml);
91 BinarySecurityToken bst = new BinarySecurityToken (doc.DocumentElement);
92 AssertNotNull ("BinarySecurityToken(XmlQualifiedName)", bst);
93 AssertEquals ("EncodingType.Name", "Base64Binary", bst.EncodingType.Name);
94 AssertEquals ("EncodingType.Namespace", "http://schemas.xmlsoap.org/ws/2002/07/secext", bst.EncodingType.Namespace);
95 AssertEquals ("ValueType.Name", name, bst.ValueType.Name);
96 AssertEquals ("ValueType.Namespace", ns, bst.ValueType.Namespace);
97 AssertNull ("RawData", bst.RawData);
98 Assert ("Id", bst.Id.StartsWith ("SecurityToken-"));
100 #endif
101 [Test]
102 [ExpectedException (typeof (ArgumentNullException))]
103 public void ConstructorNullXmlQualifiedName ()
105 // we do not want to confuse the compiler about null ;-)
106 XmlQualifiedName xqn = null;
107 BinarySecurityToken bst = new BinarySecurityToken (xqn);
110 [Test]
111 public void ConstructorXmlQualifiedName ()
113 XmlQualifiedName xqn = new XmlQualifiedName (name, ns);
114 BinarySecurityToken bst = new BinarySecurityToken (xqn);
115 AssertNotNull ("BinarySecurityToken(XmlQualifiedName)", bst);
116 AssertEquals ("EncodingType.Name", "Base64Binary", bst.EncodingType.Name);
117 AssertEquals ("EncodingType.Namespace", "http://schemas.xmlsoap.org/ws/2002/07/secext", bst.EncodingType.Namespace);
118 AssertEquals ("ValueType.Name", name, bst.ValueType.Name);
119 AssertEquals ("ValueType.Namespace", ns, bst.ValueType.Namespace);
120 AssertNull ("RawData", bst.RawData);
121 Assert ("Id", bst.Id.StartsWith ("SecurityToken-"));
124 [Test]
125 [ExpectedException (typeof (ArgumentNullException))]
126 public void NullEncodingType ()
128 XmlQualifiedName xqn = new XmlQualifiedName (name, ns);
129 BinarySecurityToken bst = new BinarySecurityToken (xqn);
130 bst.EncodingType = null;
133 [Test]
134 [ExpectedException (typeof (ArgumentNullException))]
135 public void NullValueType ()
137 XmlQualifiedName xqn = new XmlQualifiedName (name, ns);
138 BinarySecurityToken bst = new BinarySecurityToken (xqn);
139 bst.ValueType = null;
142 [Test]
143 [ExpectedException (typeof (ArgumentNullException))]
144 public void GetXmlNull ()
146 XmlQualifiedName xqn = new XmlQualifiedName (name, ns);
147 BinarySecurityToken bst = new BinarySecurityToken (xqn);
148 XmlElement xel = bst.GetXml (null);
151 [Test]
152 public void GetXml ()
154 XmlQualifiedName xqn = new XmlQualifiedName (name, ns);
155 BinarySecurityToken bst = new BinarySecurityToken (xqn);
156 bst.Id = "staticIdUsedForNUnit";
157 XmlDocument doc = new XmlDocument ();
158 XmlElement xel = bst.GetXml (doc);
159 // this one I can't generate exactly like the original so I check each parts
160 Assert ("GetXml(doc)1", xel.OuterXml.StartsWith ("<wsse:BinarySecurityToken "));
161 Assert ("GetXml(doc)2", xel.OuterXml.IndexOf ("xmlns:vt=\"http://www.go-mono.com/\"") > 0);
162 Assert ("GetXml(doc)3", xel.OuterXml.IndexOf ("ValueType=\"vt:mono\"") > 0);
163 Assert ("GetXml(doc)4", xel.OuterXml.IndexOf ("EncodingType=\"wsse:Base64Binary\"") > 0);
164 Assert ("GetXml(doc)5", xel.OuterXml.IndexOf ("xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\"") > 0);
165 Assert ("GetXml(doc)6", xel.OuterXml.IndexOf ("wsu:Id=\"staticIdUsedForNUnit\"") > 0);
166 Assert ("GetXml(doc)7", xel.OuterXml.IndexOf ("xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/07/secext\"") > 0);
169 [Test]
170 [ExpectedException (typeof (ArgumentNullException))]
171 public void LoadXmlNull ()
173 XmlQualifiedName xqn = new XmlQualifiedName (name, ns);
174 BinarySecurityToken bst = new BinarySecurityToken (xqn);
175 bst.LoadXml (null);
178 [Test]
179 public void LoadXml ()
181 XmlQualifiedName xqn = new XmlQualifiedName (name, ns);
182 BinarySecurityToken bst = new BinarySecurityToken (xqn);
183 XmlDocument doc = new XmlDocument ();
184 doc.LoadXml ("<wsse:BinarySecurityToken xmlns:vt=\"http://www.go-mono.com/\" ValueType=\"vt:mono\" EncodingType=\"wsse:Base64Binary\" xmlns:wsu=\"http://schemas.xmlsoap.org/ws/2002/07/utility\" wsu:Id=\"staticIdUsedForNUnit\" xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2002/07/secext\" />");
185 bst.LoadXml (doc.DocumentElement);
186 AssertEquals ("EncodingType.Name", "Base64Binary", bst.EncodingType.Name);
187 AssertEquals ("EncodingType.Namespace", "http://schemas.xmlsoap.org/ws/2002/07/secext", bst.EncodingType.Namespace);
188 AssertEquals ("ValueType.Name", name, bst.ValueType.Name);
189 AssertEquals ("ValueType.Namespace", ns, bst.ValueType.Namespace);
190 AssertNull ("RawData", bst.RawData);
191 AssertEquals ("Id", "staticIdUsedForNUnit", bst.Id);
194 [Test]
195 public void RawData ()
197 XmlQualifiedName xqn = new XmlQualifiedName (name, ns);
198 BinarySecurityToken bst = new BinarySecurityToken (xqn);
199 AssertNull ("RawData(empty)", bst.RawData);
200 byte[] raw = new byte [1];
201 bst.RawData = raw;
202 AssertNotNull ("RawData", bst.RawData);
203 AssertEquals ("RawData[0]=0", 0x00, bst.RawData [0]);
204 raw [0] = 1;
205 // same buffer or copy ?
206 AssertEquals ("RawData[0]=1", 0x01, bst.RawData [0]);
207 bst.RawData = null;
208 AssertNull ("RawData(null)", bst.RawData);