diff --git a/.travis.yml b/.travis.yml index 3dccb0c09..9ce1c2496 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,7 +30,7 @@ before_script: - cd tests # run unit tests, create result file -script: ../vendor/bin/phpunit --configuration phpunit.xml --coverage-text --coverage-clover=coverage.clover +script: ../vendor/bin/phpunit --verbose --debug --configuration phpunit.xml --coverage-text --coverage-clover=coverage.clover # gets tools from Scrutinizer, uploads unit tests results to Scrutinizer (?) after_script: diff --git a/application/core/Auth.php b/application/core/Auth.php index 10430b14a..84761fe7d 100644 --- a/application/core/Auth.php +++ b/application/core/Auth.php @@ -72,7 +72,7 @@ public static function checkAdminAuthentication() */ public static function checkSessionConcurrency(){ if(Session::userIsLoggedIn()){ - if(Session::isConcurrentSessionExists()){ + if(Session::isSessionBroken()){ LoginModel::logout(); Redirect::home(); exit(); diff --git a/application/core/Session.php b/application/core/Session.php index 89d64c6ef..a489a6ec5 100644 --- a/application/core/Session.php +++ b/application/core/Session.php @@ -84,8 +84,10 @@ public static function updateSessionId($userId, $sessionId = null) } /** - * checks for session concurrency - * + * checks for broken session + * Session could be broken by Session concurrency or when user is deleted / suspended + * + * - Session concurrency is done as the following: * This is done as the following: * UserA logs in with his session id('123') and it will be stored in the database. * Then, UserB logs in also using the same email and password of UserA from another PC, @@ -94,6 +96,9 @@ public static function updateSessionId($userId, $sessionId = null) * Now, Whenever UserA performs any action, * You then check the session_id() against the last one stored in the database('456'), * If they don't match then log both of them out. + * + * - Check for deleted / suspended users: + * Suspended/deleted users have no userSessionId anymore stored in database * * @access public * @static static method @@ -101,7 +106,7 @@ public static function updateSessionId($userId, $sessionId = null) * @see Session::updateSessionId() * @see http://stackoverflow.com/questions/6126285/php-stop-concurrent-user-logins */ - public static function isConcurrentSessionExists() + public static function isSessionBroken() { $session_id = session_id(); $userId = Session::get('user_id'); @@ -117,7 +122,7 @@ public static function isConcurrentSessionExists() $result = $query->fetch(); $userSessionId = !empty($result)? $result->session_id: null; - return $session_id !== $userSessionId; + return empty($userSessionId) || $session_id !== $userSessionId; } return false; diff --git a/tests/core/ConfigTest.php b/tests/core/ConfigTest.php index 11dae0508..fe20047d4 100644 --- a/tests/core/ConfigTest.php +++ b/tests/core/ConfigTest.php @@ -23,9 +23,14 @@ public function tearDown() /** * Checks if the correct config file for an EXISTING environment / config is called. + * + * @runInSeparateProcess */ public function testGetDefaultEnvironment() { + // for testing + header_remove(); + // manually set environment to "development" putenv('APPLICATION_ENV=development'); @@ -33,8 +38,14 @@ public function testGetDefaultEnvironment() $this->assertEquals('index', Config::get('DEFAULT_ACTION')); } + /** + * @runInSeparateProcess + */ public function testGetFailingEnvironment() { + // for testing + header_remove(); + // manually set environment to "foobar" (and non-existing environment) putenv('APPLICATION_ENV=foobar'); diff --git a/tests/core/EnvironmentTest.php b/tests/core/EnvironmentTest.php index a6d32cf72..462144b85 100644 --- a/tests/core/EnvironmentTest.php +++ b/tests/core/EnvironmentTest.php @@ -4,14 +4,12 @@ class EnvironmentTest extends PHPUnit_Framework_TestCase { public function testGetDefault() { - // call for environment should return "development" - $this->assertEquals('development', Environment::get()); - } + // call for environment should return "testing" like set in .travis.yml + $this->assertEquals('testing', Environment::get()); - public function testGetDevelopment() - { - putenv('APPLICATION_ENV=development'); - // call for environment should return "development" + putenv('APPLICATION_ENV='); + + // call for environment should now return "development", the default value $this->assertEquals('development', Environment::get()); } @@ -20,4 +18,12 @@ public function testGetProduction() putenv('APPLICATION_ENV=production'); $this->assertEquals('production', Environment::get()); } + + public function testGetDevelopment() + { + putenv('APPLICATION_ENV=development'); + // call for environment should return "development" + $this->assertEquals('development', Environment::get()); + } + }