Couple more 'bockbuild split' mixups
[mono.git] / mcs / class / System.ServiceModel / Test / System.ServiceModel.Security.Tokens / SecureConversationSecurityTokenParametersTest.cs
1 //
2 // SecureConversationSecurityTokenParametersTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.  http://www.novell.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 using System;
29 using System.Collections.Generic;
30 using System.Collections.ObjectModel;
31 using System.Net;
32 using System.Net.Security;
33 using System.IdentityModel.Selectors;
34 using System.ServiceModel;
35 using System.ServiceModel.Channels;
36 using System.ServiceModel.Description;
37 using System.ServiceModel.Security;
38 using System.ServiceModel.Security.Tokens;
39 using NUnit.Framework;
40
41 using Parameters = System.ServiceModel.Security.Tokens.SecureConversationSecurityTokenParameters;
42
43 namespace MonoTests.System.ServiceModel
44 {
45         [TestFixture]
46         public class SecureConversationSecurityTokenParametersTest
47         {
48                 class MyParameters : Parameters
49                 {
50                         public MyParameters ()
51                         {
52                         }
53
54                         public MyParameters (SecurityBindingElement element)
55                                 : base (element)
56                         {
57                         }
58
59                         public MyParameters (SecurityBindingElement element,
60                                 bool cancel,
61                                 ChannelProtectionRequirements requirements)
62                                 : base (element, cancel, requirements)
63                         {
64                         }
65
66                         public bool Asym {
67                                 get { return HasAsymmetricKey; }
68                         }
69
70                         public bool Client {
71                                 get { return SupportsClientAuthentication; }
72                         }
73
74                         public bool Win {
75                                 get { return SupportsClientWindowsIdentity; }
76                         }
77
78                         public bool Server {
79                                 get { return SupportsServerAuthentication; }
80                         }
81
82                         public void InitRequirement (SecurityTokenRequirement r)
83                         {
84                                 InitializeSecurityTokenRequirement (r);
85                         }
86                 }
87
88                 [Test]
89                 public void DefaultValues ()
90                 {
91                         MyParameters p = new MyParameters ();
92                         Assert.IsNull (p.BootstrapSecurityBindingElement, "#1-1");
93                         Assert.IsNotNull (p.BootstrapProtectionRequirements, "#1-2");
94                         Assert.AreEqual (true, p.RequireCancellation, "#1-3");
95
96                         Assert.AreEqual (false, p.Asym, "#1-4");
97                         // they cause NRE on winfx, likely a bug.
98                         //Assert.AreEqual (true, p.Client, "#1-5");
99                         //Assert.AreEqual (true, p.Win, "#1-6");
100                         //Assert.AreEqual (true, p.Server, "#1-7");
101
102                         p = new MyParameters (new AsymmetricSecurityBindingElement ());
103                         Assert.IsNotNull (p.BootstrapSecurityBindingElement, "#2-1");
104                         Assert.IsNotNull (p.BootstrapProtectionRequirements, "#2-2");
105                         Assert.AreEqual (true, p.RequireCancellation, "#2-3");
106
107                         Assert.AreEqual (false, p.Asym, "#2-4"); // regardless of binding element.
108                         Assert.AreEqual (false, p.Client, "#2-5");
109                         Assert.AreEqual (false, p.Win, "#2-6");
110                         Assert.AreEqual (false, p.Server, "#2-7");
111
112                         ChannelProtectionRequirements r =
113                                 p.BootstrapProtectionRequirements;
114                         Assert.IsTrue (r.IncomingSignatureParts.ChannelParts.IsBodyIncluded, "#3-1");
115                         Assert.IsTrue (r.OutgoingSignatureParts.ChannelParts.IsBodyIncluded, "#3-2");
116                         Assert.IsTrue (r.IncomingEncryptionParts.ChannelParts.IsBodyIncluded, "#3-3");
117                         Assert.IsTrue (r.OutgoingEncryptionParts.ChannelParts.IsBodyIncluded, "#3-4");
118                 }
119
120                 [Test]
121                 public void NullArgs ()
122                 {
123                         new Parameters ((SecurityBindingElement) null);
124                         new Parameters (null, false, null);
125                 }
126
127                 [Test]
128                 [Ignore ("winfx bug")]
129                 public void InitializeSecurityTokenRequirement ()
130                 {
131                         ServiceModelSecurityTokenRequirement r =
132                                 new InitiatorServiceModelSecurityTokenRequirement ();
133                         SymmetricSecurityBindingElement sbe = 
134 //                              new SymmetricSecurityBindingElement ();
135                                 new WSHttpBinding ().CreateBindingElements ().Find<SymmetricSecurityBindingElement> ();
136                         sbe.ProtectionTokenParameters = new X509SecurityTokenParameters ();
137 //                      MyParameters p = new MyParameters (sbe);
138                         // NRE occurs on winfx (likely a bug).
139 //                      p.InitRequirement (r);
140                 }
141         }
142 }