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.

Commit6076a48

Browse files
committed
Support validation when value contains response
If the user passes in the response value directly to isValid(), e.g. bytaking the `g-recaptcha-response` value directly, then this should work!Fixes#30
1 parentd2809f1 commit6076a48

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

‎phpunit.xml.dist‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
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+
<envname="TESTS_ZEND_SERVICE_RECAPTCHA_SITE_KEY"value="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"/>
32+
<envname="TESTS_ZEND_SERVICE_RECAPTCHA_SECRET_KEY"value="6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"/>
33+
<envname="TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE"value="03AI-r6f4PlCfbU_-3HGwscafLbnxjinCf7GKEErJlUHDVF1uJ_SoVebG8gJewkGjNTwLxMZNQPJ4XRTvovB8J6vHLHCVZ1yV_KzJc1Mca6QVZ_6MsNJxYsXa-5NUWTHRvl7XGkju_oPTlxRNDC7DPPkd3eaav0HW1SfdJY1uRd_w5Fkin7KBXz-Eg8oQRSRQ-MplJacQQ3rlKkpEssu1seliTNNidAmuuHWksZwdVAi4ZMyT52BA98_KitLVipT7yiqSka2m8oJZMa9uYb2buNR7X3qnqsJfUc9BxT5lF2HLiX79STktdSAI"/>
3034

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

‎src/ReCaptcha.php‎

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

262262
$service =$this->getService();
263+
if (array_key_exists($value,$context)) {
264+
$value =$context[$value];
265+
}
263266

264-
$res =$service->verify($context[$value]);
267+
$res =$service->verify($value);
265268
if (!$res) {
266269
$this->error(self::ERR_CAPTCHA);
267270
returnfalse;

‎test/ReCaptchaTest.php‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ public function setUp()
2828
if (!getenv('TESTS_ZEND_CAPTCHA_RECAPTCHA_SUPPORT')) {
2929
$this->markTestSkipped('Enable TESTS_ZEND_CAPTCHA_RECAPTCHA_SUPPORT to test PDF render');
3030
}
31-
32-
if (isset($this->word)) {
33-
unset($this->word);
34-
}
35-
36-
$this->captcha =newReCaptcha([
37-
'sessionClass' =>'ZendTest\Captcha\TestAsset\SessionContainer'
38-
]);
3931
}
4032

4133
publicfunctiontestConstructorShouldSetOptions()
@@ -163,4 +155,34 @@ public function testUsesReCaptchaHelper()
163155
$captcha =newReCaptcha;
164156
$this->assertEquals('captcha/recaptcha',$captcha->getHelperName());
165157
}
158+
159+
publicfunctiontestValidationForDifferentElementName()
160+
{
161+
$captcha =newReCaptcha([
162+
'site_key' =>getenv('TESTS_ZEND_SERVICE_RECAPTCHA_SITE_KEY'),
163+
'secret_key' =>getenv('TESTS_ZEND_SERVICE_RECAPTCHA_SECRET_KEY'),
164+
]);
165+
$captcha->getService()->setIp('127.0.0.1');
166+
167+
$response =getenv('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE');
168+
$value ='g-recaptcha-response';
169+
$context = ['g-recaptcha-response' =>getenv('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE')];
170+
171+
$this->assertTrue($captcha->isValid($value,$context));
172+
}
173+
174+
publicfunctiontestValidationForResponseElementName()
175+
{
176+
$captcha =newReCaptcha([
177+
'site_key' =>getenv('TESTS_ZEND_SERVICE_RECAPTCHA_SITE_KEY'),
178+
'secret_key' =>getenv('TESTS_ZEND_SERVICE_RECAPTCHA_SECRET_KEY'),
179+
]);
180+
$captcha->getService()->setIp('127.0.0.1');
181+
182+
$response =getenv('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE');
183+
$value =getenv('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE');
184+
$context = ['g-recaptcha-response' =>getenv('TESTS_ZEND_SERVICE_RECAPTCHA_RESPONSE')];
185+
186+
$this->assertTrue($captcha->isValid($value,$context));
187+
}
166188
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp