summaryrefslogtreecommitdiff
path: root/tests/units/Core
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2017-12-06 16:19:11 -0800
committerFrédéric Guillot <fguillot@apple.com>2017-12-12 15:04:28 -0800
commitccd177ada6823c27a6408427f19c238fd701c39e (patch)
tree9846c792bd4c4f9318768f00db0e8f00cc25954b /tests/units/Core
parent421531bd4f0af6a26e0b7971e23d5af1d5cf7d05 (diff)
Store PHP sessions in the database
Diffstat (limited to 'tests/units/Core')
-rw-r--r--tests/units/Core/Action/ActionManagerTest.php2
-rw-r--r--tests/units/Core/Security/AuthenticationManagerTest.php4
-rw-r--r--tests/units/Core/Session/SessionStorageTest.php60
-rw-r--r--tests/units/Core/User/UserProfileTest.php32
-rw-r--r--tests/units/Core/User/UserSessionTest.php113
5 files changed, 73 insertions, 138 deletions
diff --git a/tests/units/Core/Action/ActionManagerTest.php b/tests/units/Core/Action/ActionManagerTest.php
index 4878c0c9..cf6a88d4 100644
--- a/tests/units/Core/Action/ActionManagerTest.php
+++ b/tests/units/Core/Action/ActionManagerTest.php
@@ -116,7 +116,7 @@ class ActionManagerTest extends Base
public function testAttachEventsWithLoggedUser()
{
- $this->container['sessionStorage']->user = array('id' => 1);
+ $_SESSION['user'] = array('id' => 1);
$projectModel = new ProjectModel($this->container);
$projectUserRoleModel = new ProjectUserRoleModel($this->container);
diff --git a/tests/units/Core/Security/AuthenticationManagerTest.php b/tests/units/Core/Security/AuthenticationManagerTest.php
index c2369626..a5a23c7e 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));
- $this->container['sessionStorage']->user = array('id' => 1);
+ $_SESSION['user'] = array('id' => 1, 'username' => 'test');
$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));
- $this->container['sessionStorage']->user = array('id' => 2);
+ $_SESSION['user'] = array('id' => 42, 'username' => 'test');
$this->assertTrue($this->container['userSession']->isLogged());
$this->assertFalse($authManager->checkCurrentSession());
diff --git a/tests/units/Core/Session/SessionStorageTest.php b/tests/units/Core/Session/SessionStorageTest.php
deleted file mode 100644
index dd0040d5..00000000
--- a/tests/units/Core/Session/SessionStorageTest.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-
-require_once __DIR__.'/../../Base.php';
-
-use Kanboard\Core\Session\SessionStorage;
-
-class SessionStorageTest extends Base
-{
- public function testNotPersistentStorage()
- {
- $storage = new SessionStorage();
- $storage->something = array('a' => 'b');
- $this->assertEquals(array('a' => 'b'), $storage->something);
- $this->assertTrue(isset($storage->something));
- $this->assertFalse(isset($storage->something->x));
- $this->assertFalse(isset($storage->notFound));
- $this->assertFalse(isset($storage->notFound->x));
- $this->assertFalse(isset($storage->notFound['x']));
- }
-
- public function testPersistentStorage()
- {
- $session = array('d' => 'e');
-
- $storage = new SessionStorage();
- $storage->setStorage($session);
- $storage->something = array('a' => 'b');
-
- $this->assertEquals(array('a' => 'b'), $storage->something);
- $this->assertEquals('e', $storage->d);
-
- $storage->something['a'] = 'c';
- $this->assertEquals('c', $storage->something['a']);
-
- $storage = null;
- $this->assertEquals(array('something' => array('a' => 'c'), 'd' => 'e'), $session);
- }
-
- public function testFlush()
- {
- $session = array('d' => 'e');
-
- $storage = new SessionStorage();
- $storage->setStorage($session);
- $storage->something = array('a' => 'b');
-
- $this->assertEquals(array('a' => 'b'), $storage->something);
- $this->assertEquals('e', $storage->d);
-
- $storage->flush();
-
- $this->assertFalse(isset($storage->d));
- $this->assertFalse(isset($storage->something));
-
- $storage->foo = 'bar';
-
- $storage = null;
- $this->assertEquals(array('foo' => 'bar'), $session);
- }
-}
diff --git a/tests/units/Core/User/UserProfileTest.php b/tests/units/Core/User/UserProfileTest.php
index 6dc627b7..684db06e 100644
--- a/tests/units/Core/User/UserProfileTest.php
+++ b/tests/units/Core/User/UserProfileTest.php
@@ -15,8 +15,8 @@ class UserProfileTest extends Base
$user = new DatabaseUserProvider(array('id' => 1));
$this->assertTrue($userProfile->initialize($user));
- $this->assertNotEmpty($this->container['sessionStorage']->user);
- $this->assertEquals('admin', $this->container['sessionStorage']->user['username']);
+ $this->assertNotEmpty($_SESSION['user']);
+ $this->assertEquals('admin', $_SESSION['user']['username']);
}
public function testInitializeLocalUserNotFound()
@@ -25,7 +25,7 @@ class UserProfileTest extends Base
$user = new DatabaseUserProvider(array('id' => 2));
$this->assertFalse($userProfile->initialize($user));
- $this->assertFalse(isset($this->container['sessionStorage']->user));
+ $this->assertFalse(isset($_SESSION['user']));
}
public function testInitializeRemoteUser()
@@ -34,17 +34,17 @@ class UserProfileTest extends Base
$user = new LdapUserProvider('ldapId', 'bob', 'Bob', '', Role::APP_MANAGER, array());
$this->assertTrue($userProfile->initialize($user));
- $this->assertNotEmpty($this->container['sessionStorage']->user);
- $this->assertEquals(2, $this->container['sessionStorage']->user['id']);
- $this->assertEquals('bob', $this->container['sessionStorage']->user['username']);
- $this->assertEquals(Role::APP_MANAGER, $this->container['sessionStorage']->user['role']);
+ $this->assertNotEmpty($_SESSION['user']);
+ $this->assertEquals(2, $_SESSION['user']['id']);
+ $this->assertEquals('bob', $_SESSION['user']['username']);
+ $this->assertEquals(Role::APP_MANAGER, $_SESSION['user']['role']);
$user = new LdapUserProvider('ldapId', 'bob', 'Bob', '', Role::APP_MANAGER, array());
$this->assertTrue($userProfile->initialize($user));
- $this->assertNotEmpty($this->container['sessionStorage']->user);
- $this->assertEquals(2, $this->container['sessionStorage']->user['id']);
- $this->assertEquals('bob', $this->container['sessionStorage']->user['username']);
+ $this->assertNotEmpty($_SESSION['user']);
+ $this->assertEquals(2, $_SESSION['user']['id']);
+ $this->assertEquals('bob', $_SESSION['user']['username']);
}
public function testAssignRemoteUser()
@@ -53,11 +53,11 @@ class UserProfileTest extends Base
$user = new LdapUserProvider('ldapId', 'bob', 'Bob', '', Role::APP_MANAGER, array());
$this->assertTrue($userProfile->assign(1, $user));
- $this->assertNotEmpty($this->container['sessionStorage']->user);
- $this->assertEquals(1, $this->container['sessionStorage']->user['id']);
- $this->assertEquals('admin', $this->container['sessionStorage']->user['username']);
- $this->assertEquals('Bob', $this->container['sessionStorage']->user['name']);
- $this->assertEquals('', $this->container['sessionStorage']->user['email']);
- $this->assertEquals(Role::APP_MANAGER, $this->container['sessionStorage']->user['role']);
+ $this->assertNotEmpty($_SESSION['user']);
+ $this->assertEquals(1, $_SESSION['user']['id']);
+ $this->assertEquals('admin', $_SESSION['user']['username']);
+ $this->assertEquals('Bob', $_SESSION['user']['name']);
+ $this->assertEquals('', $_SESSION['user']['email']);
+ $this->assertEquals(Role::APP_MANAGER, $_SESSION['user']['role']);
}
}
diff --git a/tests/units/Core/User/UserSessionTest.php b/tests/units/Core/User/UserSessionTest.php
index 2a118079..5e7bab43 100644
--- a/tests/units/Core/User/UserSessionTest.php
+++ b/tests/units/Core/User/UserSessionTest.php
@@ -9,8 +9,7 @@ class UserSessionTest extends Base
{
public function testInitialize()
{
- $us = new UserSession($this->container);
-
+ $userSession = new UserSession($this->container);
$user = array(
'id' => '123',
'username' => 'john',
@@ -23,101 +22,97 @@ class UserSessionTest extends Base
'role' => Role::APP_MANAGER,
);
- $us->initialize($user);
-
- $session = $this->container['sessionStorage']->getAll();
+ $userSession->initialize($user);
- $this->assertNotEmpty($session);
- $this->assertEquals(123, $session['user']['id']);
- $this->assertEquals('john', $session['user']['username']);
- $this->assertEquals(Role::APP_MANAGER, $session['user']['role']);
- $this->assertFalse($session['user']['is_ldap_user']);
- $this->assertFalse($session['user']['twofactor_activated']);
- $this->assertArrayNotHasKey('password', $session['user']);
- $this->assertArrayNotHasKey('twofactor_secret', $session['user']);
- $this->assertArrayNotHasKey('is_admin', $session['user']);
- $this->assertArrayNotHasKey('is_project_admin', $session['user']);
+ $this->assertNotEmpty($_SESSION);
+ $this->assertEquals(123, $_SESSION['user']['id']);
+ $this->assertEquals('john', $_SESSION['user']['username']);
+ $this->assertEquals(Role::APP_MANAGER, $_SESSION['user']['role']);
+ $this->assertFalse($_SESSION['user']['is_ldap_user']);
+ $this->assertFalse($_SESSION['user']['twofactor_activated']);
+ $this->assertArrayNotHasKey('password', $_SESSION['user']);
+ $this->assertArrayNotHasKey('twofactor_secret', $_SESSION['user']);
+ $this->assertArrayNotHasKey('is_admin', $_SESSION['user']);
+ $this->assertArrayNotHasKey('is_project_admin', $_SESSION['user']);
- $this->assertEquals('john', $us->getUsername());
+ $this->assertEquals('john', $userSession->getUsername());
}
public function testGetId()
{
- $us = new UserSession($this->container);
+ $userSession = new UserSession($this->container);
- $this->assertEquals(0, $us->getId());
+ $this->assertEquals(0, $userSession->getId());
- $this->container['sessionStorage']->user = array('id' => 2);
- $this->assertEquals(2, $us->getId());
+ $_SESSION['user'] = array('id' => 2);
+ $this->assertEquals(2, $userSession->getId());
- $this->container['sessionStorage']->user = array('id' => '2');
- $this->assertEquals(2, $us->getId());
+ $_SESSION['user'] = array('id' => '2');
+ $this->assertEquals(2, $userSession->getId());
}
public function testIsLogged()
{
- $us = new UserSession($this->container);
+ $userSession = new UserSession($this->container);
+ $this->assertFalse($userSession->isLogged());
- $this->assertFalse($us->isLogged());
+ $_SESSION['user'] = array();
+ $this->assertFalse($userSession->isLogged());
- $this->container['sessionStorage']->user = array();
- $this->assertFalse($us->isLogged());
-
- $this->container['sessionStorage']->user = array('id' => 1);
- $this->assertTrue($us->isLogged());
+ $_SESSION['user'] = array('id' => 1);
+ $this->assertTrue($userSession->isLogged());
}
public function testIsAdmin()
{
- $us = new UserSession($this->container);
-
- $this->assertFalse($us->isAdmin());
+ $userSession = new UserSession($this->container);
+ $this->assertFalse($userSession->isAdmin());
- $this->container['sessionStorage']->user = array('role' => Role::APP_ADMIN);
- $this->assertTrue($us->isAdmin());
+ $_SESSION['user'] = array('role' => Role::APP_ADMIN);
+ $this->assertTrue($userSession->isAdmin());
- $this->container['sessionStorage']->user = array('role' => Role::APP_USER);
- $this->assertFalse($us->isAdmin());
+ $_SESSION['user'] = array('role' => Role::APP_USER);
+ $this->assertFalse($userSession->isAdmin());
- $this->container['sessionStorage']->user = array('role' => '');
- $this->assertFalse($us->isAdmin());
+ $_SESSION['user'] = array('role' => '');
+ $this->assertFalse($userSession->isAdmin());
}
public function testFilters()
{
- $us = new UserSession($this->container);
- $this->assertEquals('status:open', $us->getFilters(1));
+ $userSession = new UserSession($this->container);
+ $this->assertEquals('status:open', $userSession->getFilters(1));
- $us->setFilters(1, 'assignee:me');
- $this->assertEquals('assignee:me', $us->getFilters(1));
+ $userSession->setFilters(1, 'assignee:me');
+ $this->assertEquals('assignee:me', $userSession->getFilters(1));
- $this->assertEquals('status:open', $us->getFilters(2));
+ $this->assertEquals('status:open', $userSession->getFilters(2));
- $us->setFilters(2, 'assignee:bob');
- $this->assertEquals('assignee:bob', $us->getFilters(2));
+ $userSession->setFilters(2, 'assignee:bob');
+ $this->assertEquals('assignee:bob', $userSession->getFilters(2));
}
public function testPostAuthentication()
{
- $us = new UserSession($this->container);
- $this->assertFalse($us->isPostAuthenticationValidated());
+ $userSession = new UserSession($this->container);
+ $this->assertFalse($userSession->isPostAuthenticationValidated());
- $this->container['sessionStorage']->postAuthenticationValidated = false;
- $this->assertFalse($us->isPostAuthenticationValidated());
+ $_SESSION['postAuthenticationValidated'] = false;
+ $this->assertFalse($userSession->isPostAuthenticationValidated());
- $us->validatePostAuthentication();
- $this->assertTrue($us->isPostAuthenticationValidated());
+ $userSession->validatePostAuthentication();
+ $this->assertTrue($userSession->isPostAuthenticationValidated());
- $this->container['sessionStorage']->user = array();
- $this->assertFalse($us->hasPostAuthentication());
+ $_SESSION['user'] = array();
+ $this->assertFalse($userSession->hasPostAuthentication());
- $this->container['sessionStorage']->user = array('twofactor_activated' => false);
- $this->assertFalse($us->hasPostAuthentication());
+ $_SESSION['user'] = array('twofactor_activated' => false);
+ $this->assertFalse($userSession->hasPostAuthentication());
- $this->container['sessionStorage']->user = array('twofactor_activated' => true);
- $this->assertTrue($us->hasPostAuthentication());
+ $_SESSION['user'] = array('twofactor_activated' => true);
+ $this->assertTrue($userSession->hasPostAuthentication());
- $us->disablePostAuthentication();
- $this->assertFalse($us->hasPostAuthentication());
+ $userSession->disablePostAuthentication();
+ $this->assertFalse($userSession->hasPostAuthentication());
}
}