1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Cover blank passwords in existing tests

This commit is contained in:
J. King 2017-02-27 23:28:11 -05:00
parent e4852b581a
commit 000781dc36
3 changed files with 9 additions and 0 deletions

View file

@ -67,8 +67,10 @@ class TestUser extends \PHPUnit\Framework\TestCase {
function testAuthenticateAUser() { function testAuthenticateAUser() {
$this->data->user->add(self::USER1, "secret"); $this->data->user->add(self::USER1, "secret");
$this->data->user->add(self::USER2, "");
$this->assertTrue($this->data->user->auth(self::USER1, "secret")); $this->assertTrue($this->data->user->auth(self::USER1, "secret"));
$this->assertFalse($this->data->user->auth(self::USER1, "superman")); $this->assertFalse($this->data->user->auth(self::USER1, "superman"));
$this->assertTrue($this->data->user->auth(self::USER2, ""));
} }
function testChangeAPassword() { function testChangeAPassword() {
@ -76,6 +78,8 @@ class TestUser extends \PHPUnit\Framework\TestCase {
$this->assertEquals("superman", $this->data->user->passwordSet(self::USER1, "superman")); $this->assertEquals("superman", $this->data->user->passwordSet(self::USER1, "superman"));
$this->assertTrue($this->data->user->auth(self::USER1, "superman")); $this->assertTrue($this->data->user->auth(self::USER1, "superman"));
$this->assertFalse($this->data->user->auth(self::USER1, "secret")); $this->assertFalse($this->data->user->auth(self::USER1, "secret"));
$this->assertEquals("", $this->data->user->passwordSet(self::USER1, ""));
$this->assertTrue($this->data->user->auth(self::USER1, ""));
$this->assertEquals($this->data->conf->userTempPasswordLength, strlen($this->data->user->passwordSet(self::USER1))); $this->assertEquals($this->data->conf->userTempPasswordLength, strlen($this->data->user->passwordSet(self::USER1)));
} }

View file

@ -68,8 +68,10 @@ class TestUserExternal extends \PHPUnit\Framework\TestCase {
function testAuthenticateAUser() { function testAuthenticateAUser() {
$this->data->user->add(self::USER1, "secret"); $this->data->user->add(self::USER1, "secret");
$this->data->user->add(self::USER2, "");
$this->assertTrue($this->data->user->auth(self::USER1, "secret")); $this->assertTrue($this->data->user->auth(self::USER1, "secret"));
$this->assertFalse($this->data->user->auth(self::USER1, "superman")); $this->assertFalse($this->data->user->auth(self::USER1, "superman"));
$this->assertTrue($this->data->user->auth(self::USER2, ""));
} }
function testChangeAPassword() { function testChangeAPassword() {
@ -77,6 +79,8 @@ class TestUserExternal extends \PHPUnit\Framework\TestCase {
$this->assertEquals("superman", $this->data->user->passwordSet(self::USER1, "superman")); $this->assertEquals("superman", $this->data->user->passwordSet(self::USER1, "superman"));
$this->assertTrue($this->data->user->auth(self::USER1, "superman")); $this->assertTrue($this->data->user->auth(self::USER1, "superman"));
$this->assertFalse($this->data->user->auth(self::USER1, "secret")); $this->assertFalse($this->data->user->auth(self::USER1, "secret"));
$this->assertEquals("", $this->data->user->passwordSet(self::USER1, ""));
$this->assertTrue($this->data->user->auth(self::USER1, ""));
$this->assertEquals($this->data->conf->userTempPasswordLength, strlen($this->data->user->passwordSet(self::USER1))); $this->assertEquals($this->data->conf->userTempPasswordLength, strlen($this->data->user->passwordSet(self::USER1)));
} }

View file

@ -45,6 +45,7 @@ class DriverExternalMock extends DriverSkeleton implements Driver {
function auth(string $user, string $password): bool { function auth(string $user, string $password): bool {
if(!$this->userExists($user)) return false; if(!$this->userExists($user)) return false;
if($password==="" && $this->db[$user]['password']==="") return true;
if(password_verify($password, $this->db[$user]['password'])) return true; if(password_verify($password, $this->db[$user]['password'])) return true;
return false; return false;
} }