views:

32

answers:

1

We have a 3rd party webservice used to authorise users. Primarily it takes the calling user, checks their identity, and returns a cookie for subsequent requests.

I would like to unit test it, making sure it throws the appropriate exception. Ideally something like this:

var dummyIdentity = WindowsIdentity.GetAnonymous();

using (dummyIdentity.Impersonate())
{
  //Call the webservice here.. expect exception

However, this appears to not work as per: http://msdn.microsoft.com/en-us/library/system.security.principal.windowsidentity.getanonymous.aspx

The returned WindowsIdentity object cannot be used for any useful activity such as impersonation.

Apart from suggestions that revolve around setting the service account credentials our build running is running under, does anyone know if it's possible to do the above in code somehow??

A: 

Create a dummy account and impersonate it! That'll work.

Michael Howard-MSFT