Skip to content
This is the documentation for pieceofcake2/captcha, a CakePHP 2.x plugin for pieceofcake2/cakephp. About this fork.

Testing ​

The providers publish test keys. Use them in development and in browser tests. They must never be used in production.

Cloudflare Turnstile (testing):

Site keyBehaviour
1x00000000000000000000AAAlways passes (visible)
2x00000000000000000000ABAlways blocks (visible)
1x00000000000000000000BBAlways passes (invisible)
2x00000000000000000000BBAlways blocks (invisible)
3x00000000000000000000FFForces an interactive challenge (visible)
Secret keyBehaviour
1x0000000000000000000000000000000AAAlways passes
2x0000000000000000000000000000000AAAlways fails (invalid-input-response)
3x0000000000000000000000000000000AAYields a "token already spent" error (timeout-or-duplicate)

The dummy site keys produce the token XXXX.DUMMY.TOKEN.XXXX, which only the test secret keys accept. The verify response contains "hostname": "example.com", so do not set hostname with the test keys.

reCAPTCHA v2 (FAQ): site key 6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI, secret key 6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe. All verifications pass and the widget shows a warning. reCAPTCHA v3 has no test keys; create a separate key for testing.

hCaptcha (test keys): site key 10000000-ffff-ffff-ffff-000000000001, secret key 0x0000000000000000000000000000000000000000, response token 10000000-aaaa-bbbb-cccc-000000000001. They never show a challenge and always pass.

In unit tests, mock HttpSocket so no request leaves the test:

php
$http = $this->getMockBuilder(HttpSocket::class)->onlyMethods(['post'])->getMock();
$response = new HttpSocketResponse();
$response->code = 200;
$response->body = '{"success":true,"hostname":"example.com"}';
$http->method('post')->willReturn($response);

$this->Controller->Captcha->setHttpSocket($http);

See LICENSE for copyright and license information. Not affiliated with the Cake Software Foundation.