2003-12-29 Sebastien Pouliot <spouliot@videotron.ca>
authorSebastien Pouliot <sebastien@ximian.com>
Tue, 30 Dec 2003 04:16:32 +0000 (04:16 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Tue, 30 Dec 2003 04:16:32 +0000 (04:16 -0000)
* WindowsIdentityTest.cs: New. Partial unit test for WindowsIdentity.
* WindowsPrincipalTest.cs: New. Partial unit test for WindowsPrincipal.

svn path=/trunk/mcs/; revision=21545

mcs/class/corlib/Test/System.Security.Principal/ChangeLog
mcs/class/corlib/Test/System.Security.Principal/WindowsIdentityTest.cs [new file with mode: 0755]
mcs/class/corlib/Test/System.Security.Principal/WindowsPrincipalTest.cs [new file with mode: 0755]

index b72539f3ba07be7d19aa3ac29aecb7042089715f..33b0bf42a360721c72080ff203955864add09888 100644 (file)
@@ -1,3 +1,8 @@
+2003-12-29  Sebastien Pouliot  <spouliot@videotron.ca>
+
+       * WindowsIdentityTest.cs: New. Partial unit test for WindowsIdentity.
+       * WindowsPrincipalTest.cs: New. Partial unit test for WindowsPrincipal.
+
 2003-07-01  Sebastien Pouliot  <spouliot@videotron.ca>
 
        * GenericIdentityTest.cs: New. Complete unit test.
diff --git a/mcs/class/corlib/Test/System.Security.Principal/WindowsIdentityTest.cs b/mcs/class/corlib/Test/System.Security.Principal/WindowsIdentityTest.cs
new file mode 100755 (executable)
index 0000000..3450714
--- /dev/null
@@ -0,0 +1,108 @@
+//
+// WindowsIdentityTest.cs - NUnit Test Cases for WindowsIdentity
+//
+// Author:
+//     Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using NUnit.Framework;
+using System;
+using System.Runtime.Serialization;
+using System.Security.Principal;
+
+namespace MonoTests.System.Security.Principal {
+
+       [TestFixture]
+       public class WindowsIdentityTest : Assertion {
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ConstructorIntPtrZero () 
+               {
+                       WindowsIdentity id = new WindowsIdentity (IntPtr.Zero);
+               }
+
+               [Test]
+               //[ExpectedException (typeof (ArgumentNullException))]
+               [ExpectedException (typeof (NullReferenceException))]
+               public void ConstructorW2KS1_Null () 
+               {
+                       WindowsIdentity id = new WindowsIdentity (null);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ConstructorW2KS1 () 
+               {
+                       WindowsIdentity id = new WindowsIdentity (@"FARSCAPE\spouliot");
+               }
+
+               [Test]
+               //[ExpectedException (typeof (ArgumentNullException))]
+               [ExpectedException (typeof (NullReferenceException))]
+               public void ConstructorW2KS2_NullType () 
+               {
+                       WindowsIdentity id = new WindowsIdentity (null, "NTLM");
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ConstructorW2KS2_UserNull() 
+               {
+                       WindowsIdentity id = new WindowsIdentity (@"FARSCAPE\spouliot", null);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void ConstructorW2KS2 () 
+               {
+                       WindowsIdentity id = new WindowsIdentity (@"FARSCAPE\spouliot", "NTLM");
+               }
+
+               [Test]
+               public void Anonymous () 
+               {
+                       WindowsIdentity id = WindowsIdentity.GetAnonymous ();
+                       AssertEquals ("AuthenticationType", String.Empty, id.AuthenticationType);
+                       Assert ("IsAnonymous", id.IsAnonymous);
+                       Assert ("IsAuthenticated", !id.IsAuthenticated);
+                       Assert ("IsGuest", !id.IsGuest);
+                       Assert ("IsSystem", !id.IsSystem);
+                       AssertEquals ("Token", IntPtr.Zero, id.Token);
+                       AssertEquals ("Name", String.Empty, id.Name);
+               }
+
+               [Test]
+               [Ignore ("not currently supported on mono")]
+               public void Current () 
+               {
+                       WindowsIdentity id = WindowsIdentity.GetCurrent ();
+                       AssertEquals ("AuthenticationType", "NTLM", id.AuthenticationType);
+                       Assert ("IsAnonymous", !id.IsAnonymous);
+                       Assert ("IsAuthenticated", id.IsAuthenticated);
+                       Assert ("IsGuest", !id.IsGuest);
+                       Assert ("IsSystem", !id.IsSystem);
+                       Assert ("Token", (IntPtr.Zero != id.Token));
+                       // e.g. FARSCAPE\spouliot
+                       Assert ("Name", (id.Name.IndexOf (@"\") > 0));
+               }
+
+               [Test]
+               public void Interface () 
+               {
+                       WindowsIdentity id = WindowsIdentity.GetAnonymous ();
+
+                       IIdentity i = (id as IIdentity);
+                       AssertNotNull ("IIdentity", i);
+
+                       IDeserializationCallback dc = (id as IDeserializationCallback);
+                       AssertNotNull ("IDeserializationCallback", dc);
+#if NET_1_1
+                       ISerializable s = (id as ISerializable);
+                       AssertNotNull ("ISerializable", s);
+#endif
+               }
+       }
+}
diff --git a/mcs/class/corlib/Test/System.Security.Principal/WindowsPrincipalTest.cs b/mcs/class/corlib/Test/System.Security.Principal/WindowsPrincipalTest.cs
new file mode 100755 (executable)
index 0000000..cc989cc
--- /dev/null
@@ -0,0 +1,86 @@
+//
+// WindowsPrincipalTest.cs - NUnit Test Cases for WindowsPrincipal
+//
+// Author:
+//     Sebastien Pouliot (spouliot@motus.com)
+//
+// (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+
+using NUnit.Framework;
+using System;
+using System.Runtime.Serialization;
+using System.Security.Principal;
+
+namespace MonoTests.System.Security.Principal {
+
+       [TestFixture]
+       public class WindowsPrincipalTest : Assertion {
+
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ConstructorNull () 
+               {
+                       WindowsPrincipal p = new WindowsPrincipal (null);
+               }
+
+               [Test]
+               [Ignore ("not currently supported on mono")]
+               public void Current () 
+               {
+                       WindowsPrincipal p = new WindowsPrincipal (WindowsIdentity.GetCurrent ());
+                       AssertNotNull ("Identity", p.Identity);
+
+                       bool test;
+                       // we don't Assert as we don't know the current user roles
+                       test = p.IsInRole (WindowsBuiltInRole.Administrator);
+                       test = p.IsInRole (WindowsBuiltInRole.BackupOperator);
+                       test = p.IsInRole (WindowsBuiltInRole.Guest);
+                       test = p.IsInRole (WindowsBuiltInRole.PowerUser);
+                       test = p.IsInRole (WindowsBuiltInRole.Replicator);
+                       test = p.IsInRole (WindowsBuiltInRole.User);
+
+                       // doesn't work under XP in a workgroup (ArgumentException)
+//                     test = p.IsInRole (WindowsBuiltInRole.AccountOperator);
+//                     test = p.IsInRole (WindowsBuiltInRole.PrintOperator);
+//                     test = p.IsInRole (WindowsBuiltInRole.SystemOperator);
+               }
+
+               [Test]
+               [Ignore ("not currently supported on mono")]
+               public void Anonymous () 
+               {
+                       WindowsPrincipal p = new WindowsPrincipal (WindowsIdentity.GetAnonymous ());
+                       AssertNotNull ("Identity", p.Identity);
+
+                       Assert ("Administrator", !p.IsInRole (WindowsBuiltInRole.Administrator));
+                       Assert ("BackupOperator", !p.IsInRole (WindowsBuiltInRole.BackupOperator));
+                       Assert ("Guest", !p.IsInRole (WindowsBuiltInRole.Guest));
+                       Assert ("PowerUser", !p.IsInRole (WindowsBuiltInRole.PowerUser));
+                       Assert ("Replicator", !p.IsInRole (WindowsBuiltInRole.Replicator));
+                       Assert ("User", !p.IsInRole (WindowsBuiltInRole.User));
+
+                       // doesn't work under XP in a workgroup (ArgumentException)
+//                     Assert ("AccountOperator", !p.IsInRole (WindowsBuiltInRole.AccountOperator));
+//                     Assert ("PrintOperator", !p.IsInRole (WindowsBuiltInRole.PrintOperator));
+//                     Assert ("SystemOperator", !p.IsInRole (WindowsBuiltInRole.SystemOperator));
+               }
+
+               [Test]
+               //[ExpectedException (typeof (ArgumentNullException))]
+               public void IsInRole_Null ()
+               {
+                       WindowsPrincipal p = new WindowsPrincipal (WindowsIdentity.GetAnonymous ());
+                       Assert ("IsInRole(Null)", !p.IsInRole (null));
+               }
+
+               [Test]
+               public void Interface () 
+               {
+                       WindowsPrincipal wp = new WindowsPrincipal (WindowsIdentity.GetAnonymous ());
+
+                       IPrincipal p = (wp as IPrincipal);
+                       AssertNotNull ("IPrincipal", p);
+               }
+       }
+}