2003-12-29 Sebastien Pouliot <spouliot@videotron.ca>
[mono.git] / mcs / class / corlib / Test / System.Security.Principal / WindowsIdentityTest.cs
1 //
2 // WindowsIdentityTest.cs - NUnit Test Cases for WindowsIdentity
3 //
4 // Author:
5 //      Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
9
10 using NUnit.Framework;
11 using System;
12 using System.Runtime.Serialization;
13 using System.Security.Principal;
14
15 namespace MonoTests.System.Security.Principal {
16
17         [TestFixture]
18         public class WindowsIdentityTest : Assertion {
19
20                 [Test]
21                 [ExpectedException (typeof (ArgumentException))]
22                 public void ConstructorIntPtrZero () 
23                 {
24                         WindowsIdentity id = new WindowsIdentity (IntPtr.Zero);
25                 }
26
27                 [Test]
28                 //[ExpectedException (typeof (ArgumentNullException))]
29                 [ExpectedException (typeof (NullReferenceException))]
30                 public void ConstructorW2KS1_Null () 
31                 {
32                         WindowsIdentity id = new WindowsIdentity (null);
33                 }
34
35                 [Test]
36                 [ExpectedException (typeof (ArgumentException))]
37                 public void ConstructorW2KS1 () 
38                 {
39                         WindowsIdentity id = new WindowsIdentity (@"FARSCAPE\spouliot");
40                 }
41
42                 [Test]
43                 //[ExpectedException (typeof (ArgumentNullException))]
44                 [ExpectedException (typeof (NullReferenceException))]
45                 public void ConstructorW2KS2_NullType () 
46                 {
47                         WindowsIdentity id = new WindowsIdentity (null, "NTLM");
48                 }
49
50                 [Test]
51                 [ExpectedException (typeof (ArgumentException))]
52                 public void ConstructorW2KS2_UserNull() 
53                 {
54                         WindowsIdentity id = new WindowsIdentity (@"FARSCAPE\spouliot", null);
55                 }
56
57                 [Test]
58                 [ExpectedException (typeof (ArgumentException))]
59                 public void ConstructorW2KS2 () 
60                 {
61                         WindowsIdentity id = new WindowsIdentity (@"FARSCAPE\spouliot", "NTLM");
62                 }
63
64                 [Test]
65                 public void Anonymous () 
66                 {
67                         WindowsIdentity id = WindowsIdentity.GetAnonymous ();
68                         AssertEquals ("AuthenticationType", String.Empty, id.AuthenticationType);
69                         Assert ("IsAnonymous", id.IsAnonymous);
70                         Assert ("IsAuthenticated", !id.IsAuthenticated);
71                         Assert ("IsGuest", !id.IsGuest);
72                         Assert ("IsSystem", !id.IsSystem);
73                         AssertEquals ("Token", IntPtr.Zero, id.Token);
74                         AssertEquals ("Name", String.Empty, id.Name);
75                 }
76
77                 [Test]
78                 [Ignore ("not currently supported on mono")]
79                 public void Current () 
80                 {
81                         WindowsIdentity id = WindowsIdentity.GetCurrent ();
82                         AssertEquals ("AuthenticationType", "NTLM", id.AuthenticationType);
83                         Assert ("IsAnonymous", !id.IsAnonymous);
84                         Assert ("IsAuthenticated", id.IsAuthenticated);
85                         Assert ("IsGuest", !id.IsGuest);
86                         Assert ("IsSystem", !id.IsSystem);
87                         Assert ("Token", (IntPtr.Zero != id.Token));
88                         // e.g. FARSCAPE\spouliot
89                         Assert ("Name", (id.Name.IndexOf (@"\") > 0));
90                 }
91
92                 [Test]
93                 public void Interface () 
94                 {
95                         WindowsIdentity id = WindowsIdentity.GetAnonymous ();
96
97                         IIdentity i = (id as IIdentity);
98                         AssertNotNull ("IIdentity", i);
99
100                         IDeserializationCallback dc = (id as IDeserializationCallback);
101                         AssertNotNull ("IDeserializationCallback", dc);
102 #if NET_1_1
103                         ISerializable s = (id as ISerializable);
104                         AssertNotNull ("ISerializable", s);
105 #endif
106                 }
107         }
108 }