diff --git a/.gitattributes b/.gitattributes index 0d5c57a24b23d5af5a81899d0e32c6e265db7f76..e4435a893ce5847291ec31111c68eddb187b2665 100644 --- a/.gitattributes +++ b/.gitattributes @@ -827,6 +827,7 @@ application/modules/opac/views/scripts/upload/form.phtml -text application/modules/opac/views/scripts/upload/upload.phtml -text application/modules/opac/views/scripts/upload/uploadmultiple.phtml -text application/modules/push/controllers/MultimediaController.php -text +application/modules/push/controllers/WebkioskController.php -text application/modules/telephone/controllers/AbonneController.php -text application/modules/telephone/controllers/AuthController.php -text application/modules/telephone/controllers/BibNumeriqueController.php -text @@ -2315,11 +2316,16 @@ library/Class/MultiUpload/HandlerForm.php -text library/Class/MultiUpload/HandlerXhr.php -text library/Class/Multimedia.php -text library/Class/Multimedia/AuthenticateRequest.php -text +library/Class/Multimedia/Connector/Renderer/Encrypt.php -text +library/Class/Multimedia/Connector/Renderer/Json.php -text +library/Class/Multimedia/Connector/Webkiosk.php -text library/Class/Multimedia/Device.php -text library/Class/Multimedia/DeviceGroup.php -text library/Class/Multimedia/DeviceHold.php -text library/Class/Multimedia/Location.php -text +library/Class/Multimedia/PushAllUsersRequest.php -text library/Class/Multimedia/ReservationBean.php -text +library/Class/Multimedia/Utils/OpensslUtil.php -text library/Class/MusicMeLink.php -text library/Class/NatureDoc.php -text library/Class/Newsletter.php -text @@ -5944,6 +5950,7 @@ tests/application/modules/opac/controllers/SocialNetworkControllerTest.php -text tests/application/modules/opac/controllers/UploadControllerTest.php -text tests/application/modules/opac/controllers/ead.xsd -text tests/application/modules/push/controllers/MultimediaControllerTest.php -text +tests/application/modules/push/controllers/WebkioskControllerTest.php -text tests/application/modules/telephone/controllers/AbonneControllerTest.php -text tests/application/modules/telephone/controllers/AdminModuleIndexControllerTest.php -text tests/application/modules/telephone/controllers/AuthControllerTest.php -text diff --git a/application/modules/push/controllers/WebkioskController.php b/application/modules/push/controllers/WebkioskController.php new file mode 100644 index 0000000000000000000000000000000000000000..995aaa6246d9e662f39976ae0300752dca71967b --- /dev/null +++ b/application/modules/push/controllers/WebkioskController.php @@ -0,0 +1,38 @@ +<?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 WebkioskController extends Zend_Controller_Action { + + public function getAllBorrowersAction(){ + $this->getHelper('ViewRenderer')->setNoRender(); + $attributes = ['id', 'login', 'password', 'nom', 'prenom', 'email', + 'dateNaissanceIso8601', 'dateFin', 'dateDebut']; + $response = Class_Multimedia_PushAllUsersRequest::newWith( + Class_Multimedia_Connector_Webkiosk::getInstance() + ->initAttributes($attributes)) + ->getResponse($this->_request); + + $this->_response->setBody($response); + } +} + + + + diff --git a/library/Class/Multimedia/Connector/Renderer/Encrypt.php b/library/Class/Multimedia/Connector/Renderer/Encrypt.php new file mode 100644 index 0000000000000000000000000000000000000000..66ca74c510d5ad9c106bae1878257edbf09ece67 --- /dev/null +++ b/library/Class/Multimedia/Connector/Renderer/Encrypt.php @@ -0,0 +1,48 @@ +<?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 Class_Multimedia_Connector_Renderer_Encrypt{ + + protected static $_openssl; + + public function render($data){ + $sealed_data = ''; + $env_keys = array(); + $this->getOpenssl()->opensslSeal($data , $sealed_data ,$env_keys , + [Class_AdminVar::get('WEBKIOSK_KEY')]); + + $response = new StdClass(); + $response->data_encrypted = base64_encode($sealed_data); + $response->symetric_key = base64_encode($env_keys[0]); + $response->sha_data = sha1($data); + return $response; + } + + public function getOpenssl(){ + if(null !== self::$_openssl) + return self::$_openssl; + return new Class_Multimedia_Utils_OpensslUtil(); + } + + public static function setOpenssl($openssl){ + self::$_openssl = $openssl; + } +} \ No newline at end of file diff --git a/library/Class/Multimedia/Connector/Renderer/Json.php b/library/Class/Multimedia/Connector/Renderer/Json.php new file mode 100644 index 0000000000000000000000000000000000000000..bf52d1a0d1c4319591262c480d9c388b0ebcfc83 --- /dev/null +++ b/library/Class/Multimedia/Connector/Renderer/Json.php @@ -0,0 +1,26 @@ +<?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 Class_Multimedia_Connector_Renderer_Json { + public function render($data) { + return json_encode($data); + } +} \ No newline at end of file diff --git a/library/Class/Multimedia/Connector/Webkiosk.php b/library/Class/Multimedia/Connector/Webkiosk.php new file mode 100644 index 0000000000000000000000000000000000000000..cf10bff126e5a58f2ee05b01660986483945a82e --- /dev/null +++ b/library/Class/Multimedia/Connector/Webkiosk.php @@ -0,0 +1,129 @@ +<?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 Class_Multimedia_Connector_Webkiosk { + const DATA_SEPARATOR = '--@--'; + + /** @category testing */ + protected static $_instance; + + + protected $_response; + protected $_attributes; + + /** Listes des objets renders dans l'ordre à effectuer sur les datas */ + protected $_renderers = array(); + + public static function getInstance(){ + if (null !== self::$_instance) + return self::$_instance; + return new self(); + } + + /** @category testing */ + public static function setInstance($instance) { + self::$_instance = $instance; + } + + public function __construct() { + $this->_renderers = [new Class_Multimedia_Connector_Renderer_Json(), new Class_Multimedia_Connector_Renderer_Encrypt(), new Class_Multimedia_Connector_Renderer_Json()]; + } + + public function initAttributes($attributes){ + $this->_attributes = $attributes; + return $this; + } + public function setRenderers($renderers){ + $this->_renderers = $renderers; + } + + public function render($request, $itemsClosure) { + if (!$this->_renderers) + return ''; + + $this->_response = new StdClass(); + $this->_response->data = []; + $this->_response->error = ''; + + if (!$this->isValid($request)) + return $this->renderResponse(); + + $itemsClosure(); + return $this->renderResponse(); + } + + public function renderResponse() { + foreach ($this->_renderers as $renderer) + $this->_response = $renderer->render($this->_response); + return $this->_response; + } + + public function newItem($item) { + $this->_response->data[] = $this->stdClassFrom($item); + } + + public function stdClassFrom($item) { + $data = new StdClass(); + $this->_attributes = ['id', 'login', 'password', 'nom', 'prenom', 'email','dateNaissanceIso8601', 'dateFin', 'dateDebut']; + foreach ($this->_attributes as $attribute) { + $method = 'get' . ucfirst($attribute); + $data->$attribute = $item->$method(); + } + return $data; + } + + + public function isValid($request) { + if (!($sign = $request->getParam('sign'))) { + $this->_response->error = 'NO_PARAMETERS'; + return false; + } + + if(!Class_AdminVar::isWebkioskEnabled()){ + $this->_response->error = 'WEBKIOSK_DISABLED'; + return false; + } + + $openssl = new Class_Multimedia_Utils_OpensslUtil(); + $isValidated =$openssl->opensslVerify( + $this->dataFor($request->getActionName()), + base64_decode($sign), + Class_AdminVar::get('WEBKIOSK_KEY')); + restore_error_handler(); + + // openssl_free_key($public_key); + if($isValidated == -1){ + $this->_response->error = 'ERROR_CHECKING_SIGNATURE'; + return false; + } + + if($isValidated == 0){ + $this->_response->error = 'INVALID_SIGNATURE'; + return false; + } + + return true; + } + + public function dataFor($data) { + return $data . self::DATA_SEPARATOR . date('Ymd'); + } +} \ No newline at end of file diff --git a/library/Class/Multimedia/PushAllUsersRequest.php b/library/Class/Multimedia/PushAllUsersRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..b5eb26997ebbb9cbcf6aaf805f6e2888d8f18b6e --- /dev/null +++ b/library/Class/Multimedia/PushAllUsersRequest.php @@ -0,0 +1,49 @@ +<?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 Class_Multimedia_PushAllUsersRequest { + private $_connector; + + public static function newWith($connector) { + return new self($connector); + } + + public function __construct($connector) { + $this->_connector = $connector; + } + + public function getResponse($request) { + return $this->_connector->render($request, function () { + $this->withBorrowersDo(); + }); + } + + public function withBorrowersDo() { + $users = Class_Users::getAllBorrowers(); + if ($users) + $this->withUsersDo($users); + } + + public function withUsersDo($users) { + foreach ($users as $user) + $this->_connector->newItem($user); + } +} \ No newline at end of file diff --git a/library/Class/Multimedia/Utils/OpensslUtil.php b/library/Class/Multimedia/Utils/OpensslUtil.php new file mode 100644 index 0000000000000000000000000000000000000000..f530d4f881e6877567e13a956cfbc910ef4dacd5 --- /dev/null +++ b/library/Class/Multimedia/Utils/OpensslUtil.php @@ -0,0 +1,47 @@ +<?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 Class_Multimedia_Utils_OpensslUtil{ + + protected $_error_verify_sign; + + public function opensslSeal($data , &$sealed_data , + &$env_keys , $pub_key_ids){ + + return openssl_seal ($data , $sealed_data ,$env_keys ,$pub_key_ids); + + } + + public function opensllVerifyHandlerError($errno, $errstr, $errfile, $errline){ + $this->_error_verify_sign = true; + return true; + } + + + public function opensslVerify($data ,$sign, $pub_key){ + set_error_handler(array($this, 'opensllVerifyHandlerError')); + $result = @openssl_verify($data, $sign, $pub_key); + restore_error_handler(); + if($this->_error_verify_sign) + return -1; + return $result; + } +} \ No newline at end of file diff --git a/tests/application/modules/push/controllers/WebkioskControllerTest.php b/tests/application/modules/push/controllers/WebkioskControllerTest.php new file mode 100644 index 0000000000000000000000000000000000000000..ef1a09cf716348e764aeb827ba10314801c7de0d --- /dev/null +++ b/tests/application/modules/push/controllers/WebkioskControllerTest.php @@ -0,0 +1,389 @@ +<?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 + */ +require_once 'AbstractControllerTestCase.php'; +require_once 'application/modules/push/controllers/WebkioskController.php'; + + +abstract class WebkioskControllerTestCase extends AbstractControllerTestCase { + protected + $_resp, + $_private_key ="-----BEGIN RSA PRIVATE KEY----- +MIICWwIBAAKBgQCm1hgee4LI7ji06BkuV8O4XpxHe59n80Gge/r3uROj+Tuxx2AO +Sk9gX7e4JNVsdfw22ft+xVqwAii8qu4/fYuicrrZl66WXceACmsgGWEdHMB7ZPUd +4HqR5bdE1Xnr1Q0Z9IIku6Naxt/yy0P5Gv+ZlW7U287hF3sdh2dp7UgguQIDAQAB +AoGAUQv+aYh8r1myqId7/Bxckws7BirS9G+iuPChqYf6N5US37lIO4jz6JB3MniK +SYdDf+4DE8GR3aEe4xBybttxYi9JSG28LxSMvUCv13AOpj8GT34cDxDgwczDI9nb +549/hdGpRF+vW0imfA1lguyuteoQHRMUImoHdl8ZRzPXlaUCQQDWEThzawIlbjah +v5uEQ5OjHIJfDECDyV4IIBGfwcpsiCH98Rb4SzcFRvoIJ7HtmNuHT6/fR5JQmnQG +0Vn6qTw3AkEAx4Rk4e/uLSxdDrsqI3rXg+mSNUAXc1IlHUJpRvoktbpfxTwRjwxO +Pp7HmcaApw5RuJ0nOnNGE0J4GBjEAglyjwJAKJ+p+9VB2gKZYYawJ6B/YwPlBc6Y +a6oKKzaSwaOQG5qWANAA0OvNLDY0+tk1neZVOs93i8LUVHGLNUQDdFsrbwJATEXi +wzUUGpThJmaK33Fwvm8mg9DyphV7NspSsN2j9w0+24nxNHyB1RKiP7lRKYwh1a/O +dVvoKCi6/ItLM3QlJQJAEyvWEfvqKnFH13ID5oe/GVOih7O6VzgecEgd3ZawBVWd +dsZ77MnSRzIyzrfJ3LlluaXhJl2qJBITE7X8y5RTKw== +-----END RSA PRIVATE KEY-----", + + $_public_key = "-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCm1hgee4LI7ji06BkuV8O4XpxH +e59n80Gge/r3uROj+Tuxx2AOSk9gX7e4JNVsdfw22ft+xVqwAii8qu4/fYuicrrZ +l66WXceACmsgGWEdHMB7ZPUd4HqR5bdE1Xnr1Q0Z9IIku6Naxt/yy0P5Gv+ZlW7U +287hF3sdh2dp7UgguQIDAQAB +-----END PUBLIC KEY-----", + + + $_invalid_public_key = "-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC6Q3TAOV6nWuS720NH4uas8Wdn +NMBZnbqsshKYeCzCCvqZJfwAyHMcSDQVvbqN452cqsZGKmxUbsRQMtcIml0gablf +Eq5k1SeviSt8OtxkK+pzJHrsC2GBlZuppoKsS9zwwlTEPttY9EgEY53mCSLF4IGD +yIuUs1qpg+Vx0R+3VwIDAQAB +-----END PUBLIC KEY-----"; + + public function setUp() { + parent::setUp(); + } + + /** + * @param $url string + * @return stdClass + */ + public function getResponseJsonDecode($url) { + $this->dispatch($url, true); + return json_decode($this->_response->getBody()); + } + + public function getPublicKey(){ + return $this->_public_key; + } + + public function signUrl($action){ + $connector = new Class_Multimedia_Connector_Webkiosk(); + openssl_sign($connector->dataFor($action), + $sign, + $this->_private_key); + return base64_encode($sign); + } +} + + +abstract class WebkioskControllerJsonEncodeOnlyTestCase extends WebkioskControllerTestCase { + public function setUp() { + parent::setUp(); + $connector = new Class_Multimedia_Connector_Webkiosk(); + $connector->setRenderers([new Class_Multimedia_Connector_Renderer_Json()]); + Class_Multimedia_Connector_Webkiosk::setInstance($connector); + } +} + +class WebkioskControllerGetAllBorrowersValidationTest extends WebkioskControllerJsonEncodeOnlyTestCase { + public function setUp() { + parent::setUp(); + $this->_resp = $this->getResponseJsonDecode('/webkiosk/get-all-borrowers'); + } + + + /** @test */ + public function responseShouldNotBeARedirect() { + $this->assertNotRedirect(); + } + + + /** @test */ + public function controllerActionShouldBeMultimediaAllBorrowers() { + $this->assertController('webkiosk', $this->_response->getBody()); + $this->assertAction('get-all-borrowers'); + } + +} + + +class WebkioskControllerNoParameterTest extends WebkioskControllerJsonEncodeOnlyTestCase { + + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneControllerWebkioskUsersFixtures::getLoas(), + AbonneControllerWebkioskUsersFixtures::getAmadou()]); + + Class_AdminVar::getLoader() + ->newInstanceWithId('WEBKIOSK_KEY') + ->setValeur($this->getPublicKey()); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('/webkiosk/get-all-borrowers'); + } + + + /** @test */ + public function shouldHaveNumberDataZero() { + $this->assertEquals(0, count($this->_resp->data)); + } + + /** @test */ + public function shouldBeReturnedNoParameters() { + $connector = new Class_Multimedia_Connector_Webkiosk(); + $this->assertEquals('NO_PARAMETERS', $this->_resp->error); + } +} + +class WebkioskControllerWebkioskDisabledTest extends WebkioskControllerJsonEncodeOnlyTestCase { + + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneControllerWebkioskUsersFixtures::getLoas(), + AbonneControllerWebkioskUsersFixtures::getAmadou()]); + + Class_AdminVar::getLoader() + ->newInstanceWithId('WEBKIOSK_KEY') + ->setValeur(''); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('/webkiosk/get-all-borrowers?sign=' . urlencode($sign)); + } + + + /** @test */ + public function shouldHaveNumberDataZero() { + $this->assertEquals(0, count($this->_resp->data)); + } + + /** @test */ + public function shouldBeReturnedWebKioskDesabled() { + $this->assertEquals('WEBKIOSK_DISABLED', $this->_resp->error); + } +} + + + +class WebkioskControllerInvalidSignatureTest extends WebkioskControllerJsonEncodeOnlyTestCase { + + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneControllerWebkioskUsersFixtures::getLoas(), + AbonneControllerWebkioskUsersFixtures::getAmadou()]); + + Class_AdminVar::getLoader() + ->newInstanceWithId('WEBKIOSK_KEY') + ->setValeur($this->_invalid_public_key); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('/webkiosk/get-all-borrowers?sign=' . urlencode($sign)); + } + + + /** @test */ + public function shouldHaveNumberDataZero() { + $this->assertEquals(0, count($this->_resp->data)); + } + + /** @test */ + public function shouldBeReturnedInvalidSignature() { + $this->assertEquals('INVALID_SIGNATURE', $this->_resp->error); + } +} + + + +class WebkioskControllerErrorCheckingSignatureTest extends WebkioskControllerJsonEncodeOnlyTestCase { + + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneControllerWebkioskUsersFixtures::getLoas(), + AbonneControllerWebkioskUsersFixtures::getAmadou()]); + + Class_AdminVar::getLoader() + ->newInstanceWithId('WEBKIOSK_KEY') + ->setValeur('"-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCm1hgee4LI +-----END PUBLIC KEY-----"'); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('/webkiosk/get-all-borrowers?sign=' . urlencode($sign)); + } + + + /** @test */ + public function shouldHaveNumberDataZero() { + $this->assertEquals(0, count($this->_resp->data)); + } + + /** @test */ + public function shouldBeReturnedErrorCheckingSignature() { + $this->assertEquals('ERROR_CHECKING_SIGNATURE', $this->_resp->error); + } +} + + +class WebkioskControllerGetAllBorrowersNumberOfOccurencesReturnedTest extends WebkioskControllerJsonEncodeOnlyTestCase { + + public function setUp() { + parent::setUp(); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneControllerWebkioskUsersFixtures::getLoas(), + AbonneControllerWebkioskUsersFixtures::getAmadou()]); + + Class_AdminVar::getLoader() + ->newInstanceWithId('WEBKIOSK_KEY') + ->setValeur($this->getPublicKey()); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('/webkiosk/get-all-borrowers?sign=' . urlencode($sign)); + } + + /** @test */ + public function shouldHave2Borrowers() { + $connector = new Class_Multimedia_Connector_Webkiosk(); + + $this->assertEquals(2, count($this->_resp->data)); + } +} + + +class WebkioskControllerFirstBorrowerReturnedIsLoasTest extends WebkioskControllerJsonEncodeOnlyTestCase { + + + public function setUp() { + parent::setUp(); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneControllerWebkioskUsersFixtures::getLoas(), + AbonneControllerWebkioskUsersFixtures::getAmadou()]); + + Class_AdminVar::getLoader() + ->newInstanceWithId('WEBKIOSK_KEY') + ->setValeur($this->getPublicKey()); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('/webkiosk/get-all-borrowers?sign=' . urlencode($sign)); + } + + /** @test */ + public function shouldReturnedNameFisrtBorrowerIsLoas() { + $this->assertEquals('Loas', $this->_resp->data[0]->nom); + } + + + /** @test */ + public function shouldReturnedPasswordFisrtBorrowerIsLoas42Pat() { + $this->assertEquals('loas42Pat', $this->_resp->data[0]->password); + } + + /** @test */ + public function roleLevelShouldNotBePresent() { + $this->assertFalse( property_exists($this->_resp->data[0],'roleLevel')); + } +} + + + +abstract class WebkioskControllerJsonEncryptedTestCase extends WebkioskControllerTestCase { + public function setUp() { + parent::setUp(); + $connector = new Class_Multimedia_Connector_Webkiosk(); + $connector->setRenderers([new Class_Multimedia_Connector_Renderer_Json(), new Class_Multimedia_Connector_Renderer_Encrypt(), new Class_Multimedia_Connector_Renderer_Json()]); + Class_Multimedia_Connector_Webkiosk::setInstance($connector); + } +} + + +class WebkioskControllerEncryptedDataTest extends WebkioskControllerJsonEncryptedTestCase { + + public function setUp() { + parent::setUp(); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('getAllBorrowers') + ->answers([AbonneControllerWebkioskUsersFixtures::getLoas(), + AbonneControllerWebkioskUsersFixtures::getAmadou()]); + + Class_Multimedia_Connector_Renderer_Encrypt::setOpenssl(new OpensslTesting()); + Class_AdminVar::getLoader() + ->newInstanceWithId('WEBKIOSK_KEY') + ->setValeur($this->getPublicKey()); + + $sign = $this->signUrl('get-all-borrowers'); + $this->_resp = $this->getResponseJsonDecode('/webkiosk/get-all-borrowers?sign=' . urlencode($sign)); + } + + /** @test */ + public function shouldHaveDataCryptedEqualsToto() { + $this->assertEquals('toto', base64_decode($this->_resp->data_encrypted)); + } + + /** @test */ + public function shouldHaveSymetricKeyEqual123456789() { + $this->assertEquals('123456789', base64_decode($this->_resp->symetric_key)); + } +} + +class OpensslTesting extends Class_Multimedia_Utils_OpensslUtil{ + public function opensslSeal($data, &$sealed_data, &$env_keys, + $pub_key_ids){ + $sealed_data = 'toto'; + $env_keys[]= '123456789'; + + return true; + } +} + +class AbonneControllerWebkioskUsersFixtures { + public static function getLoas() { + return Class_Users::getLoader()->newInstanceWithId(11) + ->beAbonneSIGB() + ->setLogin("loas") + ->setPassword("loas42Pat") + ->setNom('Loas') + ->setPrenom('Ghislain') + ->setRoleLevel(2) + ->setIdabon('all1') + ->setNaissance('1978-02-17') + ->setDateFin('2030-01-01') + ->setDateDebut('2022-01-01') + ->setEmail('loas@mail.fr'); + } + + + public static function getAmadou() { + return Class_Users::getLoader()->newInstanceWithId(11) + ->beAbonneSIGB() + ->setLogin("ama") + ->setPassword("ama") + ->setNom('Amadou') + ->setPrenom('DIOUF') + ->setRoleLevel(2) + ->setIdabon('all2') + ->setNaissance('1980-02-17') + ->setDateFin('2030-01-01') + ->setDateDebut('2029-01-01') + ->setEmail('loas@mail.fr'); + } +} \ No newline at end of file