1

We have a custom authentication manager which uses a static factory method to spin up an instance of a repository (because we couldn't work out how to inject one) which does some security look ups from a database.

As you can imagine it's a pretty key part of our security infrastructure and I was wondering how others have approached unit testing the components to make sure they are working as per the design.

Thanks

John

1 Answer 1

2

IMHO, The best solution is to break up your Authentication and Authorization logic into separate (aka testable) methods, and unit test them like you would any other method. You can setup/Mock the IClaimsPrincipal to ensure your Authenticate method is working as expected.

We wouldn't need to unit test the ClaimsAuthenticationManager itself as Microsoft has already done that.

I would also consider setting up some integration tests that will ensure everything is working, eg (loading of policies from config, parsing them, etc and that your mocking of the IClaimsPrincipal is correct.

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.