forked from baserproject/basercms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
use BaserCore\TestSuite\BcTestCase; | ||
use BaserCore\Test\Scenario\InitAppScenario; | ||
use Cake\Event\Event; | ||
use Cake\Http\Exception\HttpException; | ||
use Cake\Http\Exception\RedirectException; | ||
use Cake\Http\Exception\UnauthorizedException; | ||
use Cake\TestSuite\EmailTrait; | ||
|
@@ -75,23 +76,22 @@ public function testImplementedEvents() | |
} | ||
|
||
/** | ||
* test afterIdentify | ||
* test afterIdentify 管理画面 | ||
*/ | ||
public function testAfterIdentify() | ||
{ | ||
$this->loadFixtureScenario(InitAppScenario::class); | ||
$siteConfigsService = $this->getService(SiteConfigsServiceInterface::class); | ||
$event = new Event('Authentication.afterIdentify', null, []); | ||
|
||
// 管理画面 | ||
$request = $this->getRequest('/baser/admin/baser-core/users/login'); | ||
$this->loginAdmin($request); | ||
|
||
// - 二段階認証無効時 | ||
// 二段階認証無効時 | ||
$siteConfigsService->setValue('use_two_factor_authentication', 0); | ||
$this->assertNull($this->BcAuthenticationEventListener->afterIdentify($event)); | ||
|
||
// - 二段階認証有効時 | ||
// 二段階認証有効時 | ||
$siteConfigsService->setValue('use_two_factor_authentication', 1); | ||
$siteConfigsService->setValue('email', '[email protected]'); | ||
|
||
|
@@ -103,21 +103,45 @@ public function testAfterIdentify() | |
$this->assertMailSentTo('[email protected]'); | ||
$this->assertMailContainsText('認証コード'); | ||
} | ||
} | ||
|
||
/** | ||
* test afterIdentify API | ||
*/ | ||
public function testAfterIdentifyApi() | ||
{ | ||
$this->loadFixtureScenario(InitAppScenario::class); | ||
$siteConfigsService = $this->getService(SiteConfigsServiceInterface::class); | ||
$event = new Event('Authentication.afterIdentify', null, []); | ||
|
||
// API | ||
$request = $this->getRequest('/baser/api/admin/baser-core/users/login.json'); | ||
$this->loginAdmin($request); | ||
|
||
// - 二段階認証無効時 | ||
// 二段階認証無効時 | ||
$siteConfigsService->setValue('use_two_factor_authentication', 0); | ||
$this->assertNull($this->BcAuthenticationEventListener->afterIdentify($event)); | ||
|
||
// - 二段階認証有効時 | ||
// 二段階認証有効時 | ||
$siteConfigsService->setValue('use_two_factor_authentication', 1); | ||
$siteConfigsService->setValue('email', '[email protected]'); | ||
|
||
try { | ||
$this->BcAuthenticationEventListener->afterIdentify($event); | ||
throw new \Exception(); | ||
} catch (UnauthorizedException $e) { | ||
$this->assertEquals('send_codeキーを付与すると認証コードをメールで送信します。', $e->getMessage()); | ||
$this->assertNoMailSent(); | ||
} | ||
|
||
// 認証コード送信要求 | ||
$request = $this->getRequest('/baser/api/admin/baser-core/users/login.json', | ||
['send_code' => '1']); | ||
$this->loginAdmin($request); | ||
|
||
try { | ||
$this->BcAuthenticationEventListener->afterIdentify($event); | ||
throw new \Exception(); | ||
} catch (HttpException $e) { | ||
$this->assertEquals('メールで受信した認証コードをcodeキーの値として送信してください。', $e->getMessage()); | ||
$this->assertMailSentTo('[email protected]'); | ||
$this->assertMailContainsText('認証コード'); | ||
|