2 // WindowsIdentityTest.cs - NUnit Test Cases for WindowsIdentity
5 // Sebastien Pouliot (spouliot@motus.com)
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
10 using NUnit.Framework;
12 using System.Runtime.Serialization;
13 using System.Security.Principal;
15 namespace MonoTests.System.Security.Principal {
18 public class WindowsIdentityTest : Assertion {
21 [ExpectedException (typeof (ArgumentException))]
22 public void ConstructorIntPtrZero ()
24 WindowsIdentity id = new WindowsIdentity (IntPtr.Zero);
28 //[ExpectedException (typeof (ArgumentNullException))]
29 [ExpectedException (typeof (NullReferenceException))]
30 public void ConstructorW2KS1_Null ()
32 WindowsIdentity id = new WindowsIdentity (null);
36 [ExpectedException (typeof (ArgumentException))]
37 public void ConstructorW2KS1 ()
39 WindowsIdentity id = new WindowsIdentity (@"FARSCAPE\spouliot");
43 //[ExpectedException (typeof (ArgumentNullException))]
44 [ExpectedException (typeof (NullReferenceException))]
45 public void ConstructorW2KS2_NullType ()
47 WindowsIdentity id = new WindowsIdentity (null, "NTLM");
51 [ExpectedException (typeof (ArgumentException))]
52 public void ConstructorW2KS2_UserNull()
54 WindowsIdentity id = new WindowsIdentity (@"FARSCAPE\spouliot", null);
58 [ExpectedException (typeof (ArgumentException))]
59 public void ConstructorW2KS2 ()
61 WindowsIdentity id = new WindowsIdentity (@"FARSCAPE\spouliot", "NTLM");
65 public void Anonymous ()
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);
78 [Ignore ("not currently supported on mono")]
79 public void Current ()
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));
93 public void Interface ()
95 WindowsIdentity id = WindowsIdentity.GetAnonymous ();
97 IIdentity i = (id as IIdentity);
98 AssertNotNull ("IIdentity", i);
100 IDeserializationCallback dc = (id as IDeserializationCallback);
101 AssertNotNull ("IDeserializationCallback", dc);
103 ISerializable s = (id as ISerializable);
104 AssertNotNull ("ISerializable", s);