views:

20

answers:

1

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.

+1  A: 

try adding the flush

 UserRole.create(userAdmin, roleAdmin, true)

http://burtbeckwith.github.com/grails-spring-security-core/docs/manual/guide/4%20Required%20and%20Optional%20Domain%20Classes.html#4.2%20Authority%20Class

Aaron Saunders
That was it Aaron. Thanks!
Gregg