Merge pull request #2417 from razzfazz/guard_substr
[mono.git] / mcs / class / System.ServiceModel / Test / System.ServiceModel.Configuration / EndpointBehaviorElementTest.cs
1 //
2 // EndpointBehaviorElementTest.cs
3 //
4 // Author:
5 //      Igor Zelmanovich <igorz@mainsoft.com>
6 //
7 // Copyright (C) 2008 Mainsoft, Inc.  http://www.mainsoft.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using System.Collections.Generic;
31 using System.Text;
32 using NUnit.Framework;
33 using System.ServiceModel.Configuration;
34 using System.Configuration;
35 using System.ServiceModel.Description;
36 using System.Security.Cryptography.X509Certificates;
37 using System.ServiceModel.Security;
38 using System.Security.Principal;
39
40 namespace MonoTests.System.ServiceModel.Configuration
41 {
42         [TestFixture]
43         public class EndpointBehaviorElementTest
44         {
45                 EndpointBehaviorElement OpenConfig () {
46                         ServiceModelSectionGroup config = (ServiceModelSectionGroup) ConfigurationManager.OpenExeConfiguration ("Test/config/endpointBehaviors").GetSectionGroup ("system.serviceModel");
47                         return config.Behaviors.EndpointBehaviors [0];
48                 }
49
50                 [Test]
51                 public void CallbackDebugElement () {
52                         EndpointBehaviorElement behavior = OpenConfig ();
53                         CallbackDebugElement callbackDebug = (CallbackDebugElement) behavior [typeof (CallbackDebugElement)];
54
55                         if (callbackDebug == null)
56                                 Assert.Fail ("CallbackDebugElement is not exist in collection.");
57
58                         Assert.AreEqual (typeof (CallbackDebugBehavior), callbackDebug.BehaviorType, "RoleProviderName");
59                         Assert.AreEqual ("callbackDebug", callbackDebug.ConfigurationElementName, "RoleProviderName");
60                         Assert.AreEqual (true, callbackDebug.IncludeExceptionDetailInFaults, "IncludeExceptionDetailInFaults");
61                 }
62
63                 [Test]
64                 public void CallbackDebugElement_defaults () {
65                         CallbackDebugElement element = new CallbackDebugElement ();
66
67                         Assert.AreEqual (typeof (CallbackDebugBehavior), element.BehaviorType, "element");
68                         Assert.AreEqual ("callbackDebug", element.ConfigurationElementName, "ConfigurationElementName");
69                         Assert.AreEqual (false, element.IncludeExceptionDetailInFaults, "IncludeExceptionDetailInFaults");
70                 }
71
72                 [Test]
73                 public void CallbackTimeoutsElement () {
74                         EndpointBehaviorElement behavior = OpenConfig ();
75                         CallbackTimeoutsElement element = (CallbackTimeoutsElement) behavior [typeof (CallbackTimeoutsElement)];
76
77                         if (element == null)
78                                 Assert.Fail ("CallbackTimeoutsElement is not exist in collection.");
79
80                         Assert.AreEqual ("System.ServiceModel.Description.CallbackTimeoutsBehavior", element.BehaviorType.FullName, "BehaviorType");
81                         Assert.AreEqual ("callbackTimeouts", element.ConfigurationElementName, "ConfigurationElementName");
82                         Assert.AreEqual (new TimeSpan (0, 2, 30), element.TransactionTimeout, "TransactionTimeout");
83                 }
84
85                 [Test]
86                 public void CallbackTimeoutsElement_defaults () {
87                         CallbackTimeoutsElement element = new CallbackTimeoutsElement ();
88
89                         Assert.AreEqual ("System.ServiceModel.Description.CallbackTimeoutsBehavior", element.BehaviorType.FullName, "BehaviorType");
90                         Assert.AreEqual ("callbackTimeouts", element.ConfigurationElementName, "ConfigurationElementName");
91                         Assert.AreEqual (new TimeSpan (0, 0, 0), element.TransactionTimeout, "TransactionTimeout");
92                 }
93
94                 [Test]
95                 public void ClientViaElement () {
96                         EndpointBehaviorElement behavior = OpenConfig ();
97                         ClientViaElement element = (ClientViaElement) behavior [typeof (ClientViaElement)];
98
99                         if (element == null)
100                                 Assert.Fail ("ClientViaElement is not exist in collection.");
101
102                         Assert.AreEqual (typeof (ClientViaBehavior), element.BehaviorType, "BehaviorType");
103                         Assert.AreEqual ("clientVia", element.ConfigurationElementName, "ConfigurationElementName");
104
105                         Assert.AreEqual ("http://via.uri", element.ViaUri.OriginalString, "ViaUri");
106                 }
107
108                 [Test]
109                 public void ClientViaElement_defaults () {
110                         ClientViaElement element = new ClientViaElement ();
111
112                         Assert.AreEqual (typeof (ClientViaBehavior), element.BehaviorType, "BehaviorType");
113                         Assert.AreEqual ("clientVia", element.ConfigurationElementName, "ConfigurationElementName");
114
115                         Assert.AreEqual (null, element.ViaUri, "ViaUri");
116                 }
117
118                 [Test]
119                 public void DataContractSerializerElement () {
120                         EndpointBehaviorElement behavior = OpenConfig ();
121                         DataContractSerializerElement element = (DataContractSerializerElement) behavior [typeof (DataContractSerializerElement)];
122
123                         if (element == null)
124                                 Assert.Fail ("DataContractSerializerElement is not exist in collection.");
125
126                         Assert.AreEqual ("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior", element.BehaviorType.FullName, "BehaviorType");
127                         Assert.AreEqual ("dataContractSerializer", element.ConfigurationElementName, "ConfigurationElementName");
128
129                         Assert.AreEqual (true, element.IgnoreExtensionDataObject, "IgnoreExtensionDataObject");
130                         Assert.AreEqual (32768, element.MaxItemsInObjectGraph, "MaxItemsInObjectGraph");
131                 }
132
133                 [Test]
134                 public void DataContractSerializerElement_defaults () {
135                         DataContractSerializerElement element = new DataContractSerializerElement ();
136
137                         Assert.AreEqual ("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior", element.BehaviorType.FullName, "BehaviorType");
138                         Assert.AreEqual ("dataContractSerializer", element.ConfigurationElementName, "ConfigurationElementName");
139
140                         Assert.AreEqual (false, element.IgnoreExtensionDataObject, "IgnoreExtensionDataObject");
141                         Assert.AreEqual (65536, element.MaxItemsInObjectGraph, "MaxItemsInObjectGraph");
142                 }
143
144                 [Test]
145                 public void SynchronousReceiveElement () {
146                         EndpointBehaviorElement behavior = OpenConfig ();
147                         SynchronousReceiveElement element = (SynchronousReceiveElement) behavior [typeof (SynchronousReceiveElement)];
148
149                         if (element == null)
150                                 Assert.Fail ("SynchronousReceiveElement is not exist in collection.");
151
152                         Assert.AreEqual (typeof (SynchronousReceiveBehavior), element.BehaviorType, "BehaviorType");
153                         Assert.AreEqual ("synchronousReceive", element.ConfigurationElementName, "ConfigurationElementName");
154                 }
155
156                 [Test]
157                 public void SynchronousReceiveElement_defaults () {
158                         SynchronousReceiveElement element = new SynchronousReceiveElement ();
159
160                         Assert.AreEqual (typeof (SynchronousReceiveBehavior), element.BehaviorType, "BehaviorType");
161                         Assert.AreEqual ("synchronousReceive", element.ConfigurationElementName, "ConfigurationElementName");
162                 }
163
164                 [Test]
165                 public void TransactedBatchingElement () {
166                         EndpointBehaviorElement behavior = OpenConfig ();
167                         TransactedBatchingElement element = (TransactedBatchingElement) behavior [typeof (TransactedBatchingElement)];
168
169                         if (element == null)
170                                 Assert.Fail ("TransactedBatchingElement is not exist in collection.");
171
172                         Assert.AreEqual (typeof (TransactedBatchingBehavior), element.BehaviorType, "BehaviorType");
173                         Assert.AreEqual ("transactedBatching", element.ConfigurationElementName, "ConfigurationElementName");
174
175                         Assert.AreEqual (16, element.MaxBatchSize, "MaxBatchSize");
176                 }
177
178                 [Test]
179                 public void TransactedBatchingElement_defaults () {
180                         TransactedBatchingElement element = new TransactedBatchingElement ();
181
182                         Assert.AreEqual (typeof (TransactedBatchingBehavior), element.BehaviorType, "BehaviorType");
183                         Assert.AreEqual ("transactedBatching", element.ConfigurationElementName, "ConfigurationElementName");
184
185                         Assert.AreEqual (0, element.MaxBatchSize, "MaxBatchSize");
186                 }
187
188                 [Test]
189                 public void ClientCredentialsElement () {
190                         EndpointBehaviorElement behavior = OpenConfig ();
191                         ClientCredentialsElement element = (ClientCredentialsElement) behavior [typeof (ClientCredentialsElement)];
192
193                         if (element == null)
194                                 Assert.Fail ("ClientCredentialsElement is not exist in collection.");
195
196                         Assert.AreEqual (typeof (ClientCredentials), element.BehaviorType, "BehaviorType");
197                         Assert.AreEqual ("clientCredentials", element.ConfigurationElementName, "ConfigurationElementName");
198
199                         Assert.AreEqual (false, element.SupportInteractive, "SupportInteractive");
200                         Assert.AreEqual ("ClientCredentialType", element.Type, "Type");
201
202                         Assert.AreEqual ("findValue", element.ClientCertificate.FindValue, "ClientCertificate.FindValue");
203                         Assert.AreEqual (StoreLocation.LocalMachine, element.ClientCertificate.StoreLocation, "ClientCertificate.StoreLocation");
204                         Assert.AreEqual (StoreName.Root, element.ClientCertificate.StoreName, "ClientCertificate.StoreName");
205                         Assert.AreEqual (X509FindType.FindByExtension, element.ClientCertificate.X509FindType, "ClientCertificate.X509FindType");
206
207                         Assert.AreEqual ("findValue", element.ServiceCertificate.DefaultCertificate.FindValue, "ServiceCertificate.DefaultCertificate.FindValue");
208                         Assert.AreEqual (StoreLocation.LocalMachine, element.ServiceCertificate.DefaultCertificate.StoreLocation, "ServiceCertificate.DefaultCertificate.StoreLocation");
209                         Assert.AreEqual (StoreName.Root, element.ServiceCertificate.DefaultCertificate.StoreName, "ServiceCertificate.DefaultCertificate.StoreName");
210                         Assert.AreEqual (X509FindType.FindByExtension, element.ServiceCertificate.DefaultCertificate.X509FindType, "ServiceCertificate.DefaultCertificate.X509FindType");
211
212                         Assert.AreEqual ("CustomCertificateValidatorType", element.ServiceCertificate.Authentication.CustomCertificateValidatorType, "ServiceCertificate.Authentication.CustomCertificateValidatorType");
213                         Assert.AreEqual (X509CertificateValidationMode.None, element.ServiceCertificate.Authentication.CertificateValidationMode, "ServiceCertificate.Authentication.CertificateValidationMode");
214                         Assert.AreEqual (X509RevocationMode.Offline, element.ServiceCertificate.Authentication.RevocationMode, "ServiceCertificate.Authentication.RevocationMode");
215                         Assert.AreEqual (StoreLocation.LocalMachine, element.ServiceCertificate.Authentication.TrustedStoreLocation, "ServiceCertificate.Authentication.TrustedStoreLocation");
216
217                         Assert.AreEqual (false, element.Windows.AllowNtlm, "Windows.AllowNtlm");
218                         Assert.AreEqual (TokenImpersonationLevel.None, element.Windows.AllowedImpersonationLevel, "Windows.AllowedImpersonationLevel");
219
220                         Assert.AreEqual (false, element.IssuedToken.CacheIssuedTokens, "IssuedToken.CacheIssuedTokens");
221                         Assert.AreEqual (SecurityKeyEntropyMode.ClientEntropy, element.IssuedToken.DefaultKeyEntropyMode, "IssuedToken.DefaultKeyEntropyMode");
222                         Assert.AreEqual (30, element.IssuedToken.IssuedTokenRenewalThresholdPercentage, "IssuedToken.IssuedTokenRenewalThresholdPercentage");
223
224                         Assert.AreEqual (TokenImpersonationLevel.None, element.HttpDigest.ImpersonationLevel, "HttpDigest.ImpersonationLevel");
225                 }
226
227                 [Test]
228                 public void ClientCredentialsElement_defaults () {
229                         ClientCredentialsElement element = new ClientCredentialsElement ();
230
231                         Assert.AreEqual (typeof (ClientCredentials), element.BehaviorType, "BehaviorType");
232                         Assert.AreEqual ("clientCredentials", element.ConfigurationElementName, "ConfigurationElementName");
233
234                         Assert.AreEqual (true, element.SupportInteractive, "SupportInteractive");
235                         Assert.AreEqual (String.Empty, element.Type, "Type");
236
237                         Assert.AreEqual (String.Empty, element.ClientCertificate.FindValue, "ClientCertificate.FindValue");
238                         Assert.AreEqual (StoreLocation.CurrentUser, element.ClientCertificate.StoreLocation, "ClientCertificate.StoreLocation");
239                         Assert.AreEqual (StoreName.My, element.ClientCertificate.StoreName, "ClientCertificate.StoreName");
240                         Assert.AreEqual (X509FindType.FindBySubjectDistinguishedName, element.ClientCertificate.X509FindType, "ClientCertificate.X509FindType");
241
242                         Assert.AreEqual (String.Empty, element.ServiceCertificate.DefaultCertificate.FindValue, "ServiceCertificate.DefaultCertificate.FindValue");
243                         Assert.AreEqual (StoreLocation.CurrentUser, element.ServiceCertificate.DefaultCertificate.StoreLocation, "ServiceCertificate.DefaultCertificate.StoreLocation");
244                         Assert.AreEqual (StoreName.My, element.ServiceCertificate.DefaultCertificate.StoreName, "ServiceCertificate.DefaultCertificate.StoreName");
245                         Assert.AreEqual (X509FindType.FindBySubjectDistinguishedName, element.ServiceCertificate.DefaultCertificate.X509FindType, "ServiceCertificate.DefaultCertificate.X509FindType");
246
247                         Assert.AreEqual (String.Empty, element.ServiceCertificate.Authentication.CustomCertificateValidatorType, "ServiceCertificate.Authentication.CustomCertificateValidatorType");
248                         Assert.AreEqual (X509CertificateValidationMode.ChainTrust, element.ServiceCertificate.Authentication.CertificateValidationMode, "ServiceCertificate.Authentication.CertificateValidationMode");
249                         Assert.AreEqual (X509RevocationMode.Online, element.ServiceCertificate.Authentication.RevocationMode, "ServiceCertificate.Authentication.RevocationMode");
250                         Assert.AreEqual (StoreLocation.CurrentUser, element.ServiceCertificate.Authentication.TrustedStoreLocation, "ServiceCertificate.Authentication.TrustedStoreLocation");
251
252                         Assert.AreEqual (true, element.Windows.AllowNtlm, "Windows.AllowNtlm");
253                         Assert.AreEqual (TokenImpersonationLevel.Identification, element.Windows.AllowedImpersonationLevel, "Windows.AllowedImpersonationLevel");
254
255                         Assert.AreEqual (true, element.IssuedToken.CacheIssuedTokens, "IssuedToken.CacheIssuedTokens");
256                         Assert.AreEqual (SecurityKeyEntropyMode.CombinedEntropy, element.IssuedToken.DefaultKeyEntropyMode, "IssuedToken.DefaultKeyEntropyMode");
257                         Assert.AreEqual (60, element.IssuedToken.IssuedTokenRenewalThresholdPercentage, "IssuedToken.IssuedTokenRenewalThresholdPercentage");
258
259                         Assert.AreEqual (TokenImpersonationLevel.Identification, element.HttpDigest.ImpersonationLevel, "HttpDigest.ImpersonationLevel");
260                 }
261         }
262 }