-
-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/allow-multiple-audiences-and-issuers'
- Loading branch information
Showing
19 changed files
with
361 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lcobucci\JWT\Claim; | ||
|
||
use Lcobucci\JWT\Claim; | ||
use Lcobucci\JWT\ValidationData; | ||
|
||
/** | ||
* Validatable claim that checks if claim value is strictly equal to an item in the given validation data set. | ||
* | ||
* @author Matthew John Marshall <matthew.marshall96@yahoo.co.uk> | ||
* @since 4.0.0 | ||
*/ | ||
class ContainedEqualsTo extends Basic implements Claim, Validatable | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function validate(ValidationData $data) : bool | ||
{ | ||
if ($data->has($this->getName())) { | ||
return in_array($this->getValue(), $data->get($this->getName())); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lcobucci\JWT\Claim; | ||
|
||
use Lcobucci\JWT\Claim; | ||
use Lcobucci\JWT\ValidationData; | ||
|
||
/** | ||
* Validatable claim that checks if the claim value set contains a value strictly equal to the validation item value. | ||
* | ||
* @author Matthew John Marshall <matthew.marshall96@yahoo.co.uk> | ||
* @since 4.0.0 | ||
*/ | ||
class ContainsEqualsTo extends Basic implements Claim, Validatable | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function validate(ValidationData $data) : bool | ||
{ | ||
if ($data->has($this->getName())) { | ||
return in_array($data->get($this->getName()), $this->getValue()); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?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 | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Lcobucci\JWT\Claim; | ||
|
||
use Lcobucci\JWT\ValidationData; | ||
|
||
/** | ||
* @author Matthew John Marshall <matthew.marshall96@yahoo.co.uk> | ||
* @since 4.0.0 | ||
*/ | ||
class ContainedEqualsToTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @test | ||
* | ||
* @uses Lcobucci\JWT\Claim\Basic | ||
* @uses Lcobucci\JWT\ValidationData | ||
* | ||
* @covers Lcobucci\JWT\Claim\ContainedEqualsTo::validate | ||
*/ | ||
public function validateShouldReturnTrueWhenValidationDoesntHaveTheClaim() | ||
{ | ||
$claim = new ContainedEqualsTo('iss', 'test'); | ||
|
||
$this->assertTrue($claim->validate(new ValidationData())); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @uses Lcobucci\JWT\Claim\Basic | ||
* @uses Lcobucci\JWT\ValidationData | ||
* | ||
* @covers Lcobucci\JWT\Claim\ContainedEqualsTo::validate | ||
*/ | ||
public function validateShouldReturnTrueWhenClaimValueIsEqualToAtLeastOneItemInValidationData() | ||
{ | ||
$claim = new ContainedEqualsTo('iss', 'test'); | ||
|
||
$data = new ValidationData(); | ||
$data->setIssuer(['test', 'test2']); | ||
|
||
$this->assertTrue($claim->validate($data)); | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @uses Lcobucci\JWT\Claim\Basic | ||
* @uses Lcobucci\JWT\ValidationData | ||
* | ||
* @covers Lcobucci\JWT\Claim\ContainedEqualsTo::validate | ||
*/ | ||
public function validateShouldReturnFalseWhenClaimValueIsNotEqualToAtLeastOneItemInValidationData() | ||
{ | ||
$claim = new ContainedEqualsTo('iss', 'test'); | ||
|
||
$data = new ValidationData(); | ||
$data->setIssuer(['test2', 'test3']); | ||
|
||
$this->assertFalse($claim->validate($data)); | ||
} | ||
} |
Oops, something went wrong.