Grails +硒 + EasyB +spring-security-core: ifAnyGranted 不起作用

发布于 2024-09-28 01:40:12 字数 1557 浏览 6 评论 0原文

Grails 1.3.5 并安装了 selenium-rc、easyb 和 spring-security-core 插件。除了我遇到的这个案例之外,一切似乎都运行得很好。我正在测试一个页面,该页面具有以下标记:

<sec:ifAnyGranted roles='ROLE_ADMIN'>
    <span class="menuButton">
      <g:link mapping="adminPage">
        <g:message code="default.admin.label" default="--Admin--"/>
      </g:link>
    </span>
</sec:ifAnyGranted>

正常运行应用程序时,一切正常。如果我以普通用户身份登录,则不会显示管理链接。如果我以管理员身份登录,该链接就会显示。运行我的测试时,无论谁登录,检查都会失败,因此永远不会呈现管理链接。

scenario "An Admin User logs into the system", {
   when "the user completes the login form with proper credentials", {

   grailsApplication = ApplicationHolder.application
   springSecurityService = ApplicationHolder.application.mainContext.getBean("springSecurityService")

   def userAdmin = new User(username: 'testAdmin', firstName: 'Test', lastName: 'Admin', enabled: true, password: springSecurityService.encodePassword("password")).save(flush: true)
   def roleAdmin = new Role(authority: 'ROLE_ADMIN').save(flush: true)
   UserRole.create(userAdmin, roleAdmin)

   selenium.openAndWait("/platform/login/auth")
   selenium.type('j_username', 'testAdmin')
   selenium.type('j_password', 'password')
   selenium.clickAndWait('signInBtn')

 }
 then "the user should be logged in and viewing their My Account page, as an admin", {
   selenium.isTextPresent("Welcome Test").shouldBe true
   selenium.isElementPresent('link=Admin').shouldBe true

 }
}

其他标签工作得很好,例如 ifLoggedIn 和 ifNotLoggedIn。有人知道这是否是一个已知问题或任何其他信息吗?谢谢。

Grails 1.3.5 and have selenium-rc, easyb, and spring-security-core plugins installed. Everything seems to work really well except this one case I've run into. I have a page I am testing which has the following markup:

<sec:ifAnyGranted roles='ROLE_ADMIN'>
    <span class="menuButton">
      <g:link mapping="adminPage">
        <g:message code="default.admin.label" default="--Admin--"/>
      </g:link>
    </span>
</sec:ifAnyGranted>

When running the application normally, everything works fine. If I'm logged in as a regular user, the Admin link doesn't show. If I log in as an admin, the link does show up. When running my test, no matter who is logged in, the check fails, so the Admin link is never rendered.

scenario "An Admin User logs into the system", {
   when "the user completes the login form with proper credentials", {

   grailsApplication = ApplicationHolder.application
   springSecurityService = ApplicationHolder.application.mainContext.getBean("springSecurityService")

   def userAdmin = new User(username: 'testAdmin', firstName: 'Test', lastName: 'Admin', enabled: true, password: springSecurityService.encodePassword("password")).save(flush: true)
   def roleAdmin = new Role(authority: 'ROLE_ADMIN').save(flush: true)
   UserRole.create(userAdmin, roleAdmin)

   selenium.openAndWait("/platform/login/auth")
   selenium.type('j_username', 'testAdmin')
   selenium.type('j_password', 'password')
   selenium.clickAndWait('signInBtn')

 }
 then "the user should be logged in and viewing their My Account page, as an admin", {
   selenium.isTextPresent("Welcome Test").shouldBe true
   selenium.isElementPresent('link=Admin').shouldBe true

 }
}

Other tags work just fine such as ifLoggedIn and ifNotLoggedIn. Anyone know if this is a known issue or any other info on it? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文