问题
We are using securesocial module for authentication in Play 2 application.
I have two questions concerning this module.
Firstly, is there an easy way to disable the authorization checking in out development environment, preferably w/o commenting all @SecureSocial.SecuredAction
annotations.
Secondly, what is the preferred way to unit test methods that use securesocial in Java? For example I have a call to ctx().args.get(SecureSocial.USER_KEY);
in controller for getting the identity. If I would want to unit test this method, how can I mock out this identity? Or maybe secure social has some utility classes that can help unit testing?
回答1:
We decided to create method getUser
in our controller and then in unit-tests we are using http://www.javassist.org/ library to remove securesocial annotations and also to change return value of getUser
to some mock that is created in test classes.
来源:https://stackoverflow.com/questions/16244541/play-securesocial-developer-environment-and-unit-testing