diff --git a/VERSIONS_HOTLINE/138333 b/VERSIONS_HOTLINE/138333 new file mode 100644 index 0000000000000000000000000000000000000000..d351f2852fa6c3bd596edbf2b6ddc29531886c4f --- /dev/null +++ b/VERSIONS_HOTLINE/138333 @@ -0,0 +1 @@ + - ticket #138333 : Cosmogramme : Correction de la vérification de l'identification \ No newline at end of file diff --git a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/IdentityTest.php b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/IdentityTest.php new file mode 100644 index 0000000000000000000000000000000000000000..28c0b05769daffb2e43259ee84ec35f7f589015f --- /dev/null +++ b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/IdentityTest.php @@ -0,0 +1,72 @@ +<?php +/** + * Copyright (c) 2012-2021, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +abstract class Cosmo_IdentityTestCase extends CosmoControllerTestCase { + public function setUp() { + parent::setUp(); + + $this->_prepareLogin() + ->dispatch('/cosmo/annexe'); + } + + + protected function _prepareLogin() { + return $this; + } + + + /** @test */ + public function controllerShouldBeAuth() { + $this->assertEquals('auth', $this->_request->getControllerName()); + } + + + /** @test */ + public function actionShouldBeNotLogged() { + $this->assertEquals('not-logged', $this->_request->getActionName()); + } + + + /** @test */ + public function pageShouldContainsVousNEtesPlusConnecte() { + $this->assertXPathContentContains('//body', 'Vous n\'êtes plus connecté'); + } +} + + + + +class Cosmo_IdentityNotLoggedTest extends Cosmo_IdentityTestCase { + protected function _prepareLogin() { + unset($_SESSION[Class_CosmoAuth::SESSION_KEY]); + return $this; + } +} + + + + +class Cosmo_IdentityFailedLoginTest extends Cosmo_IdentityTestCase { + protected function _prepareLogin() { + Class_CosmoAuth::fail(); + return $this; + } +} diff --git a/cosmogramme/php/_init.php b/cosmogramme/php/_init.php index 954976b27bc24e1c5221dbf77e6c6be3887d801d..d056534a5fd1bf3bf339969cda5232a0d9b4e412 100644 --- a/cosmogramme/php/_init.php +++ b/cosmogramme/php/_init.php @@ -57,6 +57,4 @@ if (!session_id()) // Controle login if (isset($_REQUEST["action"]) && $_REQUEST['action'] == "logout") unset($_SESSION["passe"]); -if (!isset($_SESSION["passe"])) include("_identification.php"); - -?> +if (!Class_CosmoAuth::isLogged()) include("_identification.php"); diff --git a/library/Class/CosmoAuth.php b/library/Class/CosmoAuth.php index 626cc9983d676a5bedbb3b28d10ac813392f9084..327d4eaed20e61fea0822fce8ba6523b1da75fa2 100644 --- a/library/Class/CosmoAuth.php +++ b/library/Class/CosmoAuth.php @@ -51,6 +51,16 @@ class Class_CosmoAuth { } + public static function isLogged() { + return + isset($_SESSION[static::SESSION_KEY]) + && in_array($_SESSION[static::SESSION_KEY], + [static::ROLE_CATALOG, + static::ROLE_ADMIN, + static::ROLE_SYSTEM]); + } + + public static function beSystem() { return $_SESSION[static::SESSION_KEY] = static::ROLE_SYSTEM; } @@ -72,6 +82,6 @@ class Class_CosmoAuth { public static function fail() { - return $_SESSION[static::SESSION_KEY] = ''; + return $_SESSION[static::SESSION_KEY] = null; } } diff --git a/library/ZendAfi/Controller/Plugin/CosmoAuth.php b/library/ZendAfi/Controller/Plugin/CosmoAuth.php index 04d1c0384952e9a8a2740f67fdfb9b86be9bf353..dcbb00737ef9f398fdb116191eac0f31a01b69f7 100644 --- a/library/ZendAfi/Controller/Plugin/CosmoAuth.php +++ b/library/ZendAfi/Controller/Plugin/CosmoAuth.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with BOKEH; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -26,10 +26,9 @@ class ZendAfi_Controller_Plugin_CosmoAuth extends Zend_Controller_Plugin_Abstrac || 'auth' == $request->getControllerName()) return; - if (!isset($_SESSION['passe'])) { + if (!Class_CosmoAuth::isLogged()) { $request->setControllerName('auth'); $request->setActionName('not-logged'); } } } -?> \ No newline at end of file