Search code examples
.netcode-access-security

Testing .NET code in partial trust environments


I want to test the behavior of a certain piece of .NET code in partial trust environments. What's the fastest way to set this up? Feel free to assume that I (and other readers) are total CAS noobs.

@Nick: Thanks for the reply. Alas, the tool in question is explicitly for unmanaged code. I didn't say "managed" in my question, and should not have assumed that people would infer it from the ".NET" tag.


Solution

  • This is an excellent question, especially from a TDD point of view and validating code under different trust scenarios.

    I think the way I'd approach this would be something along the lines of -

    • Create an AppDomain in my TDD code using the AppDomain.CreateDomain() overload that allows you to pass in a PermissionSet. The PermissionSet would be constructed to match the different trust scenarios you'd want to test against.

    • Load the assembly containing logic under test into the app domain

    • Create instances of types/call methods etc in app domain, trap security exceptions

    Something kinda like that. I've not had time to knock up a proof of concept yet.