Skip to content

Instantly share code, notes, and snippets.

Created March 16, 2011 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/872498 to your computer and use it in GitHub Desktop.
Save anonymous/872498 to your computer and use it in GitHub Desktop.
Unit Test for reporting a bug with PasswordField
package code
import org.specs._
import _root_.net.liftweb.mongodb.record._
import _root_.net.liftweb.record.field._
class SampleRecord extends MongoRecord[SampleRecord]
with MongoId[SampleRecord] {
def meta = SampleRecord
object password extends PasswordField(this)
}
object SampleRecord extends SampleRecord with MongoMetaRecord[SampleRecord]
object PasswordFieldSpecs extends Specification {
val password = "123456"
"Password Field value" should {
val sample = SampleRecord.password(password)
val asPersisted = sample.asDBObject
val retrieved = SampleRecord.fromDBObject(asPersisted)
"match the actual password" in {
retrieved.password.match_?(password) must be(true)
}
"not match the hashed password" in {
val hashedPassword = sample.password.is
retrieved.password.match_?(hashedPassword) must be(false)
}
}
/** The following tests require a live DB connection **/
"Persisted Password value" should {
import _root_.net.liftweb.mongodb._
MongoDB.defineDb(DefaultMongoIdentifier,
MongoAddress(MongoHost(), "passwordTests"))
val sample = SampleRecord.password(password).save
val retrieved = SampleRecord.find(sample.id).get
"match the actual password" in {
retrieved.password.match_?(password) must be(true)
}
"not match the hashed password" in {
val hashedPassword = sample.password.is
retrieved.password.match_?(hashedPassword) must be(false)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment