Update v1.0.6
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user