Skip to content

Commit

Permalink
Fix & enhance tests (#16)
Browse files Browse the repository at this point in the history
* Fix asserts using NotRegExp

Asserting against the regexp would only prove at leat one character in
the generated password is not in the given set.

Use of assertNotregExep verify that no character come from the set.

Also fix testGenerateNumerals because $capitalize default value in
constructor is set to true. Solely defined third parameter to true will
also generate upper chars.

Add specific test to generate numerals and disable $capitalize.

refs #13 #14

* Most ambiguous character are upper ones

fix #13

* We may not assert ambiguous chars will be generated

refs #13

* Setting noVovels implies having digits & uppers

https://github.com/roderik/pwgen-php/blob/7ecf653a701bfa4115fa2cc5fa438c1a5c4dfbaf/src/PWGen.php#L199

refs #13

* Fix test with noVovels set
  • Loading branch information
pips- authored and roderik committed Dec 1, 2017
1 parent 7ecf653 commit 19763b8
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions tests/PWGen/PWGenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,31 @@ public function testGenerateNumerals()

$this->assertEquals(20, $pwgen->getLength());
$this->assertTrue($pwgen->hasNumerals());
$this->assertTrue($pwgen->hasCapitalize());

$pass = $pwgen->generate();

$this->assertTrue(is_string($pass));
$this->assertEquals(20, strlen($pass));
$this->assertRegExp('/[a-z]/', $pass); // Alpha lower
$this->assertRegExp('/[A-Z]/', $pass); // Alpha upper
$this->assertRegExp('/\\d/', $pass); // Numerals
}

public function testGenerateNumeralsNoUppers()
{
$pwgen = new PWGen(20, false, true, false);

$this->assertEquals(20, $pwgen->getLength());
$this->assertTrue($pwgen->hasNumerals());
$this->assertFalse($pwgen->hasCapitalize());

$pass = $pwgen->generate();

$this->assertTrue(is_string($pass));
$this->assertEquals(20, strlen($pass));
$this->assertRegExp('/[a-z]/', $pass); // Alpha lower
$this->assertRegExp('/[^A-Z]/', $pass); // Alpha NOT upper
$this->assertNotRegExp('/[A-Z]/', $pass); // Alpha NOT upper
$this->assertRegExp('/\\d/', $pass); // Numerals
}

Expand All @@ -108,7 +126,7 @@ public function testGenerateCapitalize()
$this->assertEquals(20, strlen($pass));
$this->assertRegExp('/[a-z]/', $pass); // Alpha lower
$this->assertRegExp('/[A-Z]/', $pass); // Alpha upper
$this->assertRegExp('/[^\\d]/', $pass); // NO numerals!
$this->assertNotRegExp('/[\\d]/', $pass); // NO numerals!
}

public function testGenerateAmbiguous()
Expand All @@ -117,15 +135,15 @@ public function testGenerateAmbiguous()

$this->assertEquals(20, $pwgen->getLength());
$this->assertTrue($pwgen->hasAmbiguous());
$this->assertTrue($pwgen->hasCapitalize());

$pass = $pwgen->generate();

$this->assertTrue(is_string($pass));
$this->assertEquals(20, strlen($pass));
$this->assertRegExp('/[a-z]/', $pass); // Alpha lower
$this->assertRegExp('/[^A-Z]/', $pass); // Alpha NOT upper
$this->assertRegExp('/[^\\d]/', $pass); // NO numerals!
$this->assertRegExp('/[' . preg_quote($pwgen->getAmbiguous(), '/') . ']/', $pass); // Symbols
$this->assertRegExp('/[A-Z]/', $pass); // Alpha NOT upper
$this->assertNotRegExp('/[\\d]/', $pass); // NO numerals!
}

public function testGenerateNoVovels()
Expand All @@ -134,15 +152,17 @@ public function testGenerateNoVovels()

$this->assertEquals(20, $pwgen->getLength());
$this->assertTrue($pwgen->hasNoVovels());
$this->assertTrue($pwgen->hasNumerals());
$this->assertTrue($pwgen->hasCapitalize());

$pass = $pwgen->generate();

$this->assertTrue(is_string($pass));
$this->assertEquals(20, strlen($pass));
$this->assertRegExp('/[a-z]/', $pass); // Alpha lower
$this->assertRegExp('/[A-Z]/', $pass); // Alpha upper
$this->assertRegExp('/[^\\d]/', $pass); // NO numerals!
$this->assertRegExp('/[^' . preg_quote($pwgen->getVovels(), '/') . ']/', $pass); // Symbols
$this->assertRegExp('/[\\d]/', $pass); // numerals
$this->assertNotRegExp('/[' . preg_quote($pwgen->getVovels(), '/') . ']/', $pass); // No Vovels
}

public function testGenerateSymbols()
Expand All @@ -157,8 +177,8 @@ public function testGenerateSymbols()
$this->assertTrue(is_string($pass));
$this->assertEquals(20, strlen($pass));
$this->assertRegExp('/[a-z]/', $pass); // Alpha lower
$this->assertRegExp('/[^A-Z]/', $pass); // Alpha NOT upper
$this->assertRegExp('/[^\\d]/', $pass); // NO numerals!
$this->assertNotRegExp('/[A-Z]/', $pass); // Alpha NOT upper
$this->assertNotRegExp('/[\\d]/', $pass); // NO numerals!
$this->assertRegExp('/[' . preg_quote($pwgen->getSymbols(), '/') . ']/', $pass); // Symbols
}

Expand Down

0 comments on commit 19763b8

Please sign in to comment.