Skip to content

Commit

Permalink
CS Tweaks and Fixes (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr authored Oct 20, 2016
1 parent fd06833 commit e9f5a36
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 21 deletions.
3 changes: 3 additions & 0 deletions DependencyInjection/Security/Factory/JWTFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
/**
* JWTFactory.
*
* @deprecated since 2.0, use the "lexik_jwt_authentication.jwt_token_authenticator" Guard
* authenticator instead
*
* @author Nicolas Cabot <[email protected]>
*/
class JWTFactory implements SecurityFactoryInterface
Expand Down
14 changes: 7 additions & 7 deletions Services/JWSProvider/LcobucciJWSProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
use Lcobucci\JWT\Signer;
use Lcobucci\JWT\Signer\Key;
use Lcobucci\JWT\ValidationData;
use Lexik\Bundle\JWTAuthenticationBundle\Services\KeyLoader\KeyLoaderInterface;
use Lexik\Bundle\JWTAuthenticationBundle\Services\KeyLoader\RawKeyLoader;
use Lexik\Bundle\JWTAuthenticationBundle\Signature\CreatedJWS;
use Lexik\Bundle\JWTAuthenticationBundle\Signature\LoadedJWS;

class LcobucciJWSProvider implements JWSProviderInterface
{
/**
* @var KeyLoaderInterface
* @var RawKeyLoader
*/
private $keyLoader;

Expand All @@ -29,14 +29,14 @@ class LcobucciJWSProvider implements JWSProviderInterface
private $ttl;

/**
* @param KeyLoaderInterface $keyLoader
* @param string $cryptoEngine
* @param string $signatureAlgorithm
* @param int $ttl
* @param RawKeyLoader $keyLoader
* @param string $cryptoEngine
* @param string $signatureAlgorithm
* @param int $ttl
*
* @throws \InvalidArgumentException If the given algorithm|engine is not supported
*/
public function __construct(KeyLoaderInterface $keyLoader, $cryptoEngine, $signatureAlgorithm, $ttl)
public function __construct(RawKeyLoader $keyLoader, $cryptoEngine, $signatureAlgorithm, $ttl)
{
$this->keyLoader = $keyLoader;
$this->signer = $this->getSignerForAlgorithm($signatureAlgorithm);
Expand Down
2 changes: 1 addition & 1 deletion Services/KeyLoader/RawKeyLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class RawKeyLoader extends AbstractKeyLoader
{
/**
* {@inheritdoc}
* @param string $type
*
* @return string
*
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/SubscribedTokenAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function testAccessSecuredRouteWithExpiredToken($fail = true)
$response = $e->getResponse();

if ($response instanceof JWTAuthenticationFailureResponse) {
$e->getResponse()->setMessage('Custom JWT Expired Token message');
$response->setMessage('Custom JWT Expired Token message');
}
});

Expand Down
18 changes: 8 additions & 10 deletions Tests/Services/JWSProvider/AbstractJWSProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ abstract class AbstractJWSProviderTest extends \PHPUnit_Framework_TestCase
';

protected static $providerClass;
protected static $keyLoaderClass;

/**
* Tests to create a signed JWT Token.
Expand All @@ -69,14 +70,14 @@ public function testCreate()
->expects($this->once())
->method('loadKey')
->with('private')
->willReturn(self::$privateKey);
->willReturn(static::$privateKey);
$keyLoaderMock
->expects($this->once())
->method('getPassphrase')
->willReturn('foobar');

$payload = ['username' => 'chalasr'];
$jwsProvider = new self::$providerClass($keyLoaderMock, 'openssl', 'RS384', 3600);
$jwsProvider = new static::$providerClass($keyLoaderMock, 'openssl', 'RS384', 3600);

$this->assertInstanceOf(CreatedJWS::class, $created = $jwsProvider->create($payload));

Expand All @@ -95,9 +96,9 @@ public function testLoad($jwt)
->expects($this->once())
->method('loadKey')
->with('public')
->willReturn(self::$publicKey);
->willReturn(static::$publicKey);

$jwsProvider = new self::$providerClass($keyLoaderMock, 'openssl', 'RS384', 3600);
$jwsProvider = new static::$providerClass($keyLoaderMock, 'openssl', 'RS384', 3600);
$loadedJWS = $jwsProvider->load($jwt);
$this->assertInstanceOf(LoadedJWS::class, $loadedJWS);

Expand All @@ -113,16 +114,13 @@ public function testLoad($jwt)
*/
public function testInvalidsignatureAlgorithm()
{
new self::$providerClass($this->getKeyLoaderMock(), 'openssl', 'wrongAlgorithm', 3600);
new static::$providerClass($this->getKeyLoaderMock(), 'openssl', 'wrongAlgorithm', 3600);
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject
*/
protected function getKeyLoaderMock()
private function getKeyLoaderMock()
{
return $this
->getMockBuilder('Lexik\Bundle\JWTAuthenticationBundle\Services\KeyLoader\KeyLoaderInterface')
->getMockBuilder(static::$keyLoaderClass)
->disableOriginalConstructor()
->getMock();
}
Expand Down
4 changes: 3 additions & 1 deletion Tests/Services/JWSProvider/DefaultJWSProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lexik\Bundle\JWTAuthenticationBundle\Tests\Services\JWSProvider;

use Lexik\Bundle\JWTAuthenticationBundle\Services\JWSProvider\DefaultJWSProvider;
use Lexik\Bundle\JWTAuthenticationBundle\Services\KeyLoader\KeyLoaderInterface;

/**
* Tests the DefaultJWSProvider.
Expand All @@ -13,6 +14,7 @@ final class DefaultJWSProviderTest extends AbstractJWSProviderTest
{
public function __construct()
{
self::$providerClass = DefaultJWSProvider::class;
self::$providerClass = DefaultJWSProvider::class;
self::$keyLoaderClass = KeyLoaderInterface::class;
}
}
4 changes: 3 additions & 1 deletion Tests/Services/JWSProvider/LcobucciJWSProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Lexik\Bundle\JWTAuthenticationBundle\Tests\Services\JWSProvider;

use Lexik\Bundle\JWTAuthenticationBundle\Services\JWSProvider\LcobucciJWSProvider;
use Lexik\Bundle\JWTAuthenticationBundle\Services\KeyLoader\RawKeyLoader;

/**
* Tests the LcobucciJWSProvider.
Expand All @@ -13,6 +14,7 @@ final class LcobucciJWSProviderTest extends AbstractJWSProviderTest
{
public function __construct()
{
self::$providerClass = LcobucciJWSProvider::class;
self::$providerClass = LcobucciJWSProvider::class;
self::$keyLoaderClass = RawKeyLoader::class;
}
}

0 comments on commit e9f5a36

Please sign in to comment.