-
-
Save steveswing/944580 to your computer and use it in GitHub Desktop.
Unit Test for reporting a bug with PasswordField
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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