From 928f80d569141601c4d8f6652b2ac0a2497c7be4 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Wed, 30 Jan 2019 22:25:57 -0800 Subject: Update unit tests --- tests/units/Auth/DatabaseAuthTest.php | 15 +++++++++++---- tests/units/Core/Security/AuthenticationManagerTest.php | 4 ++-- tests/units/Middleware/AuthenticationMiddlewareTest.php | 1 - 3 files changed, 13 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/units/Auth/DatabaseAuthTest.php b/tests/units/Auth/DatabaseAuthTest.php index 50ae3c7e..e2236837 100644 --- a/tests/units/Auth/DatabaseAuthTest.php +++ b/tests/units/Auth/DatabaseAuthTest.php @@ -46,17 +46,24 @@ class DatabaseAuthTest extends Base $this->assertFalse($provider->isValidSession()); - $this->assertEquals(2, $userModel->create(array('username' => 'foobar'))); + $this->assertEquals(2, $userModel->create(array('username' => 'user1'))); + $this->assertEquals(3, $userModel->create(array('username' => 'user2'))); - $_SESSION['user'] = array('id' => 2); + $_SESSION['user'] = array('id' => 2, 'role' => 'app-user'); $this->assertTrue($provider->isValidSession()); - $_SESSION['user'] = array('id' => 3); + $_SESSION['user'] = array('id' => 4, 'role' => 'app-user'); $this->assertFalse($provider->isValidSession()); $this->assertTrue($userModel->disable(2)); - $_SESSION['user'] = array('id' => 2); + $_SESSION['user'] = array('id' => 2, 'role' => 'app-user'); + $this->assertFalse($provider->isValidSession()); + + $_SESSION['user'] = array('id' => 3, 'role' => 'app-user'); + $this->assertTrue($provider->isValidSession()); + + $_SESSION['user'] = array('id' => 3, 'role' => 'app-admin'); $this->assertFalse($provider->isValidSession()); } } diff --git a/tests/units/Core/Security/AuthenticationManagerTest.php b/tests/units/Core/Security/AuthenticationManagerTest.php index a5a23c7e..616b7fa8 100644 --- a/tests/units/Core/Security/AuthenticationManagerTest.php +++ b/tests/units/Core/Security/AuthenticationManagerTest.php @@ -56,7 +56,7 @@ class AuthenticationManagerTest extends Base $authManager = new AuthenticationManager($this->container); $authManager->register(new DatabaseAuth($this->container)); - $_SESSION['user'] = array('id' => 1, 'username' => 'test'); + $_SESSION['user'] = array('id' => 1, 'username' => 'test', 'role' => 'app-admin'); $this->assertTrue($this->container['userSession']->isLogged()); $this->assertTrue($authManager->checkCurrentSession()); @@ -67,7 +67,7 @@ class AuthenticationManagerTest extends Base $authManager = new AuthenticationManager($this->container); $authManager->register(new DatabaseAuth($this->container)); - $_SESSION['user'] = array('id' => 42, 'username' => 'test'); + $_SESSION['user'] = array('id' => 42, 'username' => 'test', 'role' => 'app-admin'); $this->assertTrue($this->container['userSession']->isLogged()); $this->assertFalse($authManager->checkCurrentSession()); diff --git a/tests/units/Middleware/AuthenticationMiddlewareTest.php b/tests/units/Middleware/AuthenticationMiddlewareTest.php index b6819adc..2cbcc123 100644 --- a/tests/units/Middleware/AuthenticationMiddlewareTest.php +++ b/tests/units/Middleware/AuthenticationMiddlewareTest.php @@ -60,7 +60,6 @@ class AuthenticationMiddlewareTest extends Base ->expects($this->never()) ->method('execute'); - $this->setExpectedException('Kanboard\Core\Controller\AccessForbiddenException'); $this->middleware->execute(); } -- cgit v1.2.3