Skip to content

Commit

Permalink
Ensure same passwords for same random seeds
Browse files Browse the repository at this point in the history
  • Loading branch information
rweisleder committed May 27, 2020
1 parent ed0f567 commit 8c4d870
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,11 @@ public void generatePassword() {
if (password != null) {
return;
}
// FIXME: Replace this with baseProducer
password = RandomStringUtils.randomAlphanumeric(8);
StringBuilder passwordPattern = new StringBuilder();
for (int i = baseProducer.randomBetween(6, 14); i > 0; i--) {
passwordPattern.append(baseProducer.randomElement("?", "#"));
}
password = baseProducer.bothify(passwordPattern.toString());
}

@Override
Expand Down
22 changes: 22 additions & 0 deletions src/test/groovy/com/devskiller/jfairy/FairySpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,28 @@ class FairySpec extends Specification {
!firstPerson.fullName.equals(secondPerson.fullName)
}

def "Second person should have the same password with the same random seed"() {
given:
Fairy firstFairy = Fairy.builder().withRandomSeed(10).build()
Fairy secondFairy = Fairy.builder().withRandomSeed(10).build()

Person firstPerson = firstFairy.person()
Person secondPerson = secondFairy.person()
expect:
firstPerson.getPassword().equals(secondPerson.getPassword())
}

def "Second person should not have the same password with the different random seeds"() {
given:
Fairy firstFairy = Fairy.builder().withRandomSeed(10).build()
Fairy secondFairy = Fairy.builder().withRandomSeed(20).build()

Person firstPerson = firstFairy.person()
Person secondPerson = secondFairy.person()
expect:
!firstPerson.getPassword().equals(secondPerson.getPassword())
}

def "should use default DataMaster when custom not provided"() {
given:
Fairy fairy = Fairy.create();
Expand Down

0 comments on commit 8c4d870

Please sign in to comment.