代码之家  ›  专栏  ›  技术社区  ›  Gregg

Grails+Selenium+EasyB+spring安全核心:ifanygrated不工作

  •  0
  • Gregg  · 技术社区  · 15 年前

    Grails 1.3.5并安装了selenium rc、easyb和spring安全核心插件。除了我遇到的这一个案子外,一切似乎都很顺利。我有一个正在测试的页面,该页面具有以下标记:

    <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。有人知道这是一个已知的问题还是关于它的任何其他信息吗?谢谢。

    1 回复  |  直到 15 年前