From 16cb0cf351df0474bdb0e160e08a1ff109c8b34d Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Mon, 9 Jul 2018 15:01:34 +0200 Subject: [PATCH] hotline #77068 : update version + fix try sso --- VERSIONS_HOTLINE/77068 | 3 +- .../opac/controllers/AuthController.php | 1 + library/Class/DigitalResource/Controller.php | 7 ++-- .../Orthodidacte/tests/OrthodidacteTest.php | 32 +++++++++++++++++-- 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/VERSIONS_HOTLINE/77068 b/VERSIONS_HOTLINE/77068 index 1e7cffa3f7c..65ee52f24f9 100644 --- a/VERSIONS_HOTLINE/77068 +++ b/VERSIONS_HOTLINE/77068 @@ -1 +1,2 @@ - - ticket #77068 : Orthodidacte : problème de connexion suite changement de mot de passe ? \ No newline at end of file + - ticket #77068 : Orthodidacte : migration de la ressource vers le système de plugin. + \ No newline at end of file diff --git a/application/modules/opac/controllers/AuthController.php b/application/modules/opac/controllers/AuthController.php index a4a6e752307..56857ad4d6f 100644 --- a/application/modules/opac/controllers/AuthController.php +++ b/application/modules/opac/controllers/AuthController.php @@ -646,6 +646,7 @@ class AuthController extends ZendAfi_Controller_Action { $this->_helper->notify($this->_('Vous êtes maintenant connecté avec l\'utilisateur "%s"', $user->getNomComplet())); + $this->_redirectToUrlOrReferer('/opac/index/index'); } } diff --git a/library/Class/DigitalResource/Controller.php b/library/Class/DigitalResource/Controller.php index 96905634ac4..cc8415c8618 100644 --- a/library/Class/DigitalResource/Controller.php +++ b/library/Class/DigitalResource/Controller.php @@ -61,12 +61,15 @@ class Class_DigitalResource_Controller extends ZendAfi_Controller_Action { public function trySsoAction() { - if (!Class_Users::getIdentity()->isSuperAdmin()) { + if (!ZendAfi_Auth_Others::getInstance()->isSuperAdminLogged()) { $this->_helper->notify($this->_('Vous n\'avez pas les droits suffisants pour utiliser cette fonctionnalité.')); return $this->_redirectToReferer(); } - ZendAfi_Auth::getInstance()->logUser($this->_config->getTestUser()); + ZendAfi_Auth_Others::getInstance() + ->swapUserWith(Class_Users::getIdentity(), + $this->_config->getTestUser()); + $this->_forward('sso'); } diff --git a/library/digital_resources/Orthodidacte/tests/OrthodidacteTest.php b/library/digital_resources/Orthodidacte/tests/OrthodidacteTest.php index 6e0f75442de..5ead53308c3 100644 --- a/library/digital_resources/Orthodidacte/tests/OrthodidacteTest.php +++ b/library/digital_resources/Orthodidacte/tests/OrthodidacteTest.php @@ -62,7 +62,6 @@ protected 'preferences' => [], 'sous_menus' => ''] ]]]]]; - $profil_adulte = $this->fixture('Class_Profil', ['id' => 22, 'parent_id' => null]) @@ -77,7 +76,6 @@ protected ->setLibelle('Profil Adulte') ->setCfgMenus($cfg_menus_without_Orthodidacte); - Class_Profil::setCurrentProfil($profil_adulte); $this->fixture('Class_UserGroup', @@ -133,12 +131,21 @@ protected + abstract class OrthodidacteActivatedTestCase extends Admin_AbstractControllerTestCase { protected $_storm_default_to_volatile = true; public function setUp() { parent::setUp(); + + ZendAfi_Auth::getInstance() + ->logUser($this->fixture('Class_Users', + ['id' => 666, + 'login' => 'Trop fort', + 'password' => 'oui', + 'role_level' => ZendAfi_Acl_AdminControllerRoles::SUPER_ADMIN])); + Class_AdminVar::set('Orthodidacte_SSO_URL', 'https://orthodidacte.com/'); $user = $this->fixture('Class_Users', ['id' => 56, @@ -157,6 +164,7 @@ abstract class OrthodidacteActivatedTestCase extends Admin_AbstractControllerTes + class OrthodidacteDashboardTest extends OrthodidacteActivatedTestCase { public function setUp() { parent::setUp(); @@ -232,3 +240,23 @@ class OrthodidacteMenuTest extends OrthodidacteActivatedTestCase { 'Lien vers Orthodidacte'); } } + + + +class OrthodidacteTrySsoTest extends OrthodidacteActivatedTestCase { + + /** @test */ + public function shouldRedirect() { + ZendAfi_Auth::getInstance()->clearIdentity(); + $this->dispatch('/Orthodidacte_Plugin/index/try-sso', true); + $this->assertRedirectTo('/'); + $this->assertFlashMessengerContentContains('Vous n\'avez pas les droits suffisants pour utiliser cette fonctionnalité.'); + } + + + /** @test */ + public function shouldRedirectWithScript() { + $this->dispatch('/Orthodidacte_Plugin/index/try-sso', true); + $this->assertXPathContentContains('//script', 'document.location.href="https://orthodidacte.com/";'); + } +} \ No newline at end of file -- GitLab