Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit97a3900

Browse files
committed
Merge branch 'element-name-g-recaptcha-response'
Close#31Fix#30
2 parentsd2809f1 +64346d0 commit97a3900

File tree

3 files changed

+61
-10
lines changed

3 files changed

+61
-10
lines changed

‎phpunit.xml.dist‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
<!-- Enable this if you have installed ZendService\ReCaptcha on the
2828
include_path or via Composer.-->
2929
<envname="TESTS_ZEND_CAPTCHA_RECAPTCHA_SUPPORT"value="false" />
30+
<!-- Change these if you want to use your own keys-->
31+
<!-- These are test keys. See: https://developers.google.com/recaptcha/docs/faq-->
32+
<envname="TESTS_ZEND_SERVICE_RECAPTCHA_SITE_KEY"value="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"/>
33+
<envname="TESTS_ZEND_SERVICE_RECAPTCHA_SECRET_KEY"value="6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"/>
34+
<envname="TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE"value="03AI-r6f4PlCfbU_-3HGwscafLbnxjinCf7GKEErJlUHDVF1uJ_SoVebG8gJewkGjNTwLxMZNQPJ4XRTvovB8J6vHLHCVZ1yV_KzJc1Mca6QVZ_6MsNJxYsXa-5NUWTHRvl7XGkju_oPTlxRNDC7DPPkd3eaav0HW1SfdJY1uRd_w5Fkin7KBXz-Eg8oQRSRQ-MplJacQQ3rlKkpEssu1seliTNNidAmuuHWksZwdVAi4ZMyT52BA98_KitLVipT7yiqSka2m8oJZMa9uYb2buNR7X3qnqsJfUc9BxT5lF2HLiX79STktdSAI"/>
3035

3136
<!-- Enable this to test GC operations. These often fail in parallel
3237
build environments.-->

‎src/ReCaptcha.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,12 @@ public function isValid($value, $context = null)
260260
}
261261

262262
$service =$this->getService();
263+
if ((is_string($value) ||is_int($value)) &&array_key_exists($value,$context)) {
264+
$res =$service->verify($context[$value]);
265+
}else {
266+
$res =$service->verify($value);
267+
}
263268

264-
$res =$service->verify($context[$value]);
265269
if (!$res) {
266270
$this->error(self::ERR_CAPTCHA);
267271
returnfalse;

‎test/ReCaptchaTest.php‎

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
namespaceZendTest\Captcha;
1111

1212
useZend\Captcha\ReCaptcha;
13+
useZend\Http\ClientasHttpClient;
14+
useZend\Http\Client\Adapter\Socket;
1315
useZendService\ReCaptcha\ReCaptchaasReCaptchaService;
1416

1517
/**
@@ -26,16 +28,8 @@ class ReCaptchaTest extends \PHPUnit_Framework_TestCase
2628
publicfunctionsetUp()
2729
{
2830
if (!getenv('TESTS_ZEND_CAPTCHA_RECAPTCHA_SUPPORT')) {
29-
$this->markTestSkipped('Enable TESTS_ZEND_CAPTCHA_RECAPTCHA_SUPPORT to testPDF render');
31+
$this->markTestSkipped('Enable TESTS_ZEND_CAPTCHA_RECAPTCHA_SUPPORT to testRecaptcha');
3032
}
31-
32-
if (isset($this->word)) {
33-
unset($this->word);
34-
}
35-
36-
$this->captcha =newReCaptcha([
37-
'sessionClass' =>'ZendTest\Captcha\TestAsset\SessionContainer'
38-
]);
3933
}
4034

4135
publicfunctiontestConstructorShouldSetOptions()
@@ -163,4 +157,52 @@ public function testUsesReCaptchaHelper()
163157
$captcha =newReCaptcha;
164158
$this->assertEquals('captcha/recaptcha',$captcha->getHelperName());
165159
}
160+
161+
publicfunctiontestValidationForDifferentElementName()
162+
{
163+
$captcha =newReCaptcha([
164+
'site_key' =>getenv('TESTS_ZEND_SERVICE_RECAPTCHA_SITE_KEY'),
165+
'secret_key' =>getenv('TESTS_ZEND_SERVICE_RECAPTCHA_SECRET_KEY'),
166+
]);
167+
$service =$captcha->getService();
168+
$service->setIp('127.0.0.1');
169+
$service->setHttpClient($this->getHttpClient());
170+
171+
$response =getenv('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE');
172+
$value ='g-recaptcha-response';
173+
$context = ['g-recaptcha-response' =>getenv('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE')];
174+
175+
$this->assertTrue($captcha->isValid($value,$context));
176+
}
177+
178+
publicfunctiontestValidationForResponseElementName()
179+
{
180+
$captcha =newReCaptcha([
181+
'site_key' =>getenv('TESTS_ZEND_SERVICE_RECAPTCHA_SITE_KEY'),
182+
'secret_key' =>getenv('TESTS_ZEND_SERVICE_RECAPTCHA_SECRET_KEY'),
183+
]);
184+
$service =$captcha->getService();
185+
$service->setIp('127.0.0.1');
186+
$service->setHttpClient($this->getHttpClient());
187+
188+
$response =getenv('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE');
189+
$value =getenv('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE');
190+
$context = ['g-recaptcha-response' =>getenv('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE')];
191+
192+
$this->assertTrue($captcha->isValid($value,$context));
193+
}
194+
195+
/**
196+
* @return HttpClient
197+
*/
198+
privatefunctiongetHttpClient()
199+
{
200+
$socket =newSocket();
201+
$socket->setOptions([
202+
'ssltransport' =>'tls',
203+
]);
204+
returnnewHttpClient(null, [
205+
'adapter' =>$socket,
206+
]);
207+
}
166208
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp