Merge pull request 'Store answers atomically and limit word cloud input' (#31) from fix/atomic-votes into main
CI / Deploy / test (push) Successful in 52s
CI / Deploy / deploy (push) Successful in 4s

Reviewed-on: #31
This commit was merged in pull request #31.
This commit is contained in:
gnilebein committed 2026-11-08 22:35:42 +01:00
commit 6912d045cf
11 files changed
+224 -50

No files matched your search

@@ -5,6 +5,8 @@ namespace App\Test\TestCase\Controller;
use App\Model\Entity\Slide;
use App\Test\TestCase\PlenarioTestTrait;
use Cake\Cache\Cache;
use Cake\Core\Configure;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
@@ -28,6 +30,7 @@ class ParticipateControllerTest extends TestCase
{
parent::setUp();
$this->enableCsrfToken();
Cache::clear('throttle');
}
public function testUnknownCodeIs404(): void
@@ -157,4 +160,24 @@ class ParticipateControllerTest extends TestCase
$this->get('/p/' . $poll->join_code);
$this->assertResponseContains('Diese Umfrage ist geschlossen');
}
public function testVotesAreThrottledPerIp(): void
{
Configure::write('Plenario.throttle.votesPerMinute', 2);
[$poll] = $this->createPoll();
$slide = $this->createSlide($poll, Slide::TYPE_WORDCLOUD);
$this->goLive($poll, $slide);
foreach (['Kaffee', 'Tee', 'Wasser'] as $i => $word) {
$this->cookie('plenario_pid', self::PID);
$this->configRequest(['headers' => ['X-Requested-With' => 'XMLHttpRequest', 'Accept' => 'application/json']]);
$this->post("/p/{$poll->join_code}/vote", ['slide_id' => $slide->id, 'word' => $word]);
$body = json_decode((string)$this->_response->getBody(), true);
$this->assertSame($i < 2, $body['ok'], $word);
}
$this->assertResponseCode(429);
$this->assertStringContainsString('Zu viele Antworten', $body['message']);
$this->assertArrayHasKey('state', $body);
$this->assertSame(2, TableRegistry::getTableLocator()->get('Responses')->find()->where(['slide_id' => $slide->id])->count());
}
}