| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- /**
- * 描述.
- *
- * @author nj <nj@gmail.com>
- * @date 2020-01-21 23:29:56
- */
- declare(strict_types=1);
- namespace HyperfTest\Features;
- use App\Repositories\Utils\JwtRepository;
- use HyperfTest\HttpTestCase;
- class JwtTest extends HttpTestCase
- {
- /**
- * 属性描述.
- *
- * @var JwtRepository|null
- */
- private $jwt = null;
- /**
- * 测试之前执行.
- */
- public function setUp():void
- {
- parent::setUp();
- $this->jwt = make(JwtRepository::class);
- }
- /**
- * 测试完毕后执行.
- */
- public function tearDown():void
- {
- parent::tearDown();
- }
- /**
- * 测试创建APP Jwt
- */
- public function testCreateAppJwt()
- {
- $user = [];
- $user['user_id'] = 'VS9LIC';
- $user['device_no'] = 'rrsepmmxj9cpenm9xmlosams3m9pycya';
- $user['device_type'] = 'A';
- $aud = 'app-users';
- $arrToken = $this->jwt->createAppJwt($user, $aud);
- var_dump($arrToken);
- $this->assertArrayHasKey('token', $arrToken);
- $this->assertArrayHasKey('expired_at', $arrToken);
- }
- /**
- * 测试创建后台 JWT
- */
- public function testCreateManageJwt()
- {
- $user = new \stdClass();
- $user->manager_id = 'YBJ66BSCJCBLBHSB';
- $user->role_id = 1;
- $arrToken = $this->jwt->createManageJwt($user);
- var_dump($arrToken);
- $this->assertArrayHasKey('token', $arrToken);
- $this->assertArrayHasKey('expired_at', $arrToken);
- }
- public function testValidateToken()
- {
- $token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvZ2Z3Lmdvb2dsZS5jb20iLCJhdWQiOiJhcHAtdXNlcnMiLCJleHAiOjE1Nzk2NzAyNDMsImp0aSI6ImRkYzUyMmI0Njg0MjRlMTk3ZTUwMmE0MTc4NjViYjRlIiwiaWF0IjoxNTc5NjI3MDQzLCJ1c2VyX2lkIjoiWUJKNjZCU0NKQ0JMQkhTQiIsImRldmljZV9ubyI6InJyc2VwbW14ajljcGVubTl4bWxvc2FtczNtOXB5Y3lhIn0.Ba3oKpa-xPZBb0lM5M9a57WX6qlwVhnlC37ctfNITEM';
- // 受众, app-user/manage-users
- $aud = 'app-users';
- $result = $this->jwt->validateToken($token, $aud);
- var_dump($result);
- $this->assertArrayHasKey('is_illegal', $result);
- $this->assertArrayHasKey('is_expired', $result);
- $this->assertArrayHasKey('is_valid', $result);
- $this->assertEquals(false, $result['is_illegal']);
- $this->assertEquals(false, $result['is_expired']);
- $this->assertEquals(true, $result['is_valid']);
- }
- }
|