[sgen] Make sure we don't sweep a block if we're not supposed to
[mono.git] / mcs / class / corlib / Test / System.Security.Claims / ClaimsIdentityTest.cs
1 //
2 // ClaimsIdentityTest.cs - NUnit Test Cases for System.Security.Claims.ClaimsIdentity
3 //
4
5 #if NET_4_5
6
7 using NUnit.Framework;
8 using System;
9 using System.Collections.Generic;
10 using System.Linq;
11 using System.Security.Claims;
12 using System.Security.Principal;
13
14 namespace MonoTests.System.Security.Claims
15 {
16         [TestFixture]
17         public class ClaimsIdentityTest
18         {
19                 #region Ctor Empty
20
21                 [Test]
22                 public void EmptyCtorWorks ()
23                 {
24                         var id = new ClaimsIdentity ();
25                         Assert.IsNull (id.AuthenticationType, "#1");
26                         Assert.IsNull (id.Actor, "#2");
27                         Assert.IsNull (id.BootstrapContext, "#3");
28                         Assert.IsNotNull (id.Claims, "#4");
29                         Assert.AreEqual (0, id.Claims.Count (), "#5");
30                         Assert.IsFalse (id.IsAuthenticated, "#6");
31                         Assert.IsNull (id.Label, "#7");
32                         Assert.IsNull (id.Name, "#8");
33                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
34                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
35                 }
36
37                 #endregion
38
39                 #region Ctor AuthTypeOnly
40
41                 [Test]
42                 public void AuthTypeOnlyCtorEmptyWorks ()
43                 {
44                         var id = new ClaimsIdentity ("");
45                         //NOTE: According to MSDN the id.AuthenticationType should be null, but it isn't on .Net 4.5
46                         //Assert.IsNull (id.AuthenticationType, "#1");
47                         Assert.AreEqual ("", id.AuthenticationType, "#1");
48                         Assert.IsNull (id.Actor, "#2");
49                         Assert.IsNull (id.BootstrapContext, "#3");
50                         Assert.IsNotNull (id.Claims, "#4");
51                         Assert.AreEqual (0, id.Claims.Count (), "#5");
52                         Assert.IsFalse (id.IsAuthenticated, "#6");
53                         Assert.IsNull (id.Label, "#7");
54                         Assert.IsNull (id.Name, "#8");
55                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
56                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
57                 }
58
59                 [Test]
60                 public void AuthTypeOnlyCtorNullWorks ()
61                 {
62                         var id = new ClaimsIdentity ((string)null);
63                         Assert.IsNull (id.AuthenticationType, "#1");
64                         Assert.IsNull (id.Actor, "#2");
65                         Assert.IsNull (id.BootstrapContext, "#3");
66                         Assert.IsNotNull (id.Claims, "#4");
67                         Assert.AreEqual (0, id.Claims.Count (), "#5");
68                         Assert.IsFalse (id.IsAuthenticated, "#6");
69                         Assert.IsNull (id.Label, "#7");
70                         Assert.IsNull (id.Name, "#8");
71                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
72                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
73                 }
74
75                 [Test]
76                 public void AuthTypeOnlyCtorNotEmptyWorks ()
77                 {
78                         var id = new ClaimsIdentity ("auth_type");
79                         Assert.AreEqual ("auth_type", id.AuthenticationType, "#1");
80                         Assert.IsNull (id.Actor, "#2");
81                         Assert.IsNull (id.BootstrapContext, "#3");
82                         Assert.IsNotNull (id.Claims, "#4");
83                         Assert.AreEqual (0, id.Claims.Count (), "#5");
84                         Assert.IsTrue (id.IsAuthenticated, "#6");
85                         Assert.IsNull (id.Label, "#7");
86                         Assert.IsNull (id.Name, "#8");
87                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
88                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
89                 }
90
91                 #endregion
92
93                 #region Ctor IEnumerable<Claim>
94
95                 [Test]
96                 public void EnumClaimsCtorNullWorks ()
97                 {
98                         var id = new ClaimsIdentity ((IEnumerable<Claim>)null);
99                         Assert.IsNull (id.AuthenticationType, "#1");
100                         Assert.IsNull (id.Actor, "#2");
101                         Assert.IsNull (id.BootstrapContext, "#3");
102                         Assert.IsNotNull (id.Claims, "#4");
103                         Assert.AreEqual (0, id.Claims.Count (), "#5");
104                         Assert.IsFalse (id.IsAuthenticated, "#6");
105                         Assert.IsNull (id.Label, "#7");
106                         Assert.IsNull (id.Name, "#8");
107                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
108                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
109                 }
110
111                 [Test]
112                 public void EnumClaimsCtorEmptyWorks ()
113                 {
114                         var id = new ClaimsIdentity ((IEnumerable<Claim>)null);
115                         Assert.IsNull (id.AuthenticationType, "#1");
116                         Assert.IsNull (id.Actor, "#2");
117                         Assert.IsNull (id.BootstrapContext, "#3");
118                         Assert.IsNotNull (id.Claims, "#4");
119                         Assert.AreEqual (0, id.Claims.Count (), "#5");
120                         Assert.IsFalse (id.IsAuthenticated, "#6");
121                         Assert.IsNull (id.Label, "#7");
122                         Assert.IsNull (id.Name, "#8");
123                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
124                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
125                 }
126
127                 [Test]
128                 public void EnumClaimsCtorWithClaimsWithNameWorks ()
129                 {
130                         var id = new ClaimsIdentity (
131                                            new [] {
132                                         new Claim ("claim_type", "claim_value"),
133                                         new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
134                                 });
135                         Assert.IsNull (id.AuthenticationType, "#1");
136                         Assert.IsNull (id.Actor, "#2");
137                         Assert.IsNull (id.BootstrapContext, "#3");
138                         Assert.IsNotNull (id.Claims, "#4");
139                         Assert.AreEqual (2, id.Claims.Count (), "#5");
140                         Assert.IsFalse (id.IsAuthenticated, "#6");
141                         Assert.IsNull (id.Label, "#7");
142                         Assert.AreEqual ("claim_name_value", id.Name, "#8");
143                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
144                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
145                 }
146
147                 [Test]
148                 public void EnumClaimsCtorWithClaimsWithoutNameWorks ()
149                 {
150                         var id = new ClaimsIdentity (
151                                            new [] {
152                                         new Claim ("claim_type", "claim_value"),
153                                         new Claim (ClaimsIdentity.DefaultNameClaimType + "_x", "claim_name_value"), 
154                                 });
155                         Assert.IsNull (id.AuthenticationType, "#1");
156                         Assert.IsNull (id.Actor, "#2");
157                         Assert.IsNull (id.BootstrapContext, "#3");
158                         Assert.IsNotNull (id.Claims, "#4");
159                         Assert.AreEqual (2, id.Claims.Count (), "#5");
160                         Assert.IsFalse (id.IsAuthenticated, "#6");
161                         Assert.IsNull (id.Label, "#7");
162                         Assert.IsNull (id.Name, "#8");
163                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
164                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
165                 }
166
167                 #endregion
168
169                 #region Ctor IEnumerable<Claim>, authType, nameType, roleType
170
171                 [Test]
172                 public void EnumClaimsAuthNameRoleTypeCtorWorks ()
173                 {
174                         var id = new ClaimsIdentity (new [] {
175                                 new Claim ("claim_type", "claim_value"),
176                                 new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
177                                 new Claim ("claim_role_type", "claim_role_value"), 
178                         },
179                                            "test_auth_type", "test_name_type", "claim_role_type");
180                         Assert.AreEqual ("test_auth_type", id.AuthenticationType, "#1");
181                         Assert.IsNull (id.Actor, "#2");
182                         Assert.IsNull (id.BootstrapContext, "#3");
183                         Assert.IsNotNull (id.Claims, "#4");
184                         Assert.AreEqual (3, id.Claims.Count (), "#5");
185                         Assert.IsTrue (id.IsAuthenticated, "#6");
186                         Assert.IsNull (id.Label, "#7");
187                         Assert.IsNull (id.Name, "#8");
188                         Assert.AreEqual ("test_name_type", id.NameClaimType, "#9");
189                         Assert.AreEqual ("claim_role_type", id.RoleClaimType, "#10");
190                 }
191
192                 [Test]
193                 public void EnumClaimsAuthNameRoleTypeCtorAllArgsNullWorks ()
194                 {
195                         var id = new ClaimsIdentity ((IEnumerable<Claim>)null, (string)null, (string)null, (string)null);
196                         Assert.IsNull (id.AuthenticationType, "#1");
197                         Assert.IsNull (id.Actor, "#2");
198                         Assert.IsNull (id.BootstrapContext, "#3");
199                         Assert.IsNotNull (id.Claims, "#4");
200                         Assert.AreEqual (0, id.Claims.Count (), "#5");
201                         Assert.IsFalse (id.IsAuthenticated, "#6");
202                         Assert.IsNull (id.Label, "#7");
203                         Assert.IsNull (id.Name, "#8");
204                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
205                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
206                 }
207
208                 [Test]
209                 public void EnumClaimsAuthNameRoleTypeCtorAllArgsEmptyWorks ()
210                 {
211                         var id = new ClaimsIdentity (new Claim [0], "", "", "");
212                         //NOTE: According to MSDN the id.AuthenticationType should be null, but it isn't on .Net 4.5
213                         //Assert.IsNull (id.AuthenticationType, "#1");
214                         Assert.AreEqual ("", id.AuthenticationType, "#1");
215                         Assert.IsNull (id.Actor, "#2");
216                         Assert.IsNull (id.BootstrapContext, "#3");
217                         Assert.IsNotNull (id.Claims, "#4");
218                         Assert.AreEqual (0, id.Claims.Count (), "#5");
219                         Assert.IsFalse (id.IsAuthenticated, "#6");
220                         Assert.IsNull (id.Label, "#7");
221                         Assert.IsNull (id.Name, "#8");
222                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
223                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
224                 }
225
226                 [Test]
227                 public void EnumClaimsAuthNameRoleTypeCtorWithTwoClaimsAndTypesEmptyWorks ()
228                 {
229                         var id = new ClaimsIdentity (
230                                            new [] {
231                                         new Claim ("claim_type", "claim_value"),
232                                         new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
233                                 },
234                                            "", "", "");
235                         //NOTE: According to MSDN the id.AuthenticationType should be null, but it isn't on .Net 4.5
236                         //Assert.IsNull (id.AuthenticationType, "#1");
237                         Assert.AreEqual ("", id.AuthenticationType, "#1");
238                         Assert.IsNull (id.Actor, "#2");
239                         Assert.IsNull (id.BootstrapContext, "#3");
240                         Assert.IsNotNull (id.Claims, "#4");
241                         Assert.AreEqual (2, id.Claims.Count (), "#5");
242                         Assert.IsFalse (id.IsAuthenticated, "#6");
243                         Assert.IsNull (id.Label, "#7");
244                         Assert.AreEqual ("claim_name_value", id.Name, "#8");
245                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
246                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
247                 }
248
249                 [Test]
250                 public void EnumClaimsAuthNameRoleTypeCtorWithTwoClaimsAndTypesNullWorks ()
251                 {
252                         var id = new ClaimsIdentity (
253                                            new [] {
254                                         new Claim ("claim_type", "claim_value"),
255                                         new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
256                                 }, 
257                                            (string)null, (string)null, (string)null);
258                         Assert.IsNull (id.AuthenticationType, "#1");
259                         Assert.IsNull (id.Actor, "#2");
260                         Assert.IsNull (id.BootstrapContext, "#3");
261                         Assert.IsNotNull (id.Claims, "#4");
262                         Assert.AreEqual (2, id.Claims.Count (), "#5");
263                         Assert.IsFalse (id.IsAuthenticated, "#6");
264                         Assert.IsNull (id.Label, "#7");
265                         Assert.AreEqual ("claim_name_value", id.Name, "#8");
266                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
267                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
268                 }
269
270                 #endregion
271
272                 #region Ctor IIdentity, IEnumerable<Claim>, authType, nameType, roleType
273
274                 [Test]
275                 public void IdentityEnumClaimsAuthNameRoleTypeCtorNullsWorks ()
276                 {
277                         var id = new ClaimsIdentity ((IIdentity)null, (IEnumerable<Claim>)null, (string)null, (string)null, (string)null);
278                         Assert.IsNull (id.AuthenticationType, "#1");
279                         Assert.IsNull (id.Actor, "#2");
280                         Assert.IsNull (id.BootstrapContext, "#3");
281                         Assert.IsNotNull (id.Claims, "#4");
282                         Assert.AreEqual (0, id.Claims.Count (), "#5");
283                         Assert.IsFalse (id.IsAuthenticated, "#6");
284                         Assert.IsNull (id.Label, "#7");
285                         Assert.IsNull (id.Name, "#8");
286                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
287                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
288                 }
289
290                 [Test]
291                 public void IdentityEnumClaimsAuthNameRoleTypeCtorIdentityNullRestEmptyWorks ()
292                 {
293                         var id = new ClaimsIdentity (null, new Claim [0], "", "", "");
294                         //NOTE: According to MSDN the id.AuthenticationType should be null, but it isn't on .Net 4.5
295                         //Assert.IsNull (id.AuthenticationType, "#1");
296                         Assert.AreEqual ("", id.AuthenticationType, "#1");
297                         Assert.IsNull (id.Actor, "#2");
298                         Assert.IsNull (id.BootstrapContext, "#3");
299                         Assert.IsNotNull (id.Claims, "#4");
300                         Assert.AreEqual (0, id.Claims.Count (), "#5");
301                         Assert.IsFalse (id.IsAuthenticated, "#6");
302                         Assert.IsNull (id.Label, "#7");
303                         Assert.IsNull (id.Name, "#8");
304                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
305                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
306                 }
307
308                 [Test]
309                 public void IdentityEnumClaimsAuthNameRoleTypeCtorNullClaimsArrayEmptyTypesWorks ()
310                 {
311                         var id = new ClaimsIdentity (
312                                            null,
313                                            new [] {
314                                         new Claim ("claim_type", "claim_value"),
315                                         new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
316                                 }, 
317                                            "", "", "");
318                         //NOTE: According to MSDN the id.AuthenticationType should be null, but it isn't on .Net 4.5
319                         //Assert.IsNull (id.AuthenticationType, "#1");
320                         Assert.AreEqual ("", id.AuthenticationType, "#1");
321                         Assert.IsNull (id.Actor, "#2");
322                         Assert.IsNull (id.BootstrapContext, "#3");
323                         Assert.IsNotNull (id.Claims, "#4");
324                         Assert.AreEqual (2, id.Claims.Count (), "#5");
325                         Assert.IsFalse (id.IsAuthenticated, "#6");
326                         Assert.IsNull (id.Label, "#7");
327                         Assert.AreEqual ("claim_name_value", id.Name, "#8");
328                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
329                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
330                 }
331
332                 [Test]
333                 public void IdentityEnumClaimsAuthNameRoleTypeCtorNullClaimsArrayNullsWorks ()
334                 {
335                         var id = new ClaimsIdentity (
336                                            null,
337                                            new [] {
338                                         new Claim ("claim_type", "claim_value"),
339                                         new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
340                                 },
341                                            (string)null, (string)null, (string)null);
342                         Assert.IsNull (id.AuthenticationType, "#1");
343                         Assert.IsNull (id.Actor, "#2");
344                         Assert.IsNull (id.BootstrapContext, "#3");
345                         Assert.IsNotNull (id.Claims, "#4");
346                         Assert.AreEqual (2, id.Claims.Count (), "#5");
347                         Assert.IsFalse (id.IsAuthenticated, "#6");
348                         Assert.IsNull (id.Label, "#7");
349                         Assert.AreEqual ("claim_name_value", id.Name, "#8");
350                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
351                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
352                 }
353
354                 [Test]
355                 public void IdentityEnumClaimsAuthNameRoleTypeCtorNullIdentityRestFilledWorks ()
356                 {
357                         var id = new ClaimsIdentity (
358                                            null,
359                                            new [] {
360                                         new Claim ("claim_type", "claim_value"),
361                                         new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
362                                         new Claim ("claim_role_type", "claim_role_value"), 
363                                 },
364                                            "test_auth_type", "test_name_type", "claim_role_type");
365                         Assert.AreEqual ("test_auth_type", id.AuthenticationType, "#1");
366                         Assert.IsNull (id.Actor, "#2");
367                         Assert.IsNull (id.BootstrapContext, "#3");
368                         Assert.IsNotNull (id.Claims, "#4");
369                         Assert.AreEqual (3, id.Claims.Count (), "#5");
370                         Assert.IsTrue (id.IsAuthenticated, "#6");
371                         Assert.IsNull (id.Label, "#7");
372                         Assert.IsNull (id.Name, "#8");
373                         Assert.AreEqual ("test_name_type", id.NameClaimType, "#9");
374                         Assert.AreEqual ("claim_role_type", id.RoleClaimType, "#10");
375                 }
376
377                 [Test]
378                 public void IdentityEnumClaimsAuthNameRoleTypeCtorClaimsIdentityRestFilledWorks ()
379                 {
380                         var baseId = new ClaimsIdentity (
381                                                    new[] { new Claim ("base_claim_type", "base_claim_value") },
382                                                    "base_auth_type");
383
384                         baseId.Actor = new ClaimsIdentity ("base_actor");
385                         baseId.BootstrapContext = "bootstrap_context";
386                         baseId.Label = "base_label";
387
388                         Assert.IsTrue (baseId.IsAuthenticated, "#0");
389
390                         var id = new ClaimsIdentity (
391                                            baseId,
392                                            new [] {
393                                         new Claim ("claim_type", "claim_value"),
394                                         new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
395                                         new Claim ("claim_role_type", "claim_role_value"), 
396                                 },
397                                            "test_auth_type", "test_name_type", "claim_role_type");
398
399                         Assert.AreEqual ("test_auth_type", id.AuthenticationType, "#1");
400
401                         Assert.IsNotNull (id.Actor, "#2");
402                         Assert.AreEqual ("base_actor", id.Actor.AuthenticationType, "#2b");
403                         Assert.AreEqual ("bootstrap_context", id.BootstrapContext, "#3");
404                         Assert.IsNotNull (id.Claims, "#4");
405                         Assert.AreEqual (4, id.Claims.Count (), "#5");
406                         Assert.AreEqual ("base_claim_type", id.Claims.First ().Type);
407                         Assert.IsTrue (id.IsAuthenticated, "#6");
408                         Assert.AreEqual ("base_label", id.Label, "#7");
409                         Assert.IsNull (id.Name, "#8");
410                         Assert.AreEqual ("test_name_type", id.NameClaimType, "#9");
411                         Assert.AreEqual ("claim_role_type", id.RoleClaimType, "#10");
412                 }
413
414                 [Test]
415                 public void IdentityEnumClaimsAuthNameRoleTypeCtorNonClaimsIdentityRestEmptyWorks ()
416                 {
417                         var baseId = new TestIdentity { Name = "base_name", AuthenticationType = "TestId_AuthType" };
418
419                         var id = new ClaimsIdentity (
420                                            baseId,
421                                            new [] {
422                                         new Claim ("claim_type", "claim_value"),
423                                         new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
424                                         new Claim ("claim_role_type", "claim_role_value"), 
425                                 },
426                                            "", "", "");
427
428                         Assert.AreEqual ("TestId_AuthType", id.AuthenticationType, "#1");
429
430                         Assert.IsNull (id.Actor, "#2");
431                         Assert.IsNull (id.BootstrapContext, "#3");
432                         Assert.IsNotNull (id.Claims, "#4");
433                         Assert.AreEqual (4, id.Claims.Count (), "#5");
434                         Assert.AreEqual (2, id.Claims.Count (_ => _.Type == ClaimsIdentity.DefaultNameClaimType), "#5b");
435                         Assert.IsTrue (id.IsAuthenticated, "#6");
436                         Assert.IsNull (id.Label, "#7");
437                         Assert.AreEqual ("base_name", id.Name, "#8");
438                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
439                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
440                 }
441
442                 #endregion
443
444                 #region Ctor IIdentity, IEnumerable<Claim>
445
446                 [Test]
447                 public void IdentityEnumClaimsCtorClaimsIdentityClaimsWorks ()
448                 {
449                         var baseId = new ClaimsIdentity (
450                                                    new [] { new Claim ("base_claim_type", "base_claim_value") },
451                                                    "base_auth_type", "base_name_claim_type", null);
452
453                         baseId.Actor = new ClaimsIdentity ("base_actor");
454                         baseId.BootstrapContext = "bootstrap_context";
455                         baseId.Label = "base_label";
456
457                         Assert.IsTrue (baseId.IsAuthenticated, "#0");
458
459                         var id = new ClaimsIdentity (
460                                            baseId,
461                                            new [] {
462                                         new Claim ("claim_type", "claim_value"),
463                                         new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
464                                         new Claim ("claim_role_type", "claim_role_value"), 
465                                 });
466
467                         Assert.AreEqual ("base_auth_type", id.AuthenticationType, "#1");
468
469                         Assert.IsNotNull (id.Actor, "#2");
470                         Assert.AreEqual ("base_actor", id.Actor.AuthenticationType, "#2b");
471                         Assert.AreEqual ("bootstrap_context", id.BootstrapContext, "#3");
472                         Assert.IsNotNull (id.Claims, "#4");
473                         Assert.AreEqual (4, id.Claims.Count (), "#5");
474                         Assert.AreEqual ("base_claim_type", id.Claims.First ().Type, "#5b");
475                         Assert.IsTrue (id.IsAuthenticated, "#6");
476                         Assert.AreEqual ("base_label", id.Label, "#7");
477                         Assert.IsNull (id.Name, "#8");
478                         Assert.AreEqual ("base_name_claim_type", id.NameClaimType, "#9");
479                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
480                 }
481
482                 [Test]
483                 public void IdentityEnumClaimsCtorNonClaimsIdentityClaimsWorks ()
484                 {
485                         var baseId = new TestIdentity {
486                                 Name = "base_name", AuthenticationType = "TestId_AuthType"
487                         };
488
489                         var id = new ClaimsIdentity (
490                                            baseId,
491                                            new [] {
492                                         new Claim ("claim_type", "claim_value"),
493                                         new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
494                                         new Claim ("claim_role_type", "claim_role_value"), 
495                                 });
496
497                         Assert.AreEqual ("TestId_AuthType", id.AuthenticationType, "#1");
498
499                         Assert.IsNull (id.Actor, "#2");
500                         Assert.IsNull (id.BootstrapContext, "#3");
501                         Assert.IsNotNull (id.Claims, "#4");
502                         Assert.AreEqual (4, id.Claims.Count (), "#5");
503                         Assert.AreEqual (2, id.Claims.Count (_ => _.Type == ClaimsIdentity.DefaultNameClaimType), "#5b");
504                         Assert.IsTrue (id.IsAuthenticated, "#6");
505                         Assert.IsNull (id.Label, "#7");
506                         Assert.AreEqual ("base_name", id.Name, "#8");
507                         Assert.AreEqual (ClaimsIdentity.DefaultNameClaimType, id.NameClaimType, "#9");
508                         Assert.AreEqual (ClaimsIdentity.DefaultRoleClaimType, id.RoleClaimType, "#10");
509                 }
510
511                 #endregion
512
513                 [Test]
514                 public void FindCaseInsensivity ()
515                 {
516                         var claim_type = new Claim("TYpe", "value");
517                         var id = new ClaimsIdentity (
518                                 new[] { claim_type },
519                                 "base_auth_type", "base_name_claim_type", null);
520
521                         var f1 = id.FindFirst ("tyPe");
522                         Assert.AreEqual ("value", f1.Value, "#1");
523
524                         var f2 = id.FindAll ("tyPE").First ();
525                         Assert.AreEqual ("value", f2.Value, "#2");
526                 }
527
528                 [Test]
529                 public void HasClaim_typeValue_Works()
530                 {
531                         var id = new ClaimsIdentity(
532                         new[] {
533                                 new Claim ("claim_type", "claim_value"),
534                                 new Claim (ClaimsIdentity.DefaultNameClaimType, "claim_name_value"), 
535                                 new Claim ("claim_role_type", "claim_role_value"), 
536                         }, "test_authority");
537
538                         Assert.IsTrue (id.HasClaim("claim_type", "claim_value"), "#1");
539                         Assert.IsTrue (id.HasClaim("cLaIm_TyPe", "claim_value"), "#2");
540                         Assert.IsFalse (id.HasClaim("claim_type", "cLaIm_VaLuE"), "#3");
541                         Assert.IsFalse (id.HasClaim("Xclaim_type", "claim_value"), "#4");
542                         Assert.IsFalse (id.HasClaim("claim_type", "Xclaim_value"), "#5");
543           }
544         }
545
546         class TestIdentity : IIdentity
547         {
548                 public string Name {
549                         get;
550                         set;
551                 }
552
553                 public string AuthenticationType {
554                         get;
555                         set;
556                 }
557
558                 public bool IsAuthenticated {
559                         get { throw new NotImplementedException (); }
560                 }
561         }
562 }
563
564 #endif