diff --git a/application/modules/opac/controllers/CasServerController.php b/application/modules/opac/controllers/CasServerController.php index 2fd3938e1821a528e42e7d6d46e851dbe7f9cc54..0a75d54eec165b9d3638d16956623110033b72f3 100644 --- a/application/modules/opac/controllers/CasServerController.php +++ b/application/modules/opac/controllers/CasServerController.php @@ -22,15 +22,7 @@ class CasServerController extends Zend_Controller_Action { use Trait_StaticFileWriter; protected $service; // url de retour protected $values; - function init() - { - // Désactiver le view renderer - $viewRenderer = $this->getHelper('ViewRenderer'); - $viewRenderer->setNoRender(); - } - - public function returnValidTicketResponse($user, $ticket) { $this->getResponse()->setHeader('Content-Type', 'application/xml;charset=utf-8'); @@ -81,12 +73,14 @@ class CasServerController extends Zend_Controller_Action { function serviceValidateAction() { + $this->getHelper('ViewRenderer')->setNoRender(); $this->getResponse()->setHeader('Content-Type', 'application/xml;charset=utf-8'); $this->getResponse()->setBody("<form method='post' action=''><div>Identifiant:<input type='text' size='15' id='username' /></div><div>Mot de passe: <input type='text' size='15' id='password' /></div></form>"); } function validateMusicmeAction() { + $this->getHelper('ViewRenderer')->setNoRender(); $bibid=$this->_request->getParam('MediaLibraryID'); $ticket=$this->_request->getParam('ticket'); @@ -106,6 +100,7 @@ class CasServerController extends Zend_Controller_Action { /* INTERNAL_ERROR - an internal error occurred during ticket validation */ function validateAction() { + $this->getHelper('ViewRenderer')->setNoRender(); $service=$this->_request->getParam('service'); $ticket=$this->_request->getParam('ticket'); if (strlen($ticket)<1 || strlen($service)<1) { diff --git a/application/modules/opac/controllers/CasServerV10Controller.php b/application/modules/opac/controllers/CasServerV10Controller.php new file mode 100644 index 0000000000000000000000000000000000000000..1c451f6781e27a1e243300674ca052029f2ce892 --- /dev/null +++ b/application/modules/opac/controllers/CasServerV10Controller.php @@ -0,0 +1,45 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 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). + * + * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +class CasServerV10Controller extends CasServerController { + // see http://www.jasig.org/cas/protocol#validate-cas-1.0 + public function returnValidTicketResponse($user, $ticket) { + $this->getResponse()->setBody('yes'.chr(10)); + } + + + public function returnFailureTicketResponse($error,$ticket=null) { + $this->getResponse()->setBody('no'.chr(10)); + } + + + public function loginAction() { + $this->_forward('login', 'auth'); + } + + + public function logoutAction() { + ZendAfi_Auth::getInstance()->clearIdentity(); + if ($url_redirect = $this->_getParam('url')) + $this->_redirect($url_redirect); + } +} + +?> diff --git a/application/modules/opac/views/scripts/cas-server-v10/logout.phtml b/application/modules/opac/views/scripts/cas-server-v10/logout.phtml new file mode 100644 index 0000000000000000000000000000000000000000..eac5946e65c8447520821b30eba549926c87225a --- /dev/null +++ b/application/modules/opac/views/scripts/cas-server-v10/logout.phtml @@ -0,0 +1 @@ +<p><?php echo $this->_('Vous avez été déconnecté'); ?></p> diff --git a/tests/application/modules/opac/controllers/CasServerControllerTest.php b/tests/application/modules/opac/controllers/CasServerControllerTest.php index 5aaa827bbed24d6bc8274664a49f06d9839dc9ac..055acafccef78a2e7d1a5c642fabf3a51c837a6d 100644 --- a/tests/application/modules/opac/controllers/CasServerControllerTest.php +++ b/tests/application/modules/opac/controllers/CasServerControllerTest.php @@ -18,8 +18,7 @@ * along with AFI-OPAC 2.0; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -require_once 'AbstractControllerTestCase.php'; -require_once 'application/modules/opac/controllers/CasServerController.php'; + class CasServerControllerValidateActionTest extends AbstractControllerTestCase { protected $session_file_contents_logged; @@ -38,7 +37,7 @@ class CasServerControllerValidateActionTest extends AbstractControllerTestCase { /** @test */ public function requestWithNoTicketShouldRespondinvalidRequestFailureXML() { $this->dispatch('/opac/cas-server/validate?service=http://test.com'); - $this->assertContains('<cas:authenticationFailure code="INVALID_REQUEST">',$this->_response->getBody()); + $this->assertContains('<cas:authenticationFailure code="INVALID_REQUEST">',$this->_response->getBody()); } @@ -77,6 +76,59 @@ class CasServerControllerValidateActionTest extends AbstractControllerTestCase { $this->assertContains('<cas:user>300</cas:user>',$this->_response->getBody()); $this->assertContains('<cas:proxyGrantingTicket>',$this->_response->getBody()); } + + + /** + * see http://www.jasig.org/cas/protocol#validate-cas-1.0 + * @test + */ + public function validateOnCasOneZeroWithValidTicketShouldAnswerYesLF() { + $this->dispatch( + '/opac/cas-server-v10/validate?ticket=ST-'.md5(Zend_Session::getId().'300').'&service=http://test.com', + true); + $this->assertEquals('yes'.chr(10), $this->_response->getBody()); + } + + + /** @test */ + public function validateOnCasOneZeroWithInValidTicketShouldAnswerNoLF() { + $this->dispatch( + '/opac/cas-server-v10/validate?ticket=zork&service=http://test.com', + true); + $this->assertEquals('no'.chr(10), $this->_response->getBody()); + } + + + /** @test */ + public function loginOnCasOneZeroShouldRedirectToServiceWithTicket() { + $this->dispatch('/opac/cas-server-v10/login?service=http://test.com', true); + $this->assertRedirectTo( + 'http://test.com?ticket='.(new Class_CasTicket())->getTicketForCurrentUser(), + $this->getResponseLocation()); + } + + + /** @test */ + public function loginOnCasOneZeroWithoutOpenedSessionShouldDisplayLoginForm() { + ZendAfi_Auth::getInstance()->clearIdentity(); + $this->dispatch('/opac/cas-server-v10/login?service=http://test.com', true); + $this->assertXPath('//form//input[@name="password"]'); + } + + + /** @test */ + public function logoutOnCasOneZeroShouldClearIdentityAndDisplayThatYouHaveBeenDisconnected() { + $this->dispatch('/opac/cas-server-v10/logout', true); + $this->assertXPathContentContains('//p', 'Vous avez été déconnecté'); + $this->assertEmpty(ZendAfi_Auth::getInstance()->getIdentity()); + } + + + /** @test */ + public function logoutOnCasOneZeroWithUrlParamShouldRedirectToIt() { + $this->dispatch('/opac/cas-server-v10/logout?url=http://go-out.com', true); + $this->assertRedirectTo('http://go-out.com'); + } } @@ -116,3 +168,5 @@ class CasServerControllerMusicMeValidateActionTest extends AbstractControllerTes } } + +?> \ No newline at end of file