Skip to content

Commit

Permalink
Merge pull request #3917 from HungDV2022/unittest_JwksController
Browse files Browse the repository at this point in the history
JwksController::initialize() & index() ユニットテスト調整
  • Loading branch information
HungDV2022 authored Oct 24, 2024
2 parents b935a69 + d8d4c83 commit 8793c2a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class JwksController extends BcAdminApiController
* Initialize
* @checked
* @noTodo
* @unitTest
*/
public function initialize(): void
{
Expand All @@ -41,6 +42,7 @@ public function initialize(): void
* JWT::decode($jwt, JWK::parseKeySet($keys), [Configure::read('Jwt.algorithm')])
* @checked
* @noTodo
* @unitTest
*/
public function index()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* baserCMS : Based Website Development Project <https://basercms.net>
* Copyright (c) NPO baser foundation <https://baserfoundation.org/>
*
* @copyright Copyright (c) NPO baser foundation
* @link https://basercms.net baserCMS Project
* @since 5.0.0
* @license https://basercms.net/license/index.html MIT License
*/

namespace BaserCore\Test\TestCase\Controller\Api\Admin;

use BaserCore\Controller\Api\Admin\JwksController;
use BaserCore\TestSuite\BcTestCase;
use BaserCore\Utility\BcContainerTrait;
use Cake\TestSuite\IntegrationTestTrait;

/**
* JwksControllerTest Test Case
*/
class JwksControllerTest extends BcTestCase
{

/**
* Trait
*/
use IntegrationTestTrait;
use BcContainerTrait;

/**
* set up
*/
public function setUp(): void
{
parent::setUp();
}

/**
* test initialize
*
* @return void
*/
public function testInitialize()
{
$controller = new JwksController($this->getRequest());
$this->assertEquals(['index'], $controller->Authentication->getUnauthenticatedActions());
}

/**
* test index
*/
public function testIndex()
{
$this->get('/baser/api/admin/baser-core/jwks/index.json');
//ステータスを確認
$this->assertResponseCode(200);
//戻り値確認
$vars = $this->_controller->viewBuilder()->getVars();
$this->assertArrayHasKey('kid', $vars['keys']['keys'][0]);
$this->assertArrayHasKey('kty', $vars['keys']['keys'][0]);
$this->assertArrayHasKey('alg', $vars['keys']['keys'][0]);
$this->assertArrayHasKey('use', $vars['keys']['keys'][0]);
$this->assertArrayHasKey('e', $vars['keys']['keys'][0]);
$this->assertArrayHasKey('n', $vars['keys']['keys'][0]);
}
}

0 comments on commit 8793c2a

Please sign in to comment.