zoran119
zoran119

Reputation: 11307

Disable password check

Is it possible to disable password check in the test environment? I cannot find a configuration item which would allow this, was thinking some meta programming in BootStrap.groovy but haven't had any success...

import grails.util.Environment
  switch (Environment.current) {
    case Environment.TEST:
      springSecurityService.metaClass.passwordOk = { true } // if it was only simple as this :)
      ...

Any ideas?

NOTE: I'm using the LDAP plugin for authentication

Upvotes: 0

Views: 97

Answers (1)

Davor Pecet
Davor Pecet

Reputation: 171

Have you tried :

test {
  grails.plugins.springsecurity.active = false        
}

This will disable spring security plugin so none of your spring security stuff will work. You have to create a stub for getting the currentUser:

class StubSpringSecurityService {

    def currentUser

    Object getCurrentUser() {
        return currentUser
    }

    String encodePassword(String password, salt = null) {
        return password
    }

}

Put in resources.groovy

if (GrailsUtil.environment == "test"){
  springSecurityService(StubSpringSecurityService)
}

And then in your bootstrap file

if (GrailsUtil.environment == "test") {
      def testUser = new User()
      testUser.save(failOnError: true)
      springSecurityService.currentUser = testUser;
}

Upvotes: 1

Related Questions