Add initial Plenario live polling app
CI / Deploy / test (push) Successful in 49s
CI / Deploy / deploy (push) Failing after 5s

CakePHP 5.4 app for live polls: create via email without login, manage
via secret admin link, join via code. Includes slide types (choice,
wordcloud, open, scale, content), presenter mode, CSV export, captcha,
throttling, tests and Gitea CI/deploy workflow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-07 13:24:29 +01:00
commit eb319f8c1e
120 files changed
+15572

No files matched your search

+79
View File
@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace App\Test\TestCase\Captcha;
use App\Captcha\CaptchaFactory;
use App\Captcha\MathCaptcha;
use App\Captcha\NoCaptcha;
use App\Captcha\RecaptchaCaptcha;
use Cake\Http\Client;
use Cake\Http\Client\Response as ClientResponse;
use Cake\Http\ServerRequest;
use Cake\Http\Session;
use Cake\TestSuite\TestCase;
use InvalidArgumentException;
/**
* Captcha implementations.
*/
class CaptchaTest extends TestCase
{
public function testFactory(): void
{
$this->assertInstanceOf(NoCaptcha::class, CaptchaFactory::create('x', 'none'));
$this->assertInstanceOf(MathCaptcha::class, CaptchaFactory::create('x', 'math'));
$this->assertInstanceOf(RecaptchaCaptcha::class, CaptchaFactory::create('x', 'recaptcha'));
$this->expectException(InvalidArgumentException::class);
CaptchaFactory::create('x', 'unknown');
}
public function testMathCaptchaIsSingleUse(): void
{
$session = new Session();
$request = new ServerRequest(['session' => $session]);
$captcha = new MathCaptcha('create');
$challenge = $captcha->challenge($request);
$this->assertSame('math', $challenge['type']);
$answer = (string)$session->read('Captcha.math.create');
$submit = (new ServerRequest(['session' => $session]))->withData('captcha_answer', $answer);
$this->assertTrue($captcha->verify($submit));
$this->assertFalse($captcha->verify($submit), 'second verification must fail');
}
public function testMathCaptchaScopesAreIndependent(): void
{
$session = new Session();
$request = new ServerRequest(['session' => $session]);
(new MathCaptcha('create'))->challenge($request);
$answer = (string)$session->read('Captcha.math.create');
$submit = (new ServerRequest(['session' => $session]))->withData('captcha_answer', $answer);
$this->assertFalse((new MathCaptcha('recover'))->verify($submit));
}
public function testRecaptchaVerifiesWithGoogle(): void
{
$client = $this->createMock(Client::class);
$client->expects($this->once())
->method('post')
->with(RecaptchaCaptcha::VERIFY_URL, $this->callback(fn($data) => $data['secret'] === 'secret' && $data['response'] === 'tok'))
->willReturn(new ClientResponse(['HTTP/1.1 200 OK', 'Content-Type: application/json'], '{"success": true}'));
$captcha = new RecaptchaCaptcha('site', 'secret', $client);
$request = (new ServerRequest())->withData('g-recaptcha-response', 'tok');
$this->assertTrue($captcha->verify($request));
}
public function testRecaptchaFailsClosed(): void
{
$client = $this->createStub(Client::class);
$client->method('post')->willReturn(new ClientResponse(['HTTP/1.1 200 OK'], '{"success": false}'));
$request = (new ServerRequest())->withData('g-recaptcha-response', 'tok');
$this->assertFalse((new RecaptchaCaptcha('site', 'secret', $client))->verify($request));
$this->assertFalse((new RecaptchaCaptcha('', '', $client))->verify($request), 'missing keys');
$this->assertFalse((new RecaptchaCaptcha('site', 'secret', $client))->verify(new ServerRequest()), 'missing token');
}
}