Integration testing grails spring security plugin?

I have it:

@Secured(['ROLE_USER', 'ROLE_HELPDESK', 'ROLE_ADMIN']) class MyController { def edit = { } @Secured(['ROLE_ADMIN']) def uploadForUser = { params.userId = params.id forward(controller: 'someController', action: 'someAction', params: params) } } 

and an integration test, which, it seems to me, should fail:

 public void test_uploadForUser_unauthenticated(){ myController.params.id = "testUser" myController.uploadForUser() } 

Nevertheless, the tests pass. Is there any way to check controllers annotated with spring security plugin?

+4
source share
1 answer

These annotations are parsed using SpringSecurityFilter , so they do not work unless you have an actual HTTP request.

Thus, you need to either switch to checking roles using conditional expressions inside actions, for example, do it here , or check it using WebDriver / Geb or some simpler frameworks - a very good approach is presented in the Grails security plugin itself .

+9
source

All Articles