Update v1.0.6.5
This commit is contained in:
82
vendor/tymon/jwt-auth/tests/BlacklistTest.php
vendored
82
vendor/tymon/jwt-auth/tests/BlacklistTest.php
vendored
@@ -1,7 +1,17 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of jwt-auth.
|
||||
*
|
||||
* (c) Sean Tymon <tymon148@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Tymon\JWTAuth\Test\Providers\JWT;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Mockery;
|
||||
use Tymon\JWTAuth\Blacklist;
|
||||
use Tymon\JWTAuth\Payload;
|
||||
@@ -9,17 +19,18 @@ use Tymon\JWTAuth\Claims\Issuer;
|
||||
use Tymon\JWTAuth\Claims\IssuedAt;
|
||||
use Tymon\JWTAuth\Claims\Expiration;
|
||||
use Tymon\JWTAuth\Claims\NotBefore;
|
||||
use Tymon\JWTAuth\Claims\Audience;
|
||||
use Tymon\JWTAuth\Claims\Subject;
|
||||
use Tymon\JWTAuth\Claims\JwtId;
|
||||
use Tymon\JWTAuth\Claims\Custom;
|
||||
|
||||
class BlacklistTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
Carbon::setTestNow(Carbon::createFromTimeStampUTC(123));
|
||||
|
||||
$this->storage = Mockery::mock('Tymon\JWTAuth\Providers\Storage\StorageInterface');
|
||||
$this->blacklist = new Blacklist($this->storage);
|
||||
$this->blacklist->setRefreshTTL(20160);
|
||||
|
||||
$this->validator = Mockery::mock('Tymon\JWTAuth\Validators\PayloadValidator');
|
||||
$this->validator->shouldReceive('setRefreshFlow->check');
|
||||
@@ -36,27 +47,44 @@ class BlacklistTest extends \PHPUnit_Framework_TestCase
|
||||
$claims = [
|
||||
new Subject(1),
|
||||
new Issuer('http://example.com'),
|
||||
new Expiration(123 + 3600),
|
||||
new NotBefore(123),
|
||||
new IssuedAt(123),
|
||||
new JwtId('foo')
|
||||
new Expiration(100 + 3600),
|
||||
new NotBefore(100),
|
||||
new IssuedAt(100),
|
||||
new JwtId('foo'),
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator);
|
||||
|
||||
$this->storage->shouldReceive('add')->with('foo', [], 61);
|
||||
$this->blacklist->add($payload);
|
||||
$this->storage->shouldReceive('add')->once()->with('foo', [], 20160);
|
||||
$this->assertTrue($this->blacklist->add($payload));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_false_when_adding_an_expired_token_to_the_blacklist()
|
||||
public function it_should_return_true_when_adding_a_refreshable_expired_token_to_the_blacklist()
|
||||
{
|
||||
$claims = [
|
||||
new Subject(1),
|
||||
new Issuer('http://example.com'),
|
||||
new Expiration(123 - 3600),
|
||||
new NotBefore(123),
|
||||
new IssuedAt(123),
|
||||
new JwtId('foo')
|
||||
new Expiration(101),
|
||||
new NotBefore(100),
|
||||
new IssuedAt(100),
|
||||
new JwtId('foo'),
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator, true);
|
||||
|
||||
$this->storage->shouldReceive('add')->once()->with('foo', [], 20160);
|
||||
$this->assertTrue($this->blacklist->add($payload));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_false_when_adding_an_unrefreshable_token_to_the_blacklist()
|
||||
{
|
||||
$claims = [
|
||||
new Subject(1),
|
||||
new Issuer('http://example.com'),
|
||||
new Expiration(100), // default refresh_ttl
|
||||
new NotBefore(100),
|
||||
new IssuedAt(100 - 20160 * 60),
|
||||
new JwtId('foo'),
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator, true);
|
||||
|
||||
@@ -64,6 +92,24 @@ class BlacklistTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($this->blacklist->add($payload));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_false_when_adding_a_unrefreshable_token_after_modifying_refresh_ttl()
|
||||
{
|
||||
$claims = [
|
||||
new Subject(1),
|
||||
new Issuer('http://example.com'),
|
||||
new Expiration(101),
|
||||
new NotBefore(100),
|
||||
new IssuedAt(100),
|
||||
new JwtId('foo'),
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator, true);
|
||||
|
||||
$this->storage->shouldReceive('add')->never();
|
||||
$this->blacklist->setRefreshTTL(0);
|
||||
$this->assertFalse($this->blacklist->add($payload));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_check_whether_a_token_has_been_blacklisted()
|
||||
{
|
||||
@@ -73,11 +119,11 @@ class BlacklistTest extends \PHPUnit_Framework_TestCase
|
||||
new Expiration(123 + 3600),
|
||||
new NotBefore(123),
|
||||
new IssuedAt(123),
|
||||
new JwtId('foobar')
|
||||
new JwtId('foobar'),
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator);
|
||||
|
||||
$this->storage->shouldReceive('has')->with('foobar')->andReturn(true);
|
||||
$this->storage->shouldReceive('has')->once()->with('foobar')->andReturn(true);
|
||||
$this->assertTrue($this->blacklist->has($payload));
|
||||
}
|
||||
|
||||
@@ -90,18 +136,18 @@ class BlacklistTest extends \PHPUnit_Framework_TestCase
|
||||
new Expiration(123 + 3600),
|
||||
new NotBefore(123),
|
||||
new IssuedAt(123),
|
||||
new JwtId('foobar')
|
||||
new JwtId('foobar'),
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator);
|
||||
|
||||
$this->storage->shouldReceive('destroy')->with('foobar')->andReturn(true);
|
||||
$this->storage->shouldReceive('destroy')->once()->with('foobar')->andReturn(true);
|
||||
$this->assertTrue($this->blacklist->remove($payload));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_empty_the_blacklist()
|
||||
{
|
||||
$this->storage->shouldReceive('flush');
|
||||
$this->storage->shouldReceive('flush')->once();
|
||||
$this->assertTrue($this->blacklist->clear());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user