I have a controller method that I write like this:
@Secured(['ROLE_ADMIN']) def save() { ... // code ommitted }
I am trying to write unit test to make sure that only the admin url can hit the url:
def "Only the admin user should be able to invoke save"() { given: def user = createNonAdminUser() // let pretend this method exists controller.springSecurityService = Mock(SpringSecurityService) controller.springSecurityService.currentUser >> user when: controller.save() then: view ==~ 'accessdenied' }
However, the returned view is a save view, not a type of access ban. It looks like it generally bypasses the @Secured annotation. Is there a way to test @Secured annotations from unit test or integration?
source share