From 8bb74bcf22c34a0a873e5e147fe7550135a2f0cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Wed, 26 Mar 2014 15:27:03 -0300 Subject: [PATCH 01/22] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c266bcd..a8993ada 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ A simple library to work with JSON Web Token and JSON Web Signature (requires PH ## Instalation -Just add to your composer.json: ```"lcobucci/jwt": "~1.0"``` +Just add to your composer.json: ```"lcobucci/jwt": "*"``` ## Basic usage From adfb0a16208e655a1a0e46881b979f808cf8c0ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Wed, 19 Nov 2014 22:51:19 -0200 Subject: [PATCH 02/22] Adding scrutinizer images. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index a8993ada..fb2fc922 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,9 @@ master [![Build Status](https://secure.travis-ci.org/lcobucci/jwt.png?branch=master)](http://travis-ci.org/#!/lcobucci/jwt) develop [![Build Status](https://secure.travis-ci.org/lcobucci/jwt.png?branch=develop)](http://travis-ci.org/#!/lcobucci/jwt) +master [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=master) +develop [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=develop) + [![Total Downloads](https://poser.pugx.org/lcobucci/jwt/downloads.png)](https://packagist.org/packages/lcobucci/jwt) [![Latest Stable Version](https://poser.pugx.org/lcobucci/jwt/v/stable.png)](https://packagist.org/packages/lcobucci/jwt) From 86878c7cf8f6adffe72962458055426f496cc4a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 09:26:49 -0200 Subject: [PATCH 03/22] Typo fix. --- src/Signer/Factory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Signer/Factory.php b/src/Signer/Factory.php index 2921c72a..8fbec1cd 100644 --- a/src/Signer/Factory.php +++ b/src/Signer/Factory.php @@ -19,7 +19,7 @@ class Factory { /** - * Retrives a signer instance + * Retrieves a signer instance * * @param string $id * From e7b0590e6e509b439fbaee8b9d7eaf548ab507db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 09:54:44 -0200 Subject: [PATCH 04/22] Initial implementation of validation improvement (#1). --- src/Builder.php | 22 ++++-- src/Claim.php | 40 +++++++++++ src/Claim/Basic.php | 73 ++++++++++++++++++++ src/Claim/EqualsTo.php | 31 +++++++++ src/Claim/Factory.php | 116 ++++++++++++++++++++++++++++++++ src/Claim/GreaterOrEqualsTo.php | 31 +++++++++ src/Claim/LesserOrEqualsTo.php | 31 +++++++++ src/Claim/Validatable.php | 26 +++++++ src/Parser.php | 61 ++++++++++++----- src/Token.php | 53 +++++++++------ 10 files changed, 445 insertions(+), 39 deletions(-) create mode 100644 src/Claim.php create mode 100644 src/Claim/Basic.php create mode 100644 src/Claim/EqualsTo.php create mode 100644 src/Claim/Factory.php create mode 100644 src/Claim/GreaterOrEqualsTo.php create mode 100644 src/Claim/LesserOrEqualsTo.php create mode 100644 src/Claim/Validatable.php diff --git a/src/Builder.php b/src/Builder.php index 82b08320..b64e78f8 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -8,6 +8,7 @@ namespace Lcobucci\JWT; use BadMethodCallException; +use Lcobucci\JWT\Claim\Factory as ClaimFactory; use Lcobucci\JWT\Parsing\Encoder; /** @@ -46,12 +47,25 @@ class Builder */ private $encoder; + /** + * The factory of claims + * + * @var ClaimFactory + */ + private $claimFactory; + /** * Initializes a new builder + * + * @param Encoder $encoder + * @param ClaimFactory $claimFactory */ - public function __construct(Encoder $encoder = null) - { + public function __construct( + Encoder $encoder = null, + ClaimFactory $claimFactory = null + ) { $this->encoder = $encoder ?: new Encoder(); + $this->claimFactory = $claimFactory ?: new ClaimFactory(); $this->header = ['typ'=> 'JWT', 'alg' => 'none']; $this->claims = []; } @@ -161,7 +175,7 @@ protected function setRegisteredClaim($name, $value, $replicate) $this->set($name, $value); if ($replicate) { - $this->header[$name] = $value; + $this->header[$name] = $this->claims[$name]; } return $this; @@ -183,7 +197,7 @@ public function set($name, $value) throw new BadMethodCallException('You must unsign before make changes'); } - $this->claims[(string) $name] = $value; + $this->claims[(string) $name] = $this->claimFactory->create($name, $value); return $this; } diff --git a/src/Claim.php b/src/Claim.php new file mode 100644 index 00000000..814c3775 --- /dev/null +++ b/src/Claim.php @@ -0,0 +1,40 @@ + + * @since 1.2.0 + */ +interface Claim extends JsonSerializable +{ + /** + * Returns the claim name + * + * @return string + */ + public function getName(); + + /** + * Returns the claim value + * + * @return string + */ + public function getValue(); + + /** + * Returns the string representation of the claim + * + * @return string + */ + public function __toString(); +} diff --git a/src/Claim/Basic.php b/src/Claim/Basic.php new file mode 100644 index 00000000..6f5e287d --- /dev/null +++ b/src/Claim/Basic.php @@ -0,0 +1,73 @@ + + * @since 1.2.0 + */ +class Basic implements Claim +{ + /** + * @var string + */ + private $name; + + /** + * @var mixed + */ + private $value; + + /** + * Initializes the claim + * + * @param string $name + * @param mixed $value + */ + public function __construct($name, $value) + { + $this->name = $name; + $this->value = $value; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return $this->name; + } + + /** + * {@inheritdoc} + */ + public function getValue() + { + return $this->value; + } + + /** + * {@inheritdoc} + */ + public function jsonSerialize() + { + return $this->value; + } + + /** + * {@inheritdoc} + */ + public function __toString() + { + return $this->value; + } +} diff --git a/src/Claim/EqualsTo.php b/src/Claim/EqualsTo.php new file mode 100644 index 00000000..21a7d481 --- /dev/null +++ b/src/Claim/EqualsTo.php @@ -0,0 +1,31 @@ + + * @since 1.2.0 + */ +class EqualsTo extends Basic implements Claim, Validatable +{ + /** + * {@inheritdoc} + */ + public function validate(array $data) + { + if (isset($data[$this->getName()])) { + return $this->getValue() === $data[$this->getName()]; + } + + return true; + } +} diff --git a/src/Claim/Factory.php b/src/Claim/Factory.php new file mode 100644 index 00000000..53a5805a --- /dev/null +++ b/src/Claim/Factory.php @@ -0,0 +1,116 @@ + + * @since 1.2.0 + */ +class Factory +{ + /** + * The list of claim callbacks + * + * @var array + */ + private $callbacks; + + /** + * Initializes the factory, registering the default callbacks + * + * @param array $callbacks + */ + public function __construct(array $callbacks = []) + { + $this->callbacks = array_merge( + [ + 'iat' => [$this, 'createLesserOrEqualsTo'], + 'nbf' => [$this, 'createLesserOrEqualsTo'], + 'exp' => [$this, 'createGreaterOrEqualsTo'], + 'iss' => [$this, 'createEqualsTo'], + 'aud' => [$this, 'createEqualsTo'], + 'sub' => [$this, 'createEqualsTo'], + 'jti' => [$this, 'createEqualsTo'] + ], + $callbacks + ); + } + + /** + * Create a new claim + * + * @param string $name + * @param mixed $value + * + * @return Claim + */ + public function create($name, $value) + { + if (!empty($this->callbacks[$name])) { + return call_user_func($this->callbacks[$name], $name, $value); + } + + return $this->createBasic($name, $value); + } + + /** + * Creates a claim that can be compared (greator or equals) + * + * @param string $name + * @param mixed $value + * + * @return GreaterOrEqualsTo + */ + private function createGreaterOrEqualsTo($name, $value) + { + return new GreaterOrEqualsTo($name, $value); + } + + /** + * Creates a claim that can be compared (greator or equals) + * + * @param string $name + * @param mixed $value + * + * @return LesserOrEqualsTo + */ + private function createLesserOrEqualsTo($name, $value) + { + return new LesserOrEqualsTo($name, $value); + } + + /** + * Creates a claim that can be compared (equals) + * + * @param string $name + * @param mixed $value + * + * @return EqualsTo + */ + private function createEqualsTo($name, $value) + { + return new EqualsTo($name, $value); + } + + /** + * Creates a basic claim + * + * @param string $name + * @param mixed $value + * + * @return Basic + */ + private function createBasic($name, $value) + { + return new Basic($name, $value); + } +} diff --git a/src/Claim/GreaterOrEqualsTo.php b/src/Claim/GreaterOrEqualsTo.php new file mode 100644 index 00000000..295de66d --- /dev/null +++ b/src/Claim/GreaterOrEqualsTo.php @@ -0,0 +1,31 @@ + + * @since 1.2.0 + */ +class GreaterOrEqualsTo extends Basic implements Claim, Validatable +{ + /** + * {@inheritdoc} + */ + public function validate(array $data) + { + if (isset($data[$this->getName()])) { + return $this->getValue() >= $data[$this->getName()]; + } + + return true; + } +} diff --git a/src/Claim/LesserOrEqualsTo.php b/src/Claim/LesserOrEqualsTo.php new file mode 100644 index 00000000..fb9ed3fe --- /dev/null +++ b/src/Claim/LesserOrEqualsTo.php @@ -0,0 +1,31 @@ + + * @since 1.2.0 + */ +class LesserOrEqualsTo extends Basic implements Claim, Validatable +{ + /** + * {@inheritdoc} + */ + public function validate(array $data) + { + if (isset($data[$this->getName()])) { + return $this->getValue() <= $data[$this->getName()]; + } + + return true; + } +} diff --git a/src/Claim/Validatable.php b/src/Claim/Validatable.php new file mode 100644 index 00000000..4c2c07a4 --- /dev/null +++ b/src/Claim/Validatable.php @@ -0,0 +1,26 @@ + + * @since 1.2.0 + */ +interface Validatable +{ + /** + * Returns if claim is valid according with given data + * + * @param array $data + * + * @return boolean + */ + public function validate(array $data); +} diff --git a/src/Parser.php b/src/Parser.php index ebee35dd..483744a4 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -8,9 +8,10 @@ namespace Lcobucci\JWT; use InvalidArgumentException; +use Lcobucci\JWT\Claim\Factory as ClaimFactory; use Lcobucci\JWT\Parsing\Decoder; use Lcobucci\JWT\Parsing\Encoder; -use Lcobucci\JWT\Signer\Factory; +use Lcobucci\JWT\Signer\Factory as SignerFactory; /** * This class parses the JWT strings and convert them into tokens @@ -37,48 +38,74 @@ class Parser /** * The signer factory * - * @var Factory + * @var SignerFactory */ - private $factory; + private $signerFactory; + + /** + * The claims factory + * + * @var ClaimFactory + */ + private $claimFactory; /** * Initializes the object * * @param Encoder $encoder * @param Decoder $decoder - * @param Factory $factory + * @param SignerFactory $signerFactory + * @param ClaimFactory $claimFactory */ public function __construct( Encoder $encoder = null, Decoder $decoder = null, - Factory $factory = null + SignerFactory $signerFactory = null, + ClaimFactory $claimFactory = null ) { $this->encoder = $encoder ?: new Encoder(); $this->decoder = $decoder ?: new Decoder(); - $this->factory = $factory ?: new Factory(); + $this->signerFactory = $signerFactory ?: new SignerFactory(); + $this->claimFactory = $claimFactory ?: new ClaimFactory(); } /** * Parses the JWT and returns a token * * @param string $jwt + * * @return Token */ public function parse($jwt) { - $data = $this->splitJwt($jwt); - - $token = new Token( - $header = $this->parseHeader($data[0]), - $this->parseClaims($data[1]), - $this->parseSignature($header, $data[2]) - ); - + $token = $this->createToken($this->splitJwt($jwt)); $token->setEncoder($this->encoder); return $token; } + /** + * Creates the token from given data + * + * @param array $data + * + * @return Token + */ + private function createToken(array $data) + { + $header = $this->parseHeader($data[0]); + $claims = $this->parseClaims($data[1]); + $signature = $this->parseSignature($header, $data[2]); + + foreach ($claims as $name => $value) { + if (isset($header[$name])) { + $header[$name] = $value; + } + } + + return new Token($header, $claims, $signature); + } + /** * Slipts the JWT string into an array * @@ -140,6 +167,10 @@ protected function parseClaims($data) throw new InvalidArgumentException('That claims are not valid'); } + foreach ($claims as $name => &$value) { + $value = $this->claimFactory->create($name, $value); + } + return $claims; } @@ -159,6 +190,6 @@ protected function parseSignature(array $header, $data) $hash = $this->decoder->base64UrlDecode($data); - return new Signature($this->factory->create($header['alg']), $hash); + return new Signature($this->signerFactory->create($header['alg']), $hash); } } diff --git a/src/Token.php b/src/Token.php index e6ec96d0..3089222b 100644 --- a/src/Token.php +++ b/src/Token.php @@ -9,6 +9,7 @@ use BadMethodCallException; use Lcobucci\JWT\Parsing\Encoder; +use Lcobucci\JWT\Claim\Validatable; /** * Basic structure of the JWT @@ -53,8 +54,11 @@ class Token * @param array $claims * @param Signature $signature */ - public function __construct(array $header = ['alg' => 'none'], array $claims = [], Signature $signature = null) - { + public function __construct( + array $header = ['alg' => 'none'], + array $claims = [], + Signature $signature = null + ) { $this->header = $header; $this->claims = $claims; $this->signature = $signature; @@ -125,6 +129,7 @@ public function verify($key) * @param string $audience * @param string $subject * @param int $currentTime + * * @return boolean */ public function validate( @@ -134,28 +139,36 @@ public function validate( $currentTime = null ) { $currentTime = $currentTime ?: time(); - - if (isset($this->claims['iss']) && $this->claims['iss'] != $issuer) { - return false; - } - - if (isset($this->claims['aud']) && $this->claims['aud'] != $audience) { - return false; - } - - if (isset($this->claims['sub']) && $this->claims['sub'] != $subject) { - return false; + $data = [ + 'iss' => $issuer, + 'aud' => $audience, + 'sub' => $subject, + 'iat' => $currentTime, + 'nbf' => $currentTime, + 'exp' => $currentTime + ]; + + foreach ($this->getValidatableClaims() as $claim) { + if (!$claim->validate($data)) { + return false; + } } - if (isset($this->claims['nbf']) && $this->claims['nbf'] > $currentTime) { - return false; - } + return true; + } - if (isset($this->claims['exp']) && $this->claims['exp'] < $currentTime) { - return false; + /** + * Yields the validatable claims + * + * @return Generator + */ + private function getValidatableClaims() + { + foreach ($this->claims as $claim) { + if ($claim instanceof Validatable) { + yield $claim; + } } - - return true; } /** From 95927e7b9706dc1a0e33694464a38d9220f25a1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 10:05:17 -0200 Subject: [PATCH 05/22] Updating dependencies. --- composer.json | 49 ++--- composer.lock | 538 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 435 insertions(+), 152 deletions(-) diff --git a/composer.json b/composer.json index bc97fbbe..5606ea3c 100644 --- a/composer.json +++ b/composer.json @@ -1,27 +1,28 @@ { - "name" : "lcobucci/jwt", - "description" : "A simple library to work with JSON Web Token and JSON Web Signature", - "type" : "library", - "authors" : [{ - "name" : "Luís Otávio Cobucci Oblonczyk", - "email" : "lcobucci@gmail.com", + "name" : "lcobucci/jwt", + "description" : "A simple library to work with JSON Web Token and JSON Web Signature", + "type" : "library", + "authors" : [ + { + "name" : "Luís Otávio Cobucci Obloncz", + "email" : "lcobucci@gmail.com", "role": "Developer" - } - ], - "keywords" : ["JWT", "JWS"], - "license" : ["BSD-3-Clause"], - "require" : { - "php" : ">=5.5" - }, - "require-dev" : { - "phpunit/phpunit" : "4.0.x", - "squizlabs/php_codesniffer" : "*", - "phpmd/phpmd" : "*" - }, - "autoload" : { - "psr-4" : { - "Lcobucci\\JWT\\" : "src", - "Lcobucci\\JWT\\Test\\" : "test" - } - } + } + ], + "keywords" : ["JWT", "JWS"], + "license" : ["BSD-3-Clause"], + "require" : { + "php" : ">=5.5" + }, + "require-dev" : { + "phpunit/phpunit" : "~4.3", + "squizlabs/php_codesniffer" : "~1.5", + "phpmd/phpmd" : "~2.1" + }, + "autoload" : { + "psr-4" : { + "Lcobucci\\JWT\\" : "src", + "Lcobucci\\JWT\\Test\\" : "test" + } + } } diff --git a/composer.lock b/composer.lock index 2b5c4cb5..d7c608a2 100644 --- a/composer.lock +++ b/composer.lock @@ -1,29 +1,88 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" - ], - "hash": "1c0271b44549953a627d59a27ad460ee", - "packages": [ - + "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" ], + "hash": "29c0f955303ff1339c0de6fb8776b101", + "packages": [], "packages-dev": [ + { + "name": "doctrine/instantiator", + "version": "1.0.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", + "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", + "shasum": "" + }, + "require": { + "php": ">=5.3,<8.0-DEV" + }, + "require-dev": { + "athletic/athletic": "~0.1.8", + "ext-pdo": "*", + "ext-phar": "*", + "phpunit/phpunit": "~4.0", + "squizlabs/php_codesniffer": "2.0.*@ALPHA" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-0": { + "Doctrine\\Instantiator\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://github.com/doctrine/instantiator", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2014-10-13 12:58:55" + }, { "name": "pdepend/pdepend", - "version": "1.1.3", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/pdepend/pdepend.git", - "reference": "1537f19d62d7b30c13ac173270106df7c6b9c459" + "reference": "dc582a3c0180664a8fbfc5a34efaf4cc13fccc60" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pdepend/pdepend/zipball/1537f19d62d7b30c13ac173270106df7c6b9c459", - "reference": "1537f19d62d7b30c13ac173270106df7c6b9c459", + "url": "https://api.github.com/repos/pdepend/pdepend/zipball/dc582a3c0180664a8fbfc5a34efaf4cc13fccc60", + "reference": "dc582a3c0180664a8fbfc5a34efaf4cc13fccc60", "shasum": "" }, "require": { - "php": ">=5.2.3" + "symfony/config": "@stable", + "symfony/dependency-injection": "@stable", + "symfony/filesystem": "@stable" + }, + "require-dev": { + "phpunit/phpunit": "3.*@stable", + "squizlabs/php_codesniffer": "@stable" }, "bin": [ "src/bin/pdepend" @@ -31,7 +90,7 @@ "type": "library", "autoload": { "psr-0": { - "PHP_": "src/main/php/" + "PDepend\\": "src/main/php/" } }, "notification-url": "https://packagist.org/downloads/", @@ -39,67 +98,75 @@ "BSD-3-Clause" ], "description": "Official version of pdepend to be handled with Composer", - "time": "2013-12-04 17:46:00" + "time": "2014-10-08 06:54:50" }, { "name": "phpmd/phpmd", - "version": "1.5.0", + "version": "2.1.3", "source": { "type": "git", "url": "https://github.com/phpmd/phpmd.git", - "reference": "692b7b1b64518091b2b1bea91b489dbb13598c07" + "reference": "1a485d9db869137af5e9678bd844568c92998b25" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpmd/phpmd/zipball/692b7b1b64518091b2b1bea91b489dbb13598c07", - "reference": "692b7b1b64518091b2b1bea91b489dbb13598c07", + "url": "https://api.github.com/repos/phpmd/phpmd/zipball/1a485d9db869137af5e9678bd844568c92998b25", + "reference": "1a485d9db869137af5e9678bd844568c92998b25", "shasum": "" }, "require": { - "pdepend/pdepend": ">=1.1.1", - "php": ">=5.3.0" + "pdepend/pdepend": "2.0.*", + "php": ">=5.3.0", + "symfony/config": "2.5.*", + "symfony/dependency-injection": "2.5.*", + "symfony/filesystem": "2.5.*" }, "bin": [ "src/bin/phpmd" ], "type": "library", + "autoload": { + "psr-0": { + "PHPMD\\": "src/main/php" + } + }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "../../pdepend/pdepend/src/main/php", - "src/main/php" + "license": [ + "BSD-3-Clause" ], "description": "Official version of PHPMD handled with Composer.", - "time": "2013-07-26 14:47:02" + "time": "2014-09-25 15:56:22" }, { "name": "phpunit/php-code-coverage", - "version": "2.0.2", + "version": "2.0.11", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "2c20ba4872d09d1d3d7ceda5a0c5f82d9a8ff31f" + "reference": "53603b3c995f5aab6b59c8e08c3a663d2cc810b7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2c20ba4872d09d1d3d7ceda5a0c5f82d9a8ff31f", - "reference": "2c20ba4872d09d1d3d7ceda5a0c5f82d9a8ff31f", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/53603b3c995f5aab6b59c8e08c3a663d2cc810b7", + "reference": "53603b3c995f5aab6b59c8e08c3a663d2cc810b7", "shasum": "" }, "require": { "php": ">=5.3.3", - "phpunit/php-file-iterator": "~1.3.1", + "phpunit/php-file-iterator": "~1.3", "phpunit/php-text-template": "~1.2", - "phpunit/php-token-stream": "~1.1.3", + "phpunit/php-token-stream": "~1.3", "sebastian/environment": "~1.0", - "sebastian/version": "~1.0.3" + "sebastian/version": "~1.0" }, "require-dev": { "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": ">=4.0.0,<4.1.0" + "phpunit/phpunit": "~4.1" }, "suggest": { "ext-dom": "*", - "ext-xdebug": ">=2.2.1" + "ext-xdebug": ">=2.2.1", + "ext-xmlwriter": "*" }, "type": "library", "extra": { @@ -133,7 +200,7 @@ "testing", "xunit" ], - "time": "2014-03-17 10:25:49" + "time": "2014-08-31 06:33:04" }, { "name": "phpunit/php-file-iterator", @@ -270,40 +337,44 @@ }, { "name": "phpunit/php-token-stream", - "version": "1.1.8", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "66a29f0c5bdf85e70112f25ec9072efec5e2d426" + "reference": "f8d5d08c56de5cfd592b3340424a81733259a876" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/66a29f0c5bdf85e70112f25ec9072efec5e2d426", - "reference": "66a29f0c5bdf85e70112f25ec9072efec5e2d426", + "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/f8d5d08c56de5cfd592b3340424a81733259a876", + "reference": "f8d5d08c56de5cfd592b3340424a81733259a876", "shasum": "" }, "require": { "ext-tokenizer": "*", "php": ">=5.3.3" }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.3-dev" + } + }, "autoload": { "classmap": [ - "PHP/" + "src/" ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], "authors": [ { "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" + "email": "sebastian@phpunit.de" } ], "description": "Wrapper around PHP's tokenizer extension.", @@ -311,43 +382,42 @@ "keywords": [ "tokenizer" ], - "time": "2013-08-02 19:10:55" + "time": "2014-08-31 06:12:13" }, { "name": "phpunit/phpunit", - "version": "4.0.9", + "version": "4.3.5", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "c7e9e4b1253142acda4cb86a7686db412684fe04" + "reference": "2dab9d593997db4abcf58d0daf798eb4e9cecfe1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c7e9e4b1253142acda4cb86a7686db412684fe04", - "reference": "c7e9e4b1253142acda4cb86a7686db412684fe04", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2dab9d593997db4abcf58d0daf798eb4e9cecfe1", + "reference": "2dab9d593997db4abcf58d0daf798eb4e9cecfe1", "shasum": "" }, "require": { "ext-dom": "*", + "ext-json": "*", "ext-pcre": "*", "ext-reflection": "*", "ext-spl": "*", "php": ">=5.3.3", - "phpunit/php-code-coverage": ">=2.0.0,<2.1.0", - "phpunit/php-file-iterator": "~1.3.1", + "phpunit/php-code-coverage": "~2.0", + "phpunit/php-file-iterator": "~1.3.2", "phpunit/php-text-template": "~1.2", "phpunit/php-timer": "~1.0.2", - "phpunit/phpunit-mock-objects": ">=2.0.0,<2.1.0", + "phpunit/phpunit-mock-objects": "~2.3", + "sebastian/comparator": "~1.0", "sebastian/diff": "~1.1", "sebastian/environment": "~1.0", - "sebastian/exporter": "~1.0.1", - "sebastian/version": "~1.0.3", + "sebastian/exporter": "~1.0", + "sebastian/version": "~1.0", "symfony/yaml": "~2.0" }, "suggest": { - "ext-json": "*", - "ext-simplexml": "*", - "ext-tokenizer": "*", "phpunit/php-invoker": "~1.1" }, "bin": [ @@ -356,7 +426,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.0.x-dev" + "dev-master": "4.3.x-dev" } }, "autoload": { @@ -386,28 +456,29 @@ "testing", "xunit" ], - "time": "2014-03-17 15:17:30" + "time": "2014-11-11 10:11:09" }, { "name": "phpunit/phpunit-mock-objects", - "version": "2.0.3", + "version": "2.3.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "5888b2501d41c34f9132c959b073b23de83235aa" + "reference": "c63d2367247365f688544f0d500af90a11a44c65" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/5888b2501d41c34f9132c959b073b23de83235aa", - "reference": "5888b2501d41c34f9132c959b073b23de83235aa", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/c63d2367247365f688544f0d500af90a11a44c65", + "reference": "c63d2367247365f688544f0d500af90a11a44c65", "shasum": "" }, "require": { + "doctrine/instantiator": "~1.0,>=1.0.1", "php": ">=5.3.3", "phpunit/php-text-template": "~1.2" }, "require-dev": { - "phpunit/phpunit": ">=4.0.0,<4.1.0" + "phpunit/phpunit": "~4.3" }, "suggest": { "ext-soap": "*" @@ -415,7 +486,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "2.3.x-dev" } }, "autoload": { @@ -424,9 +495,6 @@ ] }, "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], "license": [ "BSD-3-Clause" ], @@ -443,29 +511,96 @@ "mock", "xunit" ], - "time": "2014-03-11 09:46:18" + "time": "2014-10-03 05:12:11" + }, + { + "name": "sebastian/comparator", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", + "reference": "e54a01c0da1b87db3c5a3c4c5277ddf331da4aef", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "sebastian/diff": "~1.1", + "sebastian/exporter": "~1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "http://www.github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "time": "2014-05-11 23:00:21" }, { "name": "sebastian/diff", - "version": "1.1.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "1e091702a5a38e6b4c1ba9ca816e3dd343df2e2d" + "reference": "5843509fed39dee4b356a306401e9dd1a931fec7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/1e091702a5a38e6b4c1ba9ca816e3dd343df2e2d", - "reference": "1e091702a5a38e6b4c1ba9ca816e3dd343df2e2d", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/5843509fed39dee4b356a306401e9dd1a931fec7", + "reference": "5843509fed39dee4b356a306401e9dd1a931fec7", "shasum": "" }, "require": { "php": ">=5.3.3" }, + "require-dev": { + "phpunit/phpunit": "~4.2" + }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.1-dev" + "dev-master": "1.2-dev" } }, "autoload": { @@ -478,14 +613,13 @@ "BSD-3-Clause" ], "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - }, { "name": "Kore Nordmann", "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" } ], "description": "Diff implementation", @@ -493,32 +627,32 @@ "keywords": [ "diff" ], - "time": "2013-08-03 16:46:33" + "time": "2014-08-15 10:29:00" }, { "name": "sebastian/environment", - "version": "1.0.0", + "version": "1.2.0", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "79517609ec01139cd7e9fded0dd7ce08c952ef6a" + "reference": "0d9bf79554d2a999da194a60416c15cf461eb67d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/79517609ec01139cd7e9fded0dd7ce08c952ef6a", - "reference": "79517609ec01139cd7e9fded0dd7ce08c952ef6a", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/0d9bf79554d2a999da194a60416c15cf461eb67d", + "reference": "0d9bf79554d2a999da194a60416c15cf461eb67d", "shasum": "" }, "require": { "php": ">=5.3.3" }, "require-dev": { - "phpunit/phpunit": "4.0.*@dev" + "phpunit/phpunit": "~4.3" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.2.x-dev" } }, "autoload": { @@ -533,8 +667,7 @@ "authors": [ { "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" + "email": "sebastian@phpunit.de" } ], "description": "Provides functionality to handle HHVM/PHP environments", @@ -544,27 +677,27 @@ "environment", "hhvm" ], - "time": "2014-02-18 16:17:19" + "time": "2014-10-22 06:38:05" }, { "name": "sebastian/exporter", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "1f9a98e6f5dfe0524cb8c6166f7c82f3e9ae1529" + "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/1f9a98e6f5dfe0524cb8c6166f7c82f3e9ae1529", - "reference": "1f9a98e6f5dfe0524cb8c6166f7c82f3e9ae1529", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", + "reference": "c7d59948d6e82818e1bdff7cadb6c34710eb7dc0", "shasum": "" }, "require": { "php": ">=5.3.3" }, "require-dev": { - "phpunit/phpunit": "4.0.*@dev" + "phpunit/phpunit": "~4.0" }, "type": "library", "extra": { @@ -582,11 +715,6 @@ "BSD-3-Clause" ], "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - }, { "name": "Jeff Welch", "email": "whatthejeff@gmail.com" @@ -595,13 +723,17 @@ "name": "Volker Dusch", "email": "github@wallbash.com" }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - }, { "name": "Bernhard Schussek", "email": "bschussek@2bepublished.at" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" } ], "description": "Provides the functionality to export PHP variables for visualization", @@ -610,7 +742,7 @@ "export", "exporter" ], - "time": "2014-02-16 08:26:31" + "time": "2014-09-10 00:51:36" }, { "name": "sebastian/version", @@ -649,16 +781,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "1.5.2", + "version": "1.5.5", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "a76a39b317ce8106abe6264daa505e24e1731860" + "reference": "5d973e59cf58a0c847f298de84374c96b42b17b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/a76a39b317ce8106abe6264daa505e24e1731860", - "reference": "a76a39b317ce8106abe6264daa505e24e1731860", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5d973e59cf58a0c847f298de84374c96b42b17b3", + "reference": "5d973e59cf58a0c847f298de84374c96b42b17b3", "shasum": "" }, "require": { @@ -672,6 +804,11 @@ "scripts/phpcs" ], "type": "library", + "extra": { + "branch-alias": { + "dev-phpcs-fixer": "2.0.x-dev" + } + }, "autoload": { "classmap": [ "CodeSniffer.php", @@ -715,21 +852,173 @@ "phpcs", "standards" ], - "time": "2014-02-04 23:49:58" + "time": "2014-09-25 03:33:46" + }, + { + "name": "symfony/config", + "version": "v2.5.6", + "target-dir": "Symfony/Component/Config", + "source": { + "type": "git", + "url": "https://github.com/symfony/Config.git", + "reference": "0316364bfebc8b080077c731a99f189341476bd7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Config/zipball/0316364bfebc8b080077c731a99f189341476bd7", + "reference": "0316364bfebc8b080077c731a99f189341476bd7", + "shasum": "" + }, + "require": { + "php": ">=5.3.3", + "symfony/filesystem": "~2.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Config\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony Config Component", + "homepage": "http://symfony.com", + "time": "2014-09-23 05:25:11" + }, + { + "name": "symfony/dependency-injection", + "version": "v2.5.6", + "target-dir": "Symfony/Component/DependencyInjection", + "source": { + "type": "git", + "url": "https://github.com/symfony/DependencyInjection.git", + "reference": "fb40e4ea115d331346fbbc4da8f42825e524c7a0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/DependencyInjection/zipball/fb40e4ea115d331346fbbc4da8f42825e524c7a0", + "reference": "fb40e4ea115d331346fbbc4da8f42825e524c7a0", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "symfony/config": "~2.2", + "symfony/expression-language": "~2.4", + "symfony/yaml": "~2.0" + }, + "suggest": { + "symfony/config": "", + "symfony/proxy-manager-bridge": "Generate service proxies to lazy load them", + "symfony/yaml": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\DependencyInjection\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony DependencyInjection Component", + "homepage": "http://symfony.com", + "time": "2014-10-01 05:50:18" + }, + { + "name": "symfony/filesystem", + "version": "v2.5.6", + "target-dir": "Symfony/Component/Filesystem", + "source": { + "type": "git", + "url": "https://github.com/symfony/Filesystem.git", + "reference": "4e62fab0060a826561c78b665925b37c870c45f5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/Filesystem/zipball/4e62fab0060a826561c78b665925b37c870c45f5", + "reference": "4e62fab0060a826561c78b665925b37c870c45f5", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.5-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Filesystem\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + } + ], + "description": "Symfony Filesystem Component", + "homepage": "http://symfony.com", + "time": "2014-09-22 09:14:18" }, { "name": "symfony/yaml", - "version": "v2.4.2", + "version": "v2.5.6", "target-dir": "Symfony/Component/Yaml", "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "bb6ddaf8956139d1b8c360b4b713ed0138e876b3" + "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/bb6ddaf8956139d1b8c360b4b713ed0138e876b3", - "reference": "bb6ddaf8956139d1b8c360b4b713ed0138e876b3", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/2d9f527449cabfa8543dd7fa3a466d6ae83d6726", + "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726", "shasum": "" }, "require": { @@ -738,7 +1027,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.4-dev" + "dev-master": "2.5-dev" } }, "autoload": { @@ -751,33 +1040,26 @@ "MIT" ], "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com", - "homepage": "http://fabien.potencier.org", - "role": "Lead Developer" - }, { "name": "Symfony Community", "homepage": "http://symfony.com/contributors" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" } ], "description": "Symfony Yaml Component", "homepage": "http://symfony.com", - "time": "2014-01-07 13:28:54" + "time": "2014-10-01 05:50:18" } ], - "aliases": [ - - ], + "aliases": [], "minimum-stability": "stable", - "stability-flags": [ - - ], + "stability-flags": [], + "prefer-stable": false, "platform": { "php": ">=5.5" }, - "platform-dev": [ - - ] + "platform-dev": [] } From 5293b22028e8d71fb9ca2d470fbfd489de96b0a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 10:09:17 -0200 Subject: [PATCH 06/22] Fixing "since" annotation. --- src/Claim.php | 2 +- src/Claim/Basic.php | 2 +- src/Claim/EqualsTo.php | 2 +- src/Claim/Factory.php | 2 +- src/Claim/GreaterOrEqualsTo.php | 2 +- src/Claim/LesserOrEqualsTo.php | 2 +- src/Claim/Validatable.php | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Claim.php b/src/Claim.php index 814c3775..e5617401 100644 --- a/src/Claim.php +++ b/src/Claim.php @@ -13,7 +13,7 @@ * Basic interface for token claims * * @author Luís Otávio Cobucci Oblonczyk - * @since 1.2.0 + * @since 2.0.0 */ interface Claim extends JsonSerializable { diff --git a/src/Claim/Basic.php b/src/Claim/Basic.php index 6f5e287d..a1b54e90 100644 --- a/src/Claim/Basic.php +++ b/src/Claim/Basic.php @@ -13,7 +13,7 @@ * The default claim * * @author Luís Otávio Cobucci Oblonczyk - * @since 1.2.0 + * @since 2.0.0 */ class Basic implements Claim { diff --git a/src/Claim/EqualsTo.php b/src/Claim/EqualsTo.php index 21a7d481..55b798b0 100644 --- a/src/Claim/EqualsTo.php +++ b/src/Claim/EqualsTo.php @@ -13,7 +13,7 @@ * Validatable claim that checks if value is strictly equals to the given data * * @author Luís Otávio Cobucci Oblonczyk - * @since 1.2.0 + * @since 2.0.0 */ class EqualsTo extends Basic implements Claim, Validatable { diff --git a/src/Claim/Factory.php b/src/Claim/Factory.php index 53a5805a..9c1c2b06 100644 --- a/src/Claim/Factory.php +++ b/src/Claim/Factory.php @@ -13,7 +13,7 @@ * Class that create claims * * @author Luís Otávio Cobucci Oblonczyk - * @since 1.2.0 + * @since 2.0.0 */ class Factory { diff --git a/src/Claim/GreaterOrEqualsTo.php b/src/Claim/GreaterOrEqualsTo.php index 295de66d..37ff9696 100644 --- a/src/Claim/GreaterOrEqualsTo.php +++ b/src/Claim/GreaterOrEqualsTo.php @@ -13,7 +13,7 @@ * Validatable claim that checks if value is greater or equals the given data * * @author Luís Otávio Cobucci Oblonczyk - * @since 1.2.0 + * @since 2.0.0 */ class GreaterOrEqualsTo extends Basic implements Claim, Validatable { diff --git a/src/Claim/LesserOrEqualsTo.php b/src/Claim/LesserOrEqualsTo.php index fb9ed3fe..28f87727 100644 --- a/src/Claim/LesserOrEqualsTo.php +++ b/src/Claim/LesserOrEqualsTo.php @@ -13,7 +13,7 @@ * Validatable claim that checks if value is lesser or equals to the given data * * @author Luís Otávio Cobucci Oblonczyk - * @since 1.2.0 + * @since 2.0.0 */ class LesserOrEqualsTo extends Basic implements Claim, Validatable { diff --git a/src/Claim/Validatable.php b/src/Claim/Validatable.php index 4c2c07a4..80b7bfe0 100644 --- a/src/Claim/Validatable.php +++ b/src/Claim/Validatable.php @@ -11,7 +11,7 @@ * Basic interface for validatable token claims * * @author Luís Otávio Cobucci Oblonczyk - * @since 1.2.0 + * @since 2.0.0 */ interface Validatable { From fa75461e1d14aed071eb97f084f1655f34404022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 10:24:56 -0200 Subject: [PATCH 07/22] Adding code coverage badge. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index fb2fc922..3b56b36a 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,9 @@ develop [![Build Status](https://secure.travis-ci.org/lcobucci/jwt.png?branch=de master [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=master) develop [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=develop) +master [![Code Coverage](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=master) +develop [![Code Coverage](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=develop) + [![Total Downloads](https://poser.pugx.org/lcobucci/jwt/downloads.png)](https://packagist.org/packages/lcobucci/jwt) [![Latest Stable Version](https://poser.pugx.org/lcobucci/jwt/v/stable.png)](https://packagist.org/packages/lcobucci/jwt) From 59967811690958050803e65bc29f67d240a59453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 11:01:31 -0200 Subject: [PATCH 08/22] Decoder should always return an array. --- src/Parser.php | 10 ++-------- src/Parsing/Decoder.php | 4 ++++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/Parser.php b/src/Parser.php index 483744a4..ba54d4b2 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -143,8 +143,8 @@ protected function parseHeader($data) { $header = $this->decoder->jsonDecode($this->decoder->base64UrlDecode($data)); - if (!is_array($header) || isset($header['enc'])) { - throw new InvalidArgumentException('That header is not a valid array or uses encryption'); + if (isset($header['enc'])) { + throw new InvalidArgumentException('Encryption is not supported yet'); } return $header; @@ -156,17 +156,11 @@ protected function parseHeader($data) * @param string $data * * @return array - * - * @throws InvalidArgumentException When an invalid claim set is informed */ protected function parseClaims($data) { $claims = $this->decoder->jsonDecode($this->decoder->base64UrlDecode($data)); - if (!is_array($claims)) { - throw new InvalidArgumentException('That claims are not valid'); - } - foreach ($claims as $name => &$value) { $value = $this->claimFactory->create($name, $value); } diff --git a/src/Parsing/Decoder.php b/src/Parsing/Decoder.php index dffee87d..854ac9ee 100644 --- a/src/Parsing/Decoder.php +++ b/src/Parsing/Decoder.php @@ -36,6 +36,10 @@ public function jsonDecode($json) throw new RuntimeException('Error while decoding to JSON: ' . json_last_error_msg()); } + if (!is_array($data)) { + throw new RuntimeException('The decoded data must be an array'); + } + return $data; } From 590037af6b74de1f76a83f7b1ad58301dce95242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 11:02:06 -0200 Subject: [PATCH 09/22] Introducing a wrapper for validation data. --- src/Claim/EqualsTo.php | 7 +- src/Claim/GreaterOrEqualsTo.php | 7 +- src/Claim/LesserOrEqualsTo.php | 7 +- src/Claim/Validatable.php | 6 +- src/Token.php | 23 +------ src/ValidationData.php | 114 ++++++++++++++++++++++++++++++++ 6 files changed, 133 insertions(+), 31 deletions(-) create mode 100644 src/ValidationData.php diff --git a/src/Claim/EqualsTo.php b/src/Claim/EqualsTo.php index 55b798b0..071b74ae 100644 --- a/src/Claim/EqualsTo.php +++ b/src/Claim/EqualsTo.php @@ -8,6 +8,7 @@ namespace Lcobucci\JWT\Claim; use Lcobucci\JWT\Claim; +use Lcobucci\JWT\ValidationData; /** * Validatable claim that checks if value is strictly equals to the given data @@ -20,10 +21,10 @@ class EqualsTo extends Basic implements Claim, Validatable /** * {@inheritdoc} */ - public function validate(array $data) + public function validate(ValidationData $data) { - if (isset($data[$this->getName()])) { - return $this->getValue() === $data[$this->getName()]; + if ($data->has($this->getName())) { + return $this->getValue() === $data->get($this->getName()); } return true; diff --git a/src/Claim/GreaterOrEqualsTo.php b/src/Claim/GreaterOrEqualsTo.php index 37ff9696..0a4c2466 100644 --- a/src/Claim/GreaterOrEqualsTo.php +++ b/src/Claim/GreaterOrEqualsTo.php @@ -8,6 +8,7 @@ namespace Lcobucci\JWT\Claim; use Lcobucci\JWT\Claim; +use Lcobucci\JWT\ValidationData; /** * Validatable claim that checks if value is greater or equals the given data @@ -20,10 +21,10 @@ class GreaterOrEqualsTo extends Basic implements Claim, Validatable /** * {@inheritdoc} */ - public function validate(array $data) + public function validate(ValidationData $data) { - if (isset($data[$this->getName()])) { - return $this->getValue() >= $data[$this->getName()]; + if ($data->has($this->getName())) { + return $this->getValue() >= $data->get($this->getName()); } return true; diff --git a/src/Claim/LesserOrEqualsTo.php b/src/Claim/LesserOrEqualsTo.php index 28f87727..3d89ccf7 100644 --- a/src/Claim/LesserOrEqualsTo.php +++ b/src/Claim/LesserOrEqualsTo.php @@ -8,6 +8,7 @@ namespace Lcobucci\JWT\Claim; use Lcobucci\JWT\Claim; +use Lcobucci\JWT\ValidationData; /** * Validatable claim that checks if value is lesser or equals to the given data @@ -20,10 +21,10 @@ class LesserOrEqualsTo extends Basic implements Claim, Validatable /** * {@inheritdoc} */ - public function validate(array $data) + public function validate(ValidationData $data) { - if (isset($data[$this->getName()])) { - return $this->getValue() <= $data[$this->getName()]; + if ($data->has($this->getName())) { + return $this->getValue() <= $data->get($this->getName()); } return true; diff --git a/src/Claim/Validatable.php b/src/Claim/Validatable.php index 80b7bfe0..0e49cf22 100644 --- a/src/Claim/Validatable.php +++ b/src/Claim/Validatable.php @@ -7,6 +7,8 @@ namespace Lcobucci\JWT\Claim; +use Lcobucci\JWT\ValidationData; + /** * Basic interface for validatable token claims * @@ -18,9 +20,9 @@ interface Validatable /** * Returns if claim is valid according with given data * - * @param array $data + * @param ValidationData $data * * @return boolean */ - public function validate(array $data); + public function validate(ValidationData $data); } diff --git a/src/Token.php b/src/Token.php index 3089222b..8cdab60d 100644 --- a/src/Token.php +++ b/src/Token.php @@ -125,29 +125,12 @@ public function verify($key) /** * Validates if the token is valid * - * @param string $issuer - * @param string $audience - * @param string $subject - * @param int $currentTime + * @param ValidationData $data * * @return boolean */ - public function validate( - $issuer = null, - $audience = null, - $subject = null, - $currentTime = null - ) { - $currentTime = $currentTime ?: time(); - $data = [ - 'iss' => $issuer, - 'aud' => $audience, - 'sub' => $subject, - 'iat' => $currentTime, - 'nbf' => $currentTime, - 'exp' => $currentTime - ]; - + public function validate(ValidationData $data) + { foreach ($this->getValidatableClaims() as $claim) { if (!$claim->validate($data)) { return false; diff --git a/src/ValidationData.php b/src/ValidationData.php new file mode 100644 index 00000000..94fb93d2 --- /dev/null +++ b/src/ValidationData.php @@ -0,0 +1,114 @@ + + * @since 2.0.0 + */ +class ValidationData +{ + /** + * The list of things to be validated + * + * @var array + */ + private $items; + + /** + * Initializes the object + * + * @param string $currentTime + */ + public function __construct($currentTime = null) + { + $currentTime = $currentTime ?: time(); + + $this->items = [ + 'jti' => null, + 'iss' => null, + 'aud' => null, + 'sub' => null, + 'iat' => $currentTime, + 'nbf' => $currentTime, + 'exp' => $currentTime + ]; + } + + /** + * Configures the id + * + * @param string $id + */ + public function setId($id) + { + $this->items['jti'] = $id; + } + + /** + * Configures the issuer + * + * @param string $issuer + */ + public function setIssuer($issuer) + { + $this->items['iss'] = $issuer; + } + + /** + * @param string $audience + */ + public function setAudience($audience) + { + $this->items['aud'] = $audience; + } + + /** + * @param string $subject + */ + public function setSubject($subject) + { + $this->items['sub'] = $subject; + } + + /** + * @param int $subject + */ + public function setCurrentTime($currentTime) + { + $this->items['iat'] = $currentTime; + $this->items['nbf'] = $currentTime; + $this->items['exp'] = $currentTime; + } + + /** + * Returns the requested item + * + * @param string $name + * + * @return mixed + */ + public function get($name) + { + return isset($this->items[$name]) ? $this->items[$name] : null; + } + + /** + * Returns if the item is present + * + * @param string $name + * + * @return boolean + */ + public function has($name) + { + return !empty($this->items[$name]); + } +} From c24ad134c25f71a5251e3b154578e773f2c3615e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 11:06:31 -0200 Subject: [PATCH 10/22] Removing "Test" namespace. --- composer.json | 3 +-- composer.lock | 2 +- test/BuilderTest.php | 5 +---- test/ParserTest.php | 7 ++----- test/Parsing/DecoderTest.php | 4 +--- test/Parsing/EncoderTest.php | 4 +--- test/SignatureTest.php | 5 +---- test/Signer/BaseSignerTest.php | 3 +-- test/Signer/FactoryTest.php | 7 +------ test/Signer/HmacTest.php | 4 +--- test/Signer/Sha256Test.php | 4 +--- test/Signer/Sha384Test.php | 4 +--- test/Signer/Sha512Test.php | 4 +--- test/TokenTest.php | 4 +--- 14 files changed, 15 insertions(+), 45 deletions(-) diff --git a/composer.json b/composer.json index 5606ea3c..9ffd4457 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,7 @@ }, "autoload" : { "psr-4" : { - "Lcobucci\\JWT\\" : "src", - "Lcobucci\\JWT\\Test\\" : "test" + "Lcobucci\\JWT\\" : ["src", "test"] } } } diff --git a/composer.lock b/composer.lock index d7c608a2..6f8a7b84 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "29c0f955303ff1339c0de6fb8776b101", + "hash": "a631bbb387d91587e2e34654e2ce7aea", "packages": [], "packages-dev": [ { diff --git a/test/BuilderTest.php b/test/BuilderTest.php index 4ebf697e..4d3ba730 100644 --- a/test/BuilderTest.php +++ b/test/BuilderTest.php @@ -5,12 +5,9 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Test; +namespace Lcobucci\JWT; use Lcobucci\JWT\Parsing\Encoder; -use Lcobucci\JWT\Builder; -use Lcobucci\JWT\Signer; -use Lcobucci\JWT\Signature; /** * @author Luís Otávio Cobucci Oblonczyk diff --git a/test/ParserTest.php b/test/ParserTest.php index f28f3705..27ee2420 100644 --- a/test/ParserTest.php +++ b/test/ParserTest.php @@ -5,15 +5,12 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Test; +namespace Lcobucci\JWT; -use Lcobucci\JWT\Parser; use Lcobucci\JWT\Parsing\Decoder; use Lcobucci\JWT\Parsing\Encoder; -use RuntimeException; use Lcobucci\JWT\Signer\Factory; -use Lcobucci\JWT\Signer; -use Lcobucci\JWT\Signature; +use RuntimeException; /** * @author Luís Otávio Cobucci Oblonczyk diff --git a/test/Parsing/DecoderTest.php b/test/Parsing/DecoderTest.php index 8cf0d513..dcf7b27a 100644 --- a/test/Parsing/DecoderTest.php +++ b/test/Parsing/DecoderTest.php @@ -5,9 +5,7 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Test\Parsing; - -use Lcobucci\JWT\Parsing\Decoder; +namespace Lcobucci\JWT\Parsing; /** * @author Luís Otávio Cobucci Oblonczyk diff --git a/test/Parsing/EncoderTest.php b/test/Parsing/EncoderTest.php index f0cf6cb2..463bdedd 100644 --- a/test/Parsing/EncoderTest.php +++ b/test/Parsing/EncoderTest.php @@ -5,9 +5,7 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Test\Parsing; - -use Lcobucci\JWT\Parsing\Encoder; +namespace Lcobucci\JWT\Parsing; /** * @author Luís Otávio Cobucci Oblonczyk diff --git a/test/SignatureTest.php b/test/SignatureTest.php index dbef9e4e..3aacd1a1 100644 --- a/test/SignatureTest.php +++ b/test/SignatureTest.php @@ -5,10 +5,7 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Test; - -use Lcobucci\JWT\Signer; -use Lcobucci\JWT\Signature; +namespace Lcobucci\JWT; /** * @author Luís Otávio Cobucci Oblonczyk diff --git a/test/Signer/BaseSignerTest.php b/test/Signer/BaseSignerTest.php index 3dc32f68..e26ced4d 100644 --- a/test/Signer/BaseSignerTest.php +++ b/test/Signer/BaseSignerTest.php @@ -5,9 +5,8 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Test\Signer; +namespace Lcobucci\JWT\Signer; -use Lcobucci\JWT\Signer\BaseSigner; use Lcobucci\JWT\Signature; /** diff --git a/test/Signer/FactoryTest.php b/test/Signer/FactoryTest.php index af3bf553..ccd406e3 100644 --- a/test/Signer/FactoryTest.php +++ b/test/Signer/FactoryTest.php @@ -5,12 +5,7 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Test\Signer; - -use Lcobucci\JWT\Signer\Factory; -use Lcobucci\JWT\Signer\Sha256; -use Lcobucci\JWT\Signer\Sha384; -use Lcobucci\JWT\Signer\Sha512; +namespace Lcobucci\JWT\Signer; /** * @author Luís Otávio Cobucci Oblonczyk diff --git a/test/Signer/HmacTest.php b/test/Signer/HmacTest.php index 0ff43dc7..c519db49 100644 --- a/test/Signer/HmacTest.php +++ b/test/Signer/HmacTest.php @@ -5,9 +5,7 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Test\Signer; - -use Lcobucci\JWT\Signer\Hmac; +namespace Lcobucci\JWT\Signer; /** * @author Luís Otávio Cobucci Oblonczyk diff --git a/test/Signer/Sha256Test.php b/test/Signer/Sha256Test.php index 6fdeeb16..62940bb1 100644 --- a/test/Signer/Sha256Test.php +++ b/test/Signer/Sha256Test.php @@ -5,9 +5,7 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Test\Signer; - -use Lcobucci\JWT\Signer\Sha256; +namespace Lcobucci\JWT\Signer; /** * @author Luís Otávio Cobucci Oblonczyk diff --git a/test/Signer/Sha384Test.php b/test/Signer/Sha384Test.php index 9eddd083..2c57be23 100644 --- a/test/Signer/Sha384Test.php +++ b/test/Signer/Sha384Test.php @@ -5,9 +5,7 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Test\Signer; - -use Lcobucci\JWT\Signer\Sha384; +namespace Lcobucci\JWT\Signer; /** * @author Luís Otávio Cobucci Oblonczyk diff --git a/test/Signer/Sha512Test.php b/test/Signer/Sha512Test.php index 571f2193..98522c7f 100644 --- a/test/Signer/Sha512Test.php +++ b/test/Signer/Sha512Test.php @@ -5,9 +5,7 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Test\Signer; - -use Lcobucci\JWT\Signer\Sha512; +namespace Lcobucci\JWT\Signer; /** * @author Luís Otávio Cobucci Oblonczyk diff --git a/test/TokenTest.php b/test/TokenTest.php index 7da3ccc4..e93f58a7 100644 --- a/test/TokenTest.php +++ b/test/TokenTest.php @@ -5,11 +5,9 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Test; +namespace Lcobucci\JWT; use Lcobucci\JWT\Parsing\Encoder; -use Lcobucci\JWT\Signature; -use Lcobucci\JWT\Token; /** * @author Luís Otávio Cobucci Oblonczyk From 53f04f02ab06d91df78e7ac19afbaca8d20cc44d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 11:08:35 -0200 Subject: [PATCH 11/22] Improving Decoder coverage. --- test/Parsing/DecoderTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/Parsing/DecoderTest.php b/test/Parsing/DecoderTest.php index dcf7b27a..7c163ff7 100644 --- a/test/Parsing/DecoderTest.php +++ b/test/Parsing/DecoderTest.php @@ -26,6 +26,19 @@ public function jsonDecodeMustReturnTheDecodedData() $this->assertEquals(['test' => 'test'], $decoder->jsonDecode('{"test":"test"}')); } + /** + * @test + * @covers ::jsonDecode + * + * @expectedException \RuntimeException + */ + public function jsonDecodeMustRaiseExceptionWhenResultIsNotAnArray() + { + $decoder = new Decoder(); + + $decoder->jsonDecode('"test"'); + } + /** * @test * @covers ::jsonDecode From 2f94ba452e7831d247f0ceb5dcf01175b45b4143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 11:25:39 -0200 Subject: [PATCH 12/22] Fixing Parser tests. --- test/ParserTest.php | 134 ++++++++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 62 deletions(-) diff --git a/test/ParserTest.php b/test/ParserTest.php index 27ee2420..7b29398d 100644 --- a/test/ParserTest.php +++ b/test/ParserTest.php @@ -9,7 +9,8 @@ use Lcobucci\JWT\Parsing\Decoder; use Lcobucci\JWT\Parsing\Encoder; -use Lcobucci\JWT\Signer\Factory; +use Lcobucci\JWT\Claim\Factory as ClaimFactory; +use Lcobucci\JWT\Signer\Factory as SignerFactory; use RuntimeException; /** @@ -31,26 +32,47 @@ class ParserTest extends \PHPUnit_Framework_TestCase protected $decoder; /** - * @var Factory|\PHPUnit_Framework_MockObject_MockObject + * @var SignerFactory|\PHPUnit_Framework_MockObject_MockObject */ - protected $factory; + protected $signerFactory; + + /** + * @var ClaimFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $claimFactory; + + /** + * @var Claim|\PHPUnit_Framework_MockObject_MockObject + */ + protected $defaultClaim; /** * {@inheritdoc} */ protected function setUp() { - $this->encoder = $this->getMockBuilder(Encoder::class) - ->setMockClassName('EncoderMock') - ->getMock(); - - $this->decoder = $this->getMockBuilder(Decoder::class) - ->setMockClassName('DecoderMock') - ->getMock(); + $this->encoder = $this->getMock(Encoder::class); + $this->decoder = $this->getMock(Decoder::class); + $this->signerFactory = $this->getMock(SignerFactory::class); + $this->claimFactory = $this->getMock(ClaimFactory::class, [], [], '', false); + $this->defaultClaim = $this->getMock(Claim::class); + + $this->claimFactory->expects($this->any()) + ->method('create') + ->willReturn($this->defaultClaim); + } - $this->factory = $this->getMockBuilder(Factory::class) - ->setMockClassName('FactoryMock') - ->getMock(); + /** + * @return Parser + */ + private function createParser() + { + return new Parser( + $this->encoder, + $this->decoder, + $this->signerFactory, + $this->claimFactory + ); } /** @@ -59,11 +81,12 @@ protected function setUp() */ public function constructMustConfigureTheAttributes() { - $parser = new Parser($this->encoder, $this->decoder, $this->factory); + $parser = $this->createParser(); $this->assertAttributeSame($this->encoder, 'encoder', $parser); $this->assertAttributeSame($this->decoder, 'decoder', $parser); - $this->assertAttributeSame($this->factory, 'factory', $parser); + $this->assertAttributeSame($this->signerFactory, 'signerFactory', $parser); + $this->assertAttributeSame($this->claimFactory, 'claimFactory', $parser); } /** @@ -76,8 +99,7 @@ public function constructMustConfigureTheAttributes() */ public function parseMustRaiseExceptionWhenJWSIsNotAString() { - $parser = new Parser($this->encoder, $this->decoder, $this->factory); - + $parser = $this->createParser(); $parser->parse(['asdasd']); } @@ -91,8 +113,7 @@ public function parseMustRaiseExceptionWhenJWSIsNotAString() */ public function parseMustRaiseExceptionWhenJWSDontHaveThreeParts() { - $parser = new Parser($this->encoder, $this->decoder, $this->factory); - + $parser = $this->createParser(); $parser->parse(''); } @@ -101,6 +122,7 @@ public function parseMustRaiseExceptionWhenJWSDontHaveThreeParts() * @covers ::__construct * @covers ::parse * @covers ::splitJwt + * @covers ::createToken * @covers ::parseHeader * * @expectedException RuntimeException @@ -111,8 +133,7 @@ public function parseMustRaiseExceptionWhenHeaderCannotBeDecoded() ->method('jsonDecode') ->willThrowException(new RuntimeException()); - $parser = new Parser($this->encoder, $this->decoder, $this->factory); - + $parser = $this->createParser(); $parser->parse('asdfad.asdfasdf.'); } @@ -121,26 +142,7 @@ public function parseMustRaiseExceptionWhenHeaderCannotBeDecoded() * @covers ::__construct * @covers ::parse * @covers ::splitJwt - * @covers ::parseHeader - * - * @expectedException InvalidArgumentException - */ - public function parseMustRaiseExceptionWhenHeaderIsNotAnArray() - { - $this->decoder->expects($this->any()) - ->method('jsonDecode') - ->willReturn('asdfasdfasd'); - - $parser = new Parser($this->encoder, $this->decoder, $this->factory); - - $parser->parse('a.a.'); - } - - /** - * @test - * @covers ::__construct - * @covers ::parse - * @covers ::splitJwt + * @covers ::createToken * @covers ::parseHeader * * @expectedException InvalidArgumentException @@ -151,8 +153,7 @@ public function parseMustRaiseExceptionWhenHeaderIsFromAnEncryptedToken() ->method('jsonDecode') ->willReturn(['enc' => 'AAA']); - $parser = new Parser($this->encoder, $this->decoder, $this->factory); - + $parser = $this->createParser(); $parser->parse('a.a.'); } @@ -161,12 +162,14 @@ public function parseMustRaiseExceptionWhenHeaderIsFromAnEncryptedToken() * @covers ::__construct * @covers ::parse * @covers ::splitJwt + * @covers ::createToken * @covers ::parseHeader * @covers ::parseClaims - * - * @expectedException InvalidArgumentException + * @covers ::parseSignature + * @covers Lcobucci\JWT\Token::__construct + * @covers Lcobucci\JWT\Token::setEncoder */ - public function parseMustRaiseExceptionWhenClaimSetIsNotAnArray() + public function parseMustReturnANonSignedTokenWhenSignatureIsNotInformed() { $this->decoder->expects($this->at(1)) ->method('jsonDecode') @@ -174,11 +177,15 @@ public function parseMustRaiseExceptionWhenClaimSetIsNotAnArray() $this->decoder->expects($this->at(3)) ->method('jsonDecode') - ->willReturn('asdfasdfasd'); + ->willReturn(['aud' => 'test']); - $parser = new Parser($this->encoder, $this->decoder, $this->factory); + $parser = $this->createParser(); + $token = $parser->parse('a.a.'); - $parser->parse('a.a.'); + $this->assertAttributeEquals(['typ' => 'JWT', 'alg' => 'none'], 'header', $token); + $this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $token); + $this->assertAttributeEquals(null, 'signature', $token); + $this->assertAttributeSame($this->encoder, 'encoder', $token); } /** @@ -186,28 +193,33 @@ public function parseMustRaiseExceptionWhenClaimSetIsNotAnArray() * @covers ::__construct * @covers ::parse * @covers ::splitJwt + * @covers ::createToken * @covers ::parseHeader * @covers ::parseClaims * @covers ::parseSignature * @covers Lcobucci\JWT\Token::__construct * @covers Lcobucci\JWT\Token::setEncoder */ - public function parseMustReturnANonSignedTokenWhenSignatureIsNotInformed() + public function parseShouldReplicateClaimValueOnHeaderWhenNeeded() { $this->decoder->expects($this->at(1)) ->method('jsonDecode') - ->willReturn(['typ' => 'JWT', 'alg' => 'none']); + ->willReturn(['typ' => 'JWT', 'alg' => 'none', 'aud' => 'test']); $this->decoder->expects($this->at(3)) ->method('jsonDecode') ->willReturn(['aud' => 'test']); - $parser = new Parser($this->encoder, $this->decoder, $this->factory); - + $parser = $this->createParser(); $token = $parser->parse('a.a.'); - $this->assertAttributeEquals(['typ' => 'JWT', 'alg' => 'none'], 'header', $token); - $this->assertAttributeEquals(['aud' => 'test'], 'claims', $token); + $this->assertAttributeEquals( + ['typ' => 'JWT', 'alg' => 'none', 'aud' => $this->defaultClaim], + 'header', + $token + ); + + $this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $token); $this->assertAttributeEquals(null, 'signature', $token); $this->assertAttributeSame($this->encoder, 'encoder', $token); } @@ -217,6 +229,7 @@ public function parseMustReturnANonSignedTokenWhenSignatureIsNotInformed() * @covers ::__construct * @covers ::parse * @covers ::splitJwt + * @covers ::createToken * @covers ::parseHeader * @covers ::parseClaims * @covers ::parseSignature @@ -226,9 +239,7 @@ public function parseMustReturnANonSignedTokenWhenSignatureIsNotInformed() */ public function parseMustReturnASignedTokenWhenSignatureIsInformed() { - $signer = $this->getMockBuilder(Signer::class) - ->setMockClassName('SignerMock') - ->getMock(); + $signer = $this->getMock(Signer::class); $this->decoder->expects($this->at(1)) ->method('jsonDecode') @@ -242,16 +253,15 @@ public function parseMustReturnASignedTokenWhenSignatureIsInformed() ->method('base64UrlDecode') ->willReturn('aaa'); - $this->factory->expects($this->any()) + $this->signerFactory->expects($this->any()) ->method('create') ->willReturn($signer); - $parser = new Parser($this->encoder, $this->decoder, $this->factory); - + $parser = $this->createParser(); $token = $parser->parse('a.a.a'); $this->assertAttributeEquals(['typ' => 'JWT', 'alg' => 'HS256'], 'header', $token); - $this->assertAttributeEquals(['aud' => 'test'], 'claims', $token); + $this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $token); $this->assertAttributeEquals(new Signature($signer, 'aaa'), 'signature', $token); $this->assertAttributeSame($this->encoder, 'encoder', $token); } From 15318c676dd9d25e3964a144e260889ce03f310c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 11:27:16 -0200 Subject: [PATCH 13/22] Simplifying README. --- README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3b56b36a..861c3684 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@ # JWT -master [![Build Status](https://secure.travis-ci.org/lcobucci/jwt.png?branch=master)](http://travis-ci.org/#!/lcobucci/jwt) -develop [![Build Status](https://secure.travis-ci.org/lcobucci/jwt.png?branch=develop)](http://travis-ci.org/#!/lcobucci/jwt) - -master [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=master) -develop [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=develop) - -master [![Code Coverage](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=master) -develop [![Code Coverage](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=develop) +master +[![Build Status](https://secure.travis-ci.org/lcobucci/jwt.png?branch=master)](http://travis-ci.org/#!/lcobucci/jwt) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=master) +[![Code Coverage](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=master) + +develop +[![Build Status](https://secure.travis-ci.org/lcobucci/jwt.png?branch=develop)](http://travis-ci.org/#!/lcobucci/jwt) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/quality-score.png?b=develop)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=develop) +[![Code Coverage](https://scrutinizer-ci.com/g/lcobucci/jwt/badges/coverage.png?b=develop)](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=develop) [![Total Downloads](https://poser.pugx.org/lcobucci/jwt/downloads.png)](https://packagist.org/packages/lcobucci/jwt) [![Latest Stable Version](https://poser.pugx.org/lcobucci/jwt/v/stable.png)](https://packagist.org/packages/lcobucci/jwt) From 5821d601aa06003ca04326d7603c7c68c6ed9aef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 11:42:25 -0200 Subject: [PATCH 14/22] Fixing token test. --- test/TokenTest.php | 109 ++++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 51 deletions(-) diff --git a/test/TokenTest.php b/test/TokenTest.php index e93f58a7..8a22b36c 100644 --- a/test/TokenTest.php +++ b/test/TokenTest.php @@ -8,6 +8,10 @@ namespace Lcobucci\JWT; use Lcobucci\JWT\Parsing\Encoder; +use Lcobucci\JWT\Claim\Basic; +use Lcobucci\JWT\Claim\EqualsTo; +use Lcobucci\JWT\Claim\GreaterOrEqualsTo; +use Lcobucci\JWT\Claim\LesserOrEqualsTo; /** * @author Luís Otávio Cobucci Oblonczyk @@ -140,95 +144,98 @@ public function verifyMustDelegateTheValidationToSignature() * @test * @covers ::__construct * @covers ::validate + * @covers ::getValidatableClaims + * @covers Lcobucci\JWT\ValidationData::__construct */ public function validateShouldReturnTrueWhenClaimsAreEmpty() { $token = new Token(); - $this->assertTrue($token->validate()); + $this->assertTrue($token->validate(new ValidationData())); } /** * @test * @covers ::__construct * @covers ::validate + * @covers ::getValidatableClaims + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\Claim\Basic::__construct */ - public function validateShouldReturnFalseWhenIssuerIsDiferentThanTheGivenOne() + public function validateShouldReturnTrueWhenThereAreNoValidatableClaims() { - $token = new Token([], ['iss' => 'test']); + $token = new Token([], ['testing' => new Basic('testing', 'test')]); - $this->assertFalse($token->validate('test1')); + $this->assertTrue($token->validate(new ValidationData())); } /** * @test * @covers ::__construct * @covers ::validate + * @covers ::getValidatableClaims + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::get + * @covers Lcobucci\JWT\ValidationData::has + * @covers Lcobucci\JWT\ValidationData::setIssuer + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\Claim\Basic::getValue + * @covers Lcobucci\JWT\Claim\EqualsTo::__construct + * @covers Lcobucci\JWT\Claim\EqualsTo::validate */ - public function validateShouldReturnFalseWhenAudienceIsDiferentThanTheGivenOne() + public function validateShouldReturnFalseWhenThereIsAtLeastOneFailedValidatableClaim() { - $token = new Token([], ['aud' => 'test']); - - $this->assertFalse($token->validate(null, 'test1')); - } - - /** - * @test - * @covers ::__construct - * @covers ::validate - */ - public function validateShouldReturnFalseWhenSubjectIsDiferentThanTheGivenOne() - { - $token = new Token([], ['sub' => 'test']); - - $this->assertFalse($token->validate(null, null, 'test1')); - } - - /** - * @test - * @covers ::__construct - * @covers ::validate - */ - public function validateShouldReturnFalseWhenTokenCannotYetBeUsed() - { - $token = new Token([], ['nbf' => strtotime('+2 hours')]); - - $this->assertFalse($token->validate(null, null, null, time())); - } + $token = new Token( + [], + [ + 'iss' => new EqualsTo('iss', 'test'), + 'testing' => new Basic('testing', 'test') + ] + ); - /** - * @test - * @covers ::__construct - * @covers ::validate - */ - public function validateShouldReturnFalseWhenTokenIsExpired() - { - $token = new Token([], ['exp' => time()]); + $data = new ValidationData(); + $data->setIssuer('test1'); - $this->assertFalse($token->validate(null, null, null, strtotime('+2 hours'))); + $this->assertFalse($token->validate($data)); } /** * @test * @covers ::__construct * @covers ::validate + * @covers ::getValidatableClaims + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::get + * @covers Lcobucci\JWT\ValidationData::has + * @covers Lcobucci\JWT\ValidationData::setIssuer + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\Claim\Basic::getValue + * @covers Lcobucci\JWT\Claim\EqualsTo::__construct + * @covers Lcobucci\JWT\Claim\EqualsTo::validate + * @covers Lcobucci\JWT\Claim\LesserOrEqualsTo::__construct + * @covers Lcobucci\JWT\Claim\LesserOrEqualsTo::validate + * @covers Lcobucci\JWT\Claim\GreaterOrEqualsTo::__construct + * @covers Lcobucci\JWT\Claim\GreaterOrEqualsTo::validate */ - public function validateShouldReturnTrueWhenAllInformationsAreRight() + public function validateShouldReturnTrueWhenThereAreNoFailedValidatableClaims() { + $now = time(); $token = new Token( [], [ - 'iss' => 'test0', - 'aud' => 'test1', - 'sub' => 'test2', - 'nbf' => time(), - 'exp' => strtotime('+3 hours') + 'iss' => new EqualsTo('iss', 'test'), + 'iat' => new LesserOrEqualsTo('iat', $now), + 'exp' => new GreaterOrEqualsTo('ext', $now + 500), + 'testing' => new Basic('testing', 'test') ] ); - $this->assertTrue( - $token->validate('test0', 'test1', 'test2', strtotime('+1 hours')) - ); + $data = new ValidationData($now + 10); + $data->setIssuer('test'); + + $this->assertTrue($token->validate($data)); } /** From 992d952e01ca3958a07a4683bb776ea68e072271 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 11:48:39 -0200 Subject: [PATCH 15/22] Fixing Builder tests. --- test/BuilderTest.php | 130 +++++++++++++++++++++++++------------------ test/ParserTest.php | 2 +- 2 files changed, 78 insertions(+), 54 deletions(-) diff --git a/test/BuilderTest.php b/test/BuilderTest.php index 4d3ba730..d56d10d3 100644 --- a/test/BuilderTest.php +++ b/test/BuilderTest.php @@ -7,6 +7,7 @@ namespace Lcobucci\JWT; +use Lcobucci\JWT\Claim\Factory as ClaimFactory; use Lcobucci\JWT\Parsing\Encoder; /** @@ -22,14 +23,36 @@ class BuilderTest extends \PHPUnit_Framework_TestCase */ protected $encoder; + /** + * @var ClaimFactory|\PHPUnit_Framework_MockObject_MockObject + */ + protected $claimFactory; + + /** + * @var Claim|\PHPUnit_Framework_MockObject_MockObject + */ + protected $defaultClaim; + /** * {@inheritdoc} */ protected function setUp() { - $this->encoder = $this->getMockBuilder(Encoder::class) - ->setMockClassName('EncoderMock') - ->getMock(); + $this->encoder = $this->getMock(Encoder::class); + $this->claimFactory = $this->getMock(ClaimFactory::class, [], [], '', false); + $this->defaultClaim = $this->getMock(Claim::class); + + $this->claimFactory->expects($this->any()) + ->method('create') + ->willReturn($this->defaultClaim); + } + + /** + * @return Builder + */ + private function createBuilder() + { + return new Builder($this->encoder, $this->claimFactory); } /** @@ -38,12 +61,13 @@ protected function setUp() */ public function constructMustInitializeTheAttributes() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'header', $builder); $this->assertAttributeEquals([], 'claims', $builder); $this->assertAttributeEquals(null, 'signature', $builder); $this->assertAttributeSame($this->encoder, 'encoder', $builder); + $this->assertAttributeSame($this->claimFactory, 'claimFactory', $builder); } /** @@ -55,11 +79,11 @@ public function constructMustInitializeTheAttributes() */ public function setAudienceMustChangeTheAudClaim() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setAudience('test'); $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'header', $builder); - $this->assertAttributeEquals(['aud' => 'test'], 'claims', $builder); + $this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $builder); } /** @@ -71,11 +95,11 @@ public function setAudienceMustChangeTheAudClaim() */ public function setAudienceCanReplicateItemOnHeader() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setAudience('test', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'aud' => 'test'], 'header', $builder); - $this->assertAttributeEquals(['aud' => 'test'], 'claims', $builder); + $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'aud' => $this->defaultClaim], 'header', $builder); + $this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $builder); } /** @@ -87,7 +111,7 @@ public function setAudienceCanReplicateItemOnHeader() */ public function setAudienceMustKeepAFluentInterface() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $this->assertSame($builder, $builder->setAudience('test')); } @@ -101,11 +125,11 @@ public function setAudienceMustKeepAFluentInterface() */ public function setExpirationMustChangeTheExpClaim() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setExpiration('2'); $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'header', $builder); - $this->assertAttributeEquals(['exp' => 2], 'claims', $builder); + $this->assertAttributeEquals(['exp' => $this->defaultClaim], 'claims', $builder); } /** @@ -117,11 +141,11 @@ public function setExpirationMustChangeTheExpClaim() */ public function setExpirationCanReplicateItemOnHeader() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setExpiration('2', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'exp' => 2], 'header', $builder); - $this->assertAttributeEquals(['exp' => 2], 'claims', $builder); + $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'exp' => $this->defaultClaim], 'header', $builder); + $this->assertAttributeEquals(['exp' => $this->defaultClaim], 'claims', $builder); } /** @@ -133,7 +157,7 @@ public function setExpirationCanReplicateItemOnHeader() */ public function setExpirationMustKeepAFluentInterface() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $this->assertSame($builder, $builder->setExpiration('2')); } @@ -147,11 +171,11 @@ public function setExpirationMustKeepAFluentInterface() */ public function setIdMustChangeTheJtiClaim() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setId('2'); $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'header', $builder); - $this->assertAttributeEquals(['jti' => '2'], 'claims', $builder); + $this->assertAttributeEquals(['jti' => $this->defaultClaim], 'claims', $builder); } /** @@ -163,11 +187,11 @@ public function setIdMustChangeTheJtiClaim() */ public function setIdCanReplicateItemOnHeader() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setId('2', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'jti' => '2'], 'header', $builder); - $this->assertAttributeEquals(['jti' => '2'], 'claims', $builder); + $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'jti' => $this->defaultClaim], 'header', $builder); + $this->assertAttributeEquals(['jti' => $this->defaultClaim], 'claims', $builder); } /** @@ -179,7 +203,7 @@ public function setIdCanReplicateItemOnHeader() */ public function setIdMustKeepAFluentInterface() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $this->assertSame($builder, $builder->setId('2')); } @@ -193,11 +217,11 @@ public function setIdMustKeepAFluentInterface() */ public function setIssueAtMustChangeTheIatClaim() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setIssueAt('2'); $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'header', $builder); - $this->assertAttributeEquals(['iat' => 2], 'claims', $builder); + $this->assertAttributeEquals(['iat' => $this->defaultClaim], 'claims', $builder); } /** @@ -209,11 +233,11 @@ public function setIssueAtMustChangeTheIatClaim() */ public function setIssueAtCanReplicateItemOnHeader() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setIssueAt('2', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'iat' => 2], 'header', $builder); - $this->assertAttributeEquals(['iat' => 2], 'claims', $builder); + $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'iat' => $this->defaultClaim], 'header', $builder); + $this->assertAttributeEquals(['iat' => $this->defaultClaim], 'claims', $builder); } /** @@ -225,7 +249,7 @@ public function setIssueAtCanReplicateItemOnHeader() */ public function setIssueAtMustKeepAFluentInterface() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $this->assertSame($builder, $builder->setIssueAt('2')); } @@ -239,11 +263,11 @@ public function setIssueAtMustKeepAFluentInterface() */ public function setIssuerMustChangeTheIssClaim() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setIssuer('2'); $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'header', $builder); - $this->assertAttributeEquals(['iss' => '2'], 'claims', $builder); + $this->assertAttributeEquals(['iss' => $this->defaultClaim], 'claims', $builder); } /** @@ -255,11 +279,11 @@ public function setIssuerMustChangeTheIssClaim() */ public function setIssuerCanReplicateItemOnHeader() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setIssuer('2', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'iss' => '2'], 'header', $builder); - $this->assertAttributeEquals(['iss' => '2'], 'claims', $builder); + $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'iss' => $this->defaultClaim], 'header', $builder); + $this->assertAttributeEquals(['iss' => $this->defaultClaim], 'claims', $builder); } /** @@ -271,7 +295,7 @@ public function setIssuerCanReplicateItemOnHeader() */ public function setIssuerMustKeepAFluentInterface() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $this->assertSame($builder, $builder->setIssuer('2')); } @@ -285,11 +309,11 @@ public function setIssuerMustKeepAFluentInterface() */ public function setNotBeforeMustChangeTheNbfClaim() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setNotBefore('2'); $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'header', $builder); - $this->assertAttributeEquals(['nbf' => 2], 'claims', $builder); + $this->assertAttributeEquals(['nbf' => $this->defaultClaim], 'claims', $builder); } /** @@ -301,11 +325,11 @@ public function setNotBeforeMustChangeTheNbfClaim() */ public function setNotBeforeCanReplicateItemOnHeader() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setNotBefore('2', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'nbf' => 2], 'header', $builder); - $this->assertAttributeEquals(['nbf' => 2], 'claims', $builder); + $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'nbf' => $this->defaultClaim], 'header', $builder); + $this->assertAttributeEquals(['nbf' => $this->defaultClaim], 'claims', $builder); } /** @@ -317,7 +341,7 @@ public function setNotBeforeCanReplicateItemOnHeader() */ public function setNotBeforeMustKeepAFluentInterface() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $this->assertSame($builder, $builder->setNotBefore('2')); } @@ -331,11 +355,11 @@ public function setNotBeforeMustKeepAFluentInterface() */ public function setSubjectMustChangeTheSubClaim() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setSubject('2'); $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'header', $builder); - $this->assertAttributeEquals(['sub' => '2'], 'claims', $builder); + $this->assertAttributeEquals(['sub' => $this->defaultClaim], 'claims', $builder); } /** @@ -347,11 +371,11 @@ public function setSubjectMustChangeTheSubClaim() */ public function setSubjectCanReplicateItemOnHeader() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->setSubject('2', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'sub' => '2'], 'header', $builder); - $this->assertAttributeEquals(['sub' => '2'], 'claims', $builder); + $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'sub' => $this->defaultClaim], 'header', $builder); + $this->assertAttributeEquals(['sub' => $this->defaultClaim], 'claims', $builder); } /** @@ -363,7 +387,7 @@ public function setSubjectCanReplicateItemOnHeader() */ public function setSubjectMustKeepAFluentInterface() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $this->assertSame($builder, $builder->setSubject('2')); } @@ -375,10 +399,10 @@ public function setSubjectMustKeepAFluentInterface() */ public function setMustConfigureTheGivenClaim() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->set('userId', 2); - $this->assertAttributeEquals(['userId' => 2], 'claims', $builder); + $this->assertAttributeEquals(['userId' => $this->defaultClaim], 'claims', $builder); } /** @@ -388,7 +412,7 @@ public function setMustConfigureTheGivenClaim() */ public function setMustKeepAFluentInterface() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $this->assertSame($builder, $builder->set('userId', 2)); } @@ -406,7 +430,7 @@ public function setMustKeepAFluentInterface() */ public function getTokenMustReturnANewTokenWithCurrentConfiguration() { - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $token = $builder->set('test', 123)->getToken(); $this->assertAttributeEquals($token->getHeader(), 'header', $builder); @@ -438,7 +462,7 @@ public function signMustChangeTheSignature() ->method('sign') ->willReturn($signature); - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->sign($signer, 'test'); $this->assertAttributeSame($signature, 'signature', $builder); @@ -468,7 +492,7 @@ public function signMustKeepAFluentInterface() ->method('sign') ->willReturn($signature); - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $this->assertSame($builder, $builder->sign($signer, 'test')); @@ -524,7 +548,7 @@ public function setMustRaiseExceptionWhenTokenHasBeenSigned() ->method('sign') ->willReturn($signature); - $builder = new Builder($this->encoder); + $builder = $this->createBuilder(); $builder->sign($signer, 'test'); $builder->set('test', 123); } diff --git a/test/ParserTest.php b/test/ParserTest.php index 7b29398d..2c068246 100644 --- a/test/ParserTest.php +++ b/test/ParserTest.php @@ -7,9 +7,9 @@ namespace Lcobucci\JWT; +use Lcobucci\JWT\Claim\Factory as ClaimFactory; use Lcobucci\JWT\Parsing\Decoder; use Lcobucci\JWT\Parsing\Encoder; -use Lcobucci\JWT\Claim\Factory as ClaimFactory; use Lcobucci\JWT\Signer\Factory as SignerFactory; use RuntimeException; From 67a13273dcef7314a6cf7b0124c55caed8c3454d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 11:55:27 -0200 Subject: [PATCH 16/22] Improving signer factory. --- src/Signer/Factory.php | 58 +++++++++++++++++++++++++++++++------ test/ParserTest.php | 2 +- test/Signer/FactoryTest.php | 7 +++++ 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/Signer/Factory.php b/src/Signer/Factory.php index 8fbec1cd..e18dc644 100644 --- a/src/Signer/Factory.php +++ b/src/Signer/Factory.php @@ -18,6 +18,30 @@ */ class Factory { + /** + * The list of signers callbacks + * + * @var array + */ + private $callbacks; + + /** + * Initializes the factory, registering the default callbacks + * + * @param array $callbacks + */ + public function __construct(array $callbacks = []) + { + $this->callbacks = array_merge( + [ + 'HS256' => [$this, 'createHmacSha256'], + 'HS384' => [$this, 'createHmacSha384'], + 'HS512' => [$this, 'createHmacSha512'] + ], + $callbacks + ); + } + /** * Retrieves a signer instance * @@ -29,18 +53,34 @@ class Factory */ public function create($id) { - if ($id === 'HS256') { - return new Sha256(); + if (isset($this->callbacks[$id])) { + return call_user_func($this->callbacks[$id]); } - if ($id === 'HS384') { - return new Sha384(); - } + throw new InvalidArgumentException('Invalid signer'); + } - if ($id === 'HS512') { - return new Sha512(); - } + /** + * @return Sha256 + */ + private function createHmacSha256() + { + return new Sha256(); + } - throw new InvalidArgumentException('Invalid signer'); + /** + * @return Sha384 + */ + private function createHmacSha384() + { + return new Sha384(); + } + + /** + * @return Sha512 + */ + private function createHmacSha512() + { + return new Sha512(); } } diff --git a/test/ParserTest.php b/test/ParserTest.php index 2c068246..f3538664 100644 --- a/test/ParserTest.php +++ b/test/ParserTest.php @@ -53,7 +53,7 @@ protected function setUp() { $this->encoder = $this->getMock(Encoder::class); $this->decoder = $this->getMock(Decoder::class); - $this->signerFactory = $this->getMock(SignerFactory::class); + $this->signerFactory = $this->getMock(SignerFactory::class, [], [], '', false); $this->claimFactory = $this->getMock(ClaimFactory::class, [], [], '', false); $this->defaultClaim = $this->getMock(Claim::class); diff --git a/test/Signer/FactoryTest.php b/test/Signer/FactoryTest.php index ccd406e3..05563022 100644 --- a/test/Signer/FactoryTest.php +++ b/test/Signer/FactoryTest.php @@ -17,7 +17,9 @@ class FactoryTest extends \PHPUnit_Framework_TestCase { /** * @test + * @covers ::__construct * @covers ::create + * @covers ::createHmacSha256 */ public function createMustBeAbleReturnASha256Signer() { @@ -28,7 +30,9 @@ public function createMustBeAbleReturnASha256Signer() /** * @test + * @covers ::__construct * @covers ::create + * @covers ::createHmacSha384 */ public function createMustBeAbleReturnASha384Signer() { @@ -39,7 +43,9 @@ public function createMustBeAbleReturnASha384Signer() /** * @test + * @covers ::__construct * @covers ::create + * @covers ::createHmacSha512 */ public function createMustBeAbleReturnASha512Signer() { @@ -50,6 +56,7 @@ public function createMustBeAbleReturnASha512Signer() /** * @test + * @covers ::__construct * @covers ::create * * @expectedException InvalidArgumentException From 9d2e23ef769a7a32ad5255243b98dfc7dd1da8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 11:59:43 -0200 Subject: [PATCH 17/22] Mock builder is not needed there. --- test/BuilderTest.php | 30 ++++++------------------------ test/SignatureTest.php | 4 +--- test/Signer/BaseSignerTest.php | 4 +--- test/Signer/HmacTest.php | 4 +--- test/TokenTest.php | 20 ++++---------------- 5 files changed, 13 insertions(+), 49 deletions(-) diff --git a/test/BuilderTest.php b/test/BuilderTest.php index d56d10d3..d0e50160 100644 --- a/test/BuilderTest.php +++ b/test/BuilderTest.php @@ -449,14 +449,8 @@ public function getTokenMustReturnANewTokenWithCurrentConfiguration() */ public function signMustChangeTheSignature() { - $signer = $this->getMockBuilder(Signer::class) - ->setMockClassName('SignerMock') - ->getMock(); - - $signature = $this->getMockBuilder(Signature::class) - ->setMockClassName('SignatureMock') - ->disableOriginalConstructor() - ->getMock(); + $signer = $this->getMock(Signer::class); + $signature = $this->getMock(Signature::class, [], [], '', false); $signer->expects($this->any()) ->method('sign') @@ -479,14 +473,8 @@ public function signMustChangeTheSignature() */ public function signMustKeepAFluentInterface() { - $signer = $this->getMockBuilder(Signer::class) - ->setMockClassName('SignerMock') - ->getMock(); - - $signature = $this->getMockBuilder(Signature::class) - ->setMockClassName('SignatureMock') - ->disableOriginalConstructor() - ->getMock(); + $signer = $this->getMock(Signer::class); + $signature = $this->getMock(Signature::class, [], [], '', false); $signer->expects($this->any()) ->method('sign') @@ -535,14 +523,8 @@ public function unsignMustKeepAFluentInterface(Builder $builder) */ public function setMustRaiseExceptionWhenTokenHasBeenSigned() { - $signer = $this->getMockBuilder(Signer::class) - ->setMockClassName('SignerMock') - ->getMock(); - - $signature = $this->getMockBuilder(Signature::class) - ->setMockClassName('SignatureMock') - ->disableOriginalConstructor() - ->getMock(); + $signer = $this->getMock(Signer::class); + $signature = $this->getMock(Signature::class, [], [], '', false); $signer->expects($this->any()) ->method('sign') diff --git a/test/SignatureTest.php b/test/SignatureTest.php index 3aacd1a1..461dcbce 100644 --- a/test/SignatureTest.php +++ b/test/SignatureTest.php @@ -25,9 +25,7 @@ class SignatureTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->signer = $this->getMockBuilder(Signer::class) - ->setMockClassName('SignerMock') - ->getMock(); + $this->signer = $this->getMock(Signer::class); } /** diff --git a/test/Signer/BaseSignerTest.php b/test/Signer/BaseSignerTest.php index e26ced4d..e890999a 100644 --- a/test/Signer/BaseSignerTest.php +++ b/test/Signer/BaseSignerTest.php @@ -27,9 +27,7 @@ class BaseSignerTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->signer = $this->getMockBuilder(BaseSigner::class) - ->setMockClassName('BaseSignerMock') - ->getMockForAbstractClass(); + $this->signer = $this->getMockForAbstractClass(BaseSigner::class); $this->signer->expects($this->any()) ->method('getAlgorithmId') diff --git a/test/Signer/HmacTest.php b/test/Signer/HmacTest.php index c519db49..ee69572a 100644 --- a/test/Signer/HmacTest.php +++ b/test/Signer/HmacTest.php @@ -25,9 +25,7 @@ class HmacTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->signer = $this->getMockBuilder(Hmac::class) - ->setMockClassName('HmacMock') - ->getMockForAbstractClass(); + $this->signer = $this->getMockForAbstractClass(Hmac::class); $this->signer->expects($this->any()) ->method('getAlgorithmId') diff --git a/test/TokenTest.php b/test/TokenTest.php index 8a22b36c..fb4f9daa 100644 --- a/test/TokenTest.php +++ b/test/TokenTest.php @@ -31,9 +31,7 @@ class TokenTest extends \PHPUnit_Framework_TestCase */ protected function setUp() { - $this->encoder = $this->getMockBuilder(Encoder::class) - ->setMockClassName('EncoderMock') - ->getMock(); + $this->encoder = $this->getMock(Encoder::class); } /** @@ -93,11 +91,7 @@ public function getClaimsMustReturnTheConfiguredClaims() */ public function getSignatureMustReturnTheConfiguredSignature() { - $signature = $this->getMockBuilder(Signature::class) - ->setMockClassName('SignatureMock') - ->disableOriginalConstructor() - ->getMock(); - + $signature = $this->getMock(Signature::class, [], [], '', false); $token = new Token([], [], $signature); $this->assertSame($signature, $token->getSignature()); @@ -125,10 +119,7 @@ public function verifyMustRaiseExceptionWhenTokenIsUnsigned() */ public function verifyMustDelegateTheValidationToSignature() { - $signature = $this->getMockBuilder(Signature::class) - ->setMockClassName('SignatureMock') - ->disableOriginalConstructor() - ->getMock(); + $signature = $this->getMock(Signature::class, [], [], '', false); $signature->expects($this->once()) ->method('verify') @@ -277,10 +268,7 @@ public function toStringMustReturnEncodedDataWithEmptySignature() */ public function toStringMustReturnEncodedData() { - $signature = $this->getMockBuilder(Signature::class) - ->setMockClassName('SignatureMock') - ->disableOriginalConstructor() - ->getMock(); + $signature = $this->getMock(Signature::class, [], [], '', false); $signature->expects($this->any()) ->method('__toString') From fbf878629172f504bee8f83f1ea2dc42f952f8eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 12:55:17 -0200 Subject: [PATCH 18/22] Adding final tests and closes #1. --- src/Claim/Basic.php | 2 +- src/ValidationData.php | 8 +- test/Claim/BasicTest.php | 82 ++++++++++++ test/Claim/EqualsToTest.php | 79 ++++++++++++ test/Claim/FactoryTest.php | 137 ++++++++++++++++++++ test/Claim/GreaterOrEqualsToTest.php | 101 +++++++++++++++ test/Claim/LesserOrEqualsToTest.php | 101 +++++++++++++++ test/ValidationDataTest.php | 181 +++++++++++++++++++++++++++ 8 files changed, 689 insertions(+), 2 deletions(-) create mode 100644 test/Claim/BasicTest.php create mode 100644 test/Claim/EqualsToTest.php create mode 100644 test/Claim/FactoryTest.php create mode 100644 test/Claim/GreaterOrEqualsToTest.php create mode 100644 test/Claim/LesserOrEqualsToTest.php create mode 100644 test/ValidationDataTest.php diff --git a/src/Claim/Basic.php b/src/Claim/Basic.php index a1b54e90..96a8cd34 100644 --- a/src/Claim/Basic.php +++ b/src/Claim/Basic.php @@ -68,6 +68,6 @@ public function jsonSerialize() */ public function __toString() { - return $this->value; + return (string) $this->value; } } diff --git a/src/ValidationData.php b/src/ValidationData.php index 94fb93d2..137b3007 100644 --- a/src/ValidationData.php +++ b/src/ValidationData.php @@ -25,7 +25,7 @@ class ValidationData /** * Initializes the object * - * @param string $currentTime + * @param int $currentTime */ public function __construct($currentTime = null) { @@ -63,6 +63,8 @@ public function setIssuer($issuer) } /** + * Configures the audience + * * @param string $audience */ public function setAudience($audience) @@ -71,6 +73,8 @@ public function setAudience($audience) } /** + * Configures the subject + * * @param string $subject */ public function setSubject($subject) @@ -79,6 +83,8 @@ public function setSubject($subject) } /** + * Configures the time that "iat", "nbf" and "exp" should be based on + * * @param int $subject */ public function setCurrentTime($currentTime) diff --git a/test/Claim/BasicTest.php b/test/Claim/BasicTest.php new file mode 100644 index 00000000..4867879f --- /dev/null +++ b/test/Claim/BasicTest.php @@ -0,0 +1,82 @@ + + * @since 2.0.0 + * + * @coversDefaultClass Lcobucci\JWT\Claim\Basic + */ +class BasicTest extends \PHPUnit_Framework_TestCase +{ + /** + * @test + * + * @covers ::__construct + */ + public function constructorShouldConfigureTheAttributes() + { + $claim = new Basic('test', 1); + + $this->assertAttributeEquals('test', 'name', $claim); + $this->assertAttributeEquals(1, 'value', $claim); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::getName + */ + public function getNameShouldReturnTheClaimName() + { + $claim = new Basic('test', 1); + + $this->assertEquals('test', $claim->getName()); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::getValue + */ + public function getValueShouldReturnTheClaimValue() + { + $claim = new Basic('test', 1); + + $this->assertEquals(1, $claim->getValue()); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::jsonSerialize + */ + public function jsonSerializeShouldReturnTheClaimValue() + { + $claim = new Basic('test', 1); + + $this->assertEquals(1, $claim->jsonSerialize()); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::__toString + */ + public function toStringShouldReturnTheClaimValue() + { + $claim = new Basic('test', 1); + + $this->assertEquals('1', (string) $claim); + } +} diff --git a/test/Claim/EqualsToTest.php b/test/Claim/EqualsToTest.php new file mode 100644 index 00000000..3838f6ae --- /dev/null +++ b/test/Claim/EqualsToTest.php @@ -0,0 +1,79 @@ + + * @since 2.0.0 + * + * @coversDefaultClass Lcobucci\JWT\Claim\EqualsTo + */ +class EqualsToTest extends \PHPUnit_Framework_TestCase +{ + /** + * @test + * + * @covers ::validate + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::has + */ + public function validateShouldReturnTrueWhenValidationDontHaveTheClaim() + { + $claim = new EqualsTo('iss', 'test'); + + $this->assertTrue($claim->validate(new ValidationData())); + } + + /** + * @test + * + * @covers ::validate + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\Claim\Basic::getValue + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::setIssuer + * @covers Lcobucci\JWT\ValidationData::has + * @covers Lcobucci\JWT\ValidationData::get + */ + public function validateShouldReturnTrueWhenValueIsEqualsToValidationData() + { + $claim = new EqualsTo('iss', 'test'); + + $data = new ValidationData(); + $data->setIssuer('test'); + + $this->assertTrue($claim->validate($data)); + } + + /** + * @test + * + * @covers ::validate + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\Claim\Basic::getValue + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::setIssuer + * @covers Lcobucci\JWT\ValidationData::has + * @covers Lcobucci\JWT\ValidationData::get + */ + public function validateShouldReturnFalseWhenValueIsNotEqualsToValidationData() + { + $claim = new EqualsTo('iss', 'test'); + + $data = new ValidationData(); + $data->setIssuer('test1'); + + $this->assertFalse($claim->validate($data)); + } +} diff --git a/test/Claim/FactoryTest.php b/test/Claim/FactoryTest.php new file mode 100644 index 00000000..d60b7b38 --- /dev/null +++ b/test/Claim/FactoryTest.php @@ -0,0 +1,137 @@ + + * @since 2.0.0 + * + * @coversDefaultClass Lcobucci\JWT\Claim\Factory + */ +class FactoryTest extends \PHPUnit_Framework_TestCase +{ + /** + * @test + * + * @covers ::__construct + * @covers ::create + * @covers ::createLesserOrEqualsTo + * @covers Lcobucci\JWT\Claim\Basic::__construct + */ + public function createShouldReturnALesserOrEqualsToClaimForIssuedAt() + { + $claim = new Factory(); + + $this->assertInstanceOf(LesserOrEqualsTo::class, $claim->create('iat', 1)); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::create + * @covers ::createLesserOrEqualsTo + * @covers Lcobucci\JWT\Claim\Basic::__construct + */ + public function createShouldReturnALesserOrEqualsToClaimForNotBefore() + { + $claim = new Factory(); + + $this->assertInstanceOf(LesserOrEqualsTo::class, $claim->create('nbf', 1)); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::create + * @covers ::createGreaterOrEqualsTo + * @covers Lcobucci\JWT\Claim\Basic::__construct + */ + public function createShouldReturnAGreaterOrEqualsToClaimForExpiration() + { + $claim = new Factory(); + + $this->assertInstanceOf(GreaterOrEqualsTo::class, $claim->create('exp', 1)); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::create + * @covers ::createEqualsTo + * @covers Lcobucci\JWT\Claim\Basic::__construct + */ + public function createShouldReturnAnEqualsToClaimForId() + { + $claim = new Factory(); + + $this->assertInstanceOf(EqualsTo::class, $claim->create('jti', 1)); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::create + * @covers ::createEqualsTo + * @covers Lcobucci\JWT\Claim\Basic::__construct + */ + public function createShouldReturnAnEqualsToClaimForIssuer() + { + $claim = new Factory(); + + $this->assertInstanceOf(EqualsTo::class, $claim->create('iss', 1)); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::create + * @covers ::createEqualsTo + * @covers Lcobucci\JWT\Claim\Basic::__construct + */ + public function createShouldReturnAnEqualsToClaimForAudience() + { + $claim = new Factory(); + + $this->assertInstanceOf(EqualsTo::class, $claim->create('aud', 1)); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::create + * @covers ::createEqualsTo + * @covers Lcobucci\JWT\Claim\Basic::__construct + */ + public function createShouldReturnAnEqualsToClaimForSubject() + { + $claim = new Factory(); + + $this->assertInstanceOf(EqualsTo::class, $claim->create('sub', 1)); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::create + * @covers ::createBasic + * @covers Lcobucci\JWT\Claim\Basic::__construct + */ + public function createShouldReturnABasiclaimForOtherClaims() + { + $claim = new Factory(); + + $this->assertInstanceOf(Basic::class, $claim->create('test', 1)); + } +} diff --git a/test/Claim/GreaterOrEqualsToTest.php b/test/Claim/GreaterOrEqualsToTest.php new file mode 100644 index 00000000..a7ccfe74 --- /dev/null +++ b/test/Claim/GreaterOrEqualsToTest.php @@ -0,0 +1,101 @@ + + * @since 2.0.0 + * + * @coversDefaultClass Lcobucci\JWT\Claim\GreaterOrEqualsTo + */ +class GreaterOrEqualsToTest extends \PHPUnit_Framework_TestCase +{ + /** + * @test + * + * @covers ::validate + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::has + */ + public function validateShouldReturnTrueWhenValidationDontHaveTheClaim() + { + $claim = new GreaterOrEqualsTo('iss', 10); + + $this->assertTrue($claim->validate(new ValidationData())); + } + + /** + * @test + * + * @covers ::validate + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\Claim\Basic::getValue + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::setIssuer + * @covers Lcobucci\JWT\ValidationData::has + * @covers Lcobucci\JWT\ValidationData::get + */ + public function validateShouldReturnTrueWhenValueIsGreaterThanValidationData() + { + $claim = new GreaterOrEqualsTo('iss', 11); + + $data = new ValidationData(); + $data->setIssuer(10); + + $this->assertTrue($claim->validate($data)); + } + + /** + * @test + * + * @covers ::validate + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\Claim\Basic::getValue + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::setIssuer + * @covers Lcobucci\JWT\ValidationData::has + * @covers Lcobucci\JWT\ValidationData::get + */ + public function validateShouldReturnTrueWhenValueIsEqualsToValidationData() + { + $claim = new GreaterOrEqualsTo('iss', 10); + + $data = new ValidationData(); + $data->setIssuer(10); + + $this->assertTrue($claim->validate($data)); + } + + /** + * @test + * + * @covers ::validate + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\Claim\Basic::getValue + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::setIssuer + * @covers Lcobucci\JWT\ValidationData::has + * @covers Lcobucci\JWT\ValidationData::get + */ + public function validateShouldReturnFalseWhenValueIsLesserThanValidationData() + { + $claim = new GreaterOrEqualsTo('iss', 10); + + $data = new ValidationData(); + $data->setIssuer(11); + + $this->assertFalse($claim->validate($data)); + } +} diff --git a/test/Claim/LesserOrEqualsToTest.php b/test/Claim/LesserOrEqualsToTest.php new file mode 100644 index 00000000..af9cbc46 --- /dev/null +++ b/test/Claim/LesserOrEqualsToTest.php @@ -0,0 +1,101 @@ + + * @since 2.0.0 + * + * @coversDefaultClass Lcobucci\JWT\Claim\LesserOrEqualsTo + */ +class LesserOrEqualsToTest extends \PHPUnit_Framework_TestCase +{ + /** + * @test + * + * @covers ::validate + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::has + */ + public function validateShouldReturnTrueWhenValidationDontHaveTheClaim() + { + $claim = new LesserOrEqualsTo('iss', 10); + + $this->assertTrue($claim->validate(new ValidationData())); + } + + /** + * @test + * + * @covers ::validate + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\Claim\Basic::getValue + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::setIssuer + * @covers Lcobucci\JWT\ValidationData::has + * @covers Lcobucci\JWT\ValidationData::get + */ + public function validateShouldReturnTrueWhenValueIsLesserThanValidationData() + { + $claim = new LesserOrEqualsTo('iss', 10); + + $data = new ValidationData(); + $data->setIssuer(11); + + $this->assertTrue($claim->validate($data)); + } + + /** + * @test + * + * @covers ::validate + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\Claim\Basic::getValue + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::setIssuer + * @covers Lcobucci\JWT\ValidationData::has + * @covers Lcobucci\JWT\ValidationData::get + */ + public function validateShouldReturnTrueWhenValueIsEqualsToValidationData() + { + $claim = new LesserOrEqualsTo('iss', 10); + + $data = new ValidationData(); + $data->setIssuer(10); + + $this->assertTrue($claim->validate($data)); + } + + /** + * @test + * + * @covers ::validate + * @covers Lcobucci\JWT\Claim\Basic::__construct + * @covers Lcobucci\JWT\Claim\Basic::getName + * @covers Lcobucci\JWT\Claim\Basic::getValue + * @covers Lcobucci\JWT\ValidationData::__construct + * @covers Lcobucci\JWT\ValidationData::setIssuer + * @covers Lcobucci\JWT\ValidationData::has + * @covers Lcobucci\JWT\ValidationData::get + */ + public function validateShouldReturnFalseWhenValueIsGreaterThanValidationData() + { + $claim = new LesserOrEqualsTo('iss', 11); + + $data = new ValidationData(); + $data->setIssuer(10); + + $this->assertFalse($claim->validate($data)); + } +} diff --git a/test/ValidationDataTest.php b/test/ValidationDataTest.php new file mode 100644 index 00000000..ff2afb5d --- /dev/null +++ b/test/ValidationDataTest.php @@ -0,0 +1,181 @@ + + * @since 2.0.0 + * + * @coversDefaultClass Lcobucci\JWT\ValidationData + */ +class ValidationDataTest extends \PHPUnit_Framework_TestCase +{ + /** + * @test + * + * @covers ::__construct + */ + public function constructorShouldConfigureTheItems() + { + $data = new ValidationData(1); + $items = ['jti' => null, 'iss' => null, 'aud' => null, 'sub' => null]; + $items['iat'] = $items['nbf'] = $items['exp'] = 1; + + $this->assertAttributeEquals($items, 'items', $data); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::setId + */ + public function setIdShouldChangeTheId() + { + $data = new ValidationData(1); + $data->setId(1); + + $items = ['jti' => 1, 'iss' => null, 'aud' => null, 'sub' => null]; + $items['iat'] = $items['nbf'] = $items['exp'] = 1; + + $this->assertAttributeEquals($items, 'items', $data); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::setIssuer + */ + public function setIssuerShouldChangeTheIssuer() + { + $data = new ValidationData(1); + $data->setIssuer('test'); + + $items = ['jti' => null, 'iss' => 'test', 'aud' => null, 'sub' => null]; + $items['iat'] = $items['nbf'] = $items['exp'] = 1; + + $this->assertAttributeEquals($items, 'items', $data); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::setAudience + */ + public function setAudienceShouldChangeTheAudience() + { + $data = new ValidationData(1); + $data->setAudience('test'); + + $items = ['jti' => null, 'iss' => null, 'aud' => 'test', 'sub' => null]; + $items['iat'] = $items['nbf'] = $items['exp'] = 1; + + $this->assertAttributeEquals($items, 'items', $data); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::setSubject + */ + public function setSubjectShouldChangeTheSubject() + { + $data = new ValidationData(1); + $data->setSubject('test'); + + $items = ['jti' => null, 'iss' => null, 'aud' => null, 'sub' => 'test']; + $items['iat'] = $items['nbf'] = $items['exp'] = 1; + + $this->assertAttributeEquals($items, 'items', $data); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::setCurrentTime + */ + public function setCurrentTimeShouldChangeTheTimeBasedValues() + { + $data = new ValidationData(1); + $data->setCurrentTime(2); + + $items = ['jti' => null, 'iss' => null, 'aud' => null, 'sub' => null]; + $items['iat'] = $items['nbf'] = $items['exp'] = 2; + + $this->assertAttributeEquals($items, 'items', $data); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::has + */ + public function hasShouldReturnTrueWhenItemIsNotEmpty() + { + $data = new ValidationData(1); + + $this->assertTrue($data->has('iat')); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::has + */ + public function hasShouldReturnFalseWhenItemIsEmpty() + { + $data = new ValidationData(1); + + $this->assertFalse($data->has('jti')); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::has + */ + public function hasShouldReturnFalseWhenItemIsNotDefined() + { + $data = new ValidationData(1); + + $this->assertFalse($data->has('test')); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::get + */ + public function getShouldReturnTheItemValue() + { + $data = new ValidationData(1); + + $this->assertEquals(1, $data->get('iat')); + } + + /** + * @test + * + * @covers ::__construct + * @covers ::get + */ + public function getShouldReturnNullWhenItemIsNotDefined() + { + $data = new ValidationData(1); + + $this->assertNull($data->get('test')); + } +} From eba26d7c7ac6979d9a202701e6e93be2463087d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 12:57:53 -0200 Subject: [PATCH 19/22] PSR-2 fixes. --- test/BuilderTest.php | 49 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/test/BuilderTest.php b/test/BuilderTest.php index d0e50160..5da72d49 100644 --- a/test/BuilderTest.php +++ b/test/BuilderTest.php @@ -98,8 +98,13 @@ public function setAudienceCanReplicateItemOnHeader() $builder = $this->createBuilder(); $builder->setAudience('test', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'aud' => $this->defaultClaim], 'header', $builder); $this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $builder); + + $this->assertAttributeEquals( + ['alg' => 'none', 'typ' => 'JWT', 'aud' => $this->defaultClaim], + 'header', + $builder + ); } /** @@ -144,8 +149,13 @@ public function setExpirationCanReplicateItemOnHeader() $builder = $this->createBuilder(); $builder->setExpiration('2', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'exp' => $this->defaultClaim], 'header', $builder); $this->assertAttributeEquals(['exp' => $this->defaultClaim], 'claims', $builder); + + $this->assertAttributeEquals( + ['alg' => 'none', 'typ' => 'JWT', 'exp' => $this->defaultClaim], + 'header', + $builder + ); } /** @@ -190,8 +200,13 @@ public function setIdCanReplicateItemOnHeader() $builder = $this->createBuilder(); $builder->setId('2', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'jti' => $this->defaultClaim], 'header', $builder); $this->assertAttributeEquals(['jti' => $this->defaultClaim], 'claims', $builder); + + $this->assertAttributeEquals( + ['alg' => 'none', 'typ' => 'JWT', 'jti' => $this->defaultClaim], + 'header', + $builder + ); } /** @@ -236,8 +251,13 @@ public function setIssueAtCanReplicateItemOnHeader() $builder = $this->createBuilder(); $builder->setIssueAt('2', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'iat' => $this->defaultClaim], 'header', $builder); $this->assertAttributeEquals(['iat' => $this->defaultClaim], 'claims', $builder); + + $this->assertAttributeEquals( + ['alg' => 'none', 'typ' => 'JWT', 'iat' => $this->defaultClaim], + 'header', + $builder + ); } /** @@ -282,8 +302,13 @@ public function setIssuerCanReplicateItemOnHeader() $builder = $this->createBuilder(); $builder->setIssuer('2', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'iss' => $this->defaultClaim], 'header', $builder); $this->assertAttributeEquals(['iss' => $this->defaultClaim], 'claims', $builder); + + $this->assertAttributeEquals( + ['alg' => 'none', 'typ' => 'JWT', 'iss' => $this->defaultClaim], + 'header', + $builder + ); } /** @@ -328,8 +353,13 @@ public function setNotBeforeCanReplicateItemOnHeader() $builder = $this->createBuilder(); $builder->setNotBefore('2', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'nbf' => $this->defaultClaim], 'header', $builder); $this->assertAttributeEquals(['nbf' => $this->defaultClaim], 'claims', $builder); + + $this->assertAttributeEquals( + ['alg' => 'none', 'typ' => 'JWT', 'nbf' => $this->defaultClaim], + 'header', + $builder + ); } /** @@ -374,8 +404,13 @@ public function setSubjectCanReplicateItemOnHeader() $builder = $this->createBuilder(); $builder->setSubject('2', true); - $this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT', 'sub' => $this->defaultClaim], 'header', $builder); $this->assertAttributeEquals(['sub' => $this->defaultClaim], 'claims', $builder); + + $this->assertAttributeEquals( + ['alg' => 'none', 'typ' => 'JWT', 'sub' => $this->defaultClaim], + 'header', + $builder + ); } /** From 22c3158678a928e97e1aa538a00d5ffbac76fb56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 13:01:33 -0200 Subject: [PATCH 20/22] Adding \Generator to uses. --- src/Token.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Token.php b/src/Token.php index 8cdab60d..27edf19c 100644 --- a/src/Token.php +++ b/src/Token.php @@ -8,6 +8,7 @@ namespace Lcobucci\JWT; use BadMethodCallException; +use Generator; use Lcobucci\JWT\Parsing\Encoder; use Lcobucci\JWT\Claim\Validatable; From 4fb01cacbad27ebded9a3fc9113973ff46a2e7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Thu, 20 Nov 2014 13:12:57 -0200 Subject: [PATCH 21/22] Reorganization of Signer namespace in order to allow other algorithms (closes #3). --- README.md | 2 +- src/Signer/Factory.php | 3 +++ src/Signer/{ => Hmac}/Sha256.php | 4 +++- src/Signer/{ => Hmac}/Sha384.php | 4 +++- src/Signer/{ => Hmac}/Sha512.php | 4 +++- test/Signer/FactoryTest.php | 4 ++++ test/Signer/{ => Hmac}/Sha256Test.php | 4 ++-- test/Signer/{ => Hmac}/Sha384Test.php | 4 ++-- test/Signer/{ => Hmac}/Sha512Test.php | 4 ++-- 9 files changed, 23 insertions(+), 10 deletions(-) rename src/Signer/{ => Hmac}/Sha256.php (88%) rename src/Signer/{ => Hmac}/Sha384.php (88%) rename src/Signer/{ => Hmac}/Sha512.php (88%) rename test/Signer/{ => Hmac}/Sha256Test.php (89%) rename test/Signer/{ => Hmac}/Sha384Test.php (89%) rename test/Signer/{ => Hmac}/Sha512Test.php (89%) diff --git a/README.md b/README.md index 861c3684..b952a3d1 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Just use the builder to create a new JWT/JWS tokens: ```php setIssuer('http://example.com') // Configures the issuer (iss claim) ->setAudience('http://example.org') // Configures the audience (aud claim) diff --git a/src/Signer/Factory.php b/src/Signer/Factory.php index e18dc644..16b633cc 100644 --- a/src/Signer/Factory.php +++ b/src/Signer/Factory.php @@ -9,6 +9,9 @@ use InvalidArgumentException; use Lcobucci\JWT\Signer; +use Lcobucci\JWT\Signer\Hmac\Sha256; +use Lcobucci\JWT\Signer\Hmac\Sha384; +use Lcobucci\JWT\Signer\Hmac\Sha512; /** * Factory that returns instance of signers diff --git a/src/Signer/Sha256.php b/src/Signer/Hmac/Sha256.php similarity index 88% rename from src/Signer/Sha256.php rename to src/Signer/Hmac/Sha256.php index 0984d411..49d10b3b 100644 --- a/src/Signer/Sha256.php +++ b/src/Signer/Hmac/Sha256.php @@ -5,7 +5,9 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Signer; +namespace Lcobucci\JWT\Signer\Hmac; + +use Lcobucci\JWT\Signer\Hmac; /** * Signer for HMAC SHA-256 diff --git a/src/Signer/Sha384.php b/src/Signer/Hmac/Sha384.php similarity index 88% rename from src/Signer/Sha384.php rename to src/Signer/Hmac/Sha384.php index 6efbd838..8618801a 100644 --- a/src/Signer/Sha384.php +++ b/src/Signer/Hmac/Sha384.php @@ -5,7 +5,9 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Signer; +namespace Lcobucci\JWT\Signer\Hmac; + +use Lcobucci\JWT\Signer\Hmac; /** * Signer for HMAC SHA-384 diff --git a/src/Signer/Sha512.php b/src/Signer/Hmac/Sha512.php similarity index 88% rename from src/Signer/Sha512.php rename to src/Signer/Hmac/Sha512.php index a5de15bb..8ae19d8f 100644 --- a/src/Signer/Sha512.php +++ b/src/Signer/Hmac/Sha512.php @@ -5,7 +5,9 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Signer; +namespace Lcobucci\JWT\Signer\Hmac; + +use Lcobucci\JWT\Signer\Hmac; /** * Signer for HMAC SHA-512 diff --git a/test/Signer/FactoryTest.php b/test/Signer/FactoryTest.php index 05563022..1d75fd00 100644 --- a/test/Signer/FactoryTest.php +++ b/test/Signer/FactoryTest.php @@ -7,6 +7,10 @@ namespace Lcobucci\JWT\Signer; +use Lcobucci\JWT\Signer\Hmac\Sha256; +use Lcobucci\JWT\Signer\Hmac\Sha384; +use Lcobucci\JWT\Signer\Hmac\Sha512; + /** * @author Luís Otávio Cobucci Oblonczyk * @since 0.1.0 diff --git a/test/Signer/Sha256Test.php b/test/Signer/Hmac/Sha256Test.php similarity index 89% rename from test/Signer/Sha256Test.php rename to test/Signer/Hmac/Sha256Test.php index 62940bb1..52b21f6f 100644 --- a/test/Signer/Sha256Test.php +++ b/test/Signer/Hmac/Sha256Test.php @@ -5,13 +5,13 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Signer; +namespace Lcobucci\JWT\Signer\Hmac; /** * @author Luís Otávio Cobucci Oblonczyk * @since 0.1.0 * - * @coversDefaultClass Lcobucci\JWT\Signer\Sha256 + * @coversDefaultClass Lcobucci\JWT\Signer\Hmac\Sha256 */ class Sha256Test extends \PHPUnit_Framework_TestCase { diff --git a/test/Signer/Sha384Test.php b/test/Signer/Hmac/Sha384Test.php similarity index 89% rename from test/Signer/Sha384Test.php rename to test/Signer/Hmac/Sha384Test.php index 2c57be23..8a9c585f 100644 --- a/test/Signer/Sha384Test.php +++ b/test/Signer/Hmac/Sha384Test.php @@ -5,13 +5,13 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Signer; +namespace Lcobucci\JWT\Signer\Hmac; /** * @author Luís Otávio Cobucci Oblonczyk * @since 0.1.0 * - * @coversDefaultClass Lcobucci\JWT\Signer\Sha384 + * @coversDefaultClass Lcobucci\JWT\Signer\Hmac\Sha384 */ class Sha384Test extends \PHPUnit_Framework_TestCase { diff --git a/test/Signer/Sha512Test.php b/test/Signer/Hmac/Sha512Test.php similarity index 89% rename from test/Signer/Sha512Test.php rename to test/Signer/Hmac/Sha512Test.php index 98522c7f..ebfb3f15 100644 --- a/test/Signer/Sha512Test.php +++ b/test/Signer/Hmac/Sha512Test.php @@ -5,13 +5,13 @@ * @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause */ -namespace Lcobucci\JWT\Signer; +namespace Lcobucci\JWT\Signer\Hmac; /** * @author Luís Otávio Cobucci Oblonczyk * @since 0.1.0 * - * @coversDefaultClass Lcobucci\JWT\Signer\Sha512 + * @coversDefaultClass Lcobucci\JWT\Signer\Hmac\Sha512 */ class Sha512Test extends \PHPUnit_Framework_TestCase { From 9ea579f410d5b9bfa33c88b7bd46c0278196db25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Ot=C3=A1vio=20Cobucci=20Oblonczyk?= Date: Sun, 23 Nov 2014 21:36:48 -0200 Subject: [PATCH 22/22] Adding which draft is being used as reference. --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b952a3d1..8877b067 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,8 @@ develop [![Total Downloads](https://poser.pugx.org/lcobucci/jwt/downloads.png)](https://packagist.org/packages/lcobucci/jwt) [![Latest Stable Version](https://poser.pugx.org/lcobucci/jwt/v/stable.png)](https://packagist.org/packages/lcobucci/jwt) -A simple library to work with JSON Web Token and JSON Web Signature (requires PHP 5.5+) +A simple library to work with JSON Web Token and JSON Web Signature (requires PHP 5.5+). +The implementation is based on the [current draft](http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-31). ## Instalation