Merge remote-tracking branch 'origin/main' into fix/atomic-votes
This commit is contained in:
commit
9d65e85c55
21 files changed
+402
-128
No files matched your search
@@ -5,7 +5,9 @@ namespace App\Test\TestCase\Controller;
|
||||
|
||||
use App\Model\Entity\Slide;
|
||||
use App\Model\Table\PollsTable;
|
||||
use App\Service\VoteService;
|
||||
use App\Test\TestCase\PlenarioTestTrait;
|
||||
use Cake\Database\Driver\Sqlite;
|
||||
use Cake\TestSuite\EmailTrait;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
@@ -180,6 +182,44 @@ class AdminControllerTest extends TestCase
|
||||
$this->assertSame(2, $this->slidesTable()->get($third->id)->position);
|
||||
}
|
||||
|
||||
public function testDeletingTheLiveSlidePausesAndResumesWithTheNextOne(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$first = $this->createSlide($poll, Slide::TYPE_OPEN);
|
||||
$second = $this->createSlide($poll, Slide::TYPE_SCALE);
|
||||
$third = $this->createSlide($poll, Slide::TYPE_CHOICE);
|
||||
$poll = $this->goLive($poll, $second);
|
||||
|
||||
$this->post("/admin/$token/slides/{$second->id}/delete");
|
||||
$poll = $this->pollsTable()->get($poll->id);
|
||||
$this->assertTrue($poll->isPaused(), 'Participants see the pause page.');
|
||||
$this->assertSame($third->id, $poll->paused_slide_id);
|
||||
|
||||
// The paused slide is deleted as well: resume with the previous one (last slide).
|
||||
$this->post("/admin/$token/slides/{$third->id}/delete");
|
||||
$poll = $this->pollsTable()->get($poll->id);
|
||||
$this->assertTrue($poll->isPaused());
|
||||
$this->assertSame($first->id, $poll->paused_slide_id);
|
||||
|
||||
// No slides left: back to "not started".
|
||||
$this->post("/admin/$token/slides/{$first->id}/delete");
|
||||
$poll = $this->pollsTable()->get($poll->id);
|
||||
$this->assertNull($poll->current_slide_id);
|
||||
$this->assertNull($poll->paused_slide_id);
|
||||
$this->assertFalse($poll->isPaused());
|
||||
}
|
||||
|
||||
public function testDeletingAnotherSlideKeepsTheLiveOne(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$live = $this->createSlide($poll, Slide::TYPE_OPEN);
|
||||
$other = $this->createSlide($poll, Slide::TYPE_SCALE);
|
||||
$poll = $this->goLive($poll, $live);
|
||||
|
||||
$this->post("/admin/$token/slides/{$other->id}/delete");
|
||||
$this->assertSame($live->id, $this->pollsTable()->get($poll->id)->current_slide_id);
|
||||
}
|
||||
|
||||
public function testReorderSlidesByDragAndDrop(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
@@ -284,6 +324,36 @@ class AdminControllerTest extends TestCase
|
||||
$this->assertFalse($this->pollsTable()->exists(['id' => $poll->id]));
|
||||
}
|
||||
|
||||
public function testDeletePollRemovesOptionsAndResponses(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$slide = $this->createSlide($poll, Slide::TYPE_CHOICE);
|
||||
$poll = $this->goLive($poll, $slide);
|
||||
(new VoteService())->submit($poll, $slide, 'participant', ['option_id' => $slide->slide_options[0]->id]);
|
||||
$options = $this->fetchTable('SlideOptions');
|
||||
$responses = $this->fetchTable('Responses');
|
||||
$this->assertTrue($responses->exists(['slide_id' => $slide->id]));
|
||||
|
||||
// A normal SQLite connection does not enforce foreign keys (the test suite turns them on),
|
||||
// so deleting must not rely on ON DELETE CASCADE.
|
||||
$connection = $responses->getConnection();
|
||||
$sqlite = $connection->getDriver() instanceof Sqlite;
|
||||
if ($sqlite) {
|
||||
$connection->execute('PRAGMA foreign_keys = OFF');
|
||||
}
|
||||
try {
|
||||
$this->post("/admin/$token/delete", ['confirm_code' => $poll->join_code]);
|
||||
} finally {
|
||||
if ($sqlite) {
|
||||
$connection->execute('PRAGMA foreign_keys = ON');
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertFalse($this->slidesTable()->exists(['id' => $slide->id]));
|
||||
$this->assertFalse($options->exists(['slide_id' => $slide->id]), 'Options must not outlive their poll.');
|
||||
$this->assertFalse($responses->exists(['slide_id' => $slide->id]), 'Responses must not outlive their poll.');
|
||||
}
|
||||
|
||||
public function testQrAndExport(): void
|
||||
{
|
||||
[, $token] = $this->createPoll();
|
||||
|
||||
@@ -70,6 +70,17 @@ class HomeControllerTest extends TestCase
|
||||
$this->assertResponseNotContains('/admin/', 'Admin link must not be shown when disabled');
|
||||
}
|
||||
|
||||
public function testCreateAcceptsEmailWithSurroundingSpaces(): void
|
||||
{
|
||||
$this->session(['Captcha.math.create' => 7]);
|
||||
$this->post('/create', ['title' => ' Retro ', 'email' => ' Owner@Example.org ', 'captcha_answer' => '7']);
|
||||
|
||||
$this->assertRedirect(['_name' => 'created']);
|
||||
$poll = $this->pollsTable()->find()->firstOrFail();
|
||||
$this->assertSame('Retro', $poll->title);
|
||||
$this->assertSame('owner@example.org', $poll->email);
|
||||
}
|
||||
|
||||
public function testIndexRendersHiddenHoneypot(): void
|
||||
{
|
||||
$this->get('/');
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Test\TestCase\Error;
|
||||
|
||||
use App\Error\RedactingErrorLogger;
|
||||
use App\Test\TestCase\PlenarioTestTrait;
|
||||
use Cake\Log\Engine\ArrayLog;
|
||||
use Cake\Log\Log;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
|
||||
/**
|
||||
* Admin tokens and embed keys must never end up in the error log.
|
||||
*/
|
||||
class RedactingErrorLoggerTest extends TestCase
|
||||
{
|
||||
use IntegrationTestTrait;
|
||||
use PlenarioTestTrait;
|
||||
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses'];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::drop('error');
|
||||
Log::setConfig('error', ['className' => ArrayLog::class, 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency']]);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Log::drop('error');
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testRedactsTokensAndKeys(): void
|
||||
{
|
||||
$token = str_repeat('a', 20) . '-_B9';
|
||||
$message = "Request URL: /admin/$token/slides/5/edit\n"
|
||||
. "Referer URL: https://example.org/e/$token/12\n"
|
||||
. "A route matching \"/admin/$token?x=1\" could not be found.\n"
|
||||
. "Request URL: /admin/$token";
|
||||
|
||||
$redacted = RedactingErrorLogger::redact($message);
|
||||
|
||||
$this->assertStringNotContainsString($token, $redacted);
|
||||
$this->assertStringContainsString('/admin/[redacted]/slides/5/edit', $redacted);
|
||||
$this->assertStringContainsString('/e/[redacted]/12', $redacted);
|
||||
$this->assertStringContainsString('"/admin/[redacted]?x=1"', $redacted);
|
||||
}
|
||||
|
||||
public function testLeavesOtherUrlsAlone(): void
|
||||
{
|
||||
$message = 'Request URL: /p/K7P2QX/state and /admin/short';
|
||||
|
||||
$this->assertSame($message, RedactingErrorLogger::redact($message));
|
||||
}
|
||||
|
||||
public function testErrorLogNeverContainsTheAdminToken(): void
|
||||
{
|
||||
[, $token] = $this->createPoll();
|
||||
|
||||
$this->get("/admin/$token/slides/999999/edit");
|
||||
$this->assertResponseCode(404);
|
||||
|
||||
$logs = implode("\n", Log::engine('error')->read());
|
||||
$this->assertStringContainsString('/admin/[redacted]/slides/999999/edit', $logs);
|
||||
$this->assertStringNotContainsString($token, $logs);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user