blob: 084c30b3ba34efc00df73038d78533c5390509a8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
<?php
namespace MediaWiki\Extensions\OAuth\Tests\Repository;
use MediaWiki\Extensions\OAuth\Entity\AccessTokenEntity;
use MediaWiki\Extensions\OAuth\Repository\AccessTokenRepository;
use MediaWiki\Extensions\OAuth\Tests\Entity\Mock_ClientEntity;
use MediaWikiTestCase;
/**
* @covers \MediaWiki\Extensions\OAuth\Repository\AccessTokenRepository
* @group Database
*/
class AccessTokenRepositoryTest extends MediaWikiTestCase {
protected $accessToken;
protected $accessTokenRepo;
protected $tablesUsed = [ 'oauth2_access_tokens' ];
protected function setUp() : void {
parent::setUp();
$this->accessToken = new AccessTokenEntity(
Mock_ClientEntity::newMock( $this->getTestUser()->getUser() ), []
);
$identifier = bin2hex( random_bytes( 40 ) );
$this->accessToken->setIdentifier( $identifier );
$this->accessToken->setExpiryDateTime(
( new \DateTimeImmutable() )->add( new \DateInterval( 'PT1H' ) )
);
$this->accessTokenRepo = new AccessTokenRepository();
}
public function testPersistingToken() {
$this->accessTokenRepo->persistNewAccessToken( $this->accessToken );
$this->assertFalse(
$this->accessTokenRepo->isAccessTokenRevoked( $this->accessToken->getIdentifier() ),
'Access token should not be revoked'
);
}
public function testRevokingToken() {
$this->accessTokenRepo->revokeAccessToken( $this->accessToken->getIdentifier() );
$this->assertTrue(
$this->accessTokenRepo->isAccessTokenRevoked( $this->accessToken->getIdentifier() ),
'Access token should be revoked'
);
}
}
|