diff --git a/FEATURES/198623 b/FEATURES/198623 new file mode 100644 index 0000000000000000000000000000000000000000..a9b645e53ef28ea192ac77a5694a0a78d4520f33 --- /dev/null +++ b/FEATURES/198623 @@ -0,0 +1,17 @@ + '198623' => + ['Label' => $this->_('Ressources numériques - Accès direct à la page d'accueil d'une ressource via le CAS d'un identity provider'), + 'Desc' => + $this->_( +' * ajout de la possibilité d\'ajouter le paramètre /id_provider/num derrière un lien de ressource numérique + De cette façon, un usager connecté à la bibliothèque référencée sur le bokeh principal en tant que id_provider num, + pourra suivre le lien http://mabibcentrale.fr/modules/nommodule/id_provider/num et être automatiquement connecté au catalogue. + * Prise en compte du paramètre url_redirect dans la connection via provider. + De cette façon, un lien https://mabib.fr/cas-server-v3/login?service=https://mabibcentrale.fr/auth/login/provider/num/url_redirect/http%3A%2F%2Fmabibcentrale.fr%2Fmodules%2Fmonmodule redirigera un usager connecté à mabib.fr + sur la page catalogue de la ressource monmodule en tant qu\'usager.'), + 'Image' => '', + 'Video' => '', + 'Category' => '', + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => '', + 'Test' => '', + 'Date' => '2024-12-30'], \ No newline at end of file diff --git a/VERSIONS_WIP/198623 b/VERSIONS_WIP/198623 new file mode 100644 index 0000000000000000000000000000000000000000..7696b20ce46b7b53a2a616741e7a743cfa509485 --- /dev/null +++ b/VERSIONS_WIP/198623 @@ -0,0 +1 @@ + - fonctionnalité #198623 : Ressources numériques : Accès direct à la page d'accueil d'une ressource via le CAS d'un identity provider \ No newline at end of file diff --git a/application/modules/opac/controllers/AuthController.php b/application/modules/opac/controllers/AuthController.php index 7a5231a7e23582f0e6756019c26ea2b87fc9a686..f48c1025612c888a732c150af3fc6f5abbb838d3 100644 --- a/application/modules/opac/controllers/AuthController.php +++ b/application/modules/opac/controllers/AuthController.php @@ -193,11 +193,15 @@ class AuthController extends ZendAfi_Controller_Action { 'cas' => $cas, 'id_notice' => $this->view->id_notice])); - $settings = ['Preferences' => $preferences, 'FormOptions' => ['data' => array_merge($preferences, $datas), - 'action' => $url_action]]; + $settings = ['Preferences' => $preferences, + 'FormOptions' => ['data' => array_merge($preferences, $datas), + 'action' => $url_action]]; $strategy->processLogin(); + if ($this->_response->isRedirect()) + return; + $this->view->titreAdd($this->_('Connexion')); $this->view->preferences = $preferences; $this->view->titre = $this->view->title = $strategy->getPageTitle($this->view); @@ -211,11 +215,7 @@ class AuthController extends ZendAfi_Controller_Action { 'action' => 'index', 'controller' => 'index']); - $redirect_candidate = $redirect_candidate ?: $this->_getParam('redirect', $default); - - if (Class_Url::isABokehUrl($redirect_candidate)) - return $redirect_candidate; - return null; + return $redirect_candidate ?: $this->_getParam('redirect', $default); } diff --git a/library/Class/Auth/IdentityProvider.php b/library/Class/Auth/IdentityProvider.php index caef91337cf9e910934d9b1622f3e225bef34fa5..ccb6e2d792b073a70c93e330bffcec1704d44185 100644 --- a/library/Class/Auth/IdentityProvider.php +++ b/library/Class/Auth/IdentityProvider.php @@ -194,8 +194,14 @@ class Class_Auth_IdentityProviderNotLogged extends Class_Auth_NotLogged { protected function _redirectToProviderSuccessOrDefaultUrl($provider) { $this->_doOnLoginSuccess(); - return $this->setRedirectUrl(($url = $provider->loginSuccessRedirectUrl()) - ? $url - : $this->default_url); + + $redirect_url = $this->controller->getRequest()->getParam('redirect_url') + ?: $provider->loginSuccessRedirectUrl() + ?: $this->controller->getRequest()->getParam('redirect') + ?: $this->default_url; + + if ($redirect_url) + return $this->setRedirectUrl($redirect_url); + return null; } } diff --git a/library/Class/DigitalResource/Controller.php b/library/Class/DigitalResource/Controller.php index 1bf131676121790f7a8a1ad0b1e6b4fa260399a0..f28c9537466db4b70297f6f7ddc049191bc4a8d0 100644 --- a/library/Class/DigitalResource/Controller.php +++ b/library/Class/DigitalResource/Controller.php @@ -30,12 +30,14 @@ class Class_DigitalResource_Controller extends ZendAfi_Controller_Action { if ($this->_config->getSsoAction() == $this->_request->getActionName()) return $this->_forward('sso', 'index', - $this->_config->getModuleName()); + $this->_config->getModuleName(), + $this->_request->getParams()); return null; } - public function indexAction() { + public function indexAction() + { if(!$user = Class_Users::getIdentity()) return $this->_afterLoginRedirectTo($this->view->absoluteUrl(), $this->_('Vous devez vous connecter pour accéder à cette page')); @@ -50,10 +52,18 @@ class Class_DigitalResource_Controller extends ZendAfi_Controller_Action { } - public function ssoAction() { - if(!$user = Class_Users::getIdentity()) + protected function _checkUserLoggedForProvider(int $identity_provider_id) + { + if (!$identity_provider = Class_IdentityProvider::find($identity_provider_id)) return $this->_afterLoginRedirectTo($this->view->absoluteUrl(), $this->_('Vous devez vous connecter pour accéder à cette page')); + + return $this->_redirect($identity_provider->loginUrl('')); + } + + + protected function _redirectToRessourceSsoIfAllowed(Class_Users $user) + { $url = $this->_config->urlFor($user, $this->_request->getParams()); return $url ? $this->_javascriptRedirectTo($url) @@ -61,6 +71,18 @@ class Class_DigitalResource_Controller extends ZendAfi_Controller_Action { } + public function ssoAction() { + if ($user = Class_Users::getIdentity()) + return $this->_redirectToRessourceSsoIfAllowed($user); + + if ($identity_provider_id = (int)$this->_getParam('id_provider')) + return $this->_checkUserLoggedForProvider($identity_provider_id); + + return $this->_afterLoginRedirectTo($this->view->absoluteUrl(), + $this->_('Vous devez vous connecter pour accéder à cette page')); + } + + public function jsonHarvestAction() { $this->_helper->json(json_decode($this->_config->getServiceInstance()->getHarvestPage(1))); } diff --git a/library/Class/Url.php b/library/Class/Url.php index b225b79766398347b06d5668d6ca7a1a5feceb95..b7a45a238399cfa3a337e3c64d3f678d539a8aff 100644 --- a/library/Class/Url.php +++ b/library/Class/Url.php @@ -105,8 +105,8 @@ class Class_Url { public static function isABokehUrl($string) { - return ((strpos('/',(string) $string) == 0) - || (strpos(static::absolute([], null, true), (string) $string) == 0)); + return ((strpos((string) $string, '/') === 0) + || (strpos((string) $string, static::absolute([], null, true)) === 0)); } diff --git a/library/digital_resources/ArteVod/tests/ArteVodSSoTest.php b/library/digital_resources/ArteVod/tests/ArteVodSSoTest.php index 0c486bb24a815fe025ecd20e4ef459266e8a2d3f..8ed48d957f83cff1c2ac35386588c24624e4be2a 100644 --- a/library/digital_resources/ArteVod/tests/ArteVodSSoTest.php +++ b/library/digital_resources/ArteVod/tests/ArteVodSSoTest.php @@ -18,7 +18,7 @@ * along with BOKEH; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class ArteSSoWithUserAndAlbumTest extends ModelTestCase { +class ArteVodSSoWithUserAndAlbumTest extends ModelTestCase { protected $_sso_key = 'secret', @@ -154,7 +154,7 @@ class ArteSSoWithUserAndAlbumTest extends ModelTestCase { -class ModulesControllerArteVodTest extends AbstractControllerTestCase { +class ArteVodSsoConnectionTest extends AbstractControllerTestCase { public function setUp(): void { @@ -163,14 +163,14 @@ class ModulesControllerArteVodTest extends AbstractControllerTestCase { Class_AdminVar::set('ArteVod_SSO_KEY', '123'); Class_AdminVar::set('ArteVod_LOGIN', '123'); - $group = $this->fixture('Class_UserGroup', + $group = $this->fixture(Class_UserGroup::class, [ 'id' => 42, 'libelle' => 'Accès ARTEVOD']); - $this->fixture('Class_Users', - ['id' => 1, - 'login' => 'Tom', - 'password' => 'pwd']) + $this->fixture(Class_Users::class, + ['id' => 1, + 'login' => 'Tom', + 'password' => 'pwd']) ->setUserGroups([$group]); Class_Users::setTimeSource(new TimeSourceForTest('2020-03-10')); } diff --git a/library/digital_resources/ArteVod/tests/ArteVodSsoConnectionWithIdentityProviderTest.php b/library/digital_resources/ArteVod/tests/ArteVodSsoConnectionWithIdentityProviderTest.php new file mode 100644 index 0000000000000000000000000000000000000000..015347f2b45e223d9957de103bd542797abe7532 --- /dev/null +++ b/library/digital_resources/ArteVod/tests/ArteVodSsoConnectionWithIdentityProviderTest.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright (c) 2012-2024, 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 + */ + + +class ArteVodSsoConnectionWithIdentityProviderTest extends AbstractControllerTestCase +{ + public function setUp(): void + { + parent::setUp(); + $this->fixture(Class_IdentityProvider::class, + ['id' => 1, + 'type' => Class_IdentityProvider_Types::CAS3, + 'active' => 1, + 'protocol' => 'openid_connect_1', + 'config' => '{"url":"https:\/\/casserver.org\/cas-server-v3\/"}' + ]); + Class_AdminVar::set('ArteVod_SSO_KEY', '123'); + Class_AdminVar::set('NOM_DOMAINE', 'mymediatheque.com'); + ZendAfi_Auth::getInstance()->clearIdentity(); + $this->dispatch('/opac/modules/arte-vod/id_provider/1'); + } + + + /** @test */ + public function pageShouldRedirectToCasServer() + { + $this->assertRedirectTo('https://casserver.org/cas-server-v3/login?service=' + .urlencode('http://localhost'.BASE_URL.'/auth/login/provider/1')); + } +} diff --git a/library/digital_resources/ArteVod/tests/ArteVodUrlRedirectTest.php b/library/digital_resources/ArteVod/tests/ArteVodUrlRedirectTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8bc4a389b3bf3038b9a28dcd710cfe5440c5e8c9 --- /dev/null +++ b/library/digital_resources/ArteVod/tests/ArteVodUrlRedirectTest.php @@ -0,0 +1,67 @@ +<?php +/** + * Copyright (c) 2012-2024, 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 + */ + + +class ArteVodUrlRedirectAuthLoginTest extends AbstractControllerTestCase +{ + + public function setUp(): void + { + parent::setUp(); + + $this->fixture(Class_IdentityProvider::class, + ['id' => 1, + 'type' => Class_IdentityProvider_Types::CAS3, + 'active' => 1, + 'protocol' => 'openid_connect_1', + 'config' => '{"url":"https:\/\/casserver.org\/cas-server-v3\/"}' + ]); + + $this->fixture(Class_Users::class, + ['id' => 33, + 'login' => 'Pierre', + 'password' => '11111' + ]); + + ZendAfi_Auth::getInstance()->logUser(Class_Users::find(33)); + + $this->fixture(Class_User_Identity::class, + ['id' => 1, + 'provider_id' => 1, + 'user_id' => 33, + 'identifier' => '9999']); + + Class_WebService_Cas3::loginWith('9999'); + + Class_AdminVar::set('ArteVod_SSO_KEY', '123'); + Class_AdminVar::set('NOM_DOMAINE', 'mymediatheque.com'); + ZendAfi_Auth::getInstance()->clearIdentity(); + + $this->dispatch('auth/login/provider/1/redirect_url/' .urlencode('https://www.arteenligne.fr')); + } + + + /** @test */ + public function pageShouldRedirectToArteEnLigneDotFr() + { + $this->assertRedirectTo('https://www.arteenligne.fr'); + } +} diff --git a/library/digital_resources/Cafeyn/tests/CafeynSsoConnectionWithIdentityProviderTest.php b/library/digital_resources/Cafeyn/tests/CafeynSsoConnectionWithIdentityProviderTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d2513b8ddc0cbd644dea2ae9a389798062e50b42 --- /dev/null +++ b/library/digital_resources/Cafeyn/tests/CafeynSsoConnectionWithIdentityProviderTest.php @@ -0,0 +1,61 @@ +<?php +/** + * Copyright (c) 2012-2024, 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 + */ + + +class CafeynSsoConnectionWithIdentityProviderTest + extends AbstractControllerTestCase +{ + public function setUp(): void + { + parent::setUp(); + + Class_AdminVar::set('Cafeyn_ID', '66'); + Class_AdminVar::set('Cafeyn_SSO_URL', "https://www.cafeyn.co/loginexternal//// \t\n"); + Class_AdminVar::set('Cafeyn_API_PASSWORD', 'POIS'); + Class_AdminVar::set('Cafeyn_API_ID', 'mybib'); + + $this->fixture(Class_IdentityProvider::class, + ['id' => 1, + 'type' => Class_IdentityProvider_Types::CAS3, + 'active' => 1, + 'protocol' => 'openid_connect_1', + 'config' => '{"url":"https:\/\/casserver.org\/cas-server-v3\/"}' + ]); + ZendAfi_Auth::getInstance()->clearIdentity(); + $this->dispatch('/opac/modules/cafeyn/id_provider/1'); + } + + public function tearDown() : void + { + Class_AdminVar::set('Cafeyn_ID', ''); + Class_AdminVar::set('Cafeyn_SSO_URL', ''); + Class_AdminVar::set('Cafeyn_API_PASSWORD', ''); + Class_AdminVar::set('Cafeyn_API_ID', ''); + } + + + /** @test */ + public function pageShouldRedirectToCasServer() + { + $this->assertRedirectTo('https://casserver.org/cas-server-v3/login?service=' + .urlencode('http://localhost'.BASE_URL.'/auth/login/provider/1')); + } +} diff --git a/library/digital_resources/Cafeyn/tests/CafeynTest.php b/library/digital_resources/Cafeyn/tests/CafeynTest.php index cd692dfa2803ec5c89b86d894882f778e30fdc11..f83257cdf8274948fa1d87bab4daf16f355360a4 100644 --- a/library/digital_resources/Cafeyn/tests/CafeynTest.php +++ b/library/digital_resources/Cafeyn/tests/CafeynTest.php @@ -41,6 +41,7 @@ class CafeynAdminVars { + abstract class CafeynActivatedTestCase extends AbstractControllerTestCase { protected $_user; diff --git a/library/digital_resources/Cvs2/tests/Cvs2SsoConnectionWithIdentityProviderTest.php b/library/digital_resources/Cvs2/tests/Cvs2SsoConnectionWithIdentityProviderTest.php new file mode 100644 index 0000000000000000000000000000000000000000..423bd130d01551c4a4043c2b121b158316a24ce2 --- /dev/null +++ b/library/digital_resources/Cvs2/tests/Cvs2SsoConnectionWithIdentityProviderTest.php @@ -0,0 +1,72 @@ +<?php +/** + * Copyright (c) 2012-2024, 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 + */ + + +class Cvs2SsoConnectionWithIdentityProviderTest extends AbstractControllerTestCase +{ + public function setUp(): void + { + parent::setUp(); + + Class_AdminVar::set('Cvs2_BMKEY', '22222'); + Class_AdminVar::set('Cvs2_BMID', '22223'); + Class_AdminVar::set('Cvs2_SOURCENAME', '22224'); + Class_AdminVar::set('Cvs2_SOURCEID', '22225'); + Class_AdminVar::set('Cvs2_SOURCEKEY', '22226'); + Class_AdminVar::set('Cvs2_SOURCEPASSWORD', '22227'); + Class_AdminVar::set('Cvs2_API_URL', 'http://cvs.api.org'); + Class_AdminVar::set('Cvs2_LOGINTEST', 'cvs_login_test'); + Class_AdminVar::set('Cvs2_CATALOG_URL', 'http://cvs-site.com'); + + $this->fixture(Class_IdentityProvider::class, + ['id' => 1, + 'type' => Class_IdentityProvider_Types::CAS3, + 'active' => 1, + 'protocol' => 'openid_connect_1', + 'config' => '{"url":"https:\/\/casserver.org\/cas-server-v3\/"}' + ]); + ZendAfi_Auth::getInstance()->clearIdentity(); + $this->dispatch('/opac/modules/cvs2/id_provider/1'); + } + + + + public function tearDown(): void + { + Class_AdminVar::set('Cvs2_BMKEY', ''); + Class_AdminVar::set('Cvs2_BMID', ''); + Class_AdminVar::set('Cvs2_SOURCENAME', ''); + Class_AdminVar::set('Cvs2_SOURCEID', ''); + Class_AdminVar::set('Cvs2_SOURCEKEY', ''); + Class_AdminVar::set('Cvs2_SOURCEPASSWORD', ''); + Class_AdminVar::set('Cvs2_API_URL', ''); + Class_AdminVar::set('Cvs2_LOGINTEST', ''); + + parent::tearDown(); + } + + /** @test */ + public function pageShouldRedirectToCasServer() + { + $this->assertRedirectTo('https://casserver.org/cas-server-v3/login?service=' + .urlencode('http://localhost'.BASE_URL.'/auth/login/provider/1')); + } +} diff --git a/library/digital_resources/Mangasio/tests/MangasioSsoConnectionWithIdentityProviderAndUserConnectedTest.php b/library/digital_resources/Mangasio/tests/MangasioSsoConnectionWithIdentityProviderAndUserConnectedTest.php new file mode 100644 index 0000000000000000000000000000000000000000..6073e31f1d329c988d0c602c2eabdf573567de36 --- /dev/null +++ b/library/digital_resources/Mangasio/tests/MangasioSsoConnectionWithIdentityProviderAndUserConnectedTest.php @@ -0,0 +1,64 @@ +<?php +/** + * Copyright (c) 2012-2024, 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 + */ + + +class MangasioSsoConnectionWithIdentityProviderAndUserConnectedTest + extends AbstractControllerTestCase +{ + public function setUp(): void + { + parent::setUp(); + Class_AdminVar::set('Mangasio_ID', '12'); + Class_AdminVar::set('Mangasio_NAME', 'afi'); + Class_AdminVar::set('Mangasio_SSO_URL', 'https://cafeyn-sso-url'); + Class_AdminVar::set('Mangasio_API_PASSWORD', 'POIS'); + Class_AdminVar::set('Mangasio_API_ID', 'mybib'); + Class_AdminVar::set('Mangasio_HARVEST_URL', 'https://app.ubd.com/api/v2'); + + $this->fixture(Class_IdentityProvider::class, + ['id' => 1, + 'type' => Class_IdentityProvider_Types::CAS3, + 'active' => 1, + 'protocol' => 'openid_connect_1', + 'config' => '{"url":"https:\/\/casserver.org\/cas-server-v3\/"}' + ]); + $this->dispatch('/opac/modules/mangasio/id_provider/1'); + } + + + public function tearDown() : void + { + Class_AdminVar::set('Mangasio_NAME', ''); + Class_AdminVar::set('Mangasio_ID', ''); + Class_AdminVar::set('Mangasio_SSO_URL', ''); + Class_AdminVar::set('Mangasio_API_PASSWORD', ''); + Class_AdminVar::set('Mangasio_API_ID', ''); + Class_AdminVar::set('Mangasio_HARVEST_URL', ''); + } + + + /** @test */ + public function pageShouldRedirectToSsoUrl() + { + $this->assertXPathContentContains('//script', + 'document.location.href="https://cafeyn-sso-url"'); + } +} diff --git a/library/digital_resources/Mangasio/tests/MangasioSsoConnectionWithIdentityProviderTest.php b/library/digital_resources/Mangasio/tests/MangasioSsoConnectionWithIdentityProviderTest.php new file mode 100644 index 0000000000000000000000000000000000000000..00216540ad48d742b6b3933f22ddb7de64dca114 --- /dev/null +++ b/library/digital_resources/Mangasio/tests/MangasioSsoConnectionWithIdentityProviderTest.php @@ -0,0 +1,65 @@ +<?php +/** + * Copyright (c) 2012-2024, 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 + */ + + +class MangasioSsoConnectionWithIdentityProviderTest + extends AbstractControllerTestCase +{ + public function setUp(): void + { + parent::setUp(); + Class_AdminVar::set('Mangasio_ID', '12'); + Class_AdminVar::set('Mangasio_NAME', 'afi'); + Class_AdminVar::set('Mangasio_SSO_URL', 'https://cafeyn-sso-url'); + Class_AdminVar::set('Mangasio_API_PASSWORD', 'POIS'); + Class_AdminVar::set('Mangasio_API_ID', 'mybib'); + Class_AdminVar::set('Mangasio_HARVEST_URL', 'https://app.ubd.com/api/v2'); + + $this->fixture(Class_IdentityProvider::class, + ['id' => 1, + 'type' => Class_IdentityProvider_Types::CAS3, + 'active' => 1, + 'protocol' => 'openid_connect_1', + 'config' => '{"url":"https:\/\/casserver.org\/cas-server-v3\/"}' + ]); + ZendAfi_Auth::getInstance()->clearIdentity(); + $this->dispatch('/opac/modules/mangasio/id_provider/1'); + } + + + public function tearDown() : void + { + Class_AdminVar::set('Mangasio_NAME', ''); + Class_AdminVar::set('Mangasio_ID', ''); + Class_AdminVar::set('Mangasio_SSO_URL', ''); + Class_AdminVar::set('Mangasio_API_PASSWORD', ''); + Class_AdminVar::set('Mangasio_API_ID', ''); + Class_AdminVar::set('Mangasio_HARVEST_URL', ''); + } + + + /** @test */ + public function pageShouldRedirectToCasServer() + { + $this->assertRedirectTo('https://casserver.org/cas-server-v3/login?service=' + .urlencode('http://localhost'.BASE_URL.'/auth/login/provider/1')); + } +} diff --git a/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationTest.php b/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationTest.php index e2b4eeb82467da5eccae998e7559cd45be2be3b5..25e836dd5179e7e7352b44b4ac0c58a7a465ceb8 100644 --- a/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationTest.php +++ b/tests/scenarios/IdentityProvider/IdentityProviderAuthenticationTest.php @@ -1182,7 +1182,7 @@ class IdentityProviderAuthenticationAuthLoginAlreadyAssociatedAchetezaTest Class_WebService_Acheteza::loginWith(9763); - $this->fixture('Class_User_Identity', + $this->fixture(Class_User_Identity::class, ['id' => 1, 'provider_id' => 5, 'user_id' => 33,