updated-packages
This commit is contained in:
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