From e0c5c7d072c03f0179c377e72162ea746a27e597 Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Fri, 25 Apr 2014 09:16:14 -0400 Subject: [PATCH] Added ReCaptcha library in prep. for VUFIND-313. --- composer.json | 1 + composer.lock | 48 +- vendor/autoload.php | 2 +- vendor/composer/autoload_namespaces.php | 1 + vendor/composer/autoload_real.php | 8 +- vendor/composer/installed.json | 48 ++ .../zendservice-recaptcha/.gitignore | 1 + .../zendservice-recaptcha/.travis.yml | 17 + .../zendservice-recaptcha/LICENSE.txt | 27 + .../zendservice-recaptcha/README.md | 11 + .../zendservice-recaptcha/composer.json | 33 ++ .../ZendService/ReCaptcha/Exception.php | 21 + .../ZendService/ReCaptcha/MailHide.php | 328 ++++++++++++ .../ReCaptcha/MailHideException.php | 21 + .../ZendService/ReCaptcha/ReCaptcha.php | 498 ++++++++++++++++++ .../ZendService/ReCaptcha/Response.php | 149 ++++++ .../zendservice-recaptcha/tests/Bootstrap.php | 92 ++++ .../tests/TestConfiguration.php.dist | 55 ++ .../tests/TestConfiguration.php.travis | 20 + .../ZendService/ReCaptcha/MailHideTest.php | 151 ++++++ .../ZendService/ReCaptcha/ReCaptchaTest.php | 303 +++++++++++ .../ZendService/ReCaptcha/ResponseTest.php | 103 ++++ .../zendservice-recaptcha/tests/_autoload.php | 40 ++ .../tests/phpunit.xml.dist | 13 + 24 files changed, 1985 insertions(+), 6 deletions(-) create mode 100644 vendor/zendframework/zendservice-recaptcha/.gitignore create mode 100644 vendor/zendframework/zendservice-recaptcha/.travis.yml create mode 100644 vendor/zendframework/zendservice-recaptcha/LICENSE.txt create mode 100644 vendor/zendframework/zendservice-recaptcha/README.md create mode 100644 vendor/zendframework/zendservice-recaptcha/composer.json create mode 100644 vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/Exception.php create mode 100644 vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/MailHide.php create mode 100644 vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/MailHideException.php create mode 100644 vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/ReCaptcha.php create mode 100644 vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/Response.php create mode 100644 vendor/zendframework/zendservice-recaptcha/tests/Bootstrap.php create mode 100644 vendor/zendframework/zendservice-recaptcha/tests/TestConfiguration.php.dist create mode 100644 vendor/zendframework/zendservice-recaptcha/tests/TestConfiguration.php.travis create mode 100644 vendor/zendframework/zendservice-recaptcha/tests/ZendService/ReCaptcha/MailHideTest.php create mode 100644 vendor/zendframework/zendservice-recaptcha/tests/ZendService/ReCaptcha/ReCaptchaTest.php create mode 100644 vendor/zendframework/zendservice-recaptcha/tests/ZendService/ReCaptcha/ResponseTest.php create mode 100644 vendor/zendframework/zendservice-recaptcha/tests/_autoload.php create mode 100644 vendor/zendframework/zendservice-recaptcha/tests/phpunit.xml.dist diff --git a/composer.json b/composer.json index 955f1b5b102..57e06cf31e3 100644 --- a/composer.json +++ b/composer.json @@ -66,6 +66,7 @@ "zendframework/zendframework": "2.2.7", "zendframework/zendrest": "2.*", "zendframework/zendservice-amazon": "2.*", + "zendframework/zendservice-recaptcha": "2.*", "jasig/phpCAS": "dev-master" } } diff --git a/composer.lock b/composer.lock index a870fe37b0f..4d0813a665f 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "0189fc21275f21ae6fd5abdc6dfb2f1e", + "hash": "e66238d1080a176e38ae125b46348914", "packages": [ { "name": "aferrandini/phpqrcode", @@ -655,6 +655,52 @@ }, "time": "2014-03-05 22:37:42" }, + { + "name": "zendframework/zendservice-recaptcha", + "version": "2.0.1", + "source": { + "type": "git", + "url": "https://github.com/zendframework/ZendService_ReCaptcha.git", + "reference": "4324cca8502d9f47b3b43a18acdd3fdbeb965536" + }, + "dist": { + "type": "zip", + "url": "https://packages.zendframework.com/composer/zendframework-zendservice-recaptcha-4324cca8502d9f47b3b43a18acdd3fdbeb965536-zip-8c45bf.zip", + "reference": "2.0.1", + "shasum": "fab92465cda889ff975c1ec79bb378d7e3f39081" + }, + "require": { + "php": ">=5.3.3", + "zendframework/zend-http": ">=2.0.0", + "zendframework/zend-uri": ">=2.0.0", + "zendframework/zend-version": ">=2.0.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "ZendService": "library/" + } + }, + "license": [ + "BSD-3-Clause" + ], + "description": "OOP wrapper for the ReCaptcha web service", + "homepage": "http://packages.zendframework.com/", + "keywords": [ + "recaptcha", + "zf2" + ], + "support": { + "source": "https://github.com/zendframework/ZendService_ReCaptcha/tree/release-2.0.1", + "issues": "https://github.com/zendframework/ZendService_ReCaptcha/issues" + }, + "time": "2012-09-24 15:18:29" + }, { "name": "zendframework/zendxml", "version": "1.0.0", diff --git a/vendor/autoload.php b/vendor/autoload.php index 88a4c4cf8ea..278a00cfb5c 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer' . '/autoload_real.php'; -return ComposerAutoloaderInit0dfc2bf3cb49d4df12e48ed4090a52b2::getLoader(); +return ComposerAutoloaderInit93ded85776ce5eba306e5022b8482349::getLoader(); diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php index 99af93b0ff9..8af2f003190 100644 --- a/vendor/composer/autoload_namespaces.php +++ b/vendor/composer/autoload_namespaces.php @@ -9,6 +9,7 @@ return array( 'Zend\\' => array($vendorDir . '/zendframework/zendframework/library'), 'ZendXml' => array($vendorDir . '/zendframework/zendxml/library'), 'ZendService\\Amazon\\' => array($vendorDir . '/zendframework/zendservice-amazon/library'), + 'ZendService' => array($vendorDir . '/zendframework/zendservice-recaptcha/library'), 'ZendRest' => array($vendorDir . '/zendframework/zendrest/library'), 'Symfony\\Component\\Yaml\\' => array($vendorDir . '/symfony/yaml'), 'SerialsSolutions' => array($vendorDir . '/serialssolutions/summon'), diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index fbcc2e94b9b..fac5d0e7c58 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit0dfc2bf3cb49d4df12e48ed4090a52b2 +class ComposerAutoloaderInit93ded85776ce5eba306e5022b8482349 { private static $loader; @@ -19,9 +19,9 @@ class ComposerAutoloaderInit0dfc2bf3cb49d4df12e48ed4090a52b2 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit0dfc2bf3cb49d4df12e48ed4090a52b2', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit93ded85776ce5eba306e5022b8482349', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit0dfc2bf3cb49d4df12e48ed4090a52b2', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit93ded85776ce5eba306e5022b8482349', 'loadClassLoader')); $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); @@ -51,7 +51,7 @@ class ComposerAutoloaderInit0dfc2bf3cb49d4df12e48ed4090a52b2 } } -function composerRequire0dfc2bf3cb49d4df12e48ed4090a52b2($file) +function composerRequire93ded85776ce5eba306e5022b8482349($file) { require $file; } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 7ecbd05685d..a5c28f1d3c3 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -732,5 +732,53 @@ "source": "https://github.com/zendframework/zf2/tree/release-2.2.7", "issues": "https://github.com/zendframework/zf2/issues" } + }, + { + "name": "zendframework/zendservice-recaptcha", + "version": "2.0.1", + "version_normalized": "2.0.1.0", + "source": { + "type": "git", + "url": "https://github.com/zendframework/ZendService_ReCaptcha.git", + "reference": "4324cca8502d9f47b3b43a18acdd3fdbeb965536" + }, + "dist": { + "type": "zip", + "url": "https://packages.zendframework.com/composer/zendframework-zendservice-recaptcha-4324cca8502d9f47b3b43a18acdd3fdbeb965536-zip-8c45bf.zip", + "reference": "2.0.1", + "shasum": "fab92465cda889ff975c1ec79bb378d7e3f39081" + }, + "require": { + "php": ">=5.3.3", + "zendframework/zend-http": ">=2.0.0", + "zendframework/zend-uri": ">=2.0.0", + "zendframework/zend-version": ">=2.0.0" + }, + "time": "2012-09-24 15:18:29", + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "installation-source": "dist", + "autoload": { + "psr-0": { + "ZendService": "library/" + } + }, + "license": [ + "BSD-3-Clause" + ], + "description": "OOP wrapper for the ReCaptcha web service", + "homepage": "http://packages.zendframework.com/", + "keywords": [ + "recaptcha", + "zf2" + ], + "support": { + "source": "https://github.com/zendframework/ZendService_ReCaptcha/tree/release-2.0.1", + "issues": "https://github.com/zendframework/ZendService_ReCaptcha/issues" + } } ] diff --git a/vendor/zendframework/zendservice-recaptcha/.gitignore b/vendor/zendframework/zendservice-recaptcha/.gitignore new file mode 100644 index 00000000000..48b8bf9072d --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/.gitignore @@ -0,0 +1 @@ +vendor/ diff --git a/vendor/zendframework/zendservice-recaptcha/.travis.yml b/vendor/zendframework/zendservice-recaptcha/.travis.yml new file mode 100644 index 00000000000..409b789c100 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/.travis.yml @@ -0,0 +1,17 @@ +language: php + +php: + - 5.3.3 + - 5.3 + - 5.4 + +before_install: + - cp tests/TestConfiguration.php.travis tests/TestConfiguration.php + - curl -s https://getcomposer.org/installer | php + - php composer.phar install --dev + +script: + - php ./tests/run-tests.php + +notifications: + irc: "irc.freenode.org#zftalk.2" diff --git a/vendor/zendframework/zendservice-recaptcha/LICENSE.txt b/vendor/zendframework/zendservice-recaptcha/LICENSE.txt new file mode 100644 index 00000000000..36e976016ef --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/LICENSE.txt @@ -0,0 +1,27 @@ +Copyright (c) 2005-2012, Zend Technologies USA, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of Zend Technologies USA, Inc. nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/zendframework/zendservice-recaptcha/README.md b/vendor/zendframework/zendservice-recaptcha/README.md new file mode 100644 index 00000000000..551338bd7c9 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/README.md @@ -0,0 +1,11 @@ +ZendService\ReCaptcha component + +You can install using: + +``` +curl -s https://getcomposer.org/installer | php +php composer.phar install +``` + +At that point, follow the instructions in the documentation folder for actual +usage of the component. (Documentation is forthcoming.) diff --git a/vendor/zendframework/zendservice-recaptcha/composer.json b/vendor/zendframework/zendservice-recaptcha/composer.json new file mode 100644 index 00000000000..cf48c924453 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/composer.json @@ -0,0 +1,33 @@ +{ + "name": "zendframework/zendservice-recaptcha", + "description": "OOP wrapper for the ReCaptcha web service", + "type": "library", + "keywords": [ + "zf2", + "recaptcha" + ], + "homepage": "http://packages.zendframework.com/", + "license": "BSD-3-Clause", + "autoload": { + "psr-0": { + "ZendService": "library/" + } + }, + "repositories": [ + { + "type": "composer", + "url": "http://packages.zendframework.com/" + } + ], + "require": { + "php": ">=5.3.3", + "zendframework/zend-http": ">=2.0.0", + "zendframework/zend-uri": ">=2.0.0", + "zendframework/zend-version": ">=2.0.0" + }, + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + } +} diff --git a/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/Exception.php b/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/Exception.php new file mode 100644 index 00000000000..0463d835a92 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/Exception.php @@ -0,0 +1,21 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @package Zend_Service + */ + +namespace ZendService\ReCaptcha; + +/** + * Zend_Service_ReCaptcha_Exception + * + * @category Zend + * @package Zend_Service + * @subpackage ReCaptcha + */ +class Exception extends \Exception +{} diff --git a/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/MailHide.php b/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/MailHide.php new file mode 100644 index 00000000000..31cbc602d44 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/MailHide.php @@ -0,0 +1,328 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @package Zend_Service + */ + +namespace ZendService\ReCaptcha; + +use Traversable; +use Zend\Stdlib\ArrayUtils; + +/** + * Zend_Service_ReCaptcha_MailHide + * + * @category Zend + * @package Zend_Service + * @subpackage ReCaptcha + */ +class MailHide extends ReCaptcha +{ + /**#@+ + * Encryption constants + */ + const ENCRYPTION_MODE = MCRYPT_MODE_CBC; + const ENCRYPTION_CIPHER = MCRYPT_RIJNDAEL_128; + const ENCRYPTION_BLOCK_SIZE = 16; + const ENCRYPTION_IV = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + /**#@-*/ + + /** + * Url to the mailhide server + * + * @var string + */ + const MAILHIDE_SERVER = 'http://mailhide.recaptcha.net/d'; + + /** + * The email address to protect + * + * @var string + */ + protected $email = null; + + /** + * @var \Zend\Validator\ValidatorInterface + */ + protected $emailValidator; + + /** + * Binary representation of the private key + * + * @var string + */ + protected $privateKeyPacked = null; + + /** + * The local part of the email + * + * @var string + */ + protected $emailLocalPart = null; + + /** + * The domain part of the email + * + * @var string + */ + protected $emailDomainPart = null; + + /** + * Local constructor + * + * @param string $publicKey + * @param string $privateKey + * @param string $email + * @param array|Traversable $options + */ + public function __construct($publicKey = null, $privateKey = null, $email = null, $options = null) + { + /* Require the mcrypt extension to be loaded */ + $this->_requireMcrypt(); + + /* If options is a Zend_Config object we want to convert it to an array so we can merge it with the default options */ + if ($options instanceof Traversable) { + $options = ArrayUtils::iteratorToArray($options); + } + + /* Merge if needed */ + if (is_array($options)) { + $options = array_merge($this->getDefaultOptions(), $options); + } else { + $options = $this->getDefaultOptions(); + } + + parent::__construct($publicKey, $privateKey, null, $options); + + if ($email !== null) { + $this->setEmail($email); + } + } + + + /** + * Get emailValidator + * + * @return \Zend\Validator\ValidatorInterface + */ + public function getEmailValidator() + { + if (null === $this->emailValidator) { + $this->setEmailValidator(new \Zend\Validator\EmailAddress()); + } + return $this->emailValidator; + } + + /** + * Set email validator + * + * @param \Zend\Validator\ValidatorInterface $validator + * @return \ZendService\ReCaptcha\MailHide + */ + public function setEmailValidator(\Zend\Validator\ValidatorInterface $validator) + { + $this->emailValidator = $validator; + return $this; + } + + + /** + * See if the mcrypt extension is available + * + * @throws \ZendService\ReCaptcha\MailHideException + */ + protected function _requireMcrypt() + { + if (!extension_loaded('mcrypt')) { + throw new MailHideException('Use of the Zend\\Service\\ReCaptcha\\MailHide component requires the mcrypt extension to be enabled in PHP'); + } + } + + /** + * Serialize as string + * + * When the instance is used as a string it will display the email address. Since we can't + * throw exceptions within this method we will trigger a user warning instead. + * + * @return string + */ + public function __toString() + { + try { + $return = $this->getHtml(); + } catch (\Exception $e) { + $return = ''; + trigger_error($e->getMessage(), E_USER_WARNING); + } + + return $return; + } + + /** + * Get the default set of parameters + * + * @return array + */ + public function getDefaultOptions() + { + return array( + 'encoding' => 'UTF-8', + 'linkTitle' => 'Reveal this e-mail address', + 'linkHiddenText' => '...', + 'popupWidth' => 500, + 'popupHeight' => 300, + ); + } + + /** + * Override the setPrivateKey method + * + * Override the parent method to store a binary representation of the private key as well. + * + * @param string $privateKey + * @return \ZendService\ReCaptcha\MailHide + */ + public function setPrivateKey($privateKey) + { + parent::setPrivateKey($privateKey); + + /* Pack the private key into a binary string */ + $this->privateKeyPacked = pack('H*', $this->privateKey); + + return $this; + } + + /** + * Set the email property + * + * This method will set the email property along with the local and domain parts + * + * @param string $email + * @return \ZendService\ReCaptcha\MailHide + */ + public function setEmail($email) + { + $this->email = $email; + + $validator = $this->getEmailValidator(); + if (!$validator->isValid($email)) { + throw new MailHideException('Invalid email address provided'); + } + + $emailParts = explode('@', $email, 2); + + /* Decide on how much of the local part we want to reveal */ + if (strlen($emailParts[0]) <= 4) { + $emailParts[0] = substr($emailParts[0], 0, 1); + } elseif (strlen($emailParts[0]) <= 6) { + $emailParts[0] = substr($emailParts[0], 0, 3); + } else { + $emailParts[0] = substr($emailParts[0], 0, 4); + } + + $this->emailLocalPart = $emailParts[0]; + $this->emailDomainPart = $emailParts[1]; + + return $this; + } + + /** + * Get the email property + * + * @return string + */ + public function getEmail() + { + return $this->email; + } + + /** + * Get the local part of the email address + * + * @return string + */ + public function getEmailLocalPart() + { + return $this->emailLocalPart; + } + + /** + * Get the domain part of the email address + * + * @return string + */ + public function getEmailDomainPart() + { + return $this->emailDomainPart; + } + + /** + * Get the HTML code needed for the mail hide + * + * @param string $email + * @return string + * @throws \ZendService\ReCaptcha\MailHideException + */ + public function getHtml($email = null) + { + if ($email !== null) { + $this->setEmail($email); + } elseif (null === ($email = $this->getEmail())) { + throw new MailHideException('Missing email address'); + } + + if ($this->publicKey === null) { + throw new MailHideException('Missing public key'); + } + + if ($this->privateKey === null) { + throw new MailHideException('Missing private key'); + } + + /* Generate the url */ + $url = $this->_getUrl(); + + $enc = $this->getOption('encoding'); + + /* Genrate the HTML used to represent the email address */ + $html = htmlentities($this->getEmailLocalPart(), ENT_COMPAT, $enc) + . '<a href="' + . htmlentities($url, ENT_COMPAT, $enc) + . '" onclick="window.open(\'' + . htmlentities($url, ENT_COMPAT, $enc) + . '\', \'\', \'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=' + . $this->options['popupWidth'] + . ',height=' + . $this->options['popupHeight'] + . '\'); return false;" title="' + . $this->options['linkTitle'] + . '">' . $this->options['linkHiddenText'] . '</a>@' + . htmlentities($this->getEmailDomainPart(), ENT_COMPAT, $enc); + + return $html; + } + + /** + * Get the url used on the "hidden" part of the email address + * + * @return string + */ + protected function _getUrl() + { + /* Figure out how much we need to pad the email */ + $numPad = self::ENCRYPTION_BLOCK_SIZE - (strlen($this->email) % self::ENCRYPTION_BLOCK_SIZE); + + /* Pad the email */ + $emailPadded = str_pad($this->email, strlen($this->email) + $numPad, chr($numPad)); + + /* Encrypt the email */ + $emailEncrypted = mcrypt_encrypt(self::ENCRYPTION_CIPHER, $this->privateKeyPacked, $emailPadded, self::ENCRYPTION_MODE, self::ENCRYPTION_IV); + + /* Return the url */ + return self::MAILHIDE_SERVER . '?k=' . $this->publicKey . '&c=' . strtr(base64_encode($emailEncrypted), '+/', '-_'); + } +} diff --git a/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/MailHideException.php b/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/MailHideException.php new file mode 100644 index 00000000000..4573a3fdf10 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/MailHideException.php @@ -0,0 +1,21 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @package Zend_Service + */ + +namespace ZendService\ReCaptcha; + +/** + * Zend_Service_ReCaptcha_MailHide_Exception + * + * @category Zend + * @package Zend_Service + * @subpackage ReCaptcha + */ +class MailHideException extends Exception +{} diff --git a/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/ReCaptcha.php b/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/ReCaptcha.php new file mode 100644 index 00000000000..1f8fd8c0550 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/ReCaptcha.php @@ -0,0 +1,498 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @package Zend_Service + */ + +namespace ZendService\ReCaptcha; + +use Traversable; +use Zend\Http\Client as HttpClient; +use Zend\Http\Request as HttpRequest; +use Zend\Stdlib\ArrayUtils; + + +/** + * Zend_Service_ReCaptcha + * + * @category Zend + * @package Zend_Service + * @subpackage ReCaptcha + */ +class ReCaptcha +{ + /** + * URI to the regular API + * + * @var string + */ + const API_SERVER = 'http://www.google.com/recaptcha/api'; + + /** + * URI to the secure API + * + * @var string + */ + const API_SECURE_SERVER = 'https://www.google.com/recaptcha/api'; + + /** + * URI to the verify server + * + * @var string + */ + const VERIFY_SERVER = 'http://www.google.com/recaptcha/api/verify'; + + /** + * Public key used when displaying the captcha + * + * @var string + */ + protected $publicKey = null; + + /** + * Private key used when verifying user input + * + * @var string + */ + protected $privateKey = null; + + /** + * Ip address used when verifying user input + * + * @var string + */ + protected $ip = null; + + /** + * Parameters for the object + * + * @var array + */ + protected $params = array( + 'ssl' => false, /* Use SSL or not when generating the recaptcha */ + 'error' => null, /* The error message to display in the recaptcha */ + 'xhtml' => false /* Enable XHTML output (this will not be XHTML Strict + compliant since the IFRAME is necessary when + Javascript is disabled) */ + ); + + /** + * Options for tailoring reCaptcha + * + * See the different options on http://recaptcha.net/apidocs/captcha/client.html + * + * @var array + */ + protected $options = array( + 'theme' => 'red', + 'lang' => 'en', + ); + + /** + * @var HttpClient + */ + protected $httpClient = null; + + /** + * Response from the verify server + * + * @var \ZendService\ReCaptcha\Response + */ + protected $_response = null; + + /** + * Class constructor + * + * @param string $publicKey + * @param string $privateKey + * @param array|Traversable $params + * @param array|Traversable $options + * @param string $ip + */ + public function __construct($publicKey = null, $privateKey = null, $params = null, $options = null, $ip = null, HttpClient $httpClient = null) + { + if ($publicKey !== null) { + $this->setPublicKey($publicKey); + } + + if ($privateKey !== null) { + $this->setPrivateKey($privateKey); + } + + if ($ip !== null) { + $this->setIp($ip); + } elseif (isset($_SERVER['REMOTE_ADDR'])) { + $this->setIp($_SERVER['REMOTE_ADDR']); + } + + if ($params !== null) { + $this->setParams($params); + } + + if ($options !== null) { + $this->setOptions($options); + } + + $this->setHttpClient($httpClient ?: new HttpClient); + } + + public function setHttpClient(HttpClient $httpClient) + { + $this->httpClient = $httpClient; + return $this; + } + + public function getHttpClient() + { + return $this->httpClient; + } + + /** + * Serialize as string + * + * When the instance is used as a string it will display the recaptcha. + * Since we can't throw exceptions within this method we will trigger + * a user warning instead. + * + * @return string + */ + public function __toString() + { + try { + $return = $this->getHtml(); + } catch (\Exception $e) { + $return = ''; + trigger_error($e->getMessage(), E_USER_WARNING); + } + + return $return; + } + + /** + * Set the ip property + * + * @param string $ip + * @return \ZendService\ReCaptcha\ReCaptcha + */ + public function setIp($ip) + { + $this->ip = $ip; + + return $this; + } + + /** + * Get the ip property + * + * @return string + */ + public function getIp() + { + return $this->ip; + } + + /** + * Set a single parameter + * + * @param string $key + * @param string $value + * @return \ZendService\ReCaptcha\ReCaptcha + */ + public function setParam($key, $value) + { + $this->params[$key] = $value; + + return $this; + } + + /** + * Set parameters + * + * @param array|Traversable $params + * @return \ZendService\ReCaptcha\ReCaptcha + * @throws \ZendService\ReCaptcha\Exception + */ + public function setParams($params) + { + if ($params instanceof Traversable) { + $params = ArrayUtils::iteratorToArray($params); + } + + if (!is_array($params)) { + throw new Exception(sprintf( + '%s expects an array or Traversable set of params; received "%s"', + __METHOD__, + (is_object($params) ? get_class($params) : gettype($params)) + )); + } + + foreach ($params as $k => $v) { + $this->setParam($k, $v); + } + + return $this; + } + + /** + * Get the parameter array + * + * @return array + */ + public function getParams() + { + return $this->params; + } + + /** + * Get a single parameter + * + * @param string $key + * @return mixed + */ + public function getParam($key) + { + return $this->params[$key]; + } + + /** + * Set a single option + * + * @param string $key + * @param string $value + * @return \ZendService\ReCaptcha\ReCaptcha + */ + public function setOption($key, $value) + { + $this->options[$key] = $value; + + return $this; + } + + /** + * Set options + * + * @param array|Traversable $options + * @return \ZendService\ReCaptcha\ReCaptcha + * @throws \ZendService\ReCaptcha\Exception + */ + public function setOptions($options) + { + if ($options instanceof Traversable) { + $options = ArrayUtils::iteratorToArray($options); + } + + if (is_array($options)) { + foreach ($options as $k => $v) { + $this->setOption($k, $v); + } + } else { + throw new Exception( + 'Expected array or Traversable object' + ); + } + + return $this; + } + + /** + * Get the options array + * + * @return array + */ + public function getOptions() + { + return $this->options; + } + + /** + * Get a single option + * + * @param string $key + * @return mixed + */ + public function getOption($key) + { + return $this->options[$key]; + } + + /** + * Get the public key + * + * @return string + */ + public function getPublicKey() + { + return $this->publicKey; + } + + /** + * Set the public key + * + * @param string $publicKey + * @return \ZendService\ReCaptcha\ReCaptcha + */ + public function setPublicKey($publicKey) + { + $this->publicKey = $publicKey; + + return $this; + } + + /** + * Get the private key + * + * @return string + */ + public function getPrivateKey() + { + return $this->privateKey; + } + + /** + * Set the private key + * + * @param string $privateKey + * @return \ZendService\ReCaptcha\ReCaptcha + */ + public function setPrivateKey($privateKey) + { + $this->privateKey = $privateKey; + + return $this; + } + + /** + * Get the HTML code for the captcha + * + * This method uses the public key to fetch a recaptcha form. + * + * @param null|string $name Base name for recaptcha form elements + * @return string + * @throws \ZendService\ReCaptcha\Exception + */ + public function getHtml($name = null) + { + if ($this->publicKey === null) { + throw new Exception('Missing public key'); + } + + $host = self::API_SERVER; + + if ((bool) $this->params['ssl'] === true) { + $host = self::API_SECURE_SERVER; + } + + $htmlBreak = '<br>'; + $htmlInputClosing = '>'; + + if ((bool) $this->params['xhtml'] === true) { + $htmlBreak = '<br />'; + $htmlInputClosing = '/>'; + } + + $errorPart = ''; + + if (!empty($this->params['error'])) { + $errorPart = '&error=' . urlencode($this->params['error']); + } + + $reCaptchaOptions = ''; + + if (!empty($this->options)) { + $encoded = \Zend\Json\Json::encode($this->options); + $reCaptchaOptions = <<<SCRIPT +<script type="text/javascript"> + var RecaptchaOptions = {$encoded}; +</script> +SCRIPT; + } + $challengeField = 'recaptcha_challenge_field'; + $responseField = 'recaptcha_response_field'; + if (!empty($name)) { + $challengeField = $name . '[' . $challengeField . ']'; + $responseField = $name . '[' . $responseField . ']'; + } + + $return = $reCaptchaOptions; + $return .= <<<HTML +<script type="text/javascript" + src="{$host}/challenge?k={$this->publicKey}{$errorPart}"> +</script> +HTML; + $return .= <<<HTML +<noscript> + <iframe src="{$host}/noscript?k={$this->publicKey}{$errorPart}" + height="300" width="500" frameborder="0"></iframe>{$htmlBreak} + <textarea name="{$challengeField}" rows="3" cols="40"> + </textarea> + <input type="hidden" name="{$responseField}" + value="manual_challenge"{$htmlInputClosing} +</noscript> +HTML; + + return $return; + } + + /** + * Post a solution to the verify server + * + * @param string $challengeField + * @param string $responseField + * @return \Zend\Http\Response + * @throws \ZendService\ReCaptcha\Exception + */ + protected function post($challengeField, $responseField) + { + if ($this->privateKey === null) { + throw new Exception('Missing private key'); + } + + if ($this->ip === null) { + throw new Exception('Missing ip address'); + } + + if (empty($challengeField)) { + throw new Exception('Missing challenge field'); + } + + if (empty($responseField)) { + throw new Exception('Missing response field'); + } + + /* Fetch an instance of the http client */ + $httpClient = $this->getHttpClient(); + + $postParams = array('privatekey' => $this->privateKey, + 'remoteip' => $this->ip, + 'challenge' => $challengeField, + 'response' => $responseField); + + $request = new HttpRequest; + $request->setUri(self::VERIFY_SERVER); + $request->getPost()->fromArray($postParams); + $request->setMethod(HttpRequest::METHOD_POST); + $httpClient->setEncType($httpClient::ENC_URLENCODED); + + return $httpClient->send($request); + } + + /** + * Verify the user input + * + * This method calls up the post method and returns a + * Zend_Service_ReCaptcha_Response object. + * + * @param string $challengeField + * @param string $responseField + * @return \ZendService\ReCaptcha\Response + */ + public function verify($challengeField, $responseField) + { + $response = $this->post($challengeField, $responseField); + return new Response(null, null, $response); + } +} diff --git a/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/Response.php b/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/Response.php new file mode 100644 index 00000000000..dbf3f0e169f --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/library/ZendService/ReCaptcha/Response.php @@ -0,0 +1,149 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @package Zend_Service + */ + +namespace ZendService\ReCaptcha; + +use Zend\Http\Response as HTTPResponse; + +/** + * Zend_Service_ReCaptcha_Response + * + * @category Zend + * @package Zend_Service + * @subpackage ReCaptcha + */ +class Response +{ + /** + * Status + * + * true if the response is valid or false otherwise + * + * @var boolean + */ + protected $status = null; + + /** + * Error code + * + * The error code if the status is false. The different error codes can be found in the + * recaptcha API docs. + * + * @var string + */ + protected $errorCode = null; + + /** + * Class constructor used to construct a response + * + * @param string $status + * @param string $errorCode + * @param \Zend\Http\Response $httpResponse If this is set the content will override $status and $errorCode + */ + public function __construct($status = null, $errorCode = null, HTTPResponse $httpResponse = null) + { + if ($status !== null) { + $this->setStatus($status); + } + + if ($errorCode !== null) { + $this->setErrorCode($errorCode); + } + + if ($httpResponse !== null) { + $this->setFromHttpResponse($httpResponse); + } + } + + /** + * Set the status + * + * @param string $status + * @return \ZendService\ReCaptcha\Response + */ + public function setStatus($status) + { + if ($status === 'true') { + $this->status = true; + } else { + $this->status = false; + } + + return $this; + } + + /** + * Get the status + * + * @return boolean + */ + public function getStatus() + { + return $this->status; + } + + /** + * Alias for getStatus() + * + * @return boolean + */ + public function isValid() + { + return $this->getStatus(); + } + + /** + * Set the error code + * + * @param string $errorCode + * @return \ZendService\ReCaptcha\Response + */ + public function setErrorCode($errorCode) + { + $this->errorCode = $errorCode; + + return $this; + } + + /** + * Get the error code + * + * @return string + */ + public function getErrorCode() + { + return $this->errorCode; + } + + /** + * Populate this instance based on a Zend_Http_Response object + * + * @param \Zend\Http\Response $response + * @return \ZendService\ReCaptcha\Response + */ + public function setFromHttpResponse(HTTPResponse $response) + { + $body = $response->getBody(); + + $parts = explode("\n", $body, 2); + + if (count($parts) !== 2) { + $status = 'false'; + $errorCode = ''; + } else { + list($status, $errorCode) = $parts; + } + + $this->setStatus($status); + $this->setErrorCode($errorCode); + + return $this; + } +} diff --git a/vendor/zendframework/zendservice-recaptcha/tests/Bootstrap.php b/vendor/zendframework/zendservice-recaptcha/tests/Bootstrap.php new file mode 100644 index 00000000000..40a74517b84 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/tests/Bootstrap.php @@ -0,0 +1,92 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @package Zend + */ + +/* + * Set error reporting to the level to which Zend Framework code must comply. + */ +error_reporting( E_ALL | E_STRICT ); + +$phpUnitVersion = PHPUnit_Runner_Version::id(); +if ('@package_version@' !== $phpUnitVersion && version_compare($phpUnitVersion, '3.5.0', '<')) { + echo 'This version of PHPUnit (' . PHPUnit_Runner_Version::id() . ') is not supported in Zend Framework 2.x unit tests.' . PHP_EOL; + exit(1); +} +unset($phpUnitVersion); + +/* + * Determine the root, library, and tests directories of the framework + * distribution. + */ +$zfRoot = realpath(dirname(__DIR__)); +$zfCoreLibrary = "$zfRoot/library"; +$zfCoreTests = "$zfRoot/tests"; + +/* + * Prepend the Zend Framework library/ and tests/ directories to the + * include_path. This allows the tests to run out of the box and helps prevent + * loading other copies of the framework code and tests that would supersede + * this copy. + */ +$path = array( + $zfCoreLibrary, + $zfCoreTests, + get_include_path(), +); +set_include_path(implode(PATH_SEPARATOR, $path)); + +/** + * Setup autoloading + */ +include __DIR__ . '/_autoload.php'; + +/* + * Load the user-defined test configuration file, if it exists; otherwise, load + * the default configuration. + */ +if (is_readable($zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php')) { + require_once $zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php'; +} else { + require_once $zfCoreTests . DIRECTORY_SEPARATOR . 'TestConfiguration.php.dist'; +} + +if (defined('TESTS_GENERATE_REPORT') && TESTS_GENERATE_REPORT === true) { + $codeCoverageFilter = PHP_CodeCoverage_Filter::getInstance(); + + $lastArg = end($_SERVER['argv']); + if (is_dir($zfCoreTests . '/' . $lastArg)) { + $codeCoverageFilter->addDirectoryToWhitelist($zfCoreLibrary . '/' . $lastArg); + } else if (is_file($zfCoreTests . '/' . $lastArg)) { + $codeCoverageFilter->addDirectoryToWhitelist(dirname($zfCoreLibrary . '/' . $lastArg)); + } else { + $codeCoverageFilter->addDirectoryToWhitelist($zfCoreLibrary); + } + + /* + * Omit from code coverage reports the contents of the tests directory + */ + $codeCoverageFilter->addDirectoryToBlacklist($zfCoreTests, ''); + $codeCoverageFilter->addDirectoryToBlacklist(PEAR_INSTALL_DIR, ''); + $codeCoverageFilter->addDirectoryToBlacklist(PHP_LIBDIR, ''); + + unset($codeCoverageFilter); +} + + +/** + * Start output buffering, if enabled + */ +if (defined('TESTS_ZEND_OB_ENABLED') && constant('TESTS_ZEND_OB_ENABLED')) { + ob_start(); +} + +/* + * Unset global variables that are no longer needed. + */ +unset($zfRoot, $zfCoreLibrary, $zfCoreTests, $path); diff --git a/vendor/zendframework/zendservice-recaptcha/tests/TestConfiguration.php.dist b/vendor/zendframework/zendservice-recaptcha/tests/TestConfiguration.php.dist new file mode 100644 index 00000000000..cac8b198b95 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/tests/TestConfiguration.php.dist @@ -0,0 +1,55 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @package UnitTests + */ + +/** + * This file defines configuration for running the unit tests for the Zend + * Framework. Some tests have dependencies to PHP extensions or databases + * which may not necessary installed on the target system. For these cases, + * the ability to disable or configure testing is provided below. Tests for + * components which should run universally are always run by the master + * suite and cannot be disabled. + * + * Do not edit this file. Instead, copy this file to TestConfiguration.php, + * and edit the new file. Never commit passwords to the source code repository. + */ + +/** + * Use the notation: + * + * defined(...) || define(...); + * + * This ensures that, when a test is marked to run in a separate process, + * PHP will not complain of a constant already being defined. + */ + +/** + * GENERAL SETTINGS + * + * OB_ENABLED should be enabled for some tests to check if all functionality + * works as expected. Such tests include those for Zend\Soap and Zend\Session, + * which require that headers not be sent in order to work. + */ +defined('TESTS_ZEND_OB_ENABLED') || define('TESTS_ZEND_OB_ENABLED', false); + +/** + * PHPUnit Code Coverage / Test Report + */ +defined('TESTS_GENERATE_REPORT') || define('TESTS_GENERATE_REPORT', false); +defined('TESTS_GENERATE_REPORT_TARGET') || define('TESTS_GENERATE_REPORT_TARGET', '/path/to/target'); + +/** + * Zend\Service\ReCaptcha tests + */ +defined('TESTS_ZEND_SERVICE_RECAPTCHA_ENABLED') || define('TESTS_ZEND_SERVICE_RECAPTCHA_ENABLED', false); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_ONLINE_ENABLED') || define('TESTS_ZEND_SERVICE_RECAPTCHA_ONLINE_ENABLED', false); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_PUBLIC_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_PUBLIC_KEY', 'public key'); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_PRIVATE_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_PRIVATE_KEY', 'private key'); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY', 'public mailhide key'); +defined('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY') || define('TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY', 'private mailhide key'); diff --git a/vendor/zendframework/zendservice-recaptcha/tests/TestConfiguration.php.travis b/vendor/zendframework/zendservice-recaptcha/tests/TestConfiguration.php.travis new file mode 100644 index 00000000000..f49b94cdbf9 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/tests/TestConfiguration.php.travis @@ -0,0 +1,20 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @package UnitTests + */ + +/** + * This file defines specific configuration that differs from the standard configuration + * for running the unit tests with Travis-CI (http://www.travis-ci.org) + * + * See TestConfiguration.php.dist to get more details. + * + * Never commit passwords to the source code repository. + */ + +require_once __DIR__ . '/TestConfiguration.php.dist'; diff --git a/vendor/zendframework/zendservice-recaptcha/tests/ZendService/ReCaptcha/MailHideTest.php b/vendor/zendframework/zendservice-recaptcha/tests/ZendService/ReCaptcha/MailHideTest.php new file mode 100644 index 00000000000..55755fe7cf1 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/tests/ZendService/ReCaptcha/MailHideTest.php @@ -0,0 +1,151 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @package Zend_Service + */ + +namespace ZendServiceTest\ReCaptcha; + +use ZendService\ReCaptcha; + +/** + * @category Zend + * @package Zend_Service_ReCaptcha + * @subpackage UnitTests + * @group Zend_Service + * @group Zend_Service_ReCaptcha + */ +class MailHideTest extends \PHPUnit_Framework_TestCase +{ + protected $publicKey = TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PUBLIC_KEY; + protected $privateKey = TESTS_ZEND_SERVICE_RECAPTCHA_MAILHIDE_PRIVATE_KEY; + protected $mailHide = null; + + public function setUp() + { + if (!extension_loaded('mcrypt')) { + $this->markTestSkipped('ZendService\ReCaptcha tests skipped due to missing mcrypt extension'); + } + if ($this->publicKey == 'public mailhide key' || $this->privateKey == 'private mailhide key') { + $this->markTestSkipped('ZendService\ReCaptcha\MailHide tests skipped due to missing keys'); + } + $this->mailHide = new ReCaptcha\MailHide(); + } + + public function testSetGetPrivateKey() + { + $this->mailHide->setPrivateKey($this->privateKey); + $this->assertSame($this->privateKey, $this->mailHide->getPrivateKey()); + } + + public function testSetGetEmail() + { + $mail = 'mail@example.com'; + + $this->mailHide->setEmail($mail); + $this->assertSame($mail, $this->mailHide->getEmail()); + $this->assertSame('example.com', $this->mailHide->getEmailDomainPart()); + } + + public function testEmailLocalPart() + { + $this->mailHide->setEmail('abcd@example.com'); + $this->assertSame('a', $this->mailHide->getEmailLocalPart()); + + $this->mailHide->setEmail('abcdef@example.com'); + $this->assertSame('abc', $this->mailHide->getEmailLocalPart()); + + $this->mailHide->setEmail('abcdefg@example.com'); + $this->assertSame('abcd', $this->mailHide->getEmailLocalPart()); + } + + public function testConstructor() + { + $mail = 'mail@example.com'; + + $options = array( + 'theme' => 'black', + 'lang' => 'no', + ); + + $config = new \Zend\Config\Config($options); + + $mailHide = new ReCaptcha\MailHide($this->publicKey, $this->privateKey, $mail, $config); + $_options = $mailHide->getOptions(); + + $this->assertSame($this->publicKey, $mailHide->getPublicKey()); + $this->assertSame($this->privateKey, $mailHide->getPrivateKey()); + $this->assertSame($mail, $mailHide->getEmail()); + $this->assertSame($options['theme'], $_options['theme']); + $this->assertSame($options['lang'], $_options['lang']); + } + + protected function _checkHtml($html) + { + $server = ReCaptcha\MailHide::MAILHIDE_SERVER; + $pubKey = $this->publicKey; + + $this->assertEquals(2, substr_count($html, 'k=' . $pubKey)); + $this->assertRegexp('/c\=[a-zA-Z0-9_=-]+"/', $html); + $this->assertRegexp('/c\=[a-zA-Z0-9_=-]+\\\'/', $html); + } + + public function testGetHtml() + { + $mail = 'mail@example.com'; + + $this->mailHide->setEmail($mail); + $this->mailHide->setPublicKey($this->publicKey); + $this->mailHide->setPrivateKey($this->privateKey); + + $html = $this->mailHide->getHtml(); + + $this->_checkHtml($html); + } + + public function testGetHtmlWithNoEmail() + { + $this->setExpectedException('Zend\\Service\\ReCaptcha\\MailHideException'); + + $html = $this->mailHide->getHtml(); + } + + public function testGetHtmlWithMissingPublicKey() + { + $mail = 'mail@example.com'; + + $this->mailHide->setEmail($mail); + $this->mailHide->setPrivateKey($this->privateKey); + + $this->setExpectedException('Zend\\Service\\ReCaptcha\\MailHideException'); + $html = $this->mailHide->getHtml(); + } + + public function testGetHtmlWithMissingPrivateKey() + { + $this->setExpectedException('Zend\\Service\\ReCaptcha\\MailHideException'); + + $mail = 'mail@example.com'; + + $this->mailHide->setEmail($mail); + $this->mailHide->setPublicKey($this->publicKey); + + $html = $this->mailHide->getHtml(); + } + + public function testGetHtmlWithParamter() + { + $mail = 'mail@example.com'; + + $this->mailHide->setPublicKey($this->publicKey); + $this->mailHide->setPrivateKey($this->privateKey); + + $html = $this->mailHide->getHtml($mail); + + $this->_checkHtml($html); + } +} diff --git a/vendor/zendframework/zendservice-recaptcha/tests/ZendService/ReCaptcha/ReCaptchaTest.php b/vendor/zendframework/zendservice-recaptcha/tests/ZendService/ReCaptcha/ReCaptchaTest.php new file mode 100644 index 00000000000..b71002a7a11 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/tests/ZendService/ReCaptcha/ReCaptchaTest.php @@ -0,0 +1,303 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @package Zend_Service + */ + +namespace ZendServiceTest\ReCaptcha; + +use ZendService\ReCaptcha\ReCaptcha; +use ZendService\ReCaptcha\Response as ReCaptchaResponse; +use Zend\Config; + +/** + * @category Zend + * @package Zend_Service_ReCaptcha + * @subpackage UnitTests + * @group Zend_Service + * @group Zend_Service_ReCaptcha + */ +class ReCaptchaTest extends \PHPUnit_Framework_TestCase +{ + protected $publicKey = TESTS_ZEND_SERVICE_RECAPTCHA_PUBLIC_KEY; + protected $privateKey = TESTS_ZEND_SERVICE_RECAPTCHA_PRIVATE_KEY; + + /** + * @var ReCaptcha + */ + protected $reCaptcha = null; + + public function setUp() + { + $this->reCaptcha = new ReCaptcha(); + } + + public function testSetAndGet() + { + /* Set and get IP address */ + $ip = '127.0.0.1'; + $this->reCaptcha->setIp($ip); + $this->assertSame($ip, $this->reCaptcha->getIp()); + + /* Set and get public key */ + $this->reCaptcha->setPublicKey($this->publicKey); + $this->assertSame($this->publicKey, $this->reCaptcha->getPublicKey()); + + /* Set and get private key */ + $this->reCaptcha->setPrivateKey($this->privateKey); + $this->assertSame($this->privateKey, $this->reCaptcha->getPrivateKey()); + } + + public function testSingleParam() + { + $key = 'ssl'; + $value = true; + + $this->reCaptcha->setParam($key, $value); + $this->assertSame($value, $this->reCaptcha->getParam($key)); + } + + public function tetsGetNonExistingParam() + { + $this->assertNull($this->reCaptcha->getParam('foobar')); + } + + public function testMultipleParams() + { + $params = array( + 'ssl' => true, + 'error' => 'errorMsg', + 'xhtml' => true, + ); + + $this->reCaptcha->setParams($params); + $_params = $this->reCaptcha->getParams(); + + $this->assertSame($params['ssl'], $_params['ssl']); + $this->assertSame($params['error'], $_params['error']); + $this->assertSame($params['xhtml'], $_params['xhtml']); + } + + public function testSingleOption() + { + $key = 'theme'; + $value = 'black'; + + $this->reCaptcha->setOption($key, $value); + $this->assertSame($value, $this->reCaptcha->getOption($key)); + } + + public function tetsGetNonExistingOption() + { + $this->assertNull($this->reCaptcha->getOption('foobar')); + } + + public function testMultipleOptions() + { + $options = array( + 'theme' => 'black', + 'lang' => 'no', + ); + + $this->reCaptcha->setOptions($options); + $_options = $this->reCaptcha->getOptions(); + + $this->assertSame($options['theme'], $_options['theme']); + $this->assertSame($options['lang'], $_options['lang']); + } + + public function testSetMultipleParamsFromZendConfig() + { + $params = array( + 'ssl' => true, + 'error' => 'errorMsg', + 'xhtml' => true, + ); + + $config = new Config\Config($params); + + $this->reCaptcha->setParams($config); + $_params = $this->reCaptcha->getParams(); + + $this->assertSame($params['ssl'], $_params['ssl']); + $this->assertSame($params['error'], $_params['error']); + $this->assertSame($params['xhtml'], $_params['xhtml']); + } + + public function testSetInvalidParams() + { + $this->setExpectedException('Zend\\Service\\ReCaptcha\\Exception'); + $var = 'string'; + $this->reCaptcha->setParams($var); + } + + public function testSetMultipleOptionsFromZendConfig() + { + $options = array( + 'theme' => 'black', + 'lang' => 'no', + ); + + $config = new Config\Config($options); + + $this->reCaptcha->setOptions($config); + $_options = $this->reCaptcha->getOptions(); + + $this->assertSame($options['theme'], $_options['theme']); + $this->assertSame($options['lang'], $_options['lang']); + } + + public function testSetInvalidOptions() + { + $this->setExpectedException('Zend\\Service\\ReCaptcha\\Exception'); + $var = 'string'; + $this->reCaptcha->setOptions($var); + } + + public function testConstructor() + { + $params = array( + 'ssl' => true, + 'error' => 'errorMsg', + 'xhtml' => true, + ); + + $options = array( + 'theme' => 'black', + 'lang' => 'no', + ); + + $ip = '127.0.0.1'; + + $reCaptcha = new ReCaptcha($this->publicKey, $this->privateKey, $params, $options, $ip); + + $_params = $reCaptcha->getParams(); + $_options = $reCaptcha->getOptions(); + + $this->assertSame($this->publicKey, $reCaptcha->getPublicKey()); + $this->assertSame($this->privateKey, $reCaptcha->getPrivateKey()); + $this->assertSame($params['ssl'], $_params['ssl']); + $this->assertSame($params['error'], $_params['error']); + $this->assertSame($params['xhtml'], $_params['xhtml']); + $this->assertSame($options['theme'], $_options['theme']); + $this->assertSame($options['lang'], $_options['lang']); + $this->assertSame($ip, $reCaptcha->getIp()); + } + + public function testConstructorWithNoIp() + { + // Fake the _SERVER value + $_SERVER['REMOTE_ADDR'] = '127.0.0.1'; + + $reCaptcha = new ReCaptcha(null, null, null, null, null); + + $this->assertSame($_SERVER['REMOTE_ADDR'], $reCaptcha->getIp()); + + unset($_SERVER['REMOTE_ADDR']); + } + + public function testGetHtmlWithNoPublicKey() + { + $this->setExpectedException('Zend\\Service\\ReCaptcha\\Exception'); + + $html = $this->reCaptcha->getHtml(); + } + + public function testVerify() + { + $this->reCaptcha->setPublicKey($this->publicKey); + $this->reCaptcha->setPrivateKey($this->privateKey); + $this->reCaptcha->setIp('127.0.0.1'); + + if (defined('TESTS_ZEND_SERVICE_RECAPTCHA_ONLINE_ENABLED') && + constant('TESTS_ZEND_SERVICE_RECAPTCHA_ONLINE_ENABLED')) { + + $this->_testVerifyOnline(); + } else { + $this->_testVerifyOffline(); + } + } + + protected function _testVerifyOnline() + { + } + + protected function _testVerifyOffline() + { + $adapter = new \Zend\Http\Client\Adapter\Test(); + $client = new \Zend\Http\Client(null, array( + 'adapter' => $adapter + )); + + $this->reCaptcha->setHttpClient($client); + + $resp = $this->reCaptcha->verify('challengeField', 'responseField'); + + // See if we have a valid object and that the status is false + $this->assertTrue($resp instanceof ReCaptchaResponse); + $this->assertFalse($resp->getStatus()); + } + + public function testGetHtml() + { + $this->reCaptcha->setPublicKey($this->publicKey); + $errorMsg = 'errorMsg'; + $this->reCaptcha->setParam('ssl', true); + $this->reCaptcha->setParam('xhtml', true); + $this->reCaptcha->setParam('error', $errorMsg); + + $html = $this->reCaptcha->getHtml(); + + // See if the options for the captcha exist in the string + $this->assertNotSame(false, strstr($html, 'var RecaptchaOptions = {"theme":"red","lang":"en"};')); + + // See if the js/iframe src is correct + $this->assertNotSame(false, strstr($html, 'src="' . ReCaptcha::API_SECURE_SERVER . '/challenge?k=' . $this->publicKey . '&error=' . $errorMsg . '"')); + } + + /** @group ZF-10991 */ + public function testHtmlGenerationWillUseSuppliedNameForNoScriptElements() + { + $this->reCaptcha->setPublicKey($this->publicKey); + $html = $this->reCaptcha->getHtml('contact'); + $this->assertContains('contact[recaptcha_challenge_field]', $html); + $this->assertContains('contact[recaptcha_response_field]', $html); + } + + public function testVerifyWithMissingPrivateKey() + { + $this->setExpectedException('Zend\\Service\\ReCaptcha\\Exception'); + + $this->reCaptcha->verify('challenge', 'response'); + } + + public function testVerifyWithMissingIp() + { + $this->setExpectedException('Zend\\Service\\ReCaptcha\\Exception'); + + $this->reCaptcha->setPrivateKey($this->privateKey); + $this->reCaptcha->verify('challenge', 'response'); + } + + public function testVerifyWithMissingChallengeField() + { + $this->setExpectedException('Zend\\Service\\ReCaptcha\\Exception'); + + $this->reCaptcha->setPrivateKey($this->privateKey); + $this->reCaptcha->setIp('127.0.0.1'); + $this->reCaptcha->verify('', 'response'); + } + + public function testVerifyWithMissingResponseField() + { + $this->setExpectedException('Zend\\Service\\ReCaptcha\\Exception'); + + $this->reCaptcha->setPrivateKey($this->privateKey); + $this->reCaptcha->setIp('127.0.0.1'); + $this->reCaptcha->verify('challenge', ''); + } +} diff --git a/vendor/zendframework/zendservice-recaptcha/tests/ZendService/ReCaptcha/ResponseTest.php b/vendor/zendframework/zendservice-recaptcha/tests/ZendService/ReCaptcha/ResponseTest.php new file mode 100644 index 00000000000..046cd9c786b --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/tests/ZendService/ReCaptcha/ResponseTest.php @@ -0,0 +1,103 @@ +<?php +/** + * Zend Framework (http://framework.zend.com/) + * + * @link http://github.com/zendframework/zf2 for the canonical source repository + * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @package Zend_Service + */ + +namespace ZendServiceTest\ReCaptcha; + +use ZendService\ReCaptcha; +use Zend\Http\Response; + +/** + * @category Zend + * @package Zend_Service_ReCaptcha + * @subpackage UnitTests + * @group Zend_Service + * @group Zend_Service_ReCaptcha + */ +class ResponseTest extends \PHPUnit_Framework_TestCase +{ + protected $_response = null; + + public function setUp() + { + $this->_response = new ReCaptcha\Response(); + } + + public function testSetAndGet() + { + /* Set and get status */ + $status = 'true'; + $this->_response->setStatus($status); + $this->assertSame(true, $this->_response->getStatus()); + + $status = 'false'; + $this->_response->setStatus($status); + $this->assertSame(false, $this->_response->getStatus()); + + /* Set and get the error code */ + $errorCode = 'foobar'; + $this->_response->setErrorCode($errorCode); + $this->assertSame($errorCode, $this->_response->getErrorCode()); + } + + public function testIsValid() + { + $this->_response->setStatus('true'); + $this->assertSame(true, $this->_response->isValid()); + } + + public function testIsInvalid() + { + $this->_response->setStatus('false'); + $this->assertSame(false, $this->_response->isValid()); + } + + public function testSetFromHttpResponse() + { + $status = 'false'; + $errorCode = 'foobar'; + $responseBody = $status . "\n" . $errorCode; + $httpResponse = new Response(); + $httpResponse->setStatusCode(200); + $httpResponse->getHeaders()->addHeaderLine('Content-Type', 'text/html'); + $httpResponse->setContent($responseBody); + + $this->_response->setFromHttpResponse($httpResponse); + + $this->assertSame(false, $this->_response->getStatus()); + $this->assertSame($errorCode, $this->_response->getErrorCode()); + } + + public function testConstructor() + { + $status = 'true'; + $errorCode = 'ok'; + + $response = new ReCaptcha\Response($status, $errorCode); + + $this->assertSame(true, $response->getStatus()); + $this->assertSame($errorCode, $response->getErrorCode()); + } + + public function testConstructorWithHttpResponse() + { + $status = 'false'; + $errorCode = 'foobar'; + $responseBody = $status . "\n" . $errorCode; + $httpResponse = new Response(); + $httpResponse->setStatusCode(200); + $httpResponse->getHeaders()->addHeaderLine('Content-Type', 'text/html'); + $httpResponse->setContent($responseBody); + + $response = new ReCaptcha\Response(null, null, $httpResponse); + + $this->assertSame(false, $response->getStatus()); + $this->assertSame($errorCode, $response->getErrorCode()); + } +} diff --git a/vendor/zendframework/zendservice-recaptcha/tests/_autoload.php b/vendor/zendframework/zendservice-recaptcha/tests/_autoload.php new file mode 100644 index 00000000000..24f5cf6bd4d --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/tests/_autoload.php @@ -0,0 +1,40 @@ +<?php +/** + * Setup autoloading + */ +if ($zf2Path = getenv('ZF2_PATH')) { + require_once $zf2Path . '/library/Zend/Loader/StandardAutoloader.php'; + + $loader = new Zend\Loader\StandardAutoloader(array( + Zend\Loader\StandardAutoloader::AUTOREGISTER_ZF => true, + Zend\Loader\StandardAutoloader::LOAD_NS => array( + 'ZendService' => __DIR__ . '/../library/ZendService' + ) + )); + $loader->register(); + +} elseif (!file_exists(__DIR__ . '/../vendor/autoload.php')) { + throw new RuntimeException('This component has dependencies that are unmet. + +Please install composer (http://getcomposer.org), and run the following +command in the root of this project: + + php /path/to/composer.phar install + +After that, you should be able to run tests.'); +} else { + include_once __DIR__ . '/../vendor/autoload.php'; +} + + +spl_autoload_register(function ($class) { + if (0 !== strpos($class, 'ZendServiceTest\\')) { + return false; + } + $normalized = str_replace('ZendServiceTest\\', '', $class); + $filename = __DIR__ . '/ZendService/' . str_replace(array('\\', '_'), '/', $normalized) . '.php'; + if (!file_exists($filename)) { + return false; + } + return include_once $filename; +}); \ No newline at end of file diff --git a/vendor/zendframework/zendservice-recaptcha/tests/phpunit.xml.dist b/vendor/zendframework/zendservice-recaptcha/tests/phpunit.xml.dist new file mode 100644 index 00000000000..55f02b1a7f8 --- /dev/null +++ b/vendor/zendframework/zendservice-recaptcha/tests/phpunit.xml.dist @@ -0,0 +1,13 @@ +<phpunit bootstrap="./Bootstrap.php" colors="true"> + <testsuites> + <testsuite name="ZendService ReCaptcha Test Suite"> + <directory>./ZendService</directory> + </testsuite> + </testsuites> + + <groups> + <exclude> + <group>disable</group> + </exclude> + </groups> +</phpunit> -- GitLab