-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from D3strukt0r/master
"google/recaptcha" library | PhpUnit | Symfony recipes | Travis-CI | Bugfix
- Loading branch information
Showing
9 changed files
with
211 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,48 @@ | ||
language: php | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
sudo: false | ||
dist: trusty | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache/files | ||
|
||
matrix: | ||
fast_finish: true | ||
include: | ||
# test 2.8 LTS | ||
- php: 5.6 | ||
env: SYMFONY_VERSION=2.8.* | ||
# test the latest stable 3.x release | ||
env: SYMFONY_VERSION=^2.8 | ||
- php: 5.6 | ||
env: SYMFONY_VERSION=^3.0 | ||
# test the latest release (including beta releases) | ||
env: SYMFONY_VERSION=^3 | ||
|
||
- php: 7.0 | ||
env: SYMFONY_VERSION=^2.8 | ||
- php: 7.0 | ||
env: SYMFONY_VERSION=^3 | ||
|
||
- php: 7.1 | ||
env: DEPENDENCIES=beta | ||
env: SYMFONY_VERSION=^2.8 | ||
- php: 7.1 | ||
env: SYMFONY_VERSION=^3 | ||
- php: 7.1 | ||
env: SYMFONY_VERSION=^4 | ||
|
||
- php: 7.2 | ||
env: SYMFONY_VERSION=^2.8 | ||
- php: 7.2 | ||
env: SYMFONY_VERSION=^3 | ||
- php: 7.2 | ||
env: SYMFONY_VERSION=^4 | ||
|
||
before_script: | ||
- if [ "$DEPENDENCIES" = "beta" ]; then composer config minimum-stability beta; fi; | ||
- composer self-update | ||
- | | ||
if [ "$SYMFONY_VERSION" != "" ]; then | ||
composer require "symfony/form:${SYMFONY_VERSION}" --no-update | ||
composer require "symfony/framework-bundle:${SYMFONY_VERSION}" --no-update | ||
composer require "symfony/security-bundle:${SYMFONY_VERSION}" --no-update | ||
composer require "symfony/validator:${SYMFONY_VERSION}" --no-update | ||
fi | ||
- composer install | ||
|
||
script: | ||
- vendor/bin/phpunit | ||
- phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit bootstrap="./tests/bootstrap.php" colors="true"> | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
|
||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.0/phpunit.xsd" | ||
bootstrap="./tests/bootstrap.php" | ||
colors="true"> | ||
|
||
<testsuites> | ||
<testsuite name="EWZRecaptchaBundle"> | ||
<directory>tests/</directory> | ||
<directory>tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">src</directory> | ||
</whitelist> | ||
</filter> | ||
|
||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace EWZ\Bundle\RecaptchaBundle\ReCaptcha\RequestMethod; | ||
|
||
use ReCaptcha\RequestMethod; | ||
use ReCaptcha\RequestParameters; | ||
|
||
/** | ||
* Sends POST requests to the reCAPTCHA service. | ||
*/ | ||
class Post implements RequestMethod | ||
{ | ||
/** | ||
* The reCAPTCHA verify server URL. | ||
* | ||
* @var string | ||
*/ | ||
private $recaptchaVerifyUrl; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param string $recaptchaVerifyServer | ||
*/ | ||
public function __construct($recaptchaVerifyServer) | ||
{ | ||
$this->recaptchaVerifyUrl = ($recaptchaVerifyServer ?: 'https://www.google.com').'/recaptcha/api/siteverify'; | ||
} | ||
|
||
/** | ||
* Submit the POST request with the specified parameters. | ||
* | ||
* @param RequestParameters $params Request parameters | ||
* @return string Body of the reCAPTCHA response | ||
*/ | ||
public function submit(RequestParameters $params) | ||
{ | ||
/** | ||
* PHP 5.6.0 changed the way you specify the peer name for SSL context options. | ||
* Using "CN_name" will still work, but it will raise deprecated errors. | ||
*/ | ||
$peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; | ||
$options = array( | ||
'http' => array( | ||
'header' => "Content-type: application/x-www-form-urlencoded\r\n", | ||
'method' => 'POST', | ||
'content' => $params->toQueryString(), | ||
// Force the peer to validate (not needed in 5.6.0+, but still works) | ||
'verify_peer' => true, | ||
// Force the peer validation to use www.google.com | ||
$peer_key => 'www.google.com', | ||
), | ||
); | ||
$context = stream_context_create($options); | ||
return file_get_contents($this->recaptchaVerifyUrl, false, $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace EWZ\Bundle\RecaptchaBundle\ReCaptcha\RequestMethod; | ||
|
||
use ReCaptcha\RequestMethod; | ||
use ReCaptcha\RequestParameters; | ||
|
||
/** | ||
* Sends POST requests to the reCAPTCHA service though a proxy. | ||
*/ | ||
class ProxyPost implements RequestMethod | ||
{ | ||
/** | ||
* HTTP Proxy informations. | ||
* | ||
* @var array | ||
*/ | ||
private $httpProxy; | ||
|
||
/** | ||
* The reCAPTCHA verify server URL. | ||
* | ||
* @var string | ||
*/ | ||
private $recaptchaVerifyUrl; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param array $httpProxy proxy data to connect to | ||
* @param string $recaptchaVerifyServer | ||
*/ | ||
public function __construct(array $httpProxy, $recaptchaVerifyServer) | ||
{ | ||
$this->httpProxy = $httpProxy; | ||
$this->recaptchaVerifyUrl = ($recaptchaVerifyServer ?: 'https://www.google.com').'/recaptcha/api/siteverify'; | ||
} | ||
|
||
/** | ||
* Submit the POST request with the specified parameters. | ||
* | ||
* @param RequestParameters $params Request parameters | ||
* @return string Body of the reCAPTCHA response | ||
*/ | ||
public function submit(RequestParameters $params) | ||
{ | ||
/** | ||
* PHP 5.6.0 changed the way you specify the peer name for SSL context options. | ||
* Using "CN_name" will still work, but it will raise deprecated errors. | ||
*/ | ||
$peer_key = version_compare(PHP_VERSION, '5.6.0', '<') ? 'CN_name' : 'peer_name'; | ||
$options = array( | ||
'http' => array( | ||
'header' => "Content-type: application/x-www-form-urlencoded\r\n".sprintf('Proxy-Authorization: Basic %s', base64_encode($this->httpProxy['auth'])), | ||
'method' => 'POST', | ||
'content' => $params->toQueryString(), | ||
// Force the peer to validate (not needed in 5.6.0+, but still works) | ||
'verify_peer' => true, | ||
// Force the peer validation to use www.google.com | ||
$peer_key => 'www.google.com', | ||
|
||
'proxy' => sprintf('tcp://%s:%s', $this->httpProxy['host'], $this->httpProxy['port']), | ||
// While this is a non-standard request format, some proxy servers require it. | ||
'request_fulluri' => true, | ||
), | ||
); | ||
$context = stream_context_create($options); | ||
return file_get_contents($this->recaptchaVerifyUrl, false, $context); | ||
} | ||
} |
Oops, something went wrong.