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:
parent
e4852b581a
commit
000781dc36
3 changed files with 9 additions and 0 deletions
|
@ -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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue