diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php index 4d38ab9b6c4ad762148fb8d37254a7264bdf1067..cd565ef452694ab74629737f1208f4bb3352d55d 100644 --- a/library/Class/AdminVar.php +++ b/library/Class/AdminVar.php @@ -272,7 +272,8 @@ class Class_AdminVarLoader extends Storm_Model_Loader { 'LEKIOSK_SSO_MODE' => Class_AdminVar_Meta::newCombo($this->_('Type de SSO lekiosk.com'), ['options' => ['selectOptions' => ['label' => $this->_('Mode d\'authentification'), - 'multioptions' => ['0' => 'Lien', '1' => 'CAS']]]])->bePrivate(), + 'multioptions' => ['' => 'Lien', + 'CAS' => 'CAS']]]])->bePrivate(), 'KIDILANGUES_VERSION' => Class_AdminVar_Meta::newCombo($this->_('Version de Kidilangues.'), ['options' => ['selectOptions' => ['label' => $this->_('Version'), diff --git a/library/Class/LeKiosk/CasLink.php b/library/Class/LeKiosk/CasLink.php new file mode 100644 index 0000000000000000000000000000000000000000..28320461f1d58aac260b9b9a08404e2e8023a972 --- /dev/null +++ b/library/Class/LeKiosk/CasLink.php @@ -0,0 +1,35 @@ +<?php +/** + * Copyright (c) 2012-2014, 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 Class_LeKiosk_CasLink { + public function url() { + return 'https://pro.lekiosk.com/AutentificationCas.aspx?' + . http_build_query( + [ + 'cas_fournisseur' => Class_Url::absolute(['controller' => 'cas-server-v10'], null, true), + 'id' => Class_AdminVar::get('LEKIOSK_ID'), + 'ReturnUrl' => $_SERVER['HTTP_REFERER'] + ] ); + } +} + +?> \ No newline at end of file diff --git a/library/Class/LeKioskLink.php b/library/Class/LeKiosk/Link.php similarity index 88% rename from library/Class/LeKioskLink.php rename to library/Class/LeKiosk/Link.php index bb9f9a03a5a5ebe70cfbc7f0fd441a2a1e8b26c8..39ef6a721714bbe7fa3116c8097722fdf210e19a 100644 --- a/library/Class/LeKioskLink.php +++ b/library/Class/LeKiosk/Link.php @@ -16,11 +16,11 @@ * * 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 */ -class Class_LeKioskLink { +class Class_LeKiosk_Link { const ROOT_URL = 'http://pro.lekiosk.com'; const BASE_URL = '/lekiosque.authenticate.aspx?'; const AES_KEY = '56FGH4sTOV9ZXr4Q'; @@ -31,7 +31,10 @@ class Class_LeKioskLink { public static function newFor($mail) { - return new self($mail); + return + ('CAS' == Class_AdminVar::get('LEKIOSK_SSO_MODE')) + ? new Class_LeKiosk_CasLink() + : new self($mail); } @@ -41,7 +44,7 @@ class Class_LeKioskLink { public function url() { - return static::ROOT_URL + return static::ROOT_URL . $this->baseUrl() . '&AccessHash=' . $this->accessHash(); } @@ -54,7 +57,7 @@ class Class_LeKioskLink { protected function baseUrl() { if (null === $this->_base_url) - $this->_base_url = static::BASE_URL + $this->_base_url = static::BASE_URL . 'email=' . $this->cryptedMail() . '&id=' . Class_AdminVar::get('LEKIOSK_ID') ; diff --git a/library/Class/Systeme/ModulesMenu/LeKiosk.php b/library/Class/Systeme/ModulesMenu/LeKiosk.php index 3d32198adedd6ac975e2aac547f653872eb96304..515d4b7d99ad46a504dca2cfc017defb35003e78 100644 --- a/library/Class/Systeme/ModulesMenu/LeKiosk.php +++ b/library/Class/Systeme/ModulesMenu/LeKiosk.php @@ -41,7 +41,7 @@ class Class_Systeme_ModulesMenu_LeKiosk extends Class_Systeme_ModulesMenu_SSOAbs return ''; } - return Class_LeKioskLink::newFor($user->getMail())->url(); + return Class_LeKiosk_Link::newFor($user->getMail())->url(); } public function isVisibleForProfil($profil) { diff --git a/tests/library/Class/LeKioskLinkTest.php b/tests/library/Class/LeKioskLinkTest.php index bcaea0f8c8e488176bf9a30ae9b0e42e8c59f44c..67e56edca8445a818b9cd295009feb659482361b 100644 --- a/tests/library/Class/LeKioskLinkTest.php +++ b/tests/library/Class/LeKioskLinkTest.php @@ -16,11 +16,13 @@ * * 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 */ +abstract class LeKioskLinkModeLinkTestCase extends ModelTestCase { + protected + $_storm_default_to_volatile = true; -class LeKioskLinkTest extends Storm_Test_ModelTestCase { public function setUp() { parent::setUp(); $this->fixture('Class_Profil', [ @@ -28,24 +30,28 @@ class LeKioskLinkTest extends Storm_Test_ModelTestCase { 'libelle' => 'portail', 'mail_site' => '']); - Class_AdminVar::newInstanceWithId('LEKIOSK_ID', ['valeur' => '29']); + Class_AdminVar::set('LEKIOSK_ID', '29'); } +} + + +class LeKioskLinkModeLinkTest extends LeKioskLinkModeLinkTestCase { /** @test */ - public function urlForMyemailAtLekioskDotComShouldBeAsExpected() { + public function urlForMyemailAtLekioskDotComShouldContainsEncryptedEmail() { $expected = 'http://pro.lekiosk.com/lekiosque.authenticate.aspx?email=1671f18f515f49271985280397c1c2bc48e1bfa31a3b638cb22e510e4953d65e&id=29&AccessHash=e6715cdcc53d6d2b130f4025ea44b67872eb5455'; $this->assertEquals( - $expected, - Class_LeKioskLink::newFor('myemail@lekiosk.com')->url() + $expected, + Class_LeKiosk_Link::newFor('myemail@lekiosk.com')->url() ); } /** @test */ - public function withoutMailShouldBeAsExpected() { + public function withoutMailShouldBeNotContainsEmailKey() { $expected = 'http://pro.lekiosk.com/lekiosque.authenticate.aspx?email=18ca3d8ad40255ce09d5d20debc1e069&id=29&AccessHash=b78f9cd4198878b85de383ccddd27ab286fc47f6'; - $this->assertEquals($expected, Class_LeKioskLink::newFor('')->url()); + $this->assertEquals($expected, Class_LeKiosk_Link::newFor('')->url()); } @@ -53,7 +59,34 @@ class LeKioskLinkTest extends Storm_Test_ModelTestCase { public function withEmptyUserMailShouldGetSiteOrProfileMail() { Class_Profil::find(1)->setMailSite('toto@example.com'); $expected = 'http://pro.lekiosk.com/lekiosque.authenticate.aspx?email=76903fe54055ab757db99c2370d89970e25c5b33b5a69cafc108c0031685af88&id=29&AccessHash=c5d56beb8fbd723bc562739cbc3f70ed43a79b9e'; - $this->assertEquals($expected, Class_LeKioskLink::newFor('')->url()); + $this->assertEquals($expected, Class_LeKiosk_Link::newFor('')->url()); + } +} + + + + +class LeKioskLinkModeSSOTest extends LeKioskLinkModeLinkTestCase { + public function setUp() { + parent::setUp(); + + $_SERVER['HTTP_REFERER'] = 'http://localhost/view/notice'; + Zend_Controller_Front::getInstance() + ->getRouter() + ->route(new Zend_Controller_Request_Http('http://localhost/')); + Class_AdminVar::set('LEKIOSK_SSO_MODE', 'CAS'); + } + + + /** @test */ + public function linkShouldBeCasUrlWithLeKioskId() { + $url = 'https://pro.lekiosk.com/AutentificationCas.aspx?' + .'cas_fournisseur=' . urlencode('http://localhost' . BASE_URL . '/cas-server-v10') + .'&id=29' + .'&ReturnUrl=' . urlencode('http://localhost/view/notice'); + + $this->assertEquals($url, + Class_LeKiosk_Link::newFor('')->url()); } } ?> \ No newline at end of file