updated-packages
This commit is contained in:
5
vendor/lcobucci/jwt/.gitignore
vendored
5
vendor/lcobucci/jwt/.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
vendor
|
||||
phpunit.xml
|
||||
/vendor
|
||||
/phpunit.xml
|
||||
/composer.lock
|
||||
|
9
vendor/lcobucci/jwt/.travis.yml
vendored
9
vendor/lcobucci/jwt/.travis.yml
vendored
@@ -1,22 +1,15 @@
|
||||
language: php
|
||||
php:
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7.0
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- nightly
|
||||
- hhvm
|
||||
- hhvm-nightly
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
- php: 7.1
|
||||
- php: 7.2
|
||||
- php: nightly
|
||||
- php: hhvm
|
||||
- php: hhvm-nightly
|
||||
|
||||
before_script:
|
||||
- composer selfupdate
|
||||
- composer install --prefer-dist -o
|
||||
|
119
vendor/lcobucci/jwt/README.md
vendored
119
vendor/lcobucci/jwt/README.md
vendored
@@ -6,8 +6,8 @@
|
||||
[](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=master)
|
||||
[](https://scrutinizer-ci.com/g/lcobucci/jwt/?branch=master)
|
||||
|
||||
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-32).
|
||||
A simple library to work with JSON Web Token and JSON Web Signature (requires PHP 5.6+).
|
||||
The implementation is based on the [RFC 7519](https://tools.ietf.org/html/rfc7519).
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -20,7 +20,7 @@ composer require lcobucci/jwt
|
||||
|
||||
### Dependencies
|
||||
|
||||
- PHP 5.5+
|
||||
- PHP 5.6+
|
||||
- OpenSSL Extension
|
||||
|
||||
## Basic usage
|
||||
@@ -32,13 +32,14 @@ Just use the builder to create a new JWT/JWS tokens:
|
||||
```php
|
||||
use Lcobucci\JWT\Builder;
|
||||
|
||||
$token = (new Builder())->setIssuer('http://example.com') // Configures the issuer (iss claim)
|
||||
->setAudience('http://example.org') // Configures the audience (aud claim)
|
||||
->setId('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
|
||||
->setIssuedAt(time()) // Configures the time that the token was issue (iat claim)
|
||||
->setNotBefore(time() + 60) // Configures the time that the token can be used (nbf claim)
|
||||
->setExpiration(time() + 3600) // Configures the expiration time of the token (exp claim)
|
||||
->set('uid', 1) // Configures a new claim, called "uid"
|
||||
$time = time();
|
||||
$token = (new Builder())->issuedBy('http://example.com') // Configures the issuer (iss claim)
|
||||
->permittedFor('http://example.org') // Configures the audience (aud claim)
|
||||
->identifiedBy('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
|
||||
->issuedAt($time) // Configures the time that the token was issue (iat claim)
|
||||
->canOnlyBeUsedAfter($time + 60) // Configures the time that the token can be used (nbf claim)
|
||||
->expiresAt($time + 3600) // Configures the expiration time of the token (exp claim)
|
||||
->withClaim('uid', 1) // Configures a new claim, called "uid"
|
||||
->getToken(); // Retrieves the generated token
|
||||
|
||||
|
||||
@@ -69,7 +70,7 @@ echo $token->getClaim('uid'); // will print "1"
|
||||
|
||||
### Validating
|
||||
|
||||
We can easily validate if the token is valid (using the previous token as example):
|
||||
We can easily validate if the token is valid (using the previous token and time as example):
|
||||
|
||||
```php
|
||||
use Lcobucci\JWT\ValidationData;
|
||||
@@ -79,40 +80,84 @@ $data->setIssuer('http://example.com');
|
||||
$data->setAudience('http://example.org');
|
||||
$data->setId('4f1g23a12aa');
|
||||
|
||||
var_dump($token->validate($data)); // false, because we created a token that cannot be used before of `time() + 60`
|
||||
var_dump($token->validate($data)); // false, because token cannot be used before now() + 60
|
||||
|
||||
$data->setCurrentTime(time() + 60); // changing the validation time to future
|
||||
$data->setCurrentTime($time + 61); // changing the validation time to future
|
||||
|
||||
var_dump($token->validate($data)); // true, because validation information is equals to data contained on the token
|
||||
var_dump($token->validate($data)); // true, because current time is between "nbf" and "exp" claims
|
||||
|
||||
$data->setCurrentTime(time() + 4000); // changing the validation time to future
|
||||
$data->setCurrentTime($time + 4000); // changing the validation time to future
|
||||
|
||||
var_dump($token->validate($data)); // false, because token is expired since current time is greater than exp
|
||||
|
||||
// We can also use the $leeway parameter to deal with clock skew (see notes below)
|
||||
// If token's claimed time is invalid but the difference between that and the validation time is less than $leeway,
|
||||
// then token is still considered valid
|
||||
$dataWithLeeway = new ValidationData($time, 20);
|
||||
$dataWithLeeway->setIssuer('http://example.com');
|
||||
$dataWithLeeway->setAudience('http://example.org');
|
||||
$dataWithLeeway->setId('4f1g23a12aa');
|
||||
|
||||
var_dump($token->validate($dataWithLeeway)); // false, because token can't be used before now() + 60, not within leeway
|
||||
|
||||
$dataWithLeeway->setCurrentTime($time + 51); // changing the validation time to future
|
||||
|
||||
var_dump($token->validate($dataWithLeeway)); // true, because current time plus leeway is between "nbf" and "exp" claims
|
||||
|
||||
$dataWithLeeway->setCurrentTime($time + 3610); // changing the validation time to future but within leeway
|
||||
|
||||
var_dump($token->validate($dataWithLeeway)); // true, because current time - 20 seconds leeway is less than exp
|
||||
|
||||
$dataWithLeeway->setCurrentTime($time + 4000); // changing the validation time to future outside of leeway
|
||||
|
||||
var_dump($token->validate($dataWithLeeway)); // false, because token is expired since current time is greater than exp
|
||||
```
|
||||
|
||||
#### Important
|
||||
|
||||
- You have to configure ```ValidationData``` informing all claims you want to validate the token.
|
||||
- If ```ValidationData``` contains claims that are not being used in token or token has claims that are not
|
||||
configured in ```ValidationData``` they will be ignored by ```Token::validate()```.
|
||||
- ```exp```, ```nbf``` and ```iat``` claims are configured by default in ```ValidationData::__construct()```
|
||||
with the current UNIX time (```time()```).
|
||||
- The optional ```$leeway``` parameter of ```ValidationData``` will cause us to use that number of seconds of leeway
|
||||
when validating the time-based claims, pretending we are further in the future for the "Issued At" (```iat```) and "Not
|
||||
Before" (```nbf```) claims and pretending we are further in the past for the "Expiration Time" (```exp```) claim. This
|
||||
allows for situations where the clock of the issuing server has a different time than the clock of the verifying server,
|
||||
as mentioned in [section 4.1 of RFC 7519](https://tools.ietf.org/html/rfc7519#section-4.1).
|
||||
|
||||
## Token signature
|
||||
|
||||
We can use signatures to be able to verify if the token was not modified after its generation. This library implements Hmac, RSA and ECDSA signatures (using 256, 384 and 512).
|
||||
|
||||
### Important
|
||||
|
||||
Do not allow the string sent to the Parser to dictate which signature algorithm
|
||||
to use, or else your application will be vulnerable to a [critical JWT security vulnerability](https://auth0.com/blog/2015/03/31/critical-vulnerabilities-in-json-web-token-libraries).
|
||||
|
||||
The examples below are safe because the choice in `Signer` is hard-coded and
|
||||
cannot be influenced by malicious users.
|
||||
|
||||
### Hmac
|
||||
|
||||
Hmac signatures are really simple to be used:
|
||||
|
||||
```php
|
||||
use Lcobucci\JWT\Builder;
|
||||
use Lcobucci\JWT\Signer\Key;
|
||||
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
||||
|
||||
$signer = new Sha256();
|
||||
$time = time();
|
||||
|
||||
$token = (new Builder())->setIssuer('http://example.com') // Configures the issuer (iss claim)
|
||||
->setAudience('http://example.org') // Configures the audience (aud claim)
|
||||
->setId('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
|
||||
->setIssuedAt(time()) // Configures the time that the token was issue (iat claim)
|
||||
->setNotBefore(time() + 60) // Configures the time that the token can be used (nbf claim)
|
||||
->setExpiration(time() + 3600) // Configures the expiration time of the token (exp claim)
|
||||
->set('uid', 1) // Configures a new claim, called "uid"
|
||||
->sign($signer, 'testing') // creates a signature using "testing" as key
|
||||
->getToken(); // Retrieves the generated token
|
||||
$token = (new Builder())->issuedBy('http://example.com') // Configures the issuer (iss claim)
|
||||
->permittedFor('http://example.org') // Configures the audience (aud claim)
|
||||
->identifiedBy('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
|
||||
->issuedAt($time) // Configures the time that the token was issue (iat claim)
|
||||
->canOnlyBeUsedAfter($time + 60) // Configures the time that the token can be used (nbf claim)
|
||||
->expiresAt($time + 3600) // Configures the expiration time of the token (exp claim)
|
||||
->withClaim('uid', 1) // Configures a new claim, called "uid"
|
||||
->getToken($signer, new Key('testing')); // Retrieves the generated token
|
||||
|
||||
|
||||
var_dump($token->verify($signer, 'testing 1')); // false, because the key is different
|
||||
@@ -125,25 +170,25 @@ RSA and ECDSA signatures are based on public and private keys so you have to gen
|
||||
|
||||
```php
|
||||
use Lcobucci\JWT\Builder;
|
||||
use Lcobucci\JWT\Signer\Keychain; // just to make our life simpler
|
||||
use Lcobucci\JWT\Signer\Key;
|
||||
use Lcobucci\JWT\Signer\Rsa\Sha256; // you can use Lcobucci\JWT\Signer\Ecdsa\Sha256 if you're using ECDSA keys
|
||||
|
||||
$signer = new Sha256();
|
||||
$privateKey = new Key('file://{path to your private key}');
|
||||
$time = time();
|
||||
|
||||
$keychain = new Keychain();
|
||||
$token = (new Builder())->issuedBy('http://example.com') // Configures the issuer (iss claim)
|
||||
->permittedFor('http://example.org') // Configures the audience (aud claim)
|
||||
->identifiedBy('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
|
||||
->issuedAt($time) // Configures the time that the token was issue (iat claim)
|
||||
->canOnlyBeUsedAfter($time + 60) // Configures the time that the token can be used (nbf claim)
|
||||
->expiresAt($time + 3600) // Configures the expiration time of the token (exp claim)
|
||||
->withClaim('uid', 1) // Configures a new claim, called "uid"
|
||||
->getToken($signer, $privateKey); // Retrieves the generated token
|
||||
|
||||
$token = (new Builder())->setIssuer('http://example.com') // Configures the issuer (iss claim)
|
||||
->setAudience('http://example.org') // Configures the audience (aud claim)
|
||||
->setId('4f1g23a12aa', true) // Configures the id (jti claim), replicating as a header item
|
||||
->setIssuedAt(time()) // Configures the time that the token was issue (iat claim)
|
||||
->setNotBefore(time() + 60) // Configures the time that the token can be used (nbf claim)
|
||||
->setExpiration(time() + 3600) // Configures the expiration time of the token (nbf claim)
|
||||
->set('uid', 1) // Configures a new claim, called "uid"
|
||||
->sign($signer, $keychain->getPrivateKey('file://{path to your private key}')) // creates a signature using your private key
|
||||
->getToken(); // Retrieves the generated token
|
||||
$publicKey = new Key('file://{path to your public key}');
|
||||
|
||||
|
||||
var_dump($token->verify($signer, $keychain->getPublicKey('file://{path to your public key}'))); // true when the public key was generated by the private one =)
|
||||
var_dump($token->verify($signer, $publicKey)); // true when the public key was generated by the private one =)
|
||||
```
|
||||
|
||||
**It's important to say that if you're using RSA keys you shouldn't invoke ECDSA signers (and vice-versa), otherwise ```sign()``` and ```verify()``` will raise an exception!**
|
||||
|
13
vendor/lcobucci/jwt/composer.json
vendored
13
vendor/lcobucci/jwt/composer.json
vendored
@@ -17,19 +17,16 @@
|
||||
"BSD-3-Clause"
|
||||
],
|
||||
"require": {
|
||||
"php": ">=5.5",
|
||||
"php": "^5.6 || ^7.0",
|
||||
"ext-mbstring": "*",
|
||||
"ext-openssl": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "~4.5",
|
||||
"phpunit/phpunit": "^5.7 || ^7.3",
|
||||
"squizlabs/php_codesniffer": "~2.3",
|
||||
"phpmd/phpmd": "~2.2",
|
||||
"phpunit/php-invoker": "~1.1",
|
||||
"mikey179/vfsStream": "~1.5",
|
||||
"mdanter/ecc": "~0.3.1"
|
||||
},
|
||||
"suggest":{
|
||||
"mdanter/ecc": "Required to use Elliptic Curves based algorithms."
|
||||
"mikey179/vfsstream": "~1.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@@ -39,7 +36,7 @@
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Lcobucci\\JWT\\": [
|
||||
"test/unit",
|
||||
"test/unit",
|
||||
"test/functional"
|
||||
]
|
||||
}
|
||||
|
1898
vendor/lcobucci/jwt/composer.lock
generated
vendored
1898
vendor/lcobucci/jwt/composer.lock
generated
vendored
File diff suppressed because it is too large
Load Diff
18
vendor/lcobucci/jwt/phpunit.xml.dist
vendored
18
vendor/lcobucci/jwt/phpunit.xml.dist
vendored
@@ -1,16 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
|
||||
backupGlobals="false"
|
||||
backupStaticAttributes="false"
|
||||
bootstrap="vendor/autoload.php"
|
||||
colors="true"
|
||||
colors="true"
|
||||
verbose="true"
|
||||
beStrictAboutOutputDuringTests="true"
|
||||
beStrictAboutTestSize="true"
|
||||
beStrictAboutTestsThatDoNotTestAnything="true"
|
||||
beStrictAboutTodoAnnotatedTests="true"
|
||||
checkForUnintentionallyCoveredCode="true"
|
||||
beStrictAboutChangesToGlobalState="true"
|
||||
beStrictAboutCoversAnnotation="true"
|
||||
beStrictAboutResourceUsageDuringSmallTests="true"
|
||||
beStrictAboutTestsThatDoNotTestAnything="true"
|
||||
forceCoversAnnotation="true">
|
||||
<testsuites>
|
||||
<testsuite name="Unit Test Suite">
|
||||
@@ -20,14 +18,10 @@
|
||||
<directory>test/functional</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">src</directory>
|
||||
</whitelist>
|
||||
|
||||
<blacklist>
|
||||
<directory suffix=".php">vendor</directory>
|
||||
</blacklist>
|
||||
</filter>
|
||||
</phpunit>
|
||||
|
281
vendor/lcobucci/jwt/src/Builder.php
vendored
281
vendor/lcobucci/jwt/src/Builder.php
vendored
@@ -7,10 +7,10 @@
|
||||
|
||||
namespace Lcobucci\JWT;
|
||||
|
||||
use BadMethodCallException;
|
||||
use Lcobucci\JWT\Claim\Factory as ClaimFactory;
|
||||
use Lcobucci\JWT\Parsing\Encoder;
|
||||
use Lcobucci\JWT\Signer\Key;
|
||||
use function implode;
|
||||
|
||||
/**
|
||||
* This class makes easier the token creation process
|
||||
@@ -25,21 +25,14 @@ class Builder
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $headers;
|
||||
private $headers = ['typ'=> 'JWT', 'alg' => 'none'];
|
||||
|
||||
/**
|
||||
* The token claim set
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $claims;
|
||||
|
||||
/**
|
||||
* The token signature
|
||||
*
|
||||
* @var Signature
|
||||
*/
|
||||
private $signature;
|
||||
private $claims = [];
|
||||
|
||||
/**
|
||||
* The data encoder
|
||||
@@ -55,6 +48,16 @@ class Builder
|
||||
*/
|
||||
private $claimFactory;
|
||||
|
||||
/**
|
||||
* @var Signer|null
|
||||
*/
|
||||
private $signer;
|
||||
|
||||
/**
|
||||
* @var Key|null
|
||||
*/
|
||||
private $key;
|
||||
|
||||
/**
|
||||
* Initializes a new builder
|
||||
*
|
||||
@@ -67,13 +70,43 @@ class Builder
|
||||
) {
|
||||
$this->encoder = $encoder ?: new Encoder();
|
||||
$this->claimFactory = $claimFactory ?: new ClaimFactory();
|
||||
$this->headers = ['typ'=> 'JWT', 'alg' => 'none'];
|
||||
$this->claims = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the audience
|
||||
*
|
||||
* @deprecated This method has been wrongly added and doesn't exist on v4
|
||||
* @see Builder::permittedFor()
|
||||
*
|
||||
* @param string $audience
|
||||
* @param bool $replicateAsHeader
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function canOnlyBeUsedBy($audience, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->setRegisteredClaim('aud', (string) $audience, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the audience
|
||||
*
|
||||
* @param string $audience
|
||||
* @param bool $replicateAsHeader
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function permittedFor($audience, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->setRegisteredClaim('aud', (string) $audience, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the audience
|
||||
*
|
||||
* @deprecated This method will be removed on v4
|
||||
* @see Builder::permittedFor()
|
||||
*
|
||||
* @param string $audience
|
||||
* @param boolean $replicateAsHeader
|
||||
*
|
||||
@@ -92,6 +125,22 @@ class Builder
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function expiresAt($expiration, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->setRegisteredClaim('exp', (int) $expiration, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the expiration time
|
||||
*
|
||||
* @deprecated This method will be removed on v4
|
||||
* @see Builder::expiresAt()
|
||||
*
|
||||
* @param int $expiration
|
||||
* @param boolean $replicateAsHeader
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function setExpiration($expiration, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->setRegisteredClaim('exp', (int) $expiration, $replicateAsHeader);
|
||||
@@ -105,11 +154,27 @@ class Builder
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function setId($id, $replicateAsHeader = false)
|
||||
public function identifiedBy($id, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->setRegisteredClaim('jti', (string) $id, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the token id
|
||||
*
|
||||
* @deprecated This method will be removed on v4
|
||||
* @see Builder::identifiedBy()
|
||||
*
|
||||
* @param string $id
|
||||
* @param boolean $replicateAsHeader
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function setId($id, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->identifiedBy($id, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the time that the token was issued
|
||||
*
|
||||
@@ -118,11 +183,27 @@ class Builder
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function setIssuedAt($issuedAt, $replicateAsHeader = false)
|
||||
public function issuedAt($issuedAt, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->setRegisteredClaim('iat', (int) $issuedAt, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the time that the token was issued
|
||||
*
|
||||
* @deprecated This method will be removed on v4
|
||||
* @see Builder::issuedAt()
|
||||
*
|
||||
* @param int $issuedAt
|
||||
* @param boolean $replicateAsHeader
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function setIssuedAt($issuedAt, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->issuedAt($issuedAt, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the issuer
|
||||
*
|
||||
@@ -131,11 +212,27 @@ class Builder
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function setIssuer($issuer, $replicateAsHeader = false)
|
||||
public function issuedBy($issuer, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->setRegisteredClaim('iss', (string) $issuer, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the issuer
|
||||
*
|
||||
* @deprecated This method will be removed on v4
|
||||
* @see Builder::issuedBy()
|
||||
*
|
||||
* @param string $issuer
|
||||
* @param boolean $replicateAsHeader
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function setIssuer($issuer, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->issuedBy($issuer, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the time before which the token cannot be accepted
|
||||
*
|
||||
@@ -144,11 +241,27 @@ class Builder
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function setNotBefore($notBefore, $replicateAsHeader = false)
|
||||
public function canOnlyBeUsedAfter($notBefore, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->setRegisteredClaim('nbf', (int) $notBefore, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the time before which the token cannot be accepted
|
||||
*
|
||||
* @deprecated This method will be removed on v4
|
||||
* @see Builder::canOnlyBeUsedAfter()
|
||||
*
|
||||
* @param int $notBefore
|
||||
* @param boolean $replicateAsHeader
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function setNotBefore($notBefore, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->canOnlyBeUsedAfter($notBefore, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the subject
|
||||
*
|
||||
@@ -157,13 +270,29 @@ class Builder
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function setSubject($subject, $replicateAsHeader = false)
|
||||
public function relatedTo($subject, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->setRegisteredClaim('sub', (string) $subject, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a registed claim
|
||||
* Configures the subject
|
||||
*
|
||||
* @deprecated This method will be removed on v4
|
||||
* @see Builder::relatedTo()
|
||||
*
|
||||
* @param string $subject
|
||||
* @param boolean $replicateAsHeader
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function setSubject($subject, $replicateAsHeader = false)
|
||||
{
|
||||
return $this->relatedTo($subject, $replicateAsHeader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a registered claim
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
@@ -173,7 +302,7 @@ class Builder
|
||||
*/
|
||||
protected function setRegisteredClaim($name, $value, $replicate)
|
||||
{
|
||||
$this->set($name, $value);
|
||||
$this->withClaim($name, $value);
|
||||
|
||||
if ($replicate) {
|
||||
$this->headers[$name] = $this->claims[$name];
|
||||
@@ -189,20 +318,46 @@ class Builder
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Builder
|
||||
*
|
||||
* @throws BadMethodCallException When data has been already signed
|
||||
*/
|
||||
public function setHeader($name, $value)
|
||||
public function withHeader($name, $value)
|
||||
{
|
||||
if ($this->signature) {
|
||||
throw new BadMethodCallException('You must unsign before make changes');
|
||||
}
|
||||
|
||||
$this->headers[(string) $name] = $this->claimFactory->create($name, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a header item
|
||||
*
|
||||
* @deprecated This method will be removed on v4
|
||||
* @see Builder::withHeader()
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function setHeader($name, $value)
|
||||
{
|
||||
return $this->withHeader($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a claim item
|
||||
*
|
||||
* @deprecated This method has been wrongly added and doesn't exist on v4
|
||||
* @see Builder::withClaim()
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function with($name, $value)
|
||||
{
|
||||
return $this->withClaim($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a claim item
|
||||
*
|
||||
@@ -210,23 +365,36 @@ class Builder
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Builder
|
||||
*
|
||||
* @throws BadMethodCallException When data has been already signed
|
||||
*/
|
||||
public function set($name, $value)
|
||||
public function withClaim($name, $value)
|
||||
{
|
||||
if ($this->signature) {
|
||||
throw new BadMethodCallException('You must unsign before making changes');
|
||||
}
|
||||
|
||||
$this->claims[(string) $name] = $this->claimFactory->create($name, $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a claim item
|
||||
*
|
||||
* @deprecated This method will be removed on v4
|
||||
* @see Builder::withClaim()
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
return $this->withClaim($name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Signs the data
|
||||
*
|
||||
* @deprecated This method will be removed on v4
|
||||
* @see Builder::getToken()
|
||||
*
|
||||
* @param Signer $signer
|
||||
* @param Key|string $key
|
||||
*
|
||||
@@ -234,12 +402,12 @@ class Builder
|
||||
*/
|
||||
public function sign(Signer $signer, $key)
|
||||
{
|
||||
$signer->modifyHeader($this->headers);
|
||||
if (! $key instanceof Key) {
|
||||
$key = new Key($key);
|
||||
}
|
||||
|
||||
$this->signature = $signer->sign(
|
||||
$this->getToken()->getPayload(),
|
||||
$key
|
||||
);
|
||||
$this->signer = $signer;
|
||||
$this->key = $key;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -247,11 +415,15 @@ class Builder
|
||||
/**
|
||||
* Removes the signature from the builder
|
||||
*
|
||||
* @deprecated This method will be removed on v4
|
||||
* @see Builder::getToken()
|
||||
*
|
||||
* @return Builder
|
||||
*/
|
||||
public function unsign()
|
||||
{
|
||||
$this->signature = null;
|
||||
$this->signer = null;
|
||||
$this->key = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -261,17 +433,40 @@ class Builder
|
||||
*
|
||||
* @return Token
|
||||
*/
|
||||
public function getToken()
|
||||
public function getToken(Signer $signer = null, Key $key = null)
|
||||
{
|
||||
$signer = $signer ?: $this->signer;
|
||||
$key = $key ?: $this->key;
|
||||
|
||||
if ($signer instanceof Signer) {
|
||||
$signer->modifyHeader($this->headers);
|
||||
}
|
||||
|
||||
$payload = [
|
||||
$this->encoder->base64UrlEncode($this->encoder->jsonEncode($this->headers)),
|
||||
$this->encoder->base64UrlEncode($this->encoder->jsonEncode($this->claims))
|
||||
];
|
||||
|
||||
if ($this->signature !== null) {
|
||||
$payload[] = $this->encoder->base64UrlEncode($this->signature);
|
||||
$signature = $this->createSignature($payload, $signer, $key);
|
||||
|
||||
if ($signature !== null) {
|
||||
$payload[] = $this->encoder->base64UrlEncode($signature);
|
||||
}
|
||||
|
||||
return new Token($this->headers, $this->claims, $this->signature, $payload);
|
||||
return new Token($this->headers, $this->claims, $signature, $payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $payload
|
||||
*
|
||||
* @return Signature|null
|
||||
*/
|
||||
private function createSignature(array $payload, Signer $signer = null, Key $key = null)
|
||||
{
|
||||
if ($signer === null || $key === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $signer->sign(implode('.', $payload), $key);
|
||||
}
|
||||
}
|
||||
|
2
vendor/lcobucci/jwt/src/Claim.php
vendored
2
vendor/lcobucci/jwt/src/Claim.php
vendored
@@ -27,7 +27,7 @@ interface Claim extends JsonSerializable
|
||||
/**
|
||||
* Returns the claim value
|
||||
*
|
||||
* @return string
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue();
|
||||
|
||||
|
2
vendor/lcobucci/jwt/src/Claim/Basic.php
vendored
2
vendor/lcobucci/jwt/src/Claim/Basic.php
vendored
@@ -12,6 +12,8 @@ use Lcobucci\JWT\Claim;
|
||||
/**
|
||||
* The default claim
|
||||
*
|
||||
* @deprecated This class will be removed on v4
|
||||
*
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
2
vendor/lcobucci/jwt/src/Claim/EqualsTo.php
vendored
2
vendor/lcobucci/jwt/src/Claim/EqualsTo.php
vendored
@@ -13,6 +13,8 @@ use Lcobucci\JWT\ValidationData;
|
||||
/**
|
||||
* Validatable claim that checks if value is strictly equals to the given data
|
||||
*
|
||||
* @deprecated This class will be removed on v4
|
||||
*
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
2
vendor/lcobucci/jwt/src/Claim/Factory.php
vendored
2
vendor/lcobucci/jwt/src/Claim/Factory.php
vendored
@@ -12,6 +12,8 @@ use Lcobucci\JWT\Claim;
|
||||
/**
|
||||
* Class that create claims
|
||||
*
|
||||
* @deprecated This class will be removed on v4
|
||||
*
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
@@ -13,6 +13,8 @@ use Lcobucci\JWT\ValidationData;
|
||||
/**
|
||||
* Validatable claim that checks if value is greater or equals the given data
|
||||
*
|
||||
* @deprecated This class will be removed on v4
|
||||
*
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
@@ -13,6 +13,8 @@ use Lcobucci\JWT\ValidationData;
|
||||
/**
|
||||
* Validatable claim that checks if value is lesser or equals to the given data
|
||||
*
|
||||
* @deprecated This class will be removed on v4
|
||||
*
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
@@ -12,6 +12,8 @@ use Lcobucci\JWT\ValidationData;
|
||||
/**
|
||||
* Basic interface for validatable token claims
|
||||
*
|
||||
* @deprecated This interface will be removed on v4
|
||||
*
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
4
vendor/lcobucci/jwt/src/Signature.php
vendored
4
vendor/lcobucci/jwt/src/Signature.php
vendored
@@ -7,6 +7,8 @@
|
||||
|
||||
namespace Lcobucci\JWT;
|
||||
|
||||
use Lcobucci\JWT\Signer\Key;
|
||||
|
||||
/**
|
||||
* This class represents a token signature
|
||||
*
|
||||
@@ -38,7 +40,7 @@ class Signature
|
||||
*
|
||||
* @param Signer $signer
|
||||
* @param string $payload
|
||||
* @param string $key
|
||||
* @param Key|string $key
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
|
@@ -13,6 +13,8 @@ use Lcobucci\JWT\Signer;
|
||||
/**
|
||||
* Base class for signers
|
||||
*
|
||||
* @deprecated This class will be removed on v4
|
||||
*
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 0.1.0
|
||||
*/
|
||||
|
134
vendor/lcobucci/jwt/src/Signer/Ecdsa.php
vendored
134
vendor/lcobucci/jwt/src/Signer/Ecdsa.php
vendored
@@ -7,13 +7,9 @@
|
||||
|
||||
namespace Lcobucci\JWT\Signer;
|
||||
|
||||
use Lcobucci\JWT\Signer\Ecdsa\KeyParser;
|
||||
use Mdanter\Ecc\Crypto\Signature\Signature;
|
||||
use Mdanter\Ecc\Crypto\Signature\Signer;
|
||||
use Mdanter\Ecc\EccFactory;
|
||||
use Mdanter\Ecc\Math\MathAdapterInterface as Adapter;
|
||||
use Mdanter\Ecc\Random\RandomGeneratorFactory;
|
||||
use Mdanter\Ecc\Random\RandomNumberGeneratorInterface;
|
||||
use Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter;
|
||||
use Lcobucci\JWT\Signer\Ecdsa\SignatureConverter;
|
||||
use const OPENSSL_KEYTYPE_EC;
|
||||
|
||||
/**
|
||||
* Base class for ECDSA signers
|
||||
@@ -21,133 +17,53 @@ use Mdanter\Ecc\Random\RandomNumberGeneratorInterface;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
abstract class Ecdsa extends BaseSigner
|
||||
abstract class Ecdsa extends OpenSSL
|
||||
{
|
||||
/**
|
||||
* @var Adapter
|
||||
* @var SignatureConverter
|
||||
*/
|
||||
private $adapter;
|
||||
private $converter;
|
||||
|
||||
/**
|
||||
* @var Signer
|
||||
*/
|
||||
private $signer;
|
||||
|
||||
/**
|
||||
* @var KeyParser
|
||||
*/
|
||||
private $parser;
|
||||
|
||||
/**
|
||||
* @param Adapter $adapter
|
||||
* @param EcdsaSigner $signer
|
||||
* @param KeyParser $parser
|
||||
*/
|
||||
public function __construct(Adapter $adapter = null, Signer $signer = null, KeyParser $parser = null)
|
||||
public function __construct(SignatureConverter $converter = null)
|
||||
{
|
||||
$this->adapter = $adapter ?: EccFactory::getAdapter();
|
||||
$this->signer = $signer ?: EccFactory::getSigner($this->adapter);
|
||||
$this->parser = $parser ?: new KeyParser($this->adapter);
|
||||
$this->converter = $converter ?: new MultibyteStringConverter();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createHash(
|
||||
$payload,
|
||||
Key $key,
|
||||
RandomNumberGeneratorInterface $generator = null
|
||||
) {
|
||||
$privateKey = $this->parser->getPrivateKey($key);
|
||||
$generator = $generator ?: RandomGeneratorFactory::getRandomGenerator();
|
||||
|
||||
return $this->createSignatureHash(
|
||||
$this->signer->sign(
|
||||
$privateKey,
|
||||
$this->createSigningHash($payload),
|
||||
$generator->generate($privateKey->getPoint()->getOrder())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a binary signature with R and S coordinates
|
||||
*
|
||||
* @param Signature $signature
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function createSignatureHash(Signature $signature)
|
||||
public function createHash($payload, Key $key)
|
||||
{
|
||||
$length = $this->getSignatureLength();
|
||||
|
||||
return pack(
|
||||
'H*',
|
||||
sprintf(
|
||||
'%s%s',
|
||||
str_pad($this->adapter->decHex($signature->getR()), $length, '0', STR_PAD_LEFT),
|
||||
str_pad($this->adapter->decHex($signature->getS()), $length, '0', STR_PAD_LEFT)
|
||||
)
|
||||
return $this->converter->fromAsn1(
|
||||
parent::createHash($payload, $key),
|
||||
$this->getKeyLength()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a hash using the signer algorithm with given payload
|
||||
*
|
||||
* @param string $payload
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
private function createSigningHash($payload)
|
||||
{
|
||||
return $this->adapter->hexDec(hash($this->getAlgorithm(), $payload));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function doVerify($expected, $payload, Key $key)
|
||||
{
|
||||
return $this->signer->verify(
|
||||
$this->parser->getPublicKey($key),
|
||||
$this->extractSignature($expected),
|
||||
$this->createSigningHash($payload)
|
||||
return parent::doVerify(
|
||||
$this->converter->toAsn1($expected, $this->getKeyLength()),
|
||||
$payload,
|
||||
$key
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts R and S values from given data
|
||||
* Returns the length of each point in the signature, so that we can calculate and verify R and S points properly
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return \Mdanter\Ecc\Crypto\Signature\Signature
|
||||
* @internal
|
||||
*/
|
||||
private function extractSignature($value)
|
||||
abstract public function getKeyLength();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
final public function getKeyType()
|
||||
{
|
||||
$length = $this->getSignatureLength();
|
||||
$value = unpack('H*', $value)[1];
|
||||
|
||||
return new Signature(
|
||||
$this->adapter->hexDec(substr($value, 0, $length)),
|
||||
$this->adapter->hexDec(substr($value, $length))
|
||||
);
|
||||
return OPENSSL_KEYTYPE_EC;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of signature parts
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
abstract public function getSignatureLength();
|
||||
|
||||
/**
|
||||
* Returns the name of algorithm to be used to create the signing hash
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getAlgorithm();
|
||||
}
|
||||
|
104
vendor/lcobucci/jwt/src/Signer/Ecdsa/KeyParser.php
vendored
104
vendor/lcobucci/jwt/src/Signer/Ecdsa/KeyParser.php
vendored
@@ -1,104 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of Lcobucci\JWT, a simple library to handle JWT and JWS
|
||||
*
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
|
||||
*/
|
||||
|
||||
namespace Lcobucci\JWT\Signer\Ecdsa;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Lcobucci\JWT\Signer\Key;
|
||||
use Mdanter\Ecc\Math\MathAdapterInterface;
|
||||
use Mdanter\Ecc\Serializer\PrivateKey\DerPrivateKeySerializer;
|
||||
use Mdanter\Ecc\Serializer\PrivateKey\PemPrivateKeySerializer;
|
||||
use Mdanter\Ecc\Serializer\PrivateKey\PrivateKeySerializerInterface;
|
||||
use Mdanter\Ecc\Serializer\PublicKey\DerPublicKeySerializer;
|
||||
use Mdanter\Ecc\Serializer\PublicKey\PemPublicKeySerializer;
|
||||
use Mdanter\Ecc\Serializer\PublicKey\PublicKeySerializerInterface;
|
||||
|
||||
/**
|
||||
* Base class for ECDSA signers
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 3.0.4
|
||||
*/
|
||||
class KeyParser
|
||||
{
|
||||
/**
|
||||
* @var PrivateKeySerializerInterface
|
||||
*/
|
||||
private $privateKeySerializer;
|
||||
|
||||
/**
|
||||
* @var PublicKeySerializerInterface
|
||||
*/
|
||||
private $publicKeySerializer;
|
||||
|
||||
/**
|
||||
* @param MathAdapterInterface $adapter
|
||||
* @param PrivateKeySerializerInterface $privateKeySerializer
|
||||
* @param PublicKeySerializerInterface $publicKeySerializer
|
||||
*/
|
||||
public function __construct(
|
||||
MathAdapterInterface $adapter,
|
||||
PrivateKeySerializerInterface $privateKeySerializer = null,
|
||||
PublicKeySerializerInterface $publicKeySerializer = null
|
||||
) {
|
||||
$this->privateKeySerializer = $privateKeySerializer ?: new PemPrivateKeySerializer(new DerPrivateKeySerializer($adapter));
|
||||
$this->publicKeySerializer = $publicKeySerializer ?: new PemPublicKeySerializer(new DerPublicKeySerializer($adapter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a public key from the given PEM content
|
||||
*
|
||||
* @param Key $key
|
||||
*
|
||||
* @return \Mdanter\Ecc\Crypto\Key\PublicKeyInterface
|
||||
*/
|
||||
public function getPublicKey(Key $key)
|
||||
{
|
||||
return $this->publicKeySerializer->parse($this->getKeyContent($key, 'PUBLIC KEY'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a private key from the given PEM content
|
||||
*
|
||||
* @param Key $key
|
||||
*
|
||||
* @return \Mdanter\Ecc\Crypto\Key\PrivateKeyInterface
|
||||
*/
|
||||
public function getPrivateKey(Key $key)
|
||||
{
|
||||
return $this->privateKeySerializer->parse($this->getKeyContent($key, 'EC PRIVATE KEY'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts the base 64 value from the PEM certificate
|
||||
*
|
||||
* @param Key $key
|
||||
* @param string $header
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws InvalidArgumentException When given key is not a ECDSA key
|
||||
*/
|
||||
private function getKeyContent(Key $key, $header)
|
||||
{
|
||||
$match = null;
|
||||
|
||||
preg_match(
|
||||
'/[\-]{5}BEGIN ' . $header . '[\-]{5}(.*)[\-]{5}END ' . $header . '[\-]{5}/',
|
||||
str_replace([PHP_EOL, "\n", "\r"], '', $key->getContent()),
|
||||
$match
|
||||
);
|
||||
|
||||
if (isset($match[1])) {
|
||||
return $match[1];
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException('This is not a valid ECDSA key.');
|
||||
}
|
||||
}
|
134
vendor/lcobucci/jwt/src/Signer/Ecdsa/MultibyteStringConverter.php
vendored
Normal file
134
vendor/lcobucci/jwt/src/Signer/Ecdsa/MultibyteStringConverter.php
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
/*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2014-2018 Spomky-Labs
|
||||
*
|
||||
* This software may be modified and distributed under the terms
|
||||
* of the MIT license. See the LICENSE file for details.
|
||||
*
|
||||
* @link https://github.com/web-token/jwt-framework/blob/v1.2/src/Component/Core/Util/ECSignature.php
|
||||
*/
|
||||
namespace Lcobucci\JWT\Signer\Ecdsa;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use function bin2hex;
|
||||
use function dechex;
|
||||
use function hex2bin;
|
||||
use function hexdec;
|
||||
use function mb_strlen;
|
||||
use function mb_substr;
|
||||
use function str_pad;
|
||||
use const STR_PAD_LEFT;
|
||||
|
||||
/**
|
||||
* ECDSA signature converter using ext-mbstring
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class MultibyteStringConverter implements SignatureConverter
|
||||
{
|
||||
const ASN1_SEQUENCE = '30';
|
||||
const ASN1_INTEGER = '02';
|
||||
const ASN1_MAX_SINGLE_BYTE = 128;
|
||||
const ASN1_LENGTH_2BYTES = '81';
|
||||
const ASN1_BIG_INTEGER_LIMIT = '7f';
|
||||
const ASN1_NEGATIVE_INTEGER = '00';
|
||||
const BYTE_SIZE = 2;
|
||||
|
||||
public function toAsn1($signature, $length)
|
||||
{
|
||||
$signature = bin2hex($signature);
|
||||
|
||||
if (self::octetLength($signature) !== $length) {
|
||||
throw new InvalidArgumentException('Invalid signature length.');
|
||||
}
|
||||
|
||||
$pointR = self::preparePositiveInteger(mb_substr($signature, 0, $length, '8bit'));
|
||||
$pointS = self::preparePositiveInteger(mb_substr($signature, $length, null, '8bit'));
|
||||
|
||||
$lengthR = self::octetLength($pointR);
|
||||
$lengthS = self::octetLength($pointS);
|
||||
|
||||
$totalLength = $lengthR + $lengthS + self::BYTE_SIZE + self::BYTE_SIZE;
|
||||
$lengthPrefix = $totalLength > self::ASN1_MAX_SINGLE_BYTE ? self::ASN1_LENGTH_2BYTES : '';
|
||||
|
||||
$asn1 = hex2bin(
|
||||
self::ASN1_SEQUENCE
|
||||
. $lengthPrefix . dechex($totalLength)
|
||||
. self::ASN1_INTEGER . dechex($lengthR) . $pointR
|
||||
. self::ASN1_INTEGER . dechex($lengthS) . $pointS
|
||||
);
|
||||
|
||||
return $asn1;
|
||||
}
|
||||
|
||||
private static function octetLength($data)
|
||||
{
|
||||
return (int) (mb_strlen($data, '8bit') / self::BYTE_SIZE);
|
||||
}
|
||||
|
||||
private static function preparePositiveInteger($data)
|
||||
{
|
||||
if (mb_substr($data, 0, self::BYTE_SIZE, '8bit') > self::ASN1_BIG_INTEGER_LIMIT) {
|
||||
return self::ASN1_NEGATIVE_INTEGER . $data;
|
||||
}
|
||||
|
||||
while (mb_substr($data, 0, self::BYTE_SIZE, '8bit') === self::ASN1_NEGATIVE_INTEGER
|
||||
&& mb_substr($data, 2, self::BYTE_SIZE, '8bit') <= self::ASN1_BIG_INTEGER_LIMIT) {
|
||||
$data = mb_substr($data, 2, null, '8bit');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function fromAsn1($signature, $length)
|
||||
{
|
||||
$message = bin2hex($signature);
|
||||
$position = 0;
|
||||
|
||||
if (self::readAsn1Content($message, $position, self::BYTE_SIZE) !== self::ASN1_SEQUENCE) {
|
||||
throw new InvalidArgumentException('Invalid data. Should start with a sequence.');
|
||||
}
|
||||
|
||||
if (self::readAsn1Content($message, $position, self::BYTE_SIZE) === self::ASN1_LENGTH_2BYTES) {
|
||||
$position += self::BYTE_SIZE;
|
||||
}
|
||||
|
||||
$pointR = self::retrievePositiveInteger(self::readAsn1Integer($message, $position));
|
||||
$pointS = self::retrievePositiveInteger(self::readAsn1Integer($message, $position));
|
||||
|
||||
$points = hex2bin(str_pad($pointR, $length, '0', STR_PAD_LEFT) . str_pad($pointS, $length, '0', STR_PAD_LEFT));
|
||||
|
||||
return $points;
|
||||
}
|
||||
|
||||
private static function readAsn1Content($message, &$position, $length)
|
||||
{
|
||||
$content = mb_substr($message, $position, $length, '8bit');
|
||||
$position += $length;
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
private static function readAsn1Integer($message, &$position)
|
||||
{
|
||||
if (self::readAsn1Content($message, $position, self::BYTE_SIZE) !== self::ASN1_INTEGER) {
|
||||
throw new InvalidArgumentException('Invalid data. Should contain an integer.');
|
||||
}
|
||||
|
||||
$length = (int) hexdec(self::readAsn1Content($message, $position, self::BYTE_SIZE));
|
||||
|
||||
return self::readAsn1Content($message, $position, $length * self::BYTE_SIZE);
|
||||
}
|
||||
|
||||
private static function retrievePositiveInteger($data)
|
||||
{
|
||||
while (mb_substr($data, 0, self::BYTE_SIZE, '8bit') === self::ASN1_NEGATIVE_INTEGER
|
||||
&& mb_substr($data, 2, self::BYTE_SIZE, '8bit') > self::ASN1_BIG_INTEGER_LIMIT) {
|
||||
$data = mb_substr($data, 2, null, '8bit');
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@@ -36,7 +36,7 @@ class Sha256 extends Ecdsa
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSignatureLength()
|
||||
public function getKeyLength()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ class Sha384 extends Ecdsa
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSignatureLength()
|
||||
public function getKeyLength()
|
||||
{
|
||||
return 96;
|
||||
}
|
||||
|
@@ -36,7 +36,7 @@ class Sha512 extends Ecdsa
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSignatureLength()
|
||||
public function getKeyLength()
|
||||
{
|
||||
return 132;
|
||||
}
|
||||
|
38
vendor/lcobucci/jwt/src/Signer/Ecdsa/SignatureConverter.php
vendored
Normal file
38
vendor/lcobucci/jwt/src/Signer/Ecdsa/SignatureConverter.php
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace Lcobucci\JWT\Signer\Ecdsa;
|
||||
|
||||
/**
|
||||
* Manipulates the result of a ECDSA signature (points R and S) according to the
|
||||
* JWA specs.
|
||||
*
|
||||
* OpenSSL creates a signature using the ASN.1 format and, according the JWA specs,
|
||||
* the signature for JWTs must be the concatenated values of points R and S (in
|
||||
* big-endian octet order).
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @see https://tools.ietf.org/html/rfc7518#page-9
|
||||
* @see https://en.wikipedia.org/wiki/Abstract_Syntax_Notation_One
|
||||
*/
|
||||
interface SignatureConverter
|
||||
{
|
||||
/**
|
||||
* Converts the signature generated by OpenSSL into what JWA defines
|
||||
*
|
||||
* @param string $signature
|
||||
* @param int $length
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function fromAsn1($signature, $length);
|
||||
|
||||
/**
|
||||
* Converts the JWA signature into something OpenSSL understands
|
||||
*
|
||||
* @param string $points
|
||||
* @param int $length
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toAsn1($points, $length);
|
||||
}
|
2
vendor/lcobucci/jwt/src/Signer/Key.php
vendored
2
vendor/lcobucci/jwt/src/Signer/Key.php
vendored
@@ -70,7 +70,7 @@ final class Key
|
||||
|
||||
return $content;
|
||||
} catch (Exception $exception) {
|
||||
throw new InvalidArgumentException('You must inform a valid key file', 0, $exception);
|
||||
throw new InvalidArgumentException('You must provide a valid key file', 0, $exception);
|
||||
}
|
||||
}
|
||||
|
||||
|
115
vendor/lcobucci/jwt/src/Signer/OpenSSL.php
vendored
Normal file
115
vendor/lcobucci/jwt/src/Signer/OpenSSL.php
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
namespace Lcobucci\JWT\Signer;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Lcobucci\JWT\Signer;
|
||||
use function assert;
|
||||
use function is_array;
|
||||
use function is_resource;
|
||||
use function openssl_error_string;
|
||||
use function openssl_free_key;
|
||||
use function openssl_pkey_get_details;
|
||||
use function openssl_pkey_get_private;
|
||||
use function openssl_pkey_get_public;
|
||||
use function openssl_sign;
|
||||
use function openssl_verify;
|
||||
|
||||
abstract class OpenSSL extends BaseSigner
|
||||
{
|
||||
public function createHash($payload, Key $key)
|
||||
{
|
||||
$privateKey = $this->getPrivateKey($key->getContent(), $key->getPassphrase());
|
||||
|
||||
try {
|
||||
$signature = '';
|
||||
|
||||
if (! openssl_sign($payload, $signature, $privateKey, $this->getAlgorithm())) {
|
||||
throw new InvalidArgumentException(
|
||||
'There was an error while creating the signature: ' . openssl_error_string()
|
||||
);
|
||||
}
|
||||
|
||||
return $signature;
|
||||
} finally {
|
||||
openssl_free_key($privateKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $pem
|
||||
* @param string $passphrase
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
private function getPrivateKey($pem, $passphrase)
|
||||
{
|
||||
$privateKey = openssl_pkey_get_private($pem, $passphrase);
|
||||
$this->validateKey($privateKey);
|
||||
|
||||
return $privateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $expected
|
||||
* @param $payload
|
||||
* @param $pem
|
||||
* @return bool
|
||||
*/
|
||||
public function doVerify($expected, $payload, Key $key)
|
||||
{
|
||||
$publicKey = $this->getPublicKey($key->getContent());
|
||||
$result = openssl_verify($payload, $expected, $publicKey, $this->getAlgorithm());
|
||||
openssl_free_key($publicKey);
|
||||
|
||||
return $result === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $pem
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
private function getPublicKey($pem)
|
||||
{
|
||||
$publicKey = openssl_pkey_get_public($pem);
|
||||
$this->validateKey($publicKey);
|
||||
|
||||
return $publicKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Raises an exception when the key type is not the expected type
|
||||
*
|
||||
* @param resource|bool $key
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
private function validateKey($key)
|
||||
{
|
||||
if (! is_resource($key)) {
|
||||
throw new InvalidArgumentException(
|
||||
'It was not possible to parse your key, reason: ' . openssl_error_string()
|
||||
);
|
||||
}
|
||||
|
||||
$details = openssl_pkey_get_details($key);
|
||||
|
||||
if (! isset($details['key']) || $details['type'] !== $this->getKeyType()) {
|
||||
throw new InvalidArgumentException('This key is not compatible with this signer');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of key to be used to create/verify the signature (using OpenSSL constants)
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
abstract public function getKeyType();
|
||||
|
||||
/**
|
||||
* Returns which algorithm to be used to create/verify the signature (using OpenSSL constants)
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
abstract public function getAlgorithm();
|
||||
}
|
64
vendor/lcobucci/jwt/src/Signer/Rsa.php
vendored
64
vendor/lcobucci/jwt/src/Signer/Rsa.php
vendored
@@ -7,7 +7,7 @@
|
||||
|
||||
namespace Lcobucci\JWT\Signer;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use const OPENSSL_KEYTYPE_RSA;
|
||||
|
||||
/**
|
||||
* Base class for RSASSA-PKCS1 signers
|
||||
@@ -15,66 +15,10 @@ use InvalidArgumentException;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
abstract class Rsa extends BaseSigner
|
||||
abstract class Rsa extends OpenSSL
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createHash($payload, Key $key)
|
||||
final public function getKeyType()
|
||||
{
|
||||
$key = openssl_get_privatekey($key->getContent(), $key->getPassphrase());
|
||||
$this->validateKey($key);
|
||||
|
||||
$signature = '';
|
||||
|
||||
if (!openssl_sign($payload, $signature, $key, $this->getAlgorithm())) {
|
||||
throw new InvalidArgumentException(
|
||||
'There was an error while creating the signature: ' . openssl_error_string()
|
||||
);
|
||||
}
|
||||
|
||||
return $signature;
|
||||
return OPENSSL_KEYTYPE_RSA;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function doVerify($expected, $payload, Key $key)
|
||||
{
|
||||
$key = openssl_get_publickey($key->getContent());
|
||||
$this->validateKey($key);
|
||||
|
||||
return openssl_verify($payload, $expected, $key, $this->getAlgorithm()) === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates if the given key is a valid RSA public/private key
|
||||
*
|
||||
* @param resource $key
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
private function validateKey($key)
|
||||
{
|
||||
if ($key === false) {
|
||||
throw new InvalidArgumentException(
|
||||
'It was not possible to parse your key, reason: ' . openssl_error_string()
|
||||
);
|
||||
}
|
||||
|
||||
$details = openssl_pkey_get_details($key);
|
||||
|
||||
if (!isset($details['key']) || $details['type'] !== OPENSSL_KEYTYPE_RSA) {
|
||||
throw new InvalidArgumentException('This key is not compatible with RSA signatures');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the algorithm name
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getAlgorithm();
|
||||
}
|
||||
|
3
vendor/lcobucci/jwt/src/Token.php
vendored
3
vendor/lcobucci/jwt/src/Token.php
vendored
@@ -12,6 +12,7 @@ use DateTime;
|
||||
use DateTimeInterface;
|
||||
use Generator;
|
||||
use Lcobucci\JWT\Claim\Validatable;
|
||||
use Lcobucci\JWT\Signer\Key;
|
||||
use OutOfBoundsException;
|
||||
|
||||
/**
|
||||
@@ -182,7 +183,7 @@ class Token
|
||||
* Verify if the key matches with the one that created the signature
|
||||
*
|
||||
* @param Signer $signer
|
||||
* @param string $key
|
||||
* @param Key|string $key
|
||||
*
|
||||
* @return boolean
|
||||
*
|
||||
|
27
vendor/lcobucci/jwt/src/ValidationData.php
vendored
27
vendor/lcobucci/jwt/src/ValidationData.php
vendored
@@ -22,24 +22,31 @@ class ValidationData
|
||||
*/
|
||||
private $items;
|
||||
|
||||
/**
|
||||
* The leeway (in seconds) to use when validating time claims
|
||||
* @var int
|
||||
*/
|
||||
private $leeway;
|
||||
|
||||
/**
|
||||
* Initializes the object
|
||||
*
|
||||
* @param int $currentTime
|
||||
* @param int $leeway
|
||||
*/
|
||||
public function __construct($currentTime = null)
|
||||
public function __construct($currentTime = null, $leeway = 0)
|
||||
{
|
||||
$currentTime = $currentTime ?: time();
|
||||
$currentTime = $currentTime ?: time();
|
||||
$this->leeway = (int) $leeway;
|
||||
|
||||
$this->items = [
|
||||
'jti' => null,
|
||||
'iss' => null,
|
||||
'aud' => null,
|
||||
'sub' => null,
|
||||
'iat' => $currentTime,
|
||||
'nbf' => $currentTime,
|
||||
'exp' => $currentTime
|
||||
'sub' => null
|
||||
];
|
||||
|
||||
$this->setCurrentTime($currentTime);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,9 +96,11 @@ class ValidationData
|
||||
*/
|
||||
public function setCurrentTime($currentTime)
|
||||
{
|
||||
$this->items['iat'] = (int) $currentTime;
|
||||
$this->items['nbf'] = (int) $currentTime;
|
||||
$this->items['exp'] = (int) $currentTime;
|
||||
$currentTime = (int) $currentTime;
|
||||
|
||||
$this->items['iat'] = $currentTime + $this->leeway;
|
||||
$this->items['nbf'] = $currentTime + $this->leeway;
|
||||
$this->items['exp'] = $currentTime - $this->leeway;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -21,7 +21,7 @@ use Lcobucci\JWT\Keys;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
class EcdsaTokenTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
use Keys;
|
||||
|
||||
@@ -52,8 +52,9 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
*/
|
||||
public function builderShouldRaiseExceptionWhenKeyIsInvalid()
|
||||
{
|
||||
@@ -63,7 +64,7 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
->setAudience('http://client.abc.com')
|
||||
->setIssuer('http://api.abc.com')
|
||||
->set('user', $user)
|
||||
->sign($this->signer, new Key('testing'));
|
||||
->getToken($this->signer, new Key('testing'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,8 +81,9 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
*/
|
||||
public function builderShouldRaiseExceptionWhenKeyIsNotEcdsaCompatible()
|
||||
{
|
||||
@@ -91,7 +93,7 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
->setAudience('http://client.abc.com')
|
||||
->setIssuer('http://api.abc.com')
|
||||
->set('user', $user)
|
||||
->sign($this->signer, static::$rsaKeys['private']);
|
||||
->getToken($this->signer, static::$rsaKeys['private']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,8 +108,9 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
*/
|
||||
public function builderCanGenerateAToken()
|
||||
{
|
||||
@@ -144,7 +147,6 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Parsing\Encoder
|
||||
* @covers Lcobucci\JWT\Parsing\Decoder
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
*/
|
||||
public function parserCanReadAToken(Token $generated)
|
||||
{
|
||||
@@ -169,8 +171,9 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
*/
|
||||
public function verifyShouldReturnFalseWhenKeyIsNotRight(Token $token)
|
||||
{
|
||||
@@ -192,9 +195,10 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha512
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
*/
|
||||
public function verifyShouldReturnFalseWhenAlgorithmIsDifferent(Token $token)
|
||||
{
|
||||
@@ -204,7 +208,7 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedException \InvalidArgumentException
|
||||
*
|
||||
* @depends builderCanGenerateAToken
|
||||
*
|
||||
@@ -218,8 +222,9 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
*/
|
||||
public function verifyShouldRaiseExceptionWhenKeyIsNotEcdsaCompatible(Token $token)
|
||||
{
|
||||
@@ -241,8 +246,9 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
*/
|
||||
public function verifyShouldReturnTrueWhenKeyIsRight(Token $token)
|
||||
{
|
||||
@@ -261,8 +267,9 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
*/
|
||||
public function everythingShouldWorkWithAKeyWithParams()
|
||||
{
|
||||
@@ -289,8 +296,9 @@ class EcdsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha512
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers Lcobucci\JWT\Signer\Keychain
|
||||
* @covers Lcobucci\JWT\Claim\Factory
|
||||
* @covers Lcobucci\JWT\Claim\Basic
|
||||
|
@@ -18,7 +18,7 @@ use Lcobucci\JWT\Signer\Hmac\Sha512;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class HmacTokenTest extends \PHPUnit_Framework_TestCase
|
||||
class HmacTokenTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Sha256
|
||||
|
154
vendor/lcobucci/jwt/test/functional/RFC6978VectorTest.php
vendored
Normal file
154
vendor/lcobucci/jwt/test/functional/RFC6978VectorTest.php
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
namespace Lcobucci\JWT\FunctionalTests;
|
||||
|
||||
use Lcobucci\JWT\Signer\Ecdsa;
|
||||
use Lcobucci\JWT\Signer\Ecdsa\Sha256;
|
||||
use Lcobucci\JWT\Signer\Ecdsa\Sha384;
|
||||
use Lcobucci\JWT\Signer\Ecdsa\Sha512;
|
||||
use Lcobucci\JWT\Signer\Key;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use const PHP_EOL;
|
||||
use function assert;
|
||||
use function hex2bin;
|
||||
use function is_string;
|
||||
|
||||
final class RFC6978VectorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @see https://tools.ietf.org/html/rfc6979#appendix-A.2.5
|
||||
* @see https://tools.ietf.org/html/rfc6979#appendix-A.2.6
|
||||
* @see https://tools.ietf.org/html/rfc6979#appendix-A.2.7
|
||||
*
|
||||
* @test
|
||||
* @dataProvider dataRFC6979
|
||||
*
|
||||
* @covers \Lcobucci\JWT\Signer\Key
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\Sha384
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\Sha512
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\BaseSigner
|
||||
*/
|
||||
public function theVectorsFromRFC6978CanBeVerified(
|
||||
Ecdsa $signer,
|
||||
Key $key,
|
||||
$payload,
|
||||
$expectedR,
|
||||
$expectedS
|
||||
) {
|
||||
$signature = hex2bin($expectedR . $expectedS);
|
||||
assert(is_string($signature));
|
||||
|
||||
static::assertTrue($signer->verify($signature, $payload, $key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function dataRFC6979()
|
||||
{
|
||||
return $this->sha256Data() + $this->sha384Data() + $this->sha512Data();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function sha256Data()
|
||||
{
|
||||
$signer = new Sha256();
|
||||
$key = new Key(
|
||||
'-----BEGIN PUBLIC KEY-----' . PHP_EOL
|
||||
. 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEYP7UuiVanTHJYet0xjVtaMBJuJI7' . PHP_EOL
|
||||
. 'Yfps5mliLmDyn7Z5A/4QCLi8maQa6elWKLxk8vGyDC1+n1F3o8KU1EYimQ==' . PHP_EOL
|
||||
. '-----END PUBLIC KEY-----'
|
||||
);
|
||||
|
||||
return [
|
||||
'SHA-256 (sample)' => [
|
||||
$signer,
|
||||
$key,
|
||||
'sample',
|
||||
'EFD48B2AACB6A8FD1140DD9CD45E81D69D2C877B56AAF991C34D0EA84EAF3716',
|
||||
'F7CB1C942D657C41D436C7A1B6E29F65F3E900DBB9AFF4064DC4AB2F843ACDA8',
|
||||
],
|
||||
'SHA-256 (test)' => [
|
||||
$signer,
|
||||
$key,
|
||||
'test',
|
||||
'F1ABB023518351CD71D881567B1EA663ED3EFCF6C5132B354F28D3B0B7D38367',
|
||||
'019F4113742A2B14BD25926B49C649155F267E60D3814B4C0CC84250E46F0083',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function sha384Data()
|
||||
{
|
||||
$signer = new Sha384();
|
||||
$key = new Key(
|
||||
'-----BEGIN PUBLIC KEY-----' . PHP_EOL
|
||||
. 'MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE7DpOQVtOGaRWhhgCn0J/pdqai8SukuAu' . PHP_EOL
|
||||
. 'BqrlKGswDGTe+PDqkFWGYGSiVFFUgLwTgBXZty19VyROqO+awMYhiWcIpZNn+d+5' . PHP_EOL
|
||||
. '9UyoSz8cnbEoiyMcOuDU/nNE/SUzJkcg' . PHP_EOL
|
||||
. '-----END PUBLIC KEY-----'
|
||||
);
|
||||
|
||||
return [
|
||||
'SHA-384 (sample)' => [
|
||||
$signer,
|
||||
$key,
|
||||
'sample',
|
||||
'94EDBB92A5ECB8AAD4736E56C691916B3F88140666CE9FA73D64C4EA95AD133C81A648152E44ACF96E36DD1E80FABE46',
|
||||
'99EF4AEB15F178CEA1FE40DB2603138F130E740A19624526203B6351D0A3A94FA329C145786E679E7B82C71A38628AC8',
|
||||
],
|
||||
'SHA-384 (test)' => [
|
||||
$signer,
|
||||
$key,
|
||||
'test',
|
||||
'8203B63D3C853E8D77227FB377BCF7B7B772E97892A80F36AB775D509D7A5FEB0542A7F0812998DA8F1DD3CA3CF023DB',
|
||||
'DDD0760448D42D8A43AF45AF836FCE4DE8BE06B485E9B61B827C2F13173923E06A739F040649A667BF3B828246BAA5A5',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed[]
|
||||
*/
|
||||
public function sha512Data()
|
||||
{
|
||||
$signer = new Sha512();
|
||||
$key = new Key(
|
||||
'-----BEGIN PUBLIC KEY-----' . PHP_EOL
|
||||
. 'MIGbMBAGByqGSM49AgEGBSuBBAAjA4GGAAQBiUVQ0HhZMuAOqiO2lPIT+MMSH4bc' . PHP_EOL
|
||||
. 'l6BOWnFn205bzTcRI9RuRdtrXVNwp/IPtjMVXTj/oW0r12HcrEdLmi9QI6QASTEB' . PHP_EOL
|
||||
. 'yWLNTS/d94IoXmRYQTnC+RtH+H/4I1TWYw90aiig2yV0G1s0qCgAiyKswj+ST6r7' . PHP_EOL
|
||||
. '1NM/gepmlW3+qiv9/PU=' . PHP_EOL
|
||||
. '-----END PUBLIC KEY-----'
|
||||
);
|
||||
|
||||
return [
|
||||
'SHA-512 (sample)' => [
|
||||
$signer,
|
||||
$key,
|
||||
'sample',
|
||||
'00C328FAFCBD79DD77850370C46325D987CB525569FB63C5D3BC53950E6D4C5F174E25A1EE9017B5D450606ADD152B534931D7D4E8'
|
||||
. '455CC91F9B15BF05EC36E377FA',
|
||||
'00617CCE7CF5064806C467F678D3B4080D6F1CC50AF26CA209417308281B68AF282623EAA63E5B5C0723D8B8C37FF0777B1A20F8CC'
|
||||
. 'B1DCCC43997F1EE0E44DA4A67A',
|
||||
],
|
||||
'SHA-512 (test)' => [
|
||||
$signer,
|
||||
$key,
|
||||
'test',
|
||||
'013E99020ABF5CEE7525D16B69B229652AB6BDF2AFFCAEF38773B4B7D08725F10CDB93482FDCC54EDCEE91ECA4166B2A7C6265EF0C'
|
||||
. 'E2BD7051B7CEF945BABD47EE6D',
|
||||
'01FBD0013C674AA79CB39849527916CE301C66EA7CE8B80682786AD60F98F7E78A19CA69EFF5C57400E3B3A0AD66CE0978214D13BA'
|
||||
. 'F4E9AC60752F7B155E2DE4DCE3',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
@@ -20,7 +20,7 @@ use Lcobucci\JWT\Signer\Rsa\Sha512;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class RsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
class RsaTokenTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
use Keys;
|
||||
|
||||
@@ -50,8 +50,9 @@ class RsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Parsing\Encoder
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Rsa
|
||||
* @covers Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
*/
|
||||
public function builderShouldRaiseExceptionWhenKeyIsInvalid()
|
||||
{
|
||||
@@ -61,7 +62,7 @@ class RsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
->setAudience('http://client.abc.com')
|
||||
->setIssuer('http://api.abc.com')
|
||||
->set('user', $user)
|
||||
->sign($this->signer, new Key('testing'));
|
||||
->getToken($this->signer, new Key('testing'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,8 +78,9 @@ class RsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Parsing\Encoder
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Rsa
|
||||
* @covers Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
*/
|
||||
public function builderShouldRaiseExceptionWhenKeyIsNotRsaCompatible()
|
||||
{
|
||||
@@ -88,7 +90,7 @@ class RsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
->setAudience('http://client.abc.com')
|
||||
->setIssuer('http://api.abc.com')
|
||||
->set('user', $user)
|
||||
->sign($this->signer, static::$ecdsaKeys['private']);
|
||||
->getToken($this->signer, static::$ecdsaKeys['private']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,8 +104,9 @@ class RsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Parsing\Encoder
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Rsa
|
||||
* @covers Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
*/
|
||||
public function builderCanGenerateAToken()
|
||||
{
|
||||
@@ -162,8 +165,9 @@ class RsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Claim\Basic
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Rsa
|
||||
* @covers Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
*/
|
||||
public function verifyShouldReturnFalseWhenKeyIsNotRight(Token $token)
|
||||
{
|
||||
@@ -184,9 +188,10 @@ class RsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Claim\Basic
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Rsa
|
||||
* @covers Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
* @covers Lcobucci\JWT\Signer\Rsa\Sha512
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa\Sha512
|
||||
*/
|
||||
public function verifyShouldReturnFalseWhenAlgorithmIsDifferent(Token $token)
|
||||
{
|
||||
@@ -209,8 +214,9 @@ class RsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Claim\Basic
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Rsa
|
||||
* @covers Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
*/
|
||||
public function verifyShouldRaiseExceptionWhenKeyIsNotRsaCompatible(Token $token)
|
||||
{
|
||||
@@ -231,8 +237,9 @@ class RsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Claim\Basic
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Rsa
|
||||
* @covers Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
*/
|
||||
public function verifyShouldReturnTrueWhenKeyIsRight(Token $token)
|
||||
{
|
||||
@@ -248,8 +255,9 @@ class RsaTokenTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Lcobucci\JWT\Signature
|
||||
* @covers Lcobucci\JWT\Signer\Key
|
||||
* @covers Lcobucci\JWT\Signer\BaseSigner
|
||||
* @covers Lcobucci\JWT\Signer\Rsa
|
||||
* @covers Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa\Sha256
|
||||
* @covers Lcobucci\JWT\Claim\Factory
|
||||
* @covers Lcobucci\JWT\Claim\Basic
|
||||
* @covers Lcobucci\JWT\Parsing\Encoder
|
||||
|
@@ -16,7 +16,7 @@ use Lcobucci\JWT\ValidationData;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class UnsignedTokenTest extends \PHPUnit_Framework_TestCase
|
||||
class UnsignedTokenTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
const CURRENT_TIME = 100000;
|
||||
|
||||
@@ -118,6 +118,30 @@ class UnsignedTokenTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($generated->validate($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @depends builderCanGenerateAToken
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder
|
||||
* @covers Lcobucci\JWT\Parser
|
||||
* @covers Lcobucci\JWT\Token
|
||||
* @covers Lcobucci\JWT\ValidationData
|
||||
* @covers Lcobucci\JWT\Claim\Factory
|
||||
* @covers Lcobucci\JWT\Claim\Basic
|
||||
* @covers Lcobucci\JWT\Claim\EqualsTo
|
||||
* @covers Lcobucci\JWT\Claim\GreaterOrEqualsTo
|
||||
* @covers Lcobucci\JWT\Parsing\Encoder
|
||||
* @covers Lcobucci\JWT\Parsing\Decoder
|
||||
*/
|
||||
public function tokenValidationShouldReturnTrueWhenExpectedDataMatchBecauseOfLeeway(Token $generated)
|
||||
{
|
||||
$notExpiredDueToLeeway = new ValidationData(self::CURRENT_TIME + 3020, 50);
|
||||
$notExpiredDueToLeeway->setAudience('http://client.abc.com');
|
||||
$notExpiredDueToLeeway->setIssuer('http://api.abc.com');
|
||||
$this->assertTrue($generated->validate($notExpiredDueToLeeway));
|
||||
}
|
||||
|
||||
public function invalidValidationData()
|
||||
{
|
||||
$expired = new ValidationData(self::CURRENT_TIME + 3020);
|
||||
|
300
vendor/lcobucci/jwt/test/unit/BuilderTest.php
vendored
300
vendor/lcobucci/jwt/test/unit/BuilderTest.php
vendored
@@ -9,12 +9,13 @@ namespace Lcobucci\JWT;
|
||||
|
||||
use Lcobucci\JWT\Claim\Factory as ClaimFactory;
|
||||
use Lcobucci\JWT\Parsing\Encoder;
|
||||
use Lcobucci\JWT\Signer\Key;
|
||||
|
||||
/**
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
class BuilderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Encoder|\PHPUnit_Framework_MockObject_MockObject
|
||||
@@ -36,9 +37,9 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->encoder = $this->getMock(Encoder::class);
|
||||
$this->claimFactory = $this->getMock(ClaimFactory::class, [], [], '', false);
|
||||
$this->defaultClaim = $this->getMock(Claim::class);
|
||||
$this->encoder = $this->createMock(Encoder::class);
|
||||
$this->claimFactory = $this->createMock(ClaimFactory::class);
|
||||
$this->defaultClaim = $this->createMock(Claim::class);
|
||||
|
||||
$this->claimFactory->expects($this->any())
|
||||
->method('create')
|
||||
@@ -64,7 +65,6 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
|
||||
$this->assertAttributeEquals([], 'claims', $builder);
|
||||
$this->assertAttributeEquals(null, 'signature', $builder);
|
||||
$this->assertAttributeSame($this->encoder, 'encoder', $builder);
|
||||
$this->assertAttributeSame($this->claimFactory, 'claimFactory', $builder);
|
||||
}
|
||||
@@ -73,15 +73,15 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setAudience
|
||||
* @covers Lcobucci\JWT\Builder::permittedFor
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setAudienceMustChangeTheAudClaim()
|
||||
public function permittedForMustChangeTheAudClaim()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setAudience('test');
|
||||
$builder->permittedFor('test');
|
||||
|
||||
$this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
|
||||
$this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $builder);
|
||||
@@ -91,15 +91,15 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setAudience
|
||||
* @covers Lcobucci\JWT\Builder::permittedFor
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setAudienceCanReplicateItemOnHeader()
|
||||
public function permittedForCanReplicateItemOnHeader()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setAudience('test', true);
|
||||
$builder->permittedFor('test', true);
|
||||
|
||||
$this->assertAttributeEquals(['aud' => $this->defaultClaim], 'claims', $builder);
|
||||
|
||||
@@ -114,31 +114,31 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setAudience
|
||||
* @covers Lcobucci\JWT\Builder::permittedFor
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setAudienceMustKeepAFluentInterface()
|
||||
public function permittedForMustKeepAFluentInterface()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
|
||||
$this->assertSame($builder, $builder->setAudience('test'));
|
||||
$this->assertSame($builder, $builder->permittedFor('test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setExpiration
|
||||
* @covers Lcobucci\JWT\Builder::expiresAt
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setExpirationMustChangeTheExpClaim()
|
||||
public function expiresAtMustChangeTheExpClaim()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setExpiration('2');
|
||||
$builder->expiresAt('2');
|
||||
|
||||
$this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
|
||||
$this->assertAttributeEquals(['exp' => $this->defaultClaim], 'claims', $builder);
|
||||
@@ -148,15 +148,15 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setExpiration
|
||||
* @covers Lcobucci\JWT\Builder::expiresAt
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setExpirationCanReplicateItemOnHeader()
|
||||
public function expiresAtCanReplicateItemOnHeader()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setExpiration('2', true);
|
||||
$builder->expiresAt('2', true);
|
||||
|
||||
$this->assertAttributeEquals(['exp' => $this->defaultClaim], 'claims', $builder);
|
||||
|
||||
@@ -171,31 +171,31 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setExpiration
|
||||
* @covers Lcobucci\JWT\Builder::expiresAt
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setExpirationMustKeepAFluentInterface()
|
||||
public function expiresAtMustKeepAFluentInterface()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
|
||||
$this->assertSame($builder, $builder->setExpiration('2'));
|
||||
$this->assertSame($builder, $builder->expiresAt('2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setId
|
||||
* @covers Lcobucci\JWT\Builder::identifiedBy
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setIdMustChangeTheJtiClaim()
|
||||
public function identifiedByMustChangeTheJtiClaim()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setId('2');
|
||||
$builder->identifiedBy('2');
|
||||
|
||||
$this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
|
||||
$this->assertAttributeEquals(['jti' => $this->defaultClaim], 'claims', $builder);
|
||||
@@ -205,15 +205,15 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setId
|
||||
* @covers Lcobucci\JWT\Builder::identifiedBy
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setIdCanReplicateItemOnHeader()
|
||||
public function identifiedByCanReplicateItemOnHeader()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setId('2', true);
|
||||
$builder->identifiedBy('2', true);
|
||||
|
||||
$this->assertAttributeEquals(['jti' => $this->defaultClaim], 'claims', $builder);
|
||||
|
||||
@@ -228,31 +228,31 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setId
|
||||
* @covers Lcobucci\JWT\Builder::identifiedBy
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setIdMustKeepAFluentInterface()
|
||||
public function identifiedByMustKeepAFluentInterface()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
|
||||
$this->assertSame($builder, $builder->setId('2'));
|
||||
$this->assertSame($builder, $builder->identifiedBy('2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setIssuedAt
|
||||
* @covers Lcobucci\JWT\Builder::issuedAt
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setIssuedAtMustChangeTheIatClaim()
|
||||
public function issuedAtMustChangeTheIatClaim()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setIssuedAt('2');
|
||||
$builder->issuedAt('2');
|
||||
|
||||
$this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
|
||||
$this->assertAttributeEquals(['iat' => $this->defaultClaim], 'claims', $builder);
|
||||
@@ -262,15 +262,15 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setIssuedAt
|
||||
* @covers Lcobucci\JWT\Builder::issuedAt
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setIssuedAtCanReplicateItemOnHeader()
|
||||
public function issuedAtCanReplicateItemOnHeader()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setIssuedAt('2', true);
|
||||
$builder->issuedAt('2', true);
|
||||
|
||||
$this->assertAttributeEquals(['iat' => $this->defaultClaim], 'claims', $builder);
|
||||
|
||||
@@ -285,31 +285,31 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setIssuedAt
|
||||
* @covers Lcobucci\JWT\Builder::issuedAt
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setIssuedAtMustKeepAFluentInterface()
|
||||
public function issuedAtMustKeepAFluentInterface()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
|
||||
$this->assertSame($builder, $builder->setIssuedAt('2'));
|
||||
$this->assertSame($builder, $builder->issuedAt('2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setIssuer
|
||||
* @covers Lcobucci\JWT\Builder::issuedBy
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setIssuerMustChangeTheIssClaim()
|
||||
public function issuedByMustChangeTheIssClaim()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setIssuer('2');
|
||||
$builder->issuedBy('2');
|
||||
|
||||
$this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
|
||||
$this->assertAttributeEquals(['iss' => $this->defaultClaim], 'claims', $builder);
|
||||
@@ -319,15 +319,15 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setIssuer
|
||||
* @covers Lcobucci\JWT\Builder::issuedBy
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setIssuerCanReplicateItemOnHeader()
|
||||
public function issuedByCanReplicateItemOnHeader()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setIssuer('2', true);
|
||||
$builder->issuedBy('2', true);
|
||||
|
||||
$this->assertAttributeEquals(['iss' => $this->defaultClaim], 'claims', $builder);
|
||||
|
||||
@@ -342,31 +342,31 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setIssuer
|
||||
* @covers Lcobucci\JWT\Builder::issuedBy
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setIssuerMustKeepAFluentInterface()
|
||||
public function issuedByMustKeepAFluentInterface()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
|
||||
$this->assertSame($builder, $builder->setIssuer('2'));
|
||||
$this->assertSame($builder, $builder->issuedBy('2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setNotBefore
|
||||
* @covers Lcobucci\JWT\Builder::canOnlyBeUsedAfter
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setNotBeforeMustChangeTheNbfClaim()
|
||||
public function canOnlyBeUsedAfterMustChangeTheNbfClaim()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setNotBefore('2');
|
||||
$builder->canOnlyBeUsedAfter('2');
|
||||
|
||||
$this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
|
||||
$this->assertAttributeEquals(['nbf' => $this->defaultClaim], 'claims', $builder);
|
||||
@@ -376,15 +376,15 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setNotBefore
|
||||
* @covers Lcobucci\JWT\Builder::canOnlyBeUsedAfter
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setNotBeforeCanReplicateItemOnHeader()
|
||||
public function canOnlyBeUsedAfterCanReplicateItemOnHeader()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setNotBefore('2', true);
|
||||
$builder->canOnlyBeUsedAfter('2', true);
|
||||
|
||||
$this->assertAttributeEquals(['nbf' => $this->defaultClaim], 'claims', $builder);
|
||||
|
||||
@@ -399,31 +399,31 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setNotBefore
|
||||
* @covers Lcobucci\JWT\Builder::canOnlyBeUsedAfter
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setNotBeforeMustKeepAFluentInterface()
|
||||
public function canOnlyBeUsedAfterMustKeepAFluentInterface()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
|
||||
$this->assertSame($builder, $builder->setNotBefore('2'));
|
||||
$this->assertSame($builder, $builder->canOnlyBeUsedAfter('2'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setSubject
|
||||
* @covers Lcobucci\JWT\Builder::relatedTo
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setSubjectMustChangeTheSubClaim()
|
||||
public function relatedToMustChangeTheSubClaim()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setSubject('2');
|
||||
$builder->relatedTo('2');
|
||||
|
||||
$this->assertAttributeEquals(['alg' => 'none', 'typ' => 'JWT'], 'headers', $builder);
|
||||
$this->assertAttributeEquals(['sub' => $this->defaultClaim], 'claims', $builder);
|
||||
@@ -433,15 +433,15 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setSubject
|
||||
* @covers Lcobucci\JWT\Builder::relatedTo
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setSubjectCanReplicateItemOnHeader()
|
||||
public function relatedToCanReplicateItemOnHeader()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setSubject('2', true);
|
||||
$builder->relatedTo('2', true);
|
||||
|
||||
$this->assertAttributeEquals(['sub' => $this->defaultClaim], 'claims', $builder);
|
||||
|
||||
@@ -456,16 +456,16 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setSubject
|
||||
* @covers Lcobucci\JWT\Builder::relatedTo
|
||||
* @covers Lcobucci\JWT\Builder::setRegisteredClaim
|
||||
*/
|
||||
public function setSubjectMustKeepAFluentInterface()
|
||||
public function relatedToMustKeepAFluentInterface()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
|
||||
$this->assertSame($builder, $builder->setSubject('2'));
|
||||
$this->assertSame($builder, $builder->relatedTo('2'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -473,12 +473,12 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::set
|
||||
* @covers Lcobucci\JWT\Builder::withClaim
|
||||
*/
|
||||
public function setMustConfigureTheGivenClaim()
|
||||
public function withClaimMustConfigureTheGivenClaim()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->set('userId', 2);
|
||||
$builder->withClaim('userId', 2);
|
||||
|
||||
$this->assertAttributeEquals(['userId' => $this->defaultClaim], 'claims', $builder);
|
||||
}
|
||||
@@ -488,13 +488,13 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::set
|
||||
* @covers Lcobucci\JWT\Builder::withClaim
|
||||
*/
|
||||
public function setMustKeepAFluentInterface()
|
||||
public function withClaimMustKeepAFluentInterface()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
|
||||
$this->assertSame($builder, $builder->set('userId', 2));
|
||||
$this->assertSame($builder, $builder->withClaim('userId', 2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -502,12 +502,12 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setHeader
|
||||
* @covers Lcobucci\JWT\Builder::withHeader
|
||||
*/
|
||||
public function setHeaderMustConfigureTheGivenClaim()
|
||||
public function withHeaderMustConfigureTheGivenClaim()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
$builder->setHeader('userId', 2);
|
||||
$builder->withHeader('userId', 2);
|
||||
|
||||
$this->assertAttributeEquals(
|
||||
['alg' => 'none', 'typ' => 'JWT', 'userId' => $this->defaultClaim],
|
||||
@@ -521,13 +521,13 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setHeader
|
||||
* @covers Lcobucci\JWT\Builder::withHeader
|
||||
*/
|
||||
public function setHeaderMustKeepAFluentInterface()
|
||||
public function withHeaderMustKeepAFluentInterface()
|
||||
{
|
||||
$builder = $this->createBuilder();
|
||||
|
||||
$this->assertSame($builder, $builder->setHeader('userId', 2));
|
||||
$this->assertSame($builder, $builder->withHeader('userId', 2));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -539,19 +539,15 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::sign
|
||||
*/
|
||||
public function signMustChangeTheSignature()
|
||||
public function signMustConfigureSignerAndKey()
|
||||
{
|
||||
$signer = $this->getMock(Signer::class);
|
||||
$signature = $this->getMock(Signature::class, [], [], '', false);
|
||||
|
||||
$signer->expects($this->any())
|
||||
->method('sign')
|
||||
->willReturn($signature);
|
||||
$signer = $this->createMock(Signer::class);
|
||||
|
||||
$builder = $this->createBuilder();
|
||||
$builder->sign($signer, 'test');
|
||||
|
||||
$this->assertAttributeSame($signature, 'signature', $builder);
|
||||
$this->assertAttributeSame($signer, 'signer', $builder);
|
||||
$this->assertAttributeEquals(new Key('test'), 'key', $builder);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -565,13 +561,7 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function signMustKeepAFluentInterface()
|
||||
{
|
||||
$signer = $this->getMock(Signer::class);
|
||||
$signature = $this->getMock(Signature::class, [], [], '', false);
|
||||
|
||||
$signer->expects($this->any())
|
||||
->method('sign')
|
||||
->willReturn($signature);
|
||||
|
||||
$signer = $this->createMock(Signer::class);
|
||||
$builder = $this->createBuilder();
|
||||
|
||||
$this->assertSame($builder, $builder->sign($signer, 'test'));
|
||||
@@ -586,11 +576,12 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::unsign
|
||||
*/
|
||||
public function unsignMustRemoveTheSignature(Builder $builder)
|
||||
public function unsignMustRemoveTheSignerAndKey(Builder $builder)
|
||||
{
|
||||
$builder->unsign();
|
||||
|
||||
$this->assertAttributeSame(null, 'signature', $builder);
|
||||
$this->assertAttributeSame(null, 'signer', $builder);
|
||||
$this->assertAttributeSame(null, 'key', $builder);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -609,66 +600,17 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::sign
|
||||
* @uses Lcobucci\JWT\Builder::getToken
|
||||
* @uses Lcobucci\JWT\Token
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::set
|
||||
*
|
||||
* @expectedException BadMethodCallException
|
||||
*/
|
||||
public function setMustRaiseExceptionWhenTokenHasBeenSigned()
|
||||
{
|
||||
$signer = $this->getMock(Signer::class);
|
||||
$signature = $this->getMock(Signature::class, [], [], '', false);
|
||||
|
||||
$signer->expects($this->any())
|
||||
->method('sign')
|
||||
->willReturn($signature);
|
||||
|
||||
$builder = $this->createBuilder();
|
||||
$builder->sign($signer, 'test');
|
||||
$builder->set('test', 123);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::sign
|
||||
* @uses Lcobucci\JWT\Builder::getToken
|
||||
* @uses Lcobucci\JWT\Token
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::setHeader
|
||||
*
|
||||
* @expectedException BadMethodCallException
|
||||
*/
|
||||
public function setHeaderMustRaiseExceptionWhenTokenHasBeenSigned()
|
||||
{
|
||||
$signer = $this->getMock(Signer::class);
|
||||
$signature = $this->getMock(Signature::class, [], [], '', false);
|
||||
|
||||
$signer->expects($this->any())
|
||||
->method('sign')
|
||||
->willReturn($signature);
|
||||
|
||||
$builder = $this->createBuilder();
|
||||
$builder->sign($signer, 'test');
|
||||
$builder->setHeader('test', 123);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Builder::__construct
|
||||
* @uses Lcobucci\JWT\Builder::set
|
||||
* @uses Lcobucci\JWT\Builder::withClaim
|
||||
* @uses Lcobucci\JWT\Token
|
||||
*
|
||||
* @covers Lcobucci\JWT\Builder::getToken
|
||||
*/
|
||||
public function getTokenMustReturnANewTokenWithCurrentConfiguration()
|
||||
{
|
||||
$signature = $this->getMock(Signature::class, [], [], '', false);
|
||||
$signer = $this->createMock(Signer::class);
|
||||
$signature = $this->createMock(Signature::class);
|
||||
|
||||
$signer->method('sign')->willReturn($signature);
|
||||
|
||||
$this->encoder->expects($this->exactly(2))
|
||||
->method('jsonEncode')
|
||||
@@ -680,20 +622,12 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
|
||||
->withConsecutive(['1'], ['2'], [$signature])
|
||||
->willReturnOnConsecutiveCalls('1', '2', '3');
|
||||
|
||||
$builder = $this->createBuilder()->set('test', 123);
|
||||
|
||||
$builderSign = new \ReflectionProperty($builder, 'signature');
|
||||
$builderSign->setAccessible(true);
|
||||
$builderSign->setValue($builder, $signature);
|
||||
|
||||
$token = $builder->getToken();
|
||||
|
||||
$tokenSign = new \ReflectionProperty($token, 'signature');
|
||||
$tokenSign->setAccessible(true);
|
||||
$builder = $this->createBuilder()->withClaim('test', 123);
|
||||
$token = $builder->getToken($signer, new Key('testing'));
|
||||
|
||||
$this->assertAttributeEquals(['1', '2', '3'], 'payload', $token);
|
||||
$this->assertAttributeEquals($token->getHeaders(), 'headers', $builder);
|
||||
$this->assertAttributeEquals($token->getClaims(), 'claims', $builder);
|
||||
$this->assertAttributeSame($tokenSign->getValue($token), 'signature', $builder);
|
||||
$this->assertAttributeSame($signature, 'signature', $token);
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT\Claim;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class BasicTest extends \PHPUnit_Framework_TestCase
|
||||
class BasicTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
|
@@ -13,7 +13,7 @@ use Lcobucci\JWT\ValidationData;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class EqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
class EqualsToTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
@@ -22,6 +22,7 @@ class EqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
* @uses Lcobucci\JWT\Claim\Basic::getName
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::has
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\Claim\EqualsTo::validate
|
||||
*/
|
||||
@@ -42,6 +43,7 @@ class EqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
* @uses Lcobucci\JWT\ValidationData::setIssuer
|
||||
* @uses Lcobucci\JWT\ValidationData::has
|
||||
* @uses Lcobucci\JWT\ValidationData::get
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\Claim\EqualsTo::validate
|
||||
*/
|
||||
@@ -65,6 +67,7 @@ class EqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
* @uses Lcobucci\JWT\ValidationData::setIssuer
|
||||
* @uses Lcobucci\JWT\ValidationData::has
|
||||
* @uses Lcobucci\JWT\ValidationData::get
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\Claim\EqualsTo::validate
|
||||
*/
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT\Claim;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class FactoryTest extends \PHPUnit_Framework_TestCase
|
||||
class FactoryTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
|
@@ -13,7 +13,7 @@ use Lcobucci\JWT\ValidationData;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class GreaterOrEqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
class GreaterOrEqualsToTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
@@ -22,6 +22,7 @@ class GreaterOrEqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
* @uses Lcobucci\JWT\Claim\Basic::getName
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::has
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\Claim\GreaterOrEqualsTo::validate
|
||||
*/
|
||||
@@ -42,6 +43,7 @@ class GreaterOrEqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
* @uses Lcobucci\JWT\ValidationData::setIssuer
|
||||
* @uses Lcobucci\JWT\ValidationData::has
|
||||
* @uses Lcobucci\JWT\ValidationData::get
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\Claim\GreaterOrEqualsTo::validate
|
||||
*/
|
||||
@@ -65,6 +67,7 @@ class GreaterOrEqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
* @uses Lcobucci\JWT\ValidationData::setIssuer
|
||||
* @uses Lcobucci\JWT\ValidationData::has
|
||||
* @uses Lcobucci\JWT\ValidationData::get
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\Claim\GreaterOrEqualsTo::validate
|
||||
*/
|
||||
@@ -88,6 +91,7 @@ class GreaterOrEqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
* @uses Lcobucci\JWT\ValidationData::setIssuer
|
||||
* @uses Lcobucci\JWT\ValidationData::has
|
||||
* @uses Lcobucci\JWT\ValidationData::get
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\Claim\GreaterOrEqualsTo::validate
|
||||
*/
|
||||
|
@@ -13,7 +13,7 @@ use Lcobucci\JWT\ValidationData;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class LesserOrEqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
class LesserOrEqualsToTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
@@ -22,6 +22,7 @@ class LesserOrEqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
* @uses Lcobucci\JWT\Claim\Basic::getName
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::has
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\Claim\LesserOrEqualsTo::validate
|
||||
*/
|
||||
@@ -42,6 +43,7 @@ class LesserOrEqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
* @uses Lcobucci\JWT\ValidationData::setIssuer
|
||||
* @uses Lcobucci\JWT\ValidationData::has
|
||||
* @uses Lcobucci\JWT\ValidationData::get
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\Claim\LesserOrEqualsTo::validate
|
||||
*/
|
||||
@@ -65,6 +67,7 @@ class LesserOrEqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
* @uses Lcobucci\JWT\ValidationData::setIssuer
|
||||
* @uses Lcobucci\JWT\ValidationData::has
|
||||
* @uses Lcobucci\JWT\ValidationData::get
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\Claim\LesserOrEqualsTo::validate
|
||||
*/
|
||||
@@ -88,6 +91,7 @@ class LesserOrEqualsToTest extends \PHPUnit_Framework_TestCase
|
||||
* @uses Lcobucci\JWT\ValidationData::setIssuer
|
||||
* @uses Lcobucci\JWT\ValidationData::has
|
||||
* @uses Lcobucci\JWT\ValidationData::get
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\Claim\LesserOrEqualsTo::validate
|
||||
*/
|
||||
|
8
vendor/lcobucci/jwt/test/unit/ParserTest.php
vendored
8
vendor/lcobucci/jwt/test/unit/ParserTest.php
vendored
@@ -15,7 +15,7 @@ use RuntimeException;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class ParserTest extends \PHPUnit_Framework_TestCase
|
||||
class ParserTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Decoder|\PHPUnit_Framework_MockObject_MockObject
|
||||
@@ -37,9 +37,9 @@ class ParserTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->decoder = $this->getMock(Decoder::class);
|
||||
$this->claimFactory = $this->getMock(ClaimFactory::class, [], [], '', false);
|
||||
$this->defaultClaim = $this->getMock(Claim::class);
|
||||
$this->decoder = $this->createMock(Decoder::class);
|
||||
$this->claimFactory = $this->createMock(ClaimFactory::class, [], [], '', false);
|
||||
$this->defaultClaim = $this->createMock(Claim::class);
|
||||
|
||||
$this->claimFactory->expects($this->any())
|
||||
->method('create')
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT\Parsing;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class DecoderTest extends \PHPUnit_Framework_TestCase
|
||||
class DecoderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT\Parsing;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class EncoderTest extends \PHPUnit_Framework_TestCase
|
||||
class EncoderTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class SignatureTest extends \PHPUnit_Framework_TestCase
|
||||
class SignatureTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Signer|\PHPUnit_Framework_MockObject_MockObject
|
||||
@@ -23,7 +23,7 @@ class SignatureTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->signer = $this->getMock(Signer::class);
|
||||
$this->signer = $this->createMock(Signer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -13,7 +13,7 @@ use Lcobucci\JWT\Signature;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class BaseSignerTest extends \PHPUnit_Framework_TestCase
|
||||
class BaseSignerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var BaseSigner|\PHPUnit_Framework_MockObject_MockObject
|
||||
|
@@ -1,178 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of Lcobucci\JWT, a simple library to handle JWT and JWS
|
||||
*
|
||||
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
|
||||
*/
|
||||
|
||||
namespace Lcobucci\JWT\Signer\Ecdsa;
|
||||
|
||||
use Mdanter\Ecc\Crypto\Key\PrivateKeyInterface;
|
||||
use Mdanter\Ecc\Crypto\Key\PublicKeyInterface;
|
||||
use Mdanter\Ecc\Math\MathAdapterInterface;
|
||||
use Mdanter\Ecc\Serializer\PrivateKey\PrivateKeySerializerInterface;
|
||||
use Mdanter\Ecc\Serializer\PublicKey\PublicKeySerializerInterface;
|
||||
use Lcobucci\JWT\Signer\Key;
|
||||
|
||||
/**
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 3.0.4
|
||||
*/
|
||||
class KeyParserTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var MathAdapterInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $adapter;
|
||||
|
||||
/**
|
||||
* @var PrivateKeySerializerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $privateKeySerializer;
|
||||
|
||||
/**
|
||||
* @var PublicKeySerializerInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $publicKeySerializer;
|
||||
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
public function createDependencies()
|
||||
{
|
||||
$this->adapter = $this->getMock(MathAdapterInterface::class);
|
||||
$this->privateKeySerializer = $this->getMock(PrivateKeySerializerInterface::class);
|
||||
$this->publicKeySerializer = $this->getMock(PublicKeySerializerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser::__construct
|
||||
*/
|
||||
public function constructShouldConfigureDependencies()
|
||||
{
|
||||
$parser = new KeyParser($this->adapter, $this->privateKeySerializer, $this->publicKeySerializer);
|
||||
|
||||
$this->assertAttributeSame($this->privateKeySerializer, 'privateKeySerializer', $parser);
|
||||
$this->assertAttributeSame($this->publicKeySerializer, 'publicKeySerializer', $parser);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser::__construct
|
||||
* @uses Lcobucci\JWT\Signer\Key
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser::getPrivateKey
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser::getKeyContent
|
||||
*/
|
||||
public function getPrivateKeyShouldAskSerializerToParseTheKey()
|
||||
{
|
||||
$privateKey = $this->getMock(PrivateKeyInterface::class);
|
||||
|
||||
$keyContent = 'MHcCAQEEIBGpMoZJ64MMSzuo5JbmXpf9V4qSWdLIl/8RmJLcfn/qoAoGC'
|
||||
. 'CqGSM49AwEHoUQDQgAE7it/EKmcv9bfpcV1fBreLMRXxWpnd0wxa2iF'
|
||||
. 'ruiI2tsEdGFTLTsyU+GeRqC7zN0aTnTQajarUylKJ3UWr/r1kg==';
|
||||
|
||||
$this->privateKeySerializer->expects($this->once())
|
||||
->method('parse')
|
||||
->with($keyContent)
|
||||
->willReturn($privateKey);
|
||||
|
||||
$parser = new KeyParser($this->adapter, $this->privateKeySerializer, $this->publicKeySerializer);
|
||||
$this->assertSame($privateKey, $parser->getPrivateKey($this->getPrivateKey()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser::__construct
|
||||
* @uses Lcobucci\JWT\Signer\Key
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser::getPrivateKey
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser::getKeyContent
|
||||
*/
|
||||
public function getPrivateKeyShouldRaiseExceptionWhenAWrongKeyWasGiven()
|
||||
{
|
||||
$this->privateKeySerializer->expects($this->never())
|
||||
->method('parse');
|
||||
|
||||
$parser = new KeyParser($this->adapter, $this->privateKeySerializer, $this->publicKeySerializer);
|
||||
$parser->getPrivateKey($this->getPublicKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser::__construct
|
||||
* @uses Lcobucci\JWT\Signer\Key
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser::getPublicKey
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser::getKeyContent
|
||||
*/
|
||||
public function getPublicKeyShouldAskSerializerToParseTheKey()
|
||||
{
|
||||
$publicKey = $this->getMock(PublicKeyInterface::class);
|
||||
|
||||
$keyContent = 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE7it/EKmcv9bfpcV1fBreLMRXxWpn'
|
||||
. 'd0wxa2iFruiI2tsEdGFTLTsyU+GeRqC7zN0aTnTQajarUylKJ3UWr/r1kg==';
|
||||
|
||||
$this->publicKeySerializer->expects($this->once())
|
||||
->method('parse')
|
||||
->with($keyContent)
|
||||
->willReturn($publicKey);
|
||||
|
||||
$parser = new KeyParser($this->adapter, $this->privateKeySerializer, $this->publicKeySerializer);
|
||||
$this->assertSame($publicKey, $parser->getPublicKey($this->getPublicKey()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser::__construct
|
||||
* @uses Lcobucci\JWT\Signer\Key
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser::getPublicKey
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\KeyParser::getKeyContent
|
||||
*/
|
||||
public function getPublicKeyShouldRaiseExceptionWhenAWrongKeyWasGiven()
|
||||
{
|
||||
$this->publicKeySerializer->expects($this->never())
|
||||
->method('parse');
|
||||
|
||||
$parser = new KeyParser($this->adapter, $this->privateKeySerializer, $this->publicKeySerializer);
|
||||
$parser->getPublicKey($this->getPrivateKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Key
|
||||
*/
|
||||
private function getPrivateKey()
|
||||
{
|
||||
return new Key(
|
||||
"-----BEGIN EC PRIVATE KEY-----\n"
|
||||
. "MHcCAQEEIBGpMoZJ64MMSzuo5JbmXpf9V4qSWdLIl/8RmJLcfn/qoAoGCCqGSM49\n"
|
||||
. "AwEHoUQDQgAE7it/EKmcv9bfpcV1fBreLMRXxWpnd0wxa2iFruiI2tsEdGFTLTsy\n"
|
||||
. "U+GeRqC7zN0aTnTQajarUylKJ3UWr/r1kg==\n"
|
||||
. "-----END EC PRIVATE KEY-----"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Key
|
||||
*/
|
||||
private function getPublicKey()
|
||||
{
|
||||
return new Key(
|
||||
"-----BEGIN PUBLIC KEY-----\n"
|
||||
. "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE7it/EKmcv9bfpcV1fBreLMRXxWpn\n"
|
||||
. "d0wxa2iFruiI2tsEdGFTLTsyU+GeRqC7zN0aTnTQajarUylKJ3UWr/r1kg==\n"
|
||||
. "-----END PUBLIC KEY-----"
|
||||
);
|
||||
}
|
||||
}
|
127
vendor/lcobucci/jwt/test/unit/Signer/Ecdsa/MultibyteStringConverterTest.php
vendored
Normal file
127
vendor/lcobucci/jwt/test/unit/Signer/Ecdsa/MultibyteStringConverterTest.php
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
namespace Lcobucci\JWT\Signer\Ecdsa;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use function bin2hex;
|
||||
use function hex2bin;
|
||||
use function strlen;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
*/
|
||||
final class MultibyteStringConverterTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider pointsConversionData
|
||||
*
|
||||
* @covers ::toAsn1
|
||||
* @covers ::octetLength
|
||||
* @covers ::preparePositiveInteger
|
||||
*/
|
||||
public function toAsn1ShouldReturnThePointsInAnAsn1SequenceFormat(
|
||||
$r,
|
||||
$s,
|
||||
$asn1
|
||||
) {
|
||||
$converter = new MultibyteStringConverter();
|
||||
$message = hex2bin($r . $s);
|
||||
|
||||
self::assertSame($asn1, bin2hex($converter->toAsn1($message, strlen($r))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers ::toAsn1
|
||||
* @covers ::octetLength
|
||||
*/
|
||||
public function toAsn1ShouldRaiseExceptionWhenPointsDoNotHaveCorrectLength()
|
||||
{
|
||||
$converter = new MultibyteStringConverter();
|
||||
|
||||
self::expectException(InvalidArgumentException::class);
|
||||
$converter->toAsn1('a very wrong string', 64);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider pointsConversionData
|
||||
*
|
||||
* @covers ::fromAsn1
|
||||
* @covers ::readAsn1Content
|
||||
* @covers ::readAsn1Integer
|
||||
* @covers ::retrievePositiveInteger
|
||||
*/
|
||||
public function fromAsn1ShouldReturnTheConcatenatedPoints($r, $s, $asn1)
|
||||
{
|
||||
$converter = new MultibyteStringConverter();
|
||||
$message = hex2bin($asn1);
|
||||
|
||||
self::assertSame($r . $s, bin2hex($converter->fromAsn1($message, strlen($r))));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*/
|
||||
public function pointsConversionData()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'efd48b2aacb6a8fd1140dd9cd45e81d69d2c877b56aaf991c34d0ea84eaf3716',
|
||||
'f7cb1c942d657c41d436c7a1b6e29f65f3e900dbb9aff4064dc4ab2f843acda8',
|
||||
'3046022100efd48b2aacb6a8fd1140dd9cd45e81d69d2c877b56aaf991c34d0ea84eaf3716022100f7cb1c942d657c41d436c7'
|
||||
. 'a1b6e29f65f3e900dbb9aff4064dc4ab2f843acda8',
|
||||
],
|
||||
[
|
||||
'94edbb92a5ecb8aad4736e56c691916b3f88140666ce9fa73d64c4ea95ad133c81a648152e44acf96e36dd1e80fabe46',
|
||||
'99ef4aeb15f178cea1fe40db2603138f130e740a19624526203b6351d0a3a94fa329c145786e679e7b82c71a38628ac8',
|
||||
'306602310094edbb92a5ecb8aad4736e56c691916b3f88140666ce9fa73d64c4ea95ad133c81a648152e44acf96e36dd1e80fa'
|
||||
. 'be4602310099ef4aeb15f178cea1fe40db2603138f130e740a19624526203b6351d0a3a94fa329c145786e679e7b82c71a38'
|
||||
. '628ac8',
|
||||
],
|
||||
[
|
||||
'00c328fafcbd79dd77850370c46325d987cb525569fb63c5d3bc53950e6d4c5f174e25a1ee9017b5d450606add152b534931d7'
|
||||
. 'd4e8455cc91f9b15bf05ec36e377fa',
|
||||
'00617cce7cf5064806c467f678d3b4080d6f1cc50af26ca209417308281b68af282623eaa63e5b5c0723d8b8c37ff0777b1a20'
|
||||
. 'f8ccb1dccc43997f1ee0e44da4a67a',
|
||||
'308187024200c328fafcbd79dd77850370c46325d987cb525569fb63c5d3bc53950e6d4c5f174e25a1ee9017b5d450606add15'
|
||||
. '2b534931d7d4e8455cc91f9b15bf05ec36e377fa0241617cce7cf5064806c467f678d3b4080d6f1cc50af26ca20941730828'
|
||||
. '1b68af282623eaa63e5b5c0723d8b8c37ff0777b1a20f8ccb1dccc43997f1ee0e44da4a67a',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @dataProvider invalidAsn1Structures
|
||||
*
|
||||
* @covers ::fromAsn1
|
||||
* @covers ::readAsn1Content
|
||||
* @covers ::readAsn1Integer
|
||||
* @covers ::retrievePositiveInteger
|
||||
*/
|
||||
public function fromAsn1ShouldRaiseExceptionOnInvalidMessage($message)
|
||||
{
|
||||
$converter = new MultibyteStringConverter();
|
||||
$message = hex2bin($message);
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$converter->fromAsn1($message, 64);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*/
|
||||
public function invalidAsn1Structures()
|
||||
{
|
||||
return [
|
||||
'Not a sequence' => [''],
|
||||
'Sequence without length' => ['30'],
|
||||
'Only one string element' => ['3006030204f0'],
|
||||
'Only one integer element' => ['3004020101'],
|
||||
'Integer+string elements' => ['300a020101030204f0'],
|
||||
];
|
||||
}
|
||||
}
|
@@ -11,13 +11,13 @@ namespace Lcobucci\JWT\Signer\Ecdsa;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class Sha256Test extends \PHPUnit_Framework_TestCase
|
||||
class Sha256Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @uses Lcobucci\JWT\Signer\OpenSSL
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256::getAlgorithmId
|
||||
*/
|
||||
@@ -32,7 +32,7 @@ class Sha256Test extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @uses Lcobucci\JWT\Signer\OpenSSL
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256::getAlgorithm
|
||||
*/
|
||||
@@ -47,14 +47,14 @@ class Sha256Test extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @uses Lcobucci\JWT\Signer\OpenSSL
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256::getSignatureLength
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha256::getKeyLength
|
||||
*/
|
||||
public function getSignatureLengthMustBeCorrect()
|
||||
public function getKeyLengthMustBeCorrect()
|
||||
{
|
||||
$signer = new Sha256();
|
||||
|
||||
$this->assertEquals(64, $signer->getSignatureLength());
|
||||
$this->assertEquals(64, $signer->getKeyLength());
|
||||
}
|
||||
}
|
||||
|
@@ -11,13 +11,13 @@ namespace Lcobucci\JWT\Signer\Ecdsa;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class Sha384Test extends \PHPUnit_Framework_TestCase
|
||||
class Sha384Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @uses Lcobucci\JWT\Signer\OpenSSL
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha384::getAlgorithmId
|
||||
*/
|
||||
@@ -32,7 +32,7 @@ class Sha384Test extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @uses Lcobucci\JWT\Signer\OpenSSL
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha384::getAlgorithm
|
||||
*/
|
||||
@@ -47,14 +47,14 @@ class Sha384Test extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @uses Lcobucci\JWT\Signer\OpenSSL
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha384::getSignatureLength
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha384::getKeyLength
|
||||
*/
|
||||
public function getSignatureLengthMustBeCorrect()
|
||||
public function getKeyLengthMustBeCorrect()
|
||||
{
|
||||
$signer = new Sha384();
|
||||
|
||||
$this->assertEquals(96, $signer->getSignatureLength());
|
||||
$this->assertEquals(96, $signer->getKeyLength());
|
||||
}
|
||||
}
|
||||
|
@@ -11,13 +11,13 @@ namespace Lcobucci\JWT\Signer\Ecdsa;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class Sha512Test extends \PHPUnit_Framework_TestCase
|
||||
class Sha512Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @uses Lcobucci\JWT\Signer\OpenSSL
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha512::getAlgorithmId
|
||||
*/
|
||||
@@ -32,7 +32,7 @@ class Sha512Test extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @uses Lcobucci\JWT\Signer\OpenSSL
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha512::getAlgorithm
|
||||
*/
|
||||
@@ -47,14 +47,14 @@ class Sha512Test extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa\KeyParser
|
||||
* @uses Lcobucci\JWT\Signer\OpenSSL
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha512::getSignatureLength
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa\Sha512::getKeyLength
|
||||
*/
|
||||
public function getSignatureLengthMustBeCorrect()
|
||||
public function getKeyLengthMustBeCorrect()
|
||||
{
|
||||
$signer = new Sha512();
|
||||
|
||||
$this->assertEquals(132, $signer->getSignatureLength());
|
||||
$this->assertEquals(132, $signer->getKeyLength());
|
||||
}
|
||||
}
|
||||
|
188
vendor/lcobucci/jwt/test/unit/Signer/EcdsaTest.php
vendored
188
vendor/lcobucci/jwt/test/unit/Signer/EcdsaTest.php
vendored
@@ -7,70 +7,43 @@
|
||||
|
||||
namespace Lcobucci\JWT\Signer;
|
||||
|
||||
use Lcobucci\JWT\Signer\Ecdsa\KeyParser;
|
||||
use Mdanter\Ecc\Crypto\Signature\Signature;
|
||||
use Mdanter\Ecc\Crypto\Signature\Signer;
|
||||
use Mdanter\Ecc\Crypto\Key\PrivateKeyInterface;
|
||||
use Mdanter\Ecc\Crypto\Key\PublicKeyInterface;
|
||||
use Mdanter\Ecc\Math\MathAdapterInterface as Adapter;
|
||||
use Mdanter\Ecc\Primitives\PointInterface;
|
||||
use Mdanter\Ecc\Random\RandomNumberGeneratorInterface;
|
||||
use Lcobucci\JWT\Keys;
|
||||
use Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter;
|
||||
use const OPENSSL_ALGO_SHA256;
|
||||
use function openssl_pkey_get_private;
|
||||
use function openssl_pkey_get_public;
|
||||
use function openssl_sign;
|
||||
use function openssl_verify;
|
||||
|
||||
/**
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class EcdsaTest extends \PHPUnit_Framework_TestCase
|
||||
class EcdsaTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Adapter|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $adapter;
|
||||
use Keys;
|
||||
|
||||
/**
|
||||
* @var Signer|\PHPUnit_Framework_MockObject_MockObject
|
||||
* @var MultibyteStringConverter
|
||||
*/
|
||||
private $signer;
|
||||
|
||||
/**
|
||||
* @var RandomNumberGeneratorInterface|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $randomGenerator;
|
||||
|
||||
/**
|
||||
* @var KeyParser|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
private $parser;
|
||||
private $pointsManipulator;
|
||||
|
||||
/**
|
||||
* @before
|
||||
*/
|
||||
public function createDependencies()
|
||||
{
|
||||
$this->adapter = $this->getMock(Adapter::class);
|
||||
$this->signer = $this->getMock(Signer::class, [], [$this->adapter]);
|
||||
$this->randomGenerator = $this->getMock(RandomNumberGeneratorInterface::class);
|
||||
$this->parser = $this->getMock(KeyParser::class, [], [], '', false);
|
||||
$this->pointsManipulator = new MultibyteStringConverter();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Ecdsa
|
||||
*/
|
||||
private function getSigner()
|
||||
{
|
||||
$signer = $this->getMockForAbstractClass(
|
||||
Ecdsa::class,
|
||||
[$this->adapter, $this->signer, $this->parser]
|
||||
);
|
||||
|
||||
$signer->method('getSignatureLength')
|
||||
->willReturn(64);
|
||||
$signer = $this->getMockForAbstractClass(Ecdsa::class, [$this->pointsManipulator]);
|
||||
|
||||
$signer->method('getAlgorithm')
|
||||
->willReturn('sha256');
|
||||
->willReturn(OPENSSL_ALGO_SHA256);
|
||||
|
||||
$signer->method('getAlgorithmId')
|
||||
->willReturn('ES256');
|
||||
->willReturn('ES256');
|
||||
|
||||
$signer->method('getKeyLength')
|
||||
->willReturn(64);
|
||||
|
||||
return $signer;
|
||||
}
|
||||
@@ -78,96 +51,67 @@ class EcdsaTest extends \PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa::__construct
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa::createHash
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa::getKeyType
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\BaseSigner
|
||||
*
|
||||
* @uses \Lcobucci\JWT\Signer\Ecdsa::__construct
|
||||
* @uses \Lcobucci\JWT\Signer\Key
|
||||
* @uses \Lcobucci\JWT\Signature
|
||||
*/
|
||||
public function constructShouldConfigureDependencies()
|
||||
public function createHashShouldReturnTheAHashBasedOnTheOpenSslSignature()
|
||||
{
|
||||
$signer = $this->getSigner();
|
||||
$payload = 'testing';
|
||||
|
||||
$this->assertAttributeSame($this->adapter, 'adapter', $signer);
|
||||
$this->assertAttributeSame($this->signer, 'signer', $signer);
|
||||
$this->assertAttributeSame($this->parser, 'parser', $signer);
|
||||
$signer = $this->getSigner();
|
||||
$signature = $signer->sign($payload, self::$ecdsaKeys['private']);
|
||||
|
||||
$publicKey = openssl_pkey_get_public(self::$ecdsaKeys['public1']->getContent());
|
||||
|
||||
self::assertInternalType('resource', $publicKey);
|
||||
self::assertSame(
|
||||
1,
|
||||
openssl_verify(
|
||||
$payload,
|
||||
$this->pointsManipulator->toAsn1($signature, $signer->getKeyLength()),
|
||||
$publicKey,
|
||||
OPENSSL_ALGO_SHA256
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa::__construct
|
||||
* @uses Lcobucci\JWT\Signer\Key
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa::doVerify
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa::getKeyType
|
||||
* @covers \Lcobucci\JWT\Signer\Ecdsa\MultibyteStringConverter
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\BaseSigner
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa::createHash
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa::createSigningHash
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa::createSignatureHash
|
||||
*/
|
||||
public function createHashShouldReturnAHashUsingPrivateKey()
|
||||
{
|
||||
$signer = $this->getSigner();
|
||||
$key = new Key('testing');
|
||||
$privateKey = $this->getMock(PrivateKeyInterface::class);
|
||||
$point = $this->getMock(PointInterface::class);
|
||||
|
||||
$privateKey->method('getPoint')
|
||||
->willReturn($point);
|
||||
|
||||
$point->method('getOrder')
|
||||
->willReturn('1');
|
||||
|
||||
$this->parser->expects($this->once())
|
||||
->method('getPrivateKey')
|
||||
->with($key)
|
||||
->willReturn($privateKey);
|
||||
|
||||
$this->randomGenerator->expects($this->once())
|
||||
->method('generate')
|
||||
->with('1')
|
||||
->willReturn('123');
|
||||
|
||||
$this->adapter->expects($this->once())
|
||||
->method('hexDec')
|
||||
->willReturn('123');
|
||||
|
||||
$this->adapter->expects($this->exactly(2))
|
||||
->method('decHex')
|
||||
->willReturn('123');
|
||||
|
||||
$this->signer->expects($this->once())
|
||||
->method('sign')
|
||||
->with($privateKey, $this->isType('string'), $this->isType('string'))
|
||||
->willReturn(new Signature('1234', '456'));
|
||||
|
||||
$this->assertInternalType('string', $signer->createHash('testing', $key, $this->randomGenerator));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Signer\Ecdsa::__construct
|
||||
* @uses Lcobucci\JWT\Signer\Key
|
||||
*
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa::doVerify
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa::createSigningHash
|
||||
* @covers Lcobucci\JWT\Signer\Ecdsa::extractSignature
|
||||
* @uses \Lcobucci\JWT\Signer\Ecdsa::__construct
|
||||
* @uses \Lcobucci\JWT\Signer\Key
|
||||
*/
|
||||
public function doVerifyShouldDelegateToEcdsaSignerUsingPublicKey()
|
||||
{
|
||||
$payload = 'testing';
|
||||
$privateKey = openssl_pkey_get_private(self::$ecdsaKeys['private']->getContent());
|
||||
|
||||
self::assertInternalType('resource', $privateKey);
|
||||
|
||||
$signature = '';
|
||||
openssl_sign($payload, $signature, $privateKey, OPENSSL_ALGO_SHA256);
|
||||
|
||||
$signer = $this->getSigner();
|
||||
$key = new Key('testing');
|
||||
$publicKey = $this->getMock(PublicKeyInterface::class);
|
||||
|
||||
$this->parser->expects($this->once())
|
||||
->method('getPublicKey')
|
||||
->with($key)
|
||||
->willReturn($publicKey);
|
||||
|
||||
$this->adapter->expects($this->exactly(3))
|
||||
->method('hexDec')
|
||||
->willReturn('123');
|
||||
|
||||
$this->signer->expects($this->once())
|
||||
->method('verify')
|
||||
->with($publicKey, $this->isInstanceOf(Signature::class), $this->isType('string'))
|
||||
->willReturn(true);
|
||||
|
||||
$this->assertTrue($signer->doVerify('testing', 'testing2', $key));
|
||||
self::assertTrue(
|
||||
$signer->verify(
|
||||
$this->pointsManipulator->fromAsn1($signature, $signer->getKeyLength()),
|
||||
$payload,
|
||||
self::$ecdsaKeys['public1']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT\Signer\Hmac;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class Sha256Test extends \PHPUnit_Framework_TestCase
|
||||
class Sha256Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT\Signer\Hmac;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class Sha384Test extends \PHPUnit_Framework_TestCase
|
||||
class Sha384Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT\Signer\Hmac;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class Sha512Test extends \PHPUnit_Framework_TestCase
|
||||
class Sha512Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT\Signer;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class HmacTest extends \PHPUnit_Framework_TestCase
|
||||
class HmacTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Hmac|\PHPUnit_Framework_MockObject_MockObject
|
||||
|
@@ -13,7 +13,7 @@ use org\bovigo\vfs\vfsStream;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 3.0.4
|
||||
*/
|
||||
class KeyTest extends \PHPUnit_Framework_TestCase
|
||||
class KeyTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @before
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT\Signer;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class KeychainTest extends \PHPUnit_Framework_TestCase
|
||||
class KeychainTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT\Signer\Rsa;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class Sha256Test extends \PHPUnit_Framework_TestCase
|
||||
class Sha256Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT\Signer\Rsa;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class Sha384Test extends \PHPUnit_Framework_TestCase
|
||||
class Sha384Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
|
@@ -11,7 +11,7 @@ namespace Lcobucci\JWT\Signer\Rsa;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class Sha512Test extends \PHPUnit_Framework_TestCase
|
||||
class Sha512Test extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
|
188
vendor/lcobucci/jwt/test/unit/Signer/RsaTest.php
vendored
Normal file
188
vendor/lcobucci/jwt/test/unit/Signer/RsaTest.php
vendored
Normal file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
namespace Lcobucci\JWT\Signer;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Lcobucci\JWT\Keys;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use const OPENSSL_ALGO_SHA256;
|
||||
use function openssl_pkey_get_private;
|
||||
use function openssl_pkey_get_public;
|
||||
use function openssl_sign;
|
||||
use function openssl_verify;
|
||||
|
||||
final class RsaTest extends TestCase
|
||||
{
|
||||
use Keys;
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::createHash
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::validateKey
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::getKeyType
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\BaseSigner
|
||||
*
|
||||
* @uses \Lcobucci\JWT\Signer\Key
|
||||
* @uses \Lcobucci\JWT\Signature
|
||||
*/
|
||||
public function createHashShouldReturnAValidOpensslSignature()
|
||||
{
|
||||
$payload = 'testing';
|
||||
|
||||
$signer = $this->getSigner();
|
||||
$signature = $signer->sign($payload, self::$rsaKeys['private']);
|
||||
|
||||
$publicKey = openssl_pkey_get_public(self::$rsaKeys['public']->getContent());
|
||||
self::assertInternalType('resource', $publicKey);
|
||||
self::assertSame(1, openssl_verify($payload, $signature, $publicKey, OPENSSL_ALGO_SHA256));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::createHash
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::validateKey
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::getKeyType
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\BaseSigner
|
||||
*
|
||||
* @uses \Lcobucci\JWT\Signer\Key
|
||||
*/
|
||||
public function createHashShouldRaiseAnExceptionWhenKeyIsInvalid()
|
||||
{
|
||||
$key = <<<KEY
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MGECAQACEQC4MRKSVsq5XnRBrJoX6+rnAgMBAAECECO8SZkgw6Yg66A6SUly/3kC
|
||||
CQDtPXZtCQWJuwIJAMbBu17GDOrFAggopfhNlFcjkwIIVjb7G+U0/TECCEERyvxP
|
||||
TWdN
|
||||
-----END RSA PRIVATE KEY-----
|
||||
KEY;
|
||||
|
||||
$signer = $this->getSigner();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('There was an error while creating the signature');
|
||||
|
||||
$signer->sign('testing', new Key($key));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::createHash
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::validateKey
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\BaseSigner
|
||||
*
|
||||
* @uses \Lcobucci\JWT\Signer\Key
|
||||
*/
|
||||
public function createHashShouldRaiseAnExceptionWhenKeyIsNotParseable()
|
||||
{
|
||||
$signer = $this->getSigner();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('It was not possible to parse your key');
|
||||
|
||||
$signer->sign('testing', new Key('blablabla'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::createHash
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::validateKey
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::getKeyType
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\BaseSigner
|
||||
*
|
||||
* @uses \Lcobucci\JWT\Signer\Key
|
||||
*/
|
||||
public function createHashShouldRaiseAnExceptionWhenKeyTypeIsNotRsa()
|
||||
{
|
||||
$signer = $this->getSigner();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('This key is not compatible with this signer');
|
||||
|
||||
$signer->sign('testing', self::$ecdsaKeys['private']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::doVerify
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::validateKey
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::getKeyType
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\BaseSigner
|
||||
*
|
||||
* @uses \Lcobucci\JWT\Signer\Key
|
||||
*/
|
||||
public function doVerifyShouldReturnTrueWhenSignatureIsValid()
|
||||
{
|
||||
$payload = 'testing';
|
||||
$privateKey = openssl_pkey_get_private(self::$rsaKeys['private']->getContent());
|
||||
self::assertInternalType('resource', $privateKey);
|
||||
|
||||
$signature = '';
|
||||
openssl_sign($payload, $signature, $privateKey, OPENSSL_ALGO_SHA256);
|
||||
|
||||
$signer = $this->getSigner();
|
||||
|
||||
self::assertTrue($signer->verify($signature, $payload, self::$rsaKeys['public']));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::doVerify
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::validateKey
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\BaseSigner
|
||||
*
|
||||
* @uses \Lcobucci\JWT\Signer\Key
|
||||
*/
|
||||
public function doVerifyShouldRaiseAnExceptionWhenKeyIsNotParseable()
|
||||
{
|
||||
$signer = $this->getSigner();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('It was not possible to parse your key');
|
||||
|
||||
$signer->verify('testing', 'testing', new Key('blablabla'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::doVerify
|
||||
* @covers \Lcobucci\JWT\Signer\Rsa::validateKey
|
||||
* @covers \Lcobucci\JWT\Signer\OpenSSL
|
||||
* @covers \Lcobucci\JWT\Signer\BaseSigner
|
||||
*
|
||||
* @uses \Lcobucci\JWT\Signer\Key
|
||||
*/
|
||||
public function doVerifyShouldRaiseAnExceptionWhenKeyTypeIsNotRsa()
|
||||
{
|
||||
$signer = $this->getSigner();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('It was not possible to parse your key');
|
||||
|
||||
$signer->verify('testing', 'testing', self::$ecdsaKeys['private']);
|
||||
}
|
||||
|
||||
private function getSigner()
|
||||
{
|
||||
$signer = $this->getMockForAbstractClass(Rsa::class);
|
||||
|
||||
$signer->method('getAlgorithm')
|
||||
->willReturn(OPENSSL_ALGO_SHA256);
|
||||
|
||||
$signer->method('getAlgorithmId')
|
||||
->willReturn('RS256');
|
||||
|
||||
return $signer;
|
||||
}
|
||||
}
|
85
vendor/lcobucci/jwt/test/unit/TokenTest.php
vendored
85
vendor/lcobucci/jwt/test/unit/TokenTest.php
vendored
@@ -18,7 +18,7 @@ use Lcobucci\JWT\Claim\LesserOrEqualsTo;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class TokenTest extends \PHPUnit_Framework_TestCase
|
||||
class TokenTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
@@ -246,7 +246,7 @@ class TokenTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function verifyMustRaiseExceptionWhenTokenIsUnsigned()
|
||||
{
|
||||
$signer = $this->getMock(Signer::class);
|
||||
$signer = $this->createMock(Signer::class);
|
||||
|
||||
$token = new Token();
|
||||
$token->verify($signer, 'test');
|
||||
@@ -262,8 +262,8 @@ class TokenTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function verifyShouldReturnFalseWhenTokenAlgorithmIsDifferent()
|
||||
{
|
||||
$signer = $this->getMock(Signer::class);
|
||||
$signature = $this->getMock(Signature::class, [], [], '', false);
|
||||
$signer = $this->createMock(Signer::class);
|
||||
$signature = $this->createMock(Signature::class, [], [], '', false);
|
||||
|
||||
$signer->expects($this->any())
|
||||
->method('getAlgorithmId')
|
||||
@@ -287,8 +287,8 @@ class TokenTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function verifyMustDelegateTheValidationToSignature()
|
||||
{
|
||||
$signer = $this->getMock(Signer::class);
|
||||
$signature = $this->getMock(Signature::class, [], [], '', false);
|
||||
$signer = $this->createMock(Signer::class);
|
||||
$signature = $this->createMock(Signature::class, [], [], '', false);
|
||||
|
||||
$signer->expects($this->any())
|
||||
->method('getAlgorithmId')
|
||||
@@ -309,6 +309,7 @@ class TokenTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @uses Lcobucci\JWT\Token::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\Token::validate
|
||||
* @covers Lcobucci\JWT\Token::getValidatableClaims
|
||||
@@ -325,6 +326,7 @@ class TokenTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @uses Lcobucci\JWT\Token::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
* @uses Lcobucci\JWT\Claim\Basic::__construct
|
||||
*
|
||||
* @covers Lcobucci\JWT\Token::validate
|
||||
@@ -364,6 +366,40 @@ class TokenTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($token->validate($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Token::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData
|
||||
* @uses Lcobucci\JWT\Claim\Basic
|
||||
* @uses Lcobucci\JWT\Claim\EqualsTo
|
||||
* @uses Lcobucci\JWT\Claim\LesserOrEqualsTo
|
||||
* @uses Lcobucci\JWT\Claim\GreaterOrEqualsTo
|
||||
*
|
||||
* @covers Lcobucci\JWT\Token::validate
|
||||
* @covers Lcobucci\JWT\Token::getValidatableClaims
|
||||
*/
|
||||
public function validateShouldReturnFalseWhenATimeBasedClaimFails()
|
||||
{
|
||||
$now = time();
|
||||
|
||||
$token = new Token(
|
||||
[],
|
||||
[
|
||||
'iss' => new EqualsTo('iss', 'test'),
|
||||
'iat' => new LesserOrEqualsTo('iat', $now),
|
||||
'nbf' => new LesserOrEqualsTo('nbf', $now + 20),
|
||||
'exp' => new GreaterOrEqualsTo('exp', $now + 500),
|
||||
'testing' => new Basic('testing', 'test')
|
||||
]
|
||||
);
|
||||
|
||||
$data = new ValidationData($now + 10);
|
||||
$data->setIssuer('test');
|
||||
|
||||
$this->assertFalse($token->validate($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
@@ -380,6 +416,7 @@ class TokenTest extends \PHPUnit_Framework_TestCase
|
||||
public function validateShouldReturnTrueWhenThereAreNoFailedValidatableClaims()
|
||||
{
|
||||
$now = time();
|
||||
|
||||
$token = new Token(
|
||||
[],
|
||||
[
|
||||
@@ -396,6 +433,40 @@ class TokenTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($token->validate($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\Token::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData
|
||||
* @uses Lcobucci\JWT\Claim\Basic
|
||||
* @uses Lcobucci\JWT\Claim\EqualsTo
|
||||
* @uses Lcobucci\JWT\Claim\LesserOrEqualsTo
|
||||
* @uses Lcobucci\JWT\Claim\GreaterOrEqualsTo
|
||||
*
|
||||
* @covers Lcobucci\JWT\Token::validate
|
||||
* @covers Lcobucci\JWT\Token::getValidatableClaims
|
||||
*/
|
||||
public function validateShouldReturnTrueWhenLeewayMakesAllTimeBasedClaimsTrueAndOtherClaimsAreTrue()
|
||||
{
|
||||
$now = time();
|
||||
|
||||
$token = new Token(
|
||||
[],
|
||||
[
|
||||
'iss' => new EqualsTo('iss', 'test'),
|
||||
'iat' => new LesserOrEqualsTo('iat', $now),
|
||||
'nbf' => new LesserOrEqualsTo('nbf', $now + 20),
|
||||
'exp' => new GreaterOrEqualsTo('exp', $now + 500),
|
||||
'testing' => new Basic('testing', 'test')
|
||||
]
|
||||
);
|
||||
|
||||
$data = new ValidationData($now + 10, 20);
|
||||
$data->setIssuer('test');
|
||||
|
||||
$this->assertTrue($token->validate($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
@@ -493,7 +564,7 @@ class TokenTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function toStringMustReturnEncodedData()
|
||||
{
|
||||
$signature = $this->getMock(Signature::class, [], [], '', false);
|
||||
$signature = $this->createMock(Signature::class, [], [], '', false);
|
||||
|
||||
$token = new Token(['alg' => 'none'], [], $signature, ['test', 'test', 'test']);
|
||||
|
||||
|
@@ -11,12 +11,13 @@ namespace Lcobucci\JWT;
|
||||
* @author Luís Otávio Cobucci Oblonczyk <lcobucci@gmail.com>
|
||||
* @since 2.0.0
|
||||
*/
|
||||
class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
class ValidationDataTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::__construct
|
||||
* @covers Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*/
|
||||
public function constructorShouldConfigureTheItems()
|
||||
{
|
||||
@@ -26,12 +27,27 @@ class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertAttributeSame($expected, 'items', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::__construct
|
||||
* @covers Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*/
|
||||
public function constructorWithLeewayShouldConfigureTheItems()
|
||||
{
|
||||
$expected = $this->createExpectedData(null, null, null, null, 111, 111, 89);
|
||||
$data = new ValidationData(100, 11);
|
||||
|
||||
$this->assertAttributeSame($expected, 'items', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @dataProvider claimValues
|
||||
*
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::setId
|
||||
*/
|
||||
@@ -50,6 +66,7 @@ class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
* @dataProvider claimValues
|
||||
*
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::setIssuer
|
||||
*/
|
||||
@@ -68,6 +85,7 @@ class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
* @dataProvider claimValues
|
||||
*
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::setAudience
|
||||
*/
|
||||
@@ -86,6 +104,7 @@ class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
* @dataProvider claimValues
|
||||
*
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::setSubject
|
||||
*/
|
||||
@@ -102,6 +121,7 @@ class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*/
|
||||
@@ -114,10 +134,28 @@ class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertAttributeSame($expected, 'items', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*/
|
||||
public function setCurrentTimeShouldChangeTheTimeBasedValuesUsingLeeway()
|
||||
{
|
||||
$expected = $this->createExpectedData(null, null, null, null, 30, 30, 10);
|
||||
$data = new ValidationData(15, 10);
|
||||
$data->setCurrentTime(20);
|
||||
|
||||
$this->assertAttributeSame($expected, 'items', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::has
|
||||
*/
|
||||
@@ -132,6 +170,7 @@ class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::has
|
||||
*/
|
||||
@@ -146,6 +185,7 @@ class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::has
|
||||
*/
|
||||
@@ -160,6 +200,7 @@ class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::get
|
||||
*/
|
||||
@@ -174,6 +215,7 @@ class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
* @test
|
||||
*
|
||||
* @uses Lcobucci\JWT\ValidationData::__construct
|
||||
* @uses Lcobucci\JWT\ValidationData::setCurrentTime
|
||||
*
|
||||
* @covers Lcobucci\JWT\ValidationData::get
|
||||
*/
|
||||
@@ -196,11 +238,13 @@ class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $id
|
||||
* @param string $sub
|
||||
* @param string $iss
|
||||
* @param string $aud
|
||||
* @param int $time
|
||||
* @param string|null $id
|
||||
* @param string|null $sub
|
||||
* @param string|null $iss
|
||||
* @param string|null $aud
|
||||
* @param int $iat
|
||||
* @param int|null $nbf
|
||||
* @param int|null $exp
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -209,16 +253,18 @@ class ValidationDataTest extends \PHPUnit_Framework_TestCase
|
||||
$sub = null,
|
||||
$iss = null,
|
||||
$aud = null,
|
||||
$time = 1
|
||||
$iat = 1,
|
||||
$nbf = null,
|
||||
$exp = null
|
||||
) {
|
||||
return [
|
||||
'jti' => $id !== null ? (string) $id : null,
|
||||
'iss' => $iss !== null ? (string) $iss : null,
|
||||
'aud' => $aud !== null ? (string) $aud : null,
|
||||
'sub' => $sub !== null ? (string) $sub : null,
|
||||
'iat' => $time,
|
||||
'nbf' => $time,
|
||||
'exp' => $time
|
||||
'iat' => $iat,
|
||||
'nbf' => $nbf !== null ? $nbf: $iat,
|
||||
'exp' => $exp !== null ? $exp: $iat
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user