【发布时间】:2013-05-26 19:10:50
【问题描述】:
我有一个控制器方法,我正在这样注释:
@Secured(['ROLE_ADMIN'])
def save() {
... // code ommitted
}
我正在尝试编写一个单元测试来验证只有管理员用户才能访问该 URL:
def "Only the admin user should be able to invoke save"() {
given:
def user = createNonAdminUser() // let's pretend this method exists
controller.springSecurityService = Mock(SpringSecurityService)
controller.springSecurityService.currentUser >> user
when:
controller.save()
then:
view ==~ 'accessdenied'
}
但是,返回的视图是save 视图,而不是拒绝访问视图。看起来它完全绕过了 @Secured 注释。有没有办法从单元测试或集成测试中测试@Secured 注释?
【问题讨论】:
-
你找到解决办法了吗?
标签: unit-testing grails spring-security integration-testing