← Back to team overview

nunit-core team mailing list archive

Re: [Bug 712156] Re: Tests cannot use AppDomain.SetPrincipalPolicy

 

If you ran the test as the only test in an assembly, then NUnit would only
have read the CurrentPrincipal before it executed, so your point #2
is likely correct. I'll try to figure out some way to let you call
SetPrincipalPolicy before anything else runs. That will probably
call for a special setting or an assembly-level attribute.

Charlie

On Wed, Feb 2, 2011 at 6:31 PM, John Rusk <712156@xxxxxxxxxxxxxxxxxx> wrote:
> Thanks Charlie,
>
> 1. Yes, we are trying to affect the whole domain.  If we move it to
> SetupFixture, will that run before NUnit reads CurrentPrincipal (see
> #2)?  I'm guessing "no", unfortunately for us.
>
> 2. From my understanding of SetPrincipalPolicy, it will fail even after
> _reads_ of CurrentPrincipal(!!)  That's kind of the heart of this
> defect.
>
> 3. Yes, I have run this example test as the only test in an assembly.
>
> John
>
> --
> You received this bug notification because you are a member of NUnit
> Developers, which is subscribed to NUnit V2.
> https://bugs.launchpad.net/bugs/712156
>
> Title:
>  Tests cannot use AppDomain.SetPrincipalPolicy
>

-- 
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.
https://bugs.launchpad.net/bugs/712156

Title:
  Tests cannot use AppDomain.SetPrincipalPolicy

Status in NUnit V2 Test Framework:
  New

Bug description:
  I have some unit tests that call AppDomain.SetPrinicipalPolicy (in
  order to run tests using a Windows Principal).

  Unfortunately, SetPrincipalPolicy doesn't work in tests run from the
  NUnit 2.5.9 GUI runner.  (It does work, just fine, from the NUnit
  2.4.3 GUI Runner).

  Here is a unit test to demonstrate the problem.  The test passes (as
  it should) in UNnit 2.4.3, but fails in 2.5.9:

          [Test]
          public void CanSetPrincipalPolicy()
          {
              AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
              Assert.That(Thread.CurrentPrincipal is WindowsPrincipal);
          }

  The problem appears to be the fact that NUnit's TestExecutionContext
  is accessing Thread.CurrentPrincipal before the test runs.  As per the
  documentation for SetPrincipalPolicy, it _doesn't work_ if
  Thread.CurrentPrincipal has been used _before_ SetPrincipalPolicy.

  If this cannot be solved, then can a workaround pls be suggested. E.g.
  - something in a nUnit config file to set principal policy, OR
  - a documented way to execute SetPrincipalPolicy, in the same AppDomain as the tests, before TestExecutionContext touches Thread.CurrentPrincipal.
  Is there any way to have code, in NUnit, that runs in the same app domain as the tests, but BEFORE





References