diff --git a/composer.json b/composer.json index a2ffe14..ecebcfa 100644 --- a/composer.json +++ b/composer.json @@ -12,11 +12,15 @@ "description": "Symfony JWT authentication with support for asymmetric keys and externally loaded secrets", "autoload": { "psr-4": { - "KleijnWeb\\JwtBundle\\Tests\\": "tests/unit", - "KleijnWeb\\JwtBundle\\Tests\\Functional\\": "tests/functional", "KleijnWeb\\JwtBundle\\": "src" } }, + "autoload-dev": { + "psr-4": { + "KleijnWeb\\JwtBundle\\Tests\\": "tests/unit", + "KleijnWeb\\JwtBundle\\Tests\\Functional\\": "tests/functional" + } + }, "require": { "php": "^7.0.0", "symfony/dependency-injection": ">=2.8.7", @@ -30,8 +34,7 @@ "symfony/security-bundle": ">=2.8.7" }, "require-dev": { - "phpunit/phpunit": "^5.2", - "phpunit/phpunit-mock-objects": "^3.1", + "phpunit/phpunit": "^6.5", "symfony/framework-bundle": ">=2.8.7", "symfony/browser-kit": ">=2.8.7", "symfony/form": ">=2.8.7", diff --git a/src/Jwt/JwtKey.php b/src/Jwt/JwtKey.php index 924c8ba..1d1029a 100644 --- a/src/Jwt/JwtKey.php +++ b/src/Jwt/JwtKey.php @@ -91,7 +91,7 @@ public function __construct(array $options) $options = array_merge($defaults, $options); $this->issuer = $options['issuer']; - $this->audience = $options['audience']; + $this->audience = is_array($options['audience']) ? $options['audience'] : [$options['audience']]; $this->type = $options['type']; $this->minIssueTime = $options['minIssueTime']; $this->requiredClaims = $options['require']; diff --git a/tests/functional/App/app/TestKernel.php b/tests/functional/App/app/TestKernel.php index 040b146..18589d1 100644 --- a/tests/functional/App/app/TestKernel.php +++ b/tests/functional/App/app/TestKernel.php @@ -29,6 +29,6 @@ public function registerBundles() */ public function registerContainerConfiguration(LoaderInterface $loader) { - $loader->load(__DIR__ . '/config_' . $this->getEnvironment() .'.yml'); + $loader->load(__DIR__ . '/config_' . $this->getEnvironment() . '.yml'); } } diff --git a/tests/functional/TestCacheSmashingPHPUnitListener.php b/tests/functional/TestCacheSmashingPHPUnitListener.php index 15b9847..b2f9251 100644 --- a/tests/functional/TestCacheSmashingPHPUnitListener.php +++ b/tests/functional/TestCacheSmashingPHPUnitListener.php @@ -8,61 +8,68 @@ namespace KleijnWeb\JwtBundle\Tests\Functional; -use PHPUnit_Framework_Test; -use PHPUnit_Framework_AssertionFailedError; use Exception; -use PHPUnit_Framework_TestSuite; +use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Test; +use PHPUnit\Framework\TestListener; +use PHPUnit\Framework\TestSuite; +use PHPUnit\Framework\Warning; -class TestCacheSmashingPHPUnitListener implements \PHPUnit_Framework_TestListener +class TestCacheSmashingPHPUnitListener implements TestListener { const SUITE_NAME = 'Functional'; - public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) + public function addError(Test $test, Exception $e, $time) { //NOOP } - public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) + public function addFailure(Test $test, AssertionFailedError $e, $time) { //NOOP } - public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) + public function addIncompleteTest(Test $test, Exception $e, $time) { //NOOP } - public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) + public function addRiskyTest(Test $test, Exception $e, $time) { //NOOP } - public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) + public function addSkippedTest(Test $test, Exception $e, $time) { //NOOP } - public function startTest(PHPUnit_Framework_Test $test) + public function addWarning(Test $test, Warning $e, $time) { //NOOP } - public function endTest(PHPUnit_Framework_Test $test, $time) + public function startTest(Test $test) { //NOOP } - public function startTestSuite(PHPUnit_Framework_TestSuite $suite) + public function endTest(Test $test, $time) + { + //NOOP + } + + public function startTestSuite(TestSuite $suite) { $this->smashIfFunctionalSuite($suite); } - public function endTestSuite(PHPUnit_Framework_TestSuite $suite) + public function endTestSuite(TestSuite $suite) { $this->smashIfFunctionalSuite($suite); } - private function smashIfFunctionalSuite(PHPUnit_Framework_TestSuite $suite) + private function smashIfFunctionalSuite(TestSuite $suite) { if ($suite->getName() !== self::SUITE_NAME) { return; diff --git a/tests/unit/Authentication/JwtAuthenticationProviderTest.php b/tests/unit/Authentication/JwtAuthenticationProviderTest.php index e737b69..39bb728 100644 --- a/tests/unit/Authentication/JwtAuthenticationProviderTest.php +++ b/tests/unit/Authentication/JwtAuthenticationProviderTest.php @@ -14,6 +14,7 @@ use KleijnWeb\JwtBundle\Jwt\JwtToken; use KleijnWeb\JwtBundle\User\JwtUserProvider; use KleijnWeb\JwtBundle\User\UnsafeGroupsUserInterface; +use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken; use Symfony\Component\Security\Core\Authentication\Token\PreAuthenticatedToken; use Symfony\Component\Security\Core\Exception\BadCredentialsException; @@ -23,7 +24,7 @@ /** * @author John Kleijn */ -class JwtAuthenticationProviderTest extends \PHPUnit_Framework_TestCase +class JwtAuthenticationProviderTest extends TestCase { const ISSUER = 'http://api.server1.com/oauth2/token'; const SECRET = 'A Pre-Shared Key'; diff --git a/tests/unit/Firewall/JwtAuthenticationListenerTest.php b/tests/unit/Firewall/JwtAuthenticationListenerTest.php index fc7bc2e..9943430 100644 --- a/tests/unit/Firewall/JwtAuthenticationListenerTest.php +++ b/tests/unit/Firewall/JwtAuthenticationListenerTest.php @@ -10,6 +10,7 @@ use KleijnWeb\JwtBundle\Authentication\JwtAuthenticatedToken; use KleijnWeb\JwtBundle\Authentication\JwtAuthenticationToken; use KleijnWeb\JwtBundle\Firewall\JwtAuthenticationListener; +use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; @@ -19,7 +20,7 @@ /** * @author John Kleijn */ -class JwtAuthenticationListenerTest extends \PHPUnit_Framework_TestCase +class JwtAuthenticationListenerTest extends TestCase { /** * @var AuthenticationManagerInterface diff --git a/tests/unit/Jwt/DecoderTest.php b/tests/unit/Jwt/DecoderTest.php index 6a5ba46..5c0d14a 100644 --- a/tests/unit/Jwt/DecoderTest.php +++ b/tests/unit/Jwt/DecoderTest.php @@ -8,11 +8,12 @@ namespace KleijnWeb\JwtBundle\Tests\Jwt; use KleijnWeb\JwtBundle\Jwt\Decoder; +use PHPUnit\Framework\TestCase; /** * @author John Kleijn */ -class DecoderTest extends \PHPUnit_Framework_TestCase +class DecoderTest extends TestCase { /** * @test diff --git a/tests/unit/Jwt/EncoderTest.php b/tests/unit/Jwt/EncoderTest.php index 4cdd472..5af24fd 100644 --- a/tests/unit/Jwt/EncoderTest.php +++ b/tests/unit/Jwt/EncoderTest.php @@ -8,11 +8,12 @@ namespace KleijnWeb\JwtBundle\Tests\Jwt; use KleijnWeb\JwtBundle\Jwt\Encoder; +use PHPUnit\Framework\TestCase; /** * @author John Kleijn */ -class EncoderTest extends \PHPUnit_Framework_TestCase +class EncoderTest extends TestCase { /** * @param string $data diff --git a/tests/unit/Jwt/JwtKeyTest.php b/tests/unit/Jwt/JwtKeyTest.php index 1c34a35..9087daf 100644 --- a/tests/unit/Jwt/JwtKeyTest.php +++ b/tests/unit/Jwt/JwtKeyTest.php @@ -14,11 +14,12 @@ use KleijnWeb\JwtBundle\Jwt\SecretLoader; use KleijnWeb\JwtBundle\Jwt\SignatureValidator\HmacValidator; use KleijnWeb\JwtBundle\Jwt\SignatureValidator\RsaValidator; +use PHPUnit\Framework\TestCase; /** * @author John Kleijn */ -class JwtKeyTest extends \PHPUnit_Framework_TestCase +class JwtKeyTest extends TestCase { /** * @test diff --git a/tests/unit/Jwt/JwtTokenTest.php b/tests/unit/Jwt/JwtTokenTest.php index 9deb392..ce08c80 100644 --- a/tests/unit/Jwt/JwtTokenTest.php +++ b/tests/unit/Jwt/JwtTokenTest.php @@ -9,11 +9,12 @@ use KleijnWeb\JwtBundle\Jwt\JwtToken; use KleijnWeb\JwtBundle\Jwt\SignatureValidator\SignatureValidator; +use PHPUnit\Framework\TestCase; /** * @author John Kleijn */ -class JwtTokenTest extends \PHPUnit_Framework_TestCase +class JwtTokenTest extends TestCase { // @codingStandardsIgnoreStart const EXAMPLE_TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ'; diff --git a/tests/unit/Jwt/SignatureValidator/HmacValidatorTest.php b/tests/unit/Jwt/SignatureValidator/HmacValidatorTest.php index d5e1fee..f68cdc6 100644 --- a/tests/unit/Jwt/SignatureValidator/HmacValidatorTest.php +++ b/tests/unit/Jwt/SignatureValidator/HmacValidatorTest.php @@ -9,11 +9,12 @@ namespace KleijnWeb\JwtBundle\Tests\Jwt\SignatureValidator; use KleijnWeb\JwtBundle\Jwt\SignatureValidator\HmacValidator; +use PHPUnit\Framework\TestCase; /** * @author John Kleijn */ -class HmacValidatorTest extends \PHPUnit_Framework_TestCase +class HmacValidatorTest extends TestCase { /** * @var string diff --git a/tests/unit/Jwt/SignatureValidator/RsaValidatorTest.php b/tests/unit/Jwt/SignatureValidator/RsaValidatorTest.php index b154641..56aaa92 100644 --- a/tests/unit/Jwt/SignatureValidator/RsaValidatorTest.php +++ b/tests/unit/Jwt/SignatureValidator/RsaValidatorTest.php @@ -9,11 +9,12 @@ namespace KleijnWeb\JwtBundle\Tests\Jwt\SignatureValidator; use KleijnWeb\JwtBundle\Jwt\SignatureValidator\RsaValidator; +use PHPUnit\Framework\TestCase; /** * @author John Kleijn */ -class RsaValidatorTest extends \PHPUnit_Framework_TestCase +class RsaValidatorTest extends TestCase { /** * @var string @@ -27,6 +28,7 @@ class RsaValidatorTest extends \PHPUnit_Framework_TestCase m6IDw3fRhZQrVwZ816/eN+1sqpIMZF4oo4kRA4b64U04ex67A/6BwDDQ3LH0mD4d EwIDAQAB -----END PUBLIC KEY-----'; + /** * @var string */ @@ -81,21 +83,21 @@ public static function testSetProvider() { // SHA256 - $payload1 = 'some payload'; + $payload1 = 'some payload'; $signature1 = ''; openssl_sign($payload1, $signature1, self::$privKey, RsaValidator::SHA256); - $payload2 = 'some other payload'; + $payload2 = 'some other payload'; $signature2 = ''; openssl_sign($payload2, $signature2, self::$privKey, RsaValidator::SHA256); // SHA512 - $payload3 = 'some payload'; + $payload3 = 'some payload'; $signature3 = ''; openssl_sign($payload3, $signature3, self::$privKey, RsaValidator::SHA512); - $payload4 = 'some other payload'; + $payload4 = 'some other payload'; $signature4 = ''; openssl_sign($payload4, $signature4, self::$privKey, RsaValidator::SHA512); diff --git a/tests/unit/User/JwtUserProviderTest.php b/tests/unit/User/JwtUserProviderTest.php index eccfb98..6e291e0 100644 --- a/tests/unit/User/JwtUserProviderTest.php +++ b/tests/unit/User/JwtUserProviderTest.php @@ -8,14 +8,15 @@ namespace KleijnWeb\JwtBundle\Tests\User; use KleijnWeb\JwtBundle\Jwt\JwtToken; -use KleijnWeb\JwtBundle\User\JwtUserProvider; use KleijnWeb\JwtBundle\User\JwtUser; +use KleijnWeb\JwtBundle\User\JwtUserProvider; +use PHPUnit\Framework\TestCase; use Symfony\Component\Security\Core\User\UserInterface; /** * @author John Kleijn */ -class JwtUserProviderTest extends \PHPUnit_Framework_TestCase +class JwtUserProviderTest extends TestCase { /** * @var JwtUserProvider