From 000781dc363b255f543ecc4298a50575ab4bf3ef Mon Sep 17 00:00:00 2001 From: "J. King" Date: Mon, 27 Feb 2017 23:28:11 -0500 Subject: [PATCH] Cover blank passwords in existing tests --- tests/User/TestUser.php | 4 ++++ tests/User/TestUserExternal.php | 4 ++++ tests/lib/User/DriverExternalMock.php | 1 + 3 files changed, 9 insertions(+) diff --git a/tests/User/TestUser.php b/tests/User/TestUser.php index 8478de87..60cfb4f5 100644 --- a/tests/User/TestUser.php +++ b/tests/User/TestUser.php @@ -67,8 +67,10 @@ class TestUser extends \PHPUnit\Framework\TestCase { function testAuthenticateAUser() { $this->data->user->add(self::USER1, "secret"); + $this->data->user->add(self::USER2, ""); $this->assertTrue($this->data->user->auth(self::USER1, "secret")); $this->assertFalse($this->data->user->auth(self::USER1, "superman")); + $this->assertTrue($this->data->user->auth(self::USER2, "")); } function testChangeAPassword() { @@ -76,6 +78,8 @@ class TestUser extends \PHPUnit\Framework\TestCase { $this->assertEquals("superman", $this->data->user->passwordSet(self::USER1, "superman")); $this->assertTrue($this->data->user->auth(self::USER1, "superman")); $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))); } diff --git a/tests/User/TestUserExternal.php b/tests/User/TestUserExternal.php index f5f4847c..e7e28407 100644 --- a/tests/User/TestUserExternal.php +++ b/tests/User/TestUserExternal.php @@ -68,8 +68,10 @@ class TestUserExternal extends \PHPUnit\Framework\TestCase { function testAuthenticateAUser() { $this->data->user->add(self::USER1, "secret"); + $this->data->user->add(self::USER2, ""); $this->assertTrue($this->data->user->auth(self::USER1, "secret")); $this->assertFalse($this->data->user->auth(self::USER1, "superman")); + $this->assertTrue($this->data->user->auth(self::USER2, "")); } function testChangeAPassword() { @@ -77,6 +79,8 @@ class TestUserExternal extends \PHPUnit\Framework\TestCase { $this->assertEquals("superman", $this->data->user->passwordSet(self::USER1, "superman")); $this->assertTrue($this->data->user->auth(self::USER1, "superman")); $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))); } diff --git a/tests/lib/User/DriverExternalMock.php b/tests/lib/User/DriverExternalMock.php index 3c813c2b..0d25cebf 100644 --- a/tests/lib/User/DriverExternalMock.php +++ b/tests/lib/User/DriverExternalMock.php @@ -45,6 +45,7 @@ class DriverExternalMock extends DriverSkeleton implements Driver { function auth(string $user, string $password): bool { if(!$this->userExists($user)) return false; + if($password==="" && $this->db[$user]['password']==="") return true; if(password_verify($password, $this->db[$user]['password'])) return true; return false; }