Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/Controller/MailPreviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Cake\Routing\Router;
use Cake\Utility\Inflector;
use DebugKit\Mailer\AbstractResult;
use DebugKit\Mailer\MailPreview;
use DebugKit\Mailer\PreviewResult;
use DebugKit\Mailer\SentMailResult;
use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -261,18 +262,21 @@ protected function findPreferredPart(AbstractResult $email, ?string $partType):
*
* @param string $previewName The Mailer name
* @param string $emailName The mailer preview method
* @param string $plugin The plugin where the mailer preview should be found
* @param ?string $plugin The plugin where the mailer preview should be found
* @return \DebugKit\Mailer\PreviewResult The result of the email preview
* @throws \Cake\Http\Exception\NotFoundException
*/
protected function findPreview(string $previewName, string $emailName, string $plugin = ''): PreviewResult
protected function findPreview(string $previewName, string $emailName, ?string $plugin = null): PreviewResult
{
if ($plugin) {
$plugin = "$plugin.";
}
if (str_contains($previewName, '\\')) {
throw new NotFoundException("Mailer preview $previewName not found");
}

$realClass = App::className($plugin . $previewName, 'Mailer/Preview');
if (!$realClass) {
if (!$realClass || !is_subclass_of($realClass, MailPreview::class, true)) {
throw new NotFoundException("Mailer preview $previewName not found");
}
/** @var \DebugKit\Mailer\MailPreview $mailPreview */
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Controller/MailPreviewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ public function testEmailPluginPassedToView()
$this->assertResponseContains('src="?part=html&plugin=DebugkitTestPlugin');
}

/**
* Test that invalid classnames are rejected
*
* @return void
*/
public function testEmailRejectInvalidClassName()
{
$this->get('/debug-kit/mail-preview/preview/Cake\Utility\Inflector/slug');
$this->assertResponseCode(404);

$this->get('/debug-kit/mail-preview/preview/Invalid/hello');
$this->assertResponseCode(404);
}

/** Test email template content
*
* @return void
Expand Down
Loading