Skip to content

Commit

Permalink
Refactoring (#16)
Browse files Browse the repository at this point in the history
* Update

* Update refresh token

Co-authored-by: Artem Henvald <artem.genvald@stfalcon.com>
  • Loading branch information
fre5h and Artem Henvald authored Jan 17, 2022
1 parent 3dd9b28 commit 0abf9bb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
32 changes: 30 additions & 2 deletions Entity/JWT/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace StfalconStudio\ApiBundle\Entity\JWT;

use Doctrine\ORM\Mapping as ORM;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as BaseRefreshToken;
use Gesdinet\JWTRefreshTokenBundle\Model\AbstractRefreshToken;
use Symfony\Component\Validator\Constraints as Assert;

/**
Expand All @@ -30,8 +30,36 @@
* }
* )
*/
class RefreshToken extends BaseRefreshToken
class RefreshToken extends AbstractRefreshToken
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @var string|null
*
* @ORM\Column(name="refresh_token", type="string", unique=true, length=128)
*/
protected $refreshToken;

/**
* @var string|null
*
* @ORM\Column(type="string", length=255)
*/
protected $username;

/**
* @var \DateTimeInterface|null
*
* @ORM\Column(type="datetime")
*/
protected $valid;

/**
* @ORM\Column(type="datetimetz_immutable")
*
Expand Down
2 changes: 1 addition & 1 deletion EventListener/JWT/JwtRefreshSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function getSubscribedEvents(): iterable
*/
public function processRefreshToken(RefreshEvent $event): void
{
$user = $event->getPreAuthenticatedToken()->getUser();
$user = $event->getToken()->getUser();

if ($user instanceof CredentialsInterface) {
$refreshToken = $event->getRefreshToken();
Expand Down
21 changes: 10 additions & 11 deletions Tests/EventListener/JWT/JwtRefreshSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,21 @@ final class JwtRefreshSubscriberTest extends TestCase
private $refreshEvent;

/** @var PostAuthenticationGuardToken|MockObject */
private $preAuthenticatedToken;
private $token;

/** @var RefreshToken|MockObject */
private $refreshToken;

/** @var CredentialsInterface|MockObject */
private $user;

/** @var JwtRefreshSubscriber */
private $subscriber;
private JwtRefreshSubscriber $subscriber;

protected function setUp(): void
{
$this->refreshEvent = $this->createMock(RefreshEvent::class);
$this->user = $this->createMock(CredentialsInterface::class);
$this->preAuthenticatedToken = $this->createMock(PostAuthenticationGuardToken::class);
$this->token = $this->createMock(PostAuthenticationGuardToken::class);
$this->refreshToken = $this->createMock(RefreshToken::class);
$this->subscriber = new JwtRefreshSubscriber();
}
Expand All @@ -52,7 +51,7 @@ protected function tearDown(): void
unset(
$this->refreshEvent,
$this->user,
$this->preAuthenticatedToken,
$this->token,
$this->refreshToken,
$this->subscriber,
);
Expand All @@ -76,8 +75,8 @@ public function testProcessRefreshTokenWithException(): void
{
$this->refreshEvent
->expects(self::once())
->method('getPreAuthenticatedToken')
->willReturn($this->preAuthenticatedToken)
->method('getToken')
->willReturn($this->token)
;
$this->refreshEvent
->expects(self::once())
Expand All @@ -91,7 +90,7 @@ public function testProcessRefreshTokenWithException(): void
->willReturn(new \DateTime('2030-01-01 00:00:01'))
;

$this->preAuthenticatedToken
$this->token
->expects(self::once())
->method('getUser')
->willReturn($this->user)
Expand All @@ -112,8 +111,8 @@ public function testProcessRefreshTokenWithoutException(): void
{
$this->refreshEvent
->expects(self::once())
->method('getPreAuthenticatedToken')
->willReturn($this->preAuthenticatedToken)
->method('getToken')
->willReturn($this->token)
;
$this->refreshEvent
->expects(self::once())
Expand All @@ -127,7 +126,7 @@ public function testProcessRefreshTokenWithoutException(): void
->willReturn(new \DateTime('2030-01-01 00:00:01'))
;

$this->preAuthenticatedToken
$this->token
->expects(self::once())
->method('getUser')
->willReturn($this->user)
Expand Down

0 comments on commit 0abf9bb

Please sign in to comment.