Update v1.0.6
This commit is contained in:
107
vendor/tymon/jwt-auth/tests/BlacklistTest.php
vendored
Normal file
107
vendor/tymon/jwt-auth/tests/BlacklistTest.php
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test\Providers\JWT;
|
||||
|
||||
use Mockery;
|
||||
use Tymon\JWTAuth\Blacklist;
|
||||
use Tymon\JWTAuth\Payload;
|
||||
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()
|
||||
{
|
||||
$this->storage = Mockery::mock('Tymon\JWTAuth\Providers\Storage\StorageInterface');
|
||||
$this->blacklist = new Blacklist($this->storage);
|
||||
|
||||
$this->validator = Mockery::mock('Tymon\JWTAuth\Validators\PayloadValidator');
|
||||
$this->validator->shouldReceive('setRefreshFlow->check');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_add_a_valid_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')
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator);
|
||||
|
||||
$this->storage->shouldReceive('add')->with('foo', [], 61);
|
||||
$this->blacklist->add($payload);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_false_when_adding_an_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')
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator, true);
|
||||
|
||||
$this->storage->shouldReceive('add')->never();
|
||||
$this->assertFalse($this->blacklist->add($payload));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_check_whether_a_token_has_been_blacklisted()
|
||||
{
|
||||
$claims = [
|
||||
new Subject(1),
|
||||
new Issuer('http://example.com'),
|
||||
new Expiration(123 + 3600),
|
||||
new NotBefore(123),
|
||||
new IssuedAt(123),
|
||||
new JwtId('foobar')
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator);
|
||||
|
||||
$this->storage->shouldReceive('has')->with('foobar')->andReturn(true);
|
||||
$this->assertTrue($this->blacklist->has($payload));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_remove_a_token_from_the_blacklist()
|
||||
{
|
||||
$claims = [
|
||||
new Subject(1),
|
||||
new Issuer('http://example.com'),
|
||||
new Expiration(123 + 3600),
|
||||
new NotBefore(123),
|
||||
new IssuedAt(123),
|
||||
new JwtId('foobar')
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator);
|
||||
|
||||
$this->storage->shouldReceive('destroy')->with('foobar')->andReturn(true);
|
||||
$this->assertTrue($this->blacklist->remove($payload));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_empty_the_blacklist()
|
||||
{
|
||||
$this->storage->shouldReceive('flush');
|
||||
$this->assertTrue($this->blacklist->clear());
|
||||
}
|
||||
}
|
36
vendor/tymon/jwt-auth/tests/Commands/JWTGenerateCommandTest.php
vendored
Normal file
36
vendor/tymon/jwt-auth/tests/Commands/JWTGenerateCommandTest.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test;
|
||||
|
||||
use Mockery;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Tymon\JWTAuth\Commands\JWTGenerateCommand;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
|
||||
class JWTGenerateCommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->command = new JWTGenerateCommand();
|
||||
$this->tester = new CommandTester($this->command);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_shoud_generate_random_key()
|
||||
{
|
||||
// $app = new Application();
|
||||
|
||||
// $app['path.base'] = '';
|
||||
|
||||
// $this->command->setLaravel($app);
|
||||
|
||||
// $this->runCommand($this->command);
|
||||
}
|
||||
|
||||
protected function runCommand($command, $input = array())
|
||||
{
|
||||
return $command->run(new ArrayInput($input), new NullOutput);
|
||||
}
|
||||
}
|
226
vendor/tymon/jwt-auth/tests/JWTAuthTest.php
vendored
Normal file
226
vendor/tymon/jwt-auth/tests/JWTAuthTest.php
vendored
Normal file
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test;
|
||||
|
||||
use Mockery;
|
||||
use Tymon\JWTAuth\JWTAuth;
|
||||
use Illuminate\Http\Request;
|
||||
use Tymon\JWTAuth\Token;
|
||||
|
||||
class JWTAuthTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->user = Mockery::mock('Tymon\JWTAuth\Providers\User\UserInterface');
|
||||
$this->manager = Mockery::mock('Tymon\JWTAuth\JWTManager');
|
||||
$this->auth = Mockery::mock('Tymon\JWTAuth\Providers\Auth\AuthInterface');
|
||||
|
||||
$this->jwtAuth = new JWTAuth($this->manager, $this->user, $this->auth, Request::create('/foo', 'GET'));
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_a_user_when_passing_a_token_containing_a_valid_subject_claim()
|
||||
{
|
||||
$payload = Mockery::mock('Tymon\JWTAuth\Payload');
|
||||
$payload->shouldReceive('offsetGet')->once()->andReturn(1);
|
||||
|
||||
$this->manager->shouldReceive('decode')->once()->andReturn($payload);
|
||||
$this->user->shouldReceive('getBy')->once()->andReturn((object) ['id' => 1]);
|
||||
|
||||
$user = $this->jwtAuth->toUser('foo.bar.baz');
|
||||
|
||||
$this->assertEquals(1, $user->id);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_false_when_passing_a_token_containing_an_invalid_subject_claim()
|
||||
{
|
||||
$payload = Mockery::mock('Tymon\JWTAuth\Payload');
|
||||
$payload->shouldReceive('offsetGet')->once()->andReturn(1);
|
||||
|
||||
$this->manager->shouldReceive('decode')->once()->andReturn($payload);
|
||||
$this->user->shouldReceive('getBy')->once()->andReturn(false);
|
||||
|
||||
$user = $this->jwtAuth->toUser('foo.bar.baz');
|
||||
|
||||
$this->assertFalse($user);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_a_token_when_passing_a_user()
|
||||
{
|
||||
$this->manager->shouldReceive('getPayloadFactory->make')->once()->andReturn(Mockery::mock('Tymon\JWTAuth\Payload'));
|
||||
$this->manager->shouldReceive('encode->get')->once()->andReturn('foo.bar.baz');
|
||||
|
||||
$token = $this->jwtAuth->fromUser((object) ['id' => 1]);
|
||||
|
||||
$this->assertEquals($token, 'foo.bar.baz');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_a_token_when_passing_valid_credentials_to_attempt_method()
|
||||
{
|
||||
$this->manager->shouldReceive('getPayloadFactory->make')->once()->andReturn(Mockery::mock('Tymon\JWTAuth\Payload'));
|
||||
$this->manager->shouldReceive('encode->get')->once()->andReturn('foo.bar.baz');
|
||||
|
||||
$this->auth->shouldReceive('byCredentials')->once()->andReturn(true);
|
||||
$this->auth->shouldReceive('user')->once()->andReturn((object) ['id' => 1]);
|
||||
|
||||
$token = $this->jwtAuth->attempt();
|
||||
|
||||
$this->assertEquals($token, 'foo.bar.baz');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_false_when_passing_invalid_credentials_to_attempt_method()
|
||||
{
|
||||
$this->manager->shouldReceive('encode->get')->never();
|
||||
$this->auth->shouldReceive('byCredentials')->once()->andReturn(false);
|
||||
$this->auth->shouldReceive('user')->never();
|
||||
|
||||
$token = $this->jwtAuth->attempt();
|
||||
|
||||
$this->assertFalse($token);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_an_exception_when_not_providing_a_token()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\JWTException');
|
||||
|
||||
$user = $this->jwtAuth->toUser();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_the_owning_user_from_a_token_containing_an_existing_user()
|
||||
{
|
||||
$payload = Mockery::mock('Tymon\JWTAuth\Payload');
|
||||
$payload->shouldReceive('get')->once()->with('sub')->andReturn(1);
|
||||
|
||||
$this->manager->shouldReceive('decode')->once()->andReturn($payload);
|
||||
|
||||
$this->auth->shouldReceive('byId')->once()->with(1)->andReturn(true);
|
||||
$this->auth->shouldReceive('user')->once()->andReturn((object) ['id' => 1]);
|
||||
|
||||
$user = $this->jwtAuth->authenticate('foo.bar.baz');
|
||||
|
||||
$this->assertEquals($user->id, 1);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_false_when_passing_a_token_not_containing_an_existing_user()
|
||||
{
|
||||
$payload = Mockery::mock('Tymon\JWTAuth\Payload');
|
||||
$payload->shouldReceive('get')->once()->with('sub')->andReturn(1);
|
||||
|
||||
$this->manager->shouldReceive('decode')->once()->andReturn($payload);
|
||||
|
||||
$this->auth->shouldReceive('byId')->once()->with(1)->andReturn(false);
|
||||
$this->auth->shouldReceive('user')->never();
|
||||
|
||||
$user = $this->jwtAuth->authenticate('foo.bar.baz');
|
||||
|
||||
$this->assertFalse($user);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_refresh_a_token()
|
||||
{
|
||||
$newToken = Mockery::mock('Tymon\JWTAuth\Token');
|
||||
$newToken->shouldReceive('get')->once()->andReturn('baz.bar.foo');
|
||||
|
||||
$this->manager->shouldReceive('refresh')->once()->andReturn($newToken);
|
||||
|
||||
$result = $this->jwtAuth->setToken('foo.bar.baz')->refresh();
|
||||
|
||||
$this->assertEquals($result, 'baz.bar.foo');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_invalidate_a_token()
|
||||
{
|
||||
$this->manager->shouldReceive('invalidate')->once()->andReturn(true);
|
||||
|
||||
$result = $this->jwtAuth->invalidate('foo.bar.baz');
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_retrieve_the_token_from_the_auth_header()
|
||||
{
|
||||
$request = Request::create('/foo', 'GET');
|
||||
$request->headers->set('authorization', 'Bearer foo.bar.baz');
|
||||
$jwtAuth = new JWTAuth($this->manager, $this->user, $this->auth, $request);
|
||||
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\Token', $jwtAuth->parseToken()->getToken());
|
||||
$this->assertEquals($jwtAuth->getToken(), 'foo.bar.baz');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_retrieve_the_token_from_the_query_string()
|
||||
{
|
||||
$request = Request::create('/foo', 'GET', ['token' => 'foo.bar.baz']);
|
||||
$jwtAuth = new JWTAuth($this->manager, $this->user, $this->auth, $request);
|
||||
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\Token', $jwtAuth->parseToken()->getToken());
|
||||
$this->assertEquals($jwtAuth->getToken(), 'foo.bar.baz');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_an_exception_when_token_not_present_in_request()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\JWTException');
|
||||
|
||||
$request = Request::create('/foo', 'GET');
|
||||
$jwtAuth = new JWTAuth($this->manager, $this->user, $this->auth, $request);
|
||||
|
||||
$jwtAuth->parseToken();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_false_when_no_token_is_set()
|
||||
{
|
||||
$this->assertFalse($this->jwtAuth->getToken());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_set_the_identifier()
|
||||
{
|
||||
$this->jwtAuth->setIdentifier('foo');
|
||||
|
||||
$this->assertEquals($this->jwtAuth->getIdentifier(), 'foo');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_magically_call_the_manager()
|
||||
{
|
||||
$this->manager->shouldReceive('getBlacklist')->andReturn(new \StdClass);
|
||||
|
||||
$blacklist = $this->jwtAuth->getBlacklist();
|
||||
|
||||
$this->assertInstanceOf('StdClass', $blacklist);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_set_the_request()
|
||||
{
|
||||
$request = Request::create('/foo', 'GET', ['token' => 'some.random.token']);
|
||||
|
||||
$token = $this->jwtAuth->setRequest($request)->getToken();
|
||||
|
||||
$this->assertEquals('some.random.token', $token);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_get_the_manager_instance()
|
||||
{
|
||||
$manager = $this->jwtAuth->manager();
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\JWTManager', $manager);
|
||||
}
|
||||
}
|
181
vendor/tymon/jwt-auth/tests/JWTManagerTest.php
vendored
Normal file
181
vendor/tymon/jwt-auth/tests/JWTManagerTest.php
vendored
Normal file
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test\Providers\JWT;
|
||||
|
||||
use Mockery;
|
||||
use Tymon\JWTAuth\JWTManager;
|
||||
use Tymon\JWTAuth\Payload;
|
||||
use Tymon\JWTAuth\Token;
|
||||
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 JWTManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->jwt = Mockery::mock('Tymon\JWTAuth\Providers\JWT\JWTInterface');
|
||||
$this->blacklist = Mockery::mock('Tymon\JWTAuth\Blacklist');
|
||||
$this->factory = Mockery::mock('Tymon\JWTAuth\PayloadFactory');
|
||||
$this->manager = new JWTManager($this->jwt, $this->blacklist, $this->factory);
|
||||
|
||||
$this->validator = Mockery::mock('Tymon\JWTAuth\Validators\PayloadValidator');
|
||||
$this->validator->shouldReceive('setRefreshFlow->check');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_encode_a_payload()
|
||||
{
|
||||
$claims = [
|
||||
new Subject(1),
|
||||
new Issuer('http://example.com'),
|
||||
new Expiration(123 + 3600),
|
||||
new NotBefore(123),
|
||||
new IssuedAt(123),
|
||||
new JwtId('foo')
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator);
|
||||
|
||||
$this->jwt->shouldReceive('encode')->with($payload->toArray())->andReturn('foo.bar.baz');
|
||||
|
||||
$token = $this->manager->encode($payload);
|
||||
|
||||
$this->assertEquals($token, 'foo.bar.baz');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_decode_a_token()
|
||||
{
|
||||
$claims = [
|
||||
new Subject(1),
|
||||
new Issuer('http://example.com'),
|
||||
new Expiration(123 + 3600),
|
||||
new NotBefore(123),
|
||||
new IssuedAt(123),
|
||||
new JwtId('foo')
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator);
|
||||
$token = new Token('foo.bar.baz');
|
||||
|
||||
$this->jwt->shouldReceive('decode')->once()->with('foo.bar.baz')->andReturn($payload->toArray());
|
||||
$this->factory->shouldReceive('setRefreshFlow->make')->with($payload->toArray())->andReturn($payload);
|
||||
$this->blacklist->shouldReceive('has')->with($payload)->andReturn(false);
|
||||
|
||||
$payload = $this->manager->decode($token);
|
||||
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\Payload', $payload);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_exception_when_token_is_blacklisted()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\TokenBlacklistedException');
|
||||
|
||||
$claims = [
|
||||
new Subject(1),
|
||||
new Issuer('http://example.com'),
|
||||
new Expiration(123 + 3600),
|
||||
new NotBefore(123),
|
||||
new IssuedAt(123),
|
||||
new JwtId('foo')
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator);
|
||||
$token = new Token('foo.bar.baz');
|
||||
|
||||
$this->jwt->shouldReceive('decode')->once()->with('foo.bar.baz')->andReturn($payload->toArray());
|
||||
$this->factory->shouldReceive('setRefreshFlow->make')->with($payload->toArray())->andReturn($payload);
|
||||
$this->blacklist->shouldReceive('has')->with($payload)->andReturn(true);
|
||||
|
||||
$payload = $this->manager->decode($token);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_refresh_a_token()
|
||||
{
|
||||
$claims = [
|
||||
new Subject(1),
|
||||
new Issuer('http://example.com'),
|
||||
new Expiration(123 - 3600),
|
||||
new NotBefore(123),
|
||||
new IssuedAt(123),
|
||||
new JwtId('foo')
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator, true);
|
||||
$token = new Token('foo.bar.baz');
|
||||
|
||||
$this->jwt->shouldReceive('decode')->once()->with('foo.bar.baz')->andReturn($payload->toArray());
|
||||
$this->jwt->shouldReceive('encode')->with($payload->toArray())->andReturn('baz.bar.foo');
|
||||
|
||||
$this->factory->shouldReceive('setRefreshFlow')->andReturn($this->factory);
|
||||
$this->factory->shouldReceive('make')->andReturn($payload);
|
||||
|
||||
$this->blacklist->shouldReceive('has')->with($payload)->andReturn(false);
|
||||
$this->blacklist->shouldReceive('add')->once()->with($payload);
|
||||
|
||||
$token = $this->manager->refresh($token);
|
||||
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\Token', $token);
|
||||
$this->assertEquals('baz.bar.foo', $token);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_invalidate_a_token()
|
||||
{
|
||||
$claims = [
|
||||
new Subject(1),
|
||||
new Issuer('http://example.com'),
|
||||
new Expiration(123 + 3600),
|
||||
new NotBefore(123),
|
||||
new IssuedAt(123),
|
||||
new JwtId('foo')
|
||||
];
|
||||
$payload = new Payload($claims, $this->validator);
|
||||
$token = new Token('foo.bar.baz');
|
||||
|
||||
$this->jwt->shouldReceive('decode')->once()->with('foo.bar.baz')->andReturn($payload->toArray());
|
||||
$this->factory->shouldReceive('setRefreshFlow->make')->with($payload->toArray())->andReturn($payload);
|
||||
$this->blacklist->shouldReceive('has')->with($payload)->andReturn(false);
|
||||
|
||||
$this->blacklist->shouldReceive('add')->with($payload)->andReturn(true);
|
||||
|
||||
$this->manager->invalidate($token);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_an_exception_when_enable_blacklist_is_set_to_false()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\JWTException');
|
||||
|
||||
$token = new Token('foo.bar.baz');
|
||||
|
||||
$this->manager->setBlacklistEnabled(false)->invalidate($token);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_get_the_payload_factory()
|
||||
{
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\PayloadFactory', $this->manager->getPayloadFactory());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_get_the_jwt_provider()
|
||||
{
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\Providers\JWT\JWTInterface', $this->manager->getJWTProvider());
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_get_the_blacklist()
|
||||
{
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\Blacklist', $this->manager->getBlacklist());
|
||||
}
|
||||
}
|
94
vendor/tymon/jwt-auth/tests/Middleware/GetUserFromTokenTest.php
vendored
Normal file
94
vendor/tymon/jwt-auth/tests/Middleware/GetUserFromTokenTest.php
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test;
|
||||
|
||||
use Mockery;
|
||||
use Tymon\JWTAuth\Middleware\GetUserFromToken;
|
||||
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
|
||||
use Tymon\JWTAuth\Exceptions\TokenInvalidException;
|
||||
|
||||
class GetUserFromTokenTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->events = Mockery::mock('Illuminate\Events\Dispatcher');
|
||||
$this->auth = Mockery::mock('Tymon\JWTAuth\JWTAuth');
|
||||
|
||||
$this->request = Mockery::mock('Illuminate\Http\Request');
|
||||
$this->response = Mockery::mock('Illuminate\Routing\ResponseFactory');
|
||||
|
||||
$this->middleware = new GetUserFromToken($this->response, $this->events, $this->auth);
|
||||
|
||||
$this->auth->shouldReceive('setRequest')->once()->with($this->request)->andReturn($this->auth);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_fire_an_event_when_no_token_is_available()
|
||||
{
|
||||
$this->auth->shouldReceive('getToken')->once()->andReturn(false);
|
||||
|
||||
$this->events->shouldReceive('fire')->once()->with('tymon.jwt.absent', [], true);
|
||||
$this->response->shouldReceive('json')->with(['error' => 'token_not_provided'], 400);
|
||||
|
||||
$this->middleware->handle($this->request, function () {});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_fire_an_event_when_the_token_has_expired()
|
||||
{
|
||||
$exception = new TokenExpiredException;
|
||||
|
||||
$this->auth->shouldReceive('getToken')->once()->andReturn('foo');
|
||||
$this->auth->shouldReceive('authenticate')->once()->with('foo')->andThrow($exception);
|
||||
|
||||
$this->events->shouldReceive('fire')->once()->with('tymon.jwt.expired', [$exception], true);
|
||||
$this->response->shouldReceive('json')->with(['error' => 'token_expired'], 401);
|
||||
|
||||
$this->middleware->handle($this->request, function () {});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_fire_an_event_when_the_token_is_invalid()
|
||||
{
|
||||
$exception = new TokenInvalidException;
|
||||
|
||||
$this->auth->shouldReceive('getToken')->once()->andReturn('foo');
|
||||
$this->auth->shouldReceive('authenticate')->once()->with('foo')->andThrow($exception);
|
||||
|
||||
$this->events->shouldReceive('fire')->once()->with('tymon.jwt.invalid', [$exception], true);
|
||||
$this->response->shouldReceive('json')->with(['error' => 'token_invalid'], 400);
|
||||
|
||||
$this->middleware->handle($this->request, function () {});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_fire_an_event_when_no_user_is_found()
|
||||
{
|
||||
$this->auth->shouldReceive('getToken')->once()->andReturn('foo');
|
||||
$this->auth->shouldReceive('authenticate')->once()->with('foo')->andReturn(false);
|
||||
|
||||
$this->events->shouldReceive('fire')->once()->with('tymon.jwt.user_not_found', [], true);
|
||||
$this->response->shouldReceive('json')->with(['error' => 'user_not_found'], 404);
|
||||
|
||||
$this->middleware->handle($this->request, function () {});
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_fire_an_event_when_the_token_has_been_decoded_and_user_is_found()
|
||||
{
|
||||
$user = (object) ['id' => 1];
|
||||
|
||||
$this->auth->shouldReceive('getToken')->once()->andReturn('foo');
|
||||
$this->auth->shouldReceive('authenticate')->once()->with('foo')->andReturn($user);
|
||||
|
||||
$this->events->shouldReceive('fire')->once()->with('tymon.jwt.valid', $user);
|
||||
$this->response->shouldReceive('json')->never();
|
||||
|
||||
$this->middleware->handle($this->request, function () {});
|
||||
}
|
||||
}
|
105
vendor/tymon/jwt-auth/tests/PayloadFactoryTest.php
vendored
Normal file
105
vendor/tymon/jwt-auth/tests/PayloadFactoryTest.php
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test\Providers\JWT;
|
||||
|
||||
use Mockery;
|
||||
use Tymon\JWTAuth\Payload;
|
||||
use Tymon\JWTAuth\PayloadFactory;
|
||||
use Illuminate\Http\Request;
|
||||
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 PayloadFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->claimFactory = Mockery::mock('Tymon\JWTAuth\Claims\Factory');
|
||||
$this->validator = Mockery::mock('Tymon\JWTAuth\Validators\PayloadValidator');
|
||||
$this->factory = new PayloadFactory($this->claimFactory, Request::create('/foo', 'GET'), $this->validator);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_a_payload_when_passing_an_array_of_claims_to_make_method()
|
||||
{
|
||||
$this->validator->shouldReceive('setRefreshFlow->check');
|
||||
|
||||
$expTime = time() + 3600;
|
||||
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('sub', 1)->andReturn(new Subject(1));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('iss', Mockery::any())->andReturn(new Issuer('/foo'));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('iat', 123)->andReturn(new IssuedAt(123));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('jti', 'foo')->andReturn(new JwtId('foo'));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('nbf', time())->andReturn(new NotBefore(time()));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('exp', $expTime)->andReturn(new Expiration($expTime));
|
||||
|
||||
$payload = $this->factory->make(['sub' => 1, 'jti' => 'foo', 'iat' => 123]);
|
||||
|
||||
$this->assertEquals($payload->get('sub'), 1);
|
||||
$this->assertEquals($payload->get('iat'), 123);
|
||||
$this->assertEquals($payload['exp'], $expTime);
|
||||
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\Payload', $payload);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_a_payload_when_chaining_claim_methods()
|
||||
{
|
||||
$this->validator->shouldReceive('setRefreshFlow->check');
|
||||
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('sub', 1)->andReturn(new Subject(1));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('iss', Mockery::any())->andReturn(new Issuer('/foo'));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('exp', time() + 3600)->andReturn(new Expiration(time() + 3600));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('iat', time())->andReturn(new IssuedAt(time()));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('jti', Mockery::any())->andReturn(new JwtId('foo'));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('nbf', time())->andReturn(new NotBefore(time()));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('foo', 'baz')->andReturn(new Custom('foo', 'baz'));
|
||||
|
||||
$payload = $this->factory->sub(1)->foo('baz')->make();
|
||||
|
||||
$this->assertEquals($payload['sub'], 1);
|
||||
$this->assertEquals($payload->get('jti'), 'foo');
|
||||
$this->assertEquals($payload->get('foo'), 'baz');
|
||||
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\Payload', $payload);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_a_payload_when_passing_miltidimensional_array_as_custom_claim_to_make_method()
|
||||
{
|
||||
$this->validator->shouldReceive('setRefreshFlow->check');
|
||||
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('sub', 1)->andReturn(new Subject(1));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('iss', Mockery::any())->andReturn(new Issuer('/foo'));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('exp', Mockery::any())->andReturn(new Expiration(time() + 3600));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('iat', Mockery::any())->andReturn(new IssuedAt(time()));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('jti', Mockery::any())->andReturn(new JwtId('foo'));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('nbf', Mockery::any())->andReturn(new NotBefore(time()));
|
||||
$this->claimFactory->shouldReceive('get')->once()->with('foo', ['bar' => [0, 0, 0]])->andReturn(new Custom('foo', ['bar' => [0, 0, 0]]));
|
||||
|
||||
$payload = $this->factory->sub(1)->foo(['bar' => [0, 0, 0]])->make();
|
||||
|
||||
$this->assertEquals($payload->get('sub'), 1);
|
||||
$this->assertEquals($payload->get('foo'), ['bar' => [0, 0, 0]]);
|
||||
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\Payload', $payload);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_set_the_ttl()
|
||||
{
|
||||
$this->factory->setTTL(12345);
|
||||
|
||||
$this->assertEquals($this->factory->getTTL(), 12345);
|
||||
}
|
||||
}
|
127
vendor/tymon/jwt-auth/tests/PayloadTest.php
vendored
Normal file
127
vendor/tymon/jwt-auth/tests/PayloadTest.php
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test\Providers\JWT;
|
||||
|
||||
use Tymon\JWTAuth\Providers\JWT\FirebaseAdapter;
|
||||
use Tymon\JWTAuth\Payload;
|
||||
use Tymon\JWTAuth\PayloadFactory;
|
||||
use Mockery;
|
||||
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 PayloadTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$claims = [
|
||||
new Subject(1),
|
||||
new Issuer('http://example.com'),
|
||||
new Expiration(time() + 3600),
|
||||
new NotBefore(time()),
|
||||
new IssuedAt(time()),
|
||||
new JwtId('foo')
|
||||
];
|
||||
|
||||
$this->validator = Mockery::mock('Tymon\JWTAuth\Validators\PayloadValidator');
|
||||
$this->validator->shouldReceive('setRefreshFlow->check');
|
||||
|
||||
$this->payload = new Payload($claims, $this->validator);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_when_trying_to_add_to_the_payload()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\PayloadException');
|
||||
|
||||
$this->payload['foo'] = 'bar';
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_when_trying_to_remove_a_key_from_the_payload()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\PayloadException');
|
||||
|
||||
unset($this->payload['foo']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_cast_the_payload_to_a_string_as_json()
|
||||
{
|
||||
$this->assertEquals((string) $this->payload, json_encode($this->payload->get()));
|
||||
$this->assertJsonStringEqualsJsonString((string) $this->payload, json_encode($this->payload->get()));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_allow_array_access_on_the_payload()
|
||||
{
|
||||
$this->assertTrue(isset($this->payload['iat']));
|
||||
$this->assertEquals($this->payload['sub'], 1);
|
||||
$this->assertArrayHasKey('exp', $this->payload);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_get_properties_of_payload_via_get_method()
|
||||
{
|
||||
$this->assertInternalType('array', $this->payload->get());
|
||||
$this->assertEquals($this->payload->get('sub'), 1);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_get_multiple_properties_when_passing_an_array_to_the_get_method()
|
||||
{
|
||||
$values = $this->payload->get(['sub', 'jti']);
|
||||
|
||||
list($sub, $jti) = $values;
|
||||
|
||||
$this->assertInternalType('array', $values);
|
||||
$this->assertEquals($sub, 1);
|
||||
$this->assertEquals($jti, 'foo');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_determine_whether_the_payload_has_a_claim()
|
||||
{
|
||||
$this->assertTrue($this->payload->has(new Subject(1)));
|
||||
$this->assertFalse($this->payload->has(new Audience(1)));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_magically_get_a_property()
|
||||
{
|
||||
$sub = $this->payload->getSubject();
|
||||
$jti = $this->payload->getJwtId();
|
||||
$iss = $this->payload->getIssuer();
|
||||
|
||||
$this->assertEquals($sub, 1);
|
||||
$this->assertEquals($jti, 'foo');
|
||||
$this->assertEquals($iss, 'http://example.com');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_an_exception_when_magically_getting_a_property_that_does_not_exist()
|
||||
{
|
||||
$this->setExpectedException('\BadMethodCallException');
|
||||
|
||||
$this->payload->getFoo();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_get_the_claims()
|
||||
{
|
||||
$claims = $this->payload->getClaims();
|
||||
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\Claims\Expiration', $claims[2]);
|
||||
$this->assertInstanceOf('Tymon\JWTAuth\Claims\JwtId', $claims[5]);
|
||||
}
|
||||
}
|
48
vendor/tymon/jwt-auth/tests/Providers/Auth/IlluminateAuthAdapterTest.php
vendored
Normal file
48
vendor/tymon/jwt-auth/tests/Providers/Auth/IlluminateAuthAdapterTest.php
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test\Providers\Auth;
|
||||
|
||||
use Mockery;
|
||||
use Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter;
|
||||
|
||||
class IlluminateAuthAdapterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->authManager = Mockery::mock('Illuminate\Auth\AuthManager');
|
||||
$this->auth = new IlluminateAuthAdapter($this->authManager);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_true_if_credentials_are_valid()
|
||||
{
|
||||
$this->authManager->shouldReceive('once')->once()->with(['email' => 'foo@bar.com', 'password' => 'foobar'])->andReturn(true);
|
||||
$this->assertTrue($this->auth->byCredentials(['email' => 'foo@bar.com', 'password' => 'foobar']));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_true_if_user_is_found()
|
||||
{
|
||||
$this->authManager->shouldReceive('onceUsingId')->once()->with(123)->andReturn(true);
|
||||
$this->assertTrue($this->auth->byId(123));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_false_if_user_is_not_found()
|
||||
{
|
||||
$this->authManager->shouldReceive('onceUsingId')->once()->with(123)->andThrow(new \Exception);
|
||||
$this->assertFalse($this->auth->byId(123));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_the_currently_authenticated_user()
|
||||
{
|
||||
$this->authManager->shouldReceive('user')->once()->andReturn((object) ['id' => 1]);
|
||||
$this->assertEquals($this->auth->user()->id, 1);
|
||||
}
|
||||
}
|
28
vendor/tymon/jwt-auth/tests/Providers/JWT/JWTProviderTest.php
vendored
Normal file
28
vendor/tymon/jwt-auth/tests/Providers/JWT/JWTProviderTest.php
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test\Providers\JWT;
|
||||
|
||||
use Mockery;
|
||||
use Illuminate\Http\Request;
|
||||
use Tymon\JWTAuth\Test\Stubs\JWTProviderStub;
|
||||
|
||||
class JWTProviderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->provider = new JWTProviderStub('secret', 'HS256');
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_set_the_algo()
|
||||
{
|
||||
$this->provider->setAlgo('HS512');
|
||||
|
||||
$this->assertEquals('HS512', $this->provider->getAlgo());
|
||||
}
|
||||
}
|
66
vendor/tymon/jwt-auth/tests/Providers/JWT/NamshiAdapterTest.php
vendored
Normal file
66
vendor/tymon/jwt-auth/tests/Providers/JWT/NamshiAdapterTest.php
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test\Providers\JWT;
|
||||
|
||||
use Mockery;
|
||||
use Illuminate\Http\Request;
|
||||
use Tymon\JWTAuth\Providers\JWT\NamshiAdapter;
|
||||
|
||||
class NamshiAdapterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->jws = Mockery::mock('Namshi\JOSE\JWS');
|
||||
$this->provider = new NamshiAdapter('secret', 'HS256', $this->jws);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_the_token_when_passing_a_valid_subject_to_encode()
|
||||
{
|
||||
$payload = ['sub' => 1, 'exp' => time(), 'iat' => time(), 'iss' => '/foo'];
|
||||
|
||||
$this->jws->shouldReceive('setPayload')->once()->with($payload)->andReturn(Mockery::self());
|
||||
$this->jws->shouldReceive('sign')->once()->with('secret')->andReturn(Mockery::self());
|
||||
$this->jws->shouldReceive('getTokenString')->once()->andReturn('foo.bar.baz');
|
||||
|
||||
$token = $this->provider->encode($payload);
|
||||
|
||||
$this->assertEquals('foo.bar.baz', $token);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_an_invalid_exception_when_the_payload_could_not_be_encoded()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\JWTException');
|
||||
|
||||
$this->jws->shouldReceive('sign')->andThrow(new \Exception);
|
||||
|
||||
$payload = ['sub' => 1, 'exp' => time(), 'iat' => time(), 'iss' => '/foo'];
|
||||
$token = $this->provider->encode($payload);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
// public function it_should_return_the_payload_when_passing_a_valid_token_to_decode()
|
||||
// {
|
||||
// $this->jws->shouldReceive('load')->once()->with('foo.bar.baz')->andReturn(true);
|
||||
// $this->jws->shouldReceive('verify')->andReturn(true);
|
||||
|
||||
// $payload = $this->provider->decode('foo.bar.baz');
|
||||
|
||||
// }
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_a_token_invalid_exception_when_the_token_could_not_be_decoded()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\TokenInvalidException');
|
||||
|
||||
$this->jws->shouldReceive('verify')->andReturn(false);
|
||||
|
||||
$token = $this->provider->decode('foo');
|
||||
}
|
||||
}
|
54
vendor/tymon/jwt-auth/tests/Providers/Storage/IlluminateCacheAdapterTest.php
vendored
Normal file
54
vendor/tymon/jwt-auth/tests/Providers/Storage/IlluminateCacheAdapterTest.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test\Providers\Storage;
|
||||
|
||||
use Mockery;
|
||||
use Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter;
|
||||
|
||||
class IlluminateCacheAdapterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->cache = Mockery::mock('Illuminate\Cache\CacheManager');
|
||||
$this->storage = new IlluminateCacheAdapter($this->cache);
|
||||
|
||||
$this->cache->shouldReceive('tags')->andReturn(Mockery::self());
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_add_the_item_to_storage()
|
||||
{
|
||||
$this->cache->shouldReceive('tags->put')->with('foo', 'bar', 10);
|
||||
|
||||
$this->storage->add('foo', 'bar', 10);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_check_if_the_item_exists_in_storage()
|
||||
{
|
||||
$this->cache->shouldReceive('tags->has')->with('foo')->andReturn(true);
|
||||
|
||||
$this->assertTrue($this->storage->has('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_remove_the_item_from_storage()
|
||||
{
|
||||
$this->cache->shouldReceive('tags->forget')->with('foo')->andReturn(true);
|
||||
|
||||
$this->assertTrue($this->storage->destroy('foo'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_remove_all_items_from_storage()
|
||||
{
|
||||
$this->cache->shouldReceive('tags->flush')->withNoArgs();
|
||||
|
||||
$this->storage->flush();
|
||||
}
|
||||
}
|
32
vendor/tymon/jwt-auth/tests/Providers/User/EloquentUserAdapterTest.php
vendored
Normal file
32
vendor/tymon/jwt-auth/tests/Providers/User/EloquentUserAdapterTest.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test\Providers\User;
|
||||
|
||||
use Mockery;
|
||||
use Tymon\JWTAuth\Providers\User\EloquentUserAdapter;
|
||||
|
||||
class EloquentUserAdapterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->builder = Mockery::mock('Illuminate\Database\Query\Builder');
|
||||
$this->model = Mockery::mock('Illuminate\Database\Eloquent\Model');
|
||||
$this->user = new EloquentUserAdapter($this->model);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_the_user_if_found()
|
||||
{
|
||||
$this->builder->shouldReceive('first')->once()->withNoArgs()->andReturn((object) ['id' => 1]);
|
||||
$this->model->shouldReceive('where')->once()->with('foo', 'bar')->andReturn($this->builder);
|
||||
|
||||
$user = $this->user->getBy('foo', 'bar');
|
||||
|
||||
$this->assertEquals(1, $user->id);
|
||||
}
|
||||
}
|
9
vendor/tymon/jwt-auth/tests/Stubs/JWTProviderStub.php
vendored
Normal file
9
vendor/tymon/jwt-auth/tests/Stubs/JWTProviderStub.php
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test\Stubs;
|
||||
|
||||
use Tymon\JWTAuth\Providers\JWT\JWTProvider;
|
||||
|
||||
class JWTProviderStub extends JWTProvider
|
||||
{
|
||||
}
|
25
vendor/tymon/jwt-auth/tests/TokenTest.php
vendored
Normal file
25
vendor/tymon/jwt-auth/tests/TokenTest.php
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test\Providers\JWT;
|
||||
|
||||
use Tymon\JWTAuth\Token;
|
||||
|
||||
class TokenTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->token = new Token('foo.bar.baz');
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_the_token_when_casting_to_a_string()
|
||||
{
|
||||
$this->assertEquals((string) $this->token, $this->token);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_the_token_when_calling_get_method()
|
||||
{
|
||||
$this->assertInternalType('string', $this->token->get());
|
||||
}
|
||||
}
|
109
vendor/tymon/jwt-auth/tests/Validators/PayloadValidatorTest.php
vendored
Normal file
109
vendor/tymon/jwt-auth/tests/Validators/PayloadValidatorTest.php
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test;
|
||||
|
||||
use Mockery;
|
||||
use Tymon\JWTAuth\Validators\PayloadValidator;
|
||||
|
||||
class PayloadValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->validator = new PayloadValidator();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_true_when_providing_a_valid_payload()
|
||||
{
|
||||
$payload = [
|
||||
'iss' => 'http://example.com',
|
||||
'iat' => time(),
|
||||
'nbf' => time(),
|
||||
'exp' => time() + 3600,
|
||||
'sub' => 1,
|
||||
'jti' => 'foo'
|
||||
];
|
||||
|
||||
$this->assertTrue($this->validator->isValid($payload));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_an_exception_when_providing_an_expired_payload()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\TokenExpiredException');
|
||||
|
||||
$payload = [
|
||||
'iss' => 'http://example.com',
|
||||
'iat' => time() - 3660,
|
||||
'nbf' => time() - 3660,
|
||||
'exp' => time() - 1440,
|
||||
'sub' => 1,
|
||||
'jti' => 'foo'
|
||||
];
|
||||
|
||||
$this->validator->check($payload);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_an_exception_when_providing_an_invalid_nbf_claim()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\TokenInvalidException');
|
||||
|
||||
$payload = [
|
||||
'iss' => 'http://example.com',
|
||||
'iat' => time() - 3660,
|
||||
'nbf' => time() + 3660,
|
||||
'exp' => time() + 1440,
|
||||
'sub' => 1,
|
||||
'jti' => 'foo'
|
||||
];
|
||||
|
||||
$this->validator->check($payload);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_an_exception_when_providing_an_invalid_iat_claim()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\TokenInvalidException');
|
||||
|
||||
$payload = [
|
||||
'iss' => 'http://example.com',
|
||||
'iat' => time() + 3660,
|
||||
'nbf' => time() - 3660,
|
||||
'exp' => time() + 1440,
|
||||
'sub' => 1,
|
||||
'jti' => 'foo'
|
||||
];
|
||||
|
||||
$this->validator->check($payload);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_an_exception_when_providing_an_invalid_payload()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\TokenInvalidException');
|
||||
|
||||
$payload = [
|
||||
'iss' => 'http://example.com',
|
||||
'sub' => 1
|
||||
];
|
||||
|
||||
$this->validator->check($payload);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_an_exception_when_providing_an_invalid_expiry()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\TokenInvalidException');
|
||||
|
||||
$payload = [
|
||||
'iss' => 'http://example.com',
|
||||
'iat' => time() - 3660,
|
||||
'exp' => 'foo',
|
||||
'sub' => 1,
|
||||
'jti' => 'foo'
|
||||
];
|
||||
|
||||
$this->validator->check($payload);
|
||||
}
|
||||
}
|
33
vendor/tymon/jwt-auth/tests/Validators/TokenValidatorTest.php
vendored
Normal file
33
vendor/tymon/jwt-auth/tests/Validators/TokenValidatorTest.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Tymon\JWTAuth\Test;
|
||||
|
||||
use Tymon\JWTAuth\Validators\TokenValidator;
|
||||
|
||||
class TokenValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->validator = new TokenValidator();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_true_when_providing_a_well_formed_token()
|
||||
{
|
||||
$this->assertTrue($this->validator->isValid('one.two.three'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_return_false_when_providing_a_malformed_token()
|
||||
{
|
||||
$this->assertFalse($this->validator->isValid('one.two.three.four.five'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_should_throw_an_axception_when_providing_a_malformed_token()
|
||||
{
|
||||
$this->setExpectedException('Tymon\JWTAuth\Exceptions\TokenInvalidException');
|
||||
|
||||
$this->validator->check('one.two.three.four.five');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user