-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from tacovandenbroek/use_sha1_for_password_check
Add method that does not make use of the real password
- Loading branch information
Showing
3 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace DivineOmega\PasswordExposed\Tests; | ||
|
||
use DivineOmega\PasswordExposed\PasswordExposedChecker; | ||
use DivineOmega\PasswordExposed\PasswordStatus; | ||
use Faker\Factory; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class PasswordExposedByHashTest extends TestCase | ||
{ | ||
/** @var PasswordExposedChecker */ | ||
private $checker; | ||
|
||
protected function setUp() | ||
{ | ||
$this->checker = new PasswordExposedChecker(); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function exposedPasswordHashProvider() | ||
{ | ||
return [ | ||
[sha1('test')], | ||
[sha1('password')], | ||
[sha1('hunter2')], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider exposedPasswordHashProvider | ||
* | ||
* @param string $hash | ||
*/ | ||
public function testExposedPasswords($hash) | ||
{ | ||
$this->assertEquals($this->checker->passwordExposedByHash($hash), PasswordStatus::EXPOSED); | ||
} | ||
|
||
public function testNotExposedPasswords() | ||
{ | ||
$this->assertEquals( | ||
$this->checker->passwordExposedByHash($this->getPasswordHashUnlikelyToBeExposed()), | ||
PasswordStatus::NOT_EXPOSED | ||
); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
private function getPasswordHashUnlikelyToBeExposed() | ||
{ | ||
$faker = Factory::create(); | ||
|
||
return sha1($faker->words(6, true)); | ||
} | ||
} |