From 286ff817653bb2502dbd18417a8bde665eb48a6a Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Thu, 5 Dec 2024 10:02:18 +0900 Subject: [PATCH 1/5] =?UTF-8?q?MailformHelper::create()=20=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/bc-mail/src/View/Helper/MailformHelper.php | 1 + .../tests/TestCase/View/Helper/MailformHelperTest.php | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/bc-mail/src/View/Helper/MailformHelper.php b/plugins/bc-mail/src/View/Helper/MailformHelper.php index f5dba87e79..7a62a1aa6a 100755 --- a/plugins/bc-mail/src/View/Helper/MailformHelper.php +++ b/plugins/bc-mail/src/View/Helper/MailformHelper.php @@ -252,6 +252,7 @@ public function control(string $fieldName, array $attributes = []): string * @return string * @checked * @noTodo + * @unitTest */ public function create($context = null, $options = []): string { diff --git a/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php b/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php index 27dd75067d..2411cabb90 100644 --- a/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php +++ b/plugins/bc-mail/tests/TestCase/View/Helper/MailformHelperTest.php @@ -12,6 +12,7 @@ use BaserCore\TestSuite\BcTestCase; use BcMail\Model\Entity\MailField; +use BcMail\Test\Factory\MailMessagesFactory; use BcMail\View\Helper\MailformHelper; use Cake\ORM\ResultSet; use Cake\View\View; @@ -50,7 +51,11 @@ public function testControl() */ public function testCreate() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $rs = $this->MailformHelper->create(); + $this->assertTextContains('form enctype="multipart/form-data"', $rs); + + $rs = $this->MailformHelper->create(MailMessagesFactory::make()->getEntity(), ['url' => '/test']); + $this->assertTextContains('action="/test"', $rs); } /** From a34e1ab2e5a4df0459d7df1bd280e7f63e94e8e9 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Fri, 6 Dec 2024 10:49:22 +0900 Subject: [PATCH 2/5] =?UTF-8?q?MailMessagesController::beforeFilter()=20?= =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/MailMessagesController.php | 1 + .../Admin/MailMessagesControllerTest.php | 40 +++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php index 3f0abc12b8..a5c45f74ff 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php @@ -54,6 +54,7 @@ public function initialize(): void * @return void * @checked * @noTodo + * @unitTest */ public function beforeFilter(EventInterface $event) { diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php index 54f996b53f..855390103d 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php @@ -11,12 +11,21 @@ namespace BcMail\Test\TestCase\Controller\Admin; +use BaserCore\Test\Factory\ContentFactory; +use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\TestSuite\BcTestCase; use BcMail\Controller\Admin\MailMessagesController; +use Cake\Event\Event; +use Cake\TestSuite\IntegrationTestTrait; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; class MailMessagesControllerTest extends BcTestCase { - + /** + * Trait + */ + use ScenarioAwareTrait; + use IntegrationTestTrait; /** * set up * @@ -25,7 +34,8 @@ class MailMessagesControllerTest extends BcTestCase public function setUp(): void { parent::setUp(); - $this->MailMessagesController = new MailMessagesController($this->getRequest()); + $this->loadFixtureScenario(InitAppScenario::class); + $this->MailMessagesController = new MailMessagesController($this->loginAdmin($this->getRequest())); } /** @@ -53,7 +63,31 @@ public function testInitialize() */ public function testBeforeFilter() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + ContentFactory::make([ + 'name' => 'name_test', + 'plugin' => 'BcMail', + 'type' => 'MailContent', + 'url' => '/contact/', + 'site_id' => 1, + 'title' => 'お問い合わせ', + 'entity_id' => 1 + ])->persist(); + + //正常テスト・エラーにならない + $request = $this->getRequest('/baser/admin/bc-mail/mail_messages/view/1/1'); + $request = $this->loginAdmin($request); + $this->MailMessagesController = new MailMessagesController($request); + $event = new Event('filter'); + $this->MailMessagesController->beforeFilter($event); + + //異常テスト + $request = $this->getRequest('/baser/admin/bc-mail/mail_messages/view/2222/1'); + $request = $this->loginAdmin($request); + $this->MailMessagesController = new MailMessagesController($request); + $event = new Event('filter'); + $this->expectExceptionMessage('コンテンツデータが見つかりません。'); + $this->expectException('BaserCore\Error\BcException'); + $this->MailMessagesController->beforeFilter($event); } /** From b8a51e52918b78d048f1ca24156af8731b4c7b97 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Fri, 6 Dec 2024 11:07:31 +0900 Subject: [PATCH 3/5] =?UTF-8?q?MailMessagesController::index()=20=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/MailMessagesController.php | 1 + .../Admin/MailMessagesControllerTest.php | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php index a5c45f74ff..2d2129bdec 100644 --- a/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php +++ b/plugins/bc-mail/src/Controller/Admin/MailMessagesController.php @@ -81,6 +81,7 @@ public function beforeFilter(EventInterface $event) * @return void * @checked * @noTodo + * @unitTest */ public function index(MailMessagesAdminServiceInterface $service, int $mailContentId) { diff --git a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php index 855390103d..002460464c 100644 --- a/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php +++ b/plugins/bc-mail/tests/TestCase/Controller/Admin/MailMessagesControllerTest.php @@ -15,6 +15,8 @@ use BaserCore\Test\Scenario\InitAppScenario; use BaserCore\TestSuite\BcTestCase; use BcMail\Controller\Admin\MailMessagesController; +use BcMail\Service\MailMessagesServiceInterface; +use BcMail\Test\Factory\MailContentFactory; use Cake\Event\Event; use Cake\TestSuite\IntegrationTestTrait; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; @@ -103,7 +105,26 @@ public function testBeforeRender() */ public function testIndex() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->enableSecurityToken(); + $this->enableCsrfToken(); + // メールメッセージのデータを作成する + ContentFactory::make([ + 'plugin' => 'BcMail', + 'type' => 'MailContent', + 'url' => '/contact/', + 'site_id' => 1, + 'title' => 'お問い合わせ', + 'entity_id' => 1, + ])->persist(); + MailContentFactory::make(['id' => 1])->persist(); + $MailMessagesService = $this->getService(MailMessagesServiceInterface::class); + //テストデータベースを生成 + $MailMessagesService->createTable(1); + + //正常テスト + $this->get('/baser/admin/bc-mail/mail_messages/index/1'); + $this->assertResponseOk(); + $MailMessagesService->dropTable(1); } /** From e95647ab4ea1d2b21acd03784ed5de4e3c363305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8A=A0=E8=97=A4=20=E6=9C=97?= Date: Fri, 6 Dec 2024 12:39:36 +0900 Subject: [PATCH 4/5] =?UTF-8?q?fix=20#4067=20Cookie=EF=BC=88csrfToken?= =?UTF-8?q?=EF=BC=89=E3=81=ABsecure=E5=B1=9E=E6=80=A7=E3=81=8C=E4=BB=98?= =?UTF-8?q?=E3=81=8B=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=E3=82=92=E8=A7=A3?= =?UTF-8?q?=E6=B1=BA=20(#4068)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: kato Co-authored-by: ryuring --- src/Application.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Application.php b/src/Application.php index c4a2b3fa6b..5415ec0658 100644 --- a/src/Application.php +++ b/src/Application.php @@ -64,6 +64,12 @@ public function bootstrap(): void */ public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue { + $csrfProtectionMiddlewareOptions = ['httponly' => true]; + //リクエストがhttpsならcsrfTokenにもsecureヘッダを付与 + $sessionConfig = (array) Configure::read('Session'); + if (!empty($sessionConfig['ini']['session.cookie_secure']) || (int) ini_get('session.cookie_secure') === 1) { + $csrfProtectionMiddlewareOptions['secure'] = true; + } $middlewareQueue // Catch any exceptions in the lower layers, // and make an error page/response @@ -87,9 +93,7 @@ public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue // Cross Site Request Forgery (CSRF) Protection Middleware // https://book.cakephp.org/5/en/security/csrf.html#cross-site-request-forgery-csrf-middleware - ->add(new CsrfProtectionMiddleware([ - 'httponly' => true, - ])); + ->add(new CsrfProtectionMiddleware($csrfProtectionMiddlewareOptions)); return $middlewareQueue; } From 9baca680091456fb929d05469d4c6b3a57363725 Mon Sep 17 00:00:00 2001 From: thangnn Date: Sat, 7 Dec 2024 04:41:54 +0700 Subject: [PATCH 5/5] Add unitTest_MailMessagesTable_setupUpload --- plugins/bc-mail/src/Model/Table/MailMessagesTable.php | 1 + .../tests/TestCase/Model/Table/MailMessagesTableTest.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/bc-mail/src/Model/Table/MailMessagesTable.php b/plugins/bc-mail/src/Model/Table/MailMessagesTable.php index 175eba86eb..4755c2e4ee 100755 --- a/plugins/bc-mail/src/Model/Table/MailMessagesTable.php +++ b/plugins/bc-mail/src/Model/Table/MailMessagesTable.php @@ -161,6 +161,7 @@ public function createTableName(int $mailContentId): string * アップロード設定を行う * @checked * @noTodo + * @unitTest */ public function setupUpload(int $mailContentId) { diff --git a/plugins/bc-mail/tests/TestCase/Model/Table/MailMessagesTableTest.php b/plugins/bc-mail/tests/TestCase/Model/Table/MailMessagesTableTest.php index 9e55fb0d15..bd2d04b665 100644 --- a/plugins/bc-mail/tests/TestCase/Model/Table/MailMessagesTableTest.php +++ b/plugins/bc-mail/tests/TestCase/Model/Table/MailMessagesTableTest.php @@ -89,7 +89,9 @@ public function testSetUseTable() */ public function testSetupUpload() { - $this->markTestIncomplete('このテストは、まだ実装されていません。'); + $this->MailMessage->setupUpload(1); + $bcUpload = $this->MailMessage->getBehavior('BcUpload'); + $this->assertEquals('/var/www/html/webroot/files/mail/limited/1/messages/', $bcUpload->BcFileUploader["MailMessages"]->savePath); } /**