[Mono-devel-list] [PATCH] Principal support for AppDomain and Thread
Sébastien Pouliot
spouliot at videotron.ca
Mon Feb 2 12:03:30 EST 2004
Hello Mono,
Here's a patch to add support principals to AppDomain and Thread (with unit
tests). This should enable role-based access control using imperative
permissions.
Some tests requiring unloading appdomains are [Ignore]d for the moment
because they freeze nunit-console.
IIRC unloading support is incomplte or maybe I did something wrong ?
Sébastien
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PrincipalSupport.diff
Type: application/octet-stream
Size: 11911 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20040202/8b331dde/attachment.obj
-------------- next part --------------
//
// AppDomainTest.cs - NUnit Test Cases for AppDomain
//
// Author:
// Sebastien Pouliot (sebastien at ximian.com)
//
// (C) 2004 Novell (http://www.novell.com)
//
using NUnit.Framework;
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Security;
using System.Security.Policy;
using System.Security.Principal;
namespace MonoTests.System {
[TestFixture]
public class AppDomainTest : Assertion {
private AppDomain ad;
private ArrayList files = new ArrayList ();
[TearDown]
public void Unload ()
{
if (ad != null) {
try {
// Mono has a problem unloading AppDomain
// AppDomain.Unload (ad);
ad = null;
}
catch {} // do not affect unit test results in TearDown
}
foreach (string fname in files) {
File.Delete (fname);
}
files.Clear ();
}
[Test]
public void SetThreadPrincipal ()
{
IIdentity i = new GenericIdentity ("sebastien at ximian.com", "rfc822");
IPrincipal p = new GenericPrincipal (i, null);
ad = AppDomain.CreateDomain ("SetThreadPrincipal");
ad.SetThreadPrincipal (p);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void SetThreadPrincipalNull ()
{
AppDomain.CurrentDomain.SetThreadPrincipal (null);
}
[Test]
[ExpectedException (typeof (PolicyException))]
public void SetThreadPrincipalTwice ()
{
IIdentity i = new GenericIdentity ("sebastien at ximian.com", "rfc822");
IPrincipal p = new GenericPrincipal (i, null);
ad = AppDomain.CreateDomain ("SetThreadPrincipalTwice");
ad.SetThreadPrincipal (p);
// you only live twice (or so James told me ;-)
ad.SetThreadPrincipal (p);
}
[Test]
[ExpectedException (typeof (AppDomainUnloadedException))]
[Ignore ("Unloading cause a failure in Mono - stopping the unit tests")]
public void SetThreadPrincipalUnloaded ()
{
ad = AppDomain.CreateDomain ("Ximian");
AppDomain.Unload (ad);
IIdentity i = new GenericIdentity ("sebastien at ximian.com", "rfc822");
IPrincipal p = new GenericPrincipal (i, null);
ad.SetThreadPrincipal (p);
}
[Test]
public void SetPrincipalPolicy_NoPrincipal ()
{
AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
}
[Test]
public void SetPrincipalPolicy_UnauthenticatedPrincipal ()
{
AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.UnauthenticatedPrincipal);
}
[Test]
public void SetPrincipalPolicy_WindowsPrincipal ()
{
AppDomain.CurrentDomain.SetPrincipalPolicy (PrincipalPolicy.WindowsPrincipal);
}
[Test]
[ExpectedException (typeof (AppDomainUnloadedException))]
[Ignore ("Unloading cause a failure in Mono - stopping the unit tests")]
public void SetPrincipalPolicyUnloaded ()
{
AppDomain ad = AppDomain.CreateDomain ("Ximian");
AppDomain.Unload (ad);
ad.SetPrincipalPolicy (PrincipalPolicy.NoPrincipal);
}
}
}
More information about the Mono-devel-list
mailing list