shekharpro / mb-unit

Automatically exported from code.google.com/p/mb-unit
0 stars 0 forks source link

Impersonating identity during tests #468

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Yann,
I started writing this out while replying to the question about WatiN and
Windows authentication before I realized I was on the wrong track.

It would be interesting to have some new decorators for changing the thread
principal and perhaps for performing Windows impersonation.

1. Spoofing the principal:

[Test]
[Principal(Name = "foo", Roles = new[] { "Role1", "Role2" })]
public void MyTest()
{
  ...
}

2. Windows impersonation:

[Test]
[Impersonate(UserName = "foo", Password = "bar")]
public void MyTest()
{
  ...
}

This is pretty rough but what do you think?
Jeff.

Original issue reported on code.google.com by Yann.Tre...@gmail.com on 4 Jun 2009 at 5:40

GoogleCodeExporter commented 8 years ago

Original comment by jeff.br...@gmail.com on 29 Jun 2009 at 8:33

GoogleCodeExporter commented 8 years ago

Original comment by Yann.Tre...@gmail.com on 30 Jun 2009 at 5:36

GoogleCodeExporter commented 8 years ago
Jeff,

I have implemented the ImpersonateAttribute.

But I'm not sure about the usage of PrincipalAttribute. What do you mean by 
spoofing? 
Is "foo" a completely fake user who does actually not exist? So is that 
implying to 
create a custom IPrincipal object that simulates the specified credentials?

Original comment by Yann.Tre...@gmail.com on 30 Jun 2009 at 7:43

GoogleCodeExporter commented 8 years ago
Yes, we would just create a custom IPrincipal object with the desired roles.

Of course any code that checks the type of the principal would fail.  So we 
could
make the attribute a little extensible by exposing a virtual factory method to 
create
the principle.  Users could then override how that works so they can create a
[Principal] attribute for their own principal types.

eg.

public class PrincipalAttribute : .....
{
    protected virtual IPrincipal CreatePrincipal()
    {
        return new FakePrincipal(Name, Roles);
    }
}

Original comment by jeff.br...@gmail.com on 18 Jul 2009 at 5:23

GoogleCodeExporter commented 8 years ago

Original comment by jeff.br...@gmail.com on 18 Jul 2009 at 5:24

GoogleCodeExporter commented 8 years ago
PrincipalAttribute implemented.

Original comment by Yann.Tre...@gmail.com on 24 Jul 2009 at 9:40