diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 91f869674..27ae9c741 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -16,7 +16,7 @@ - tests/UnsupportedParser.php + tests diff --git a/tests/Signer/FakeSigner.php b/tests/Signer/FakeSigner.php new file mode 100644 index 000000000..d6f934a48 --- /dev/null +++ b/tests/Signer/FakeSigner.php @@ -0,0 +1,30 @@ +signature; + } + + public function sign(string $payload, Key $key): string + { + return $this->signature . '-' . $key->contents(); + } + + public function verify(string $expected, string $payload, Key $key): bool + { + return $this->signature . '-' . $key->contents() === $expected; + } +} diff --git a/tests/Validation/Constraint/ConstraintTestCase.php b/tests/Validation/Constraint/ConstraintTestCase.php index 07860dda7..9ef13b583 100644 --- a/tests/Validation/Constraint/ConstraintTestCase.php +++ b/tests/Validation/Constraint/ConstraintTestCase.php @@ -3,9 +3,14 @@ namespace Lcobucci\JWT\Tests\Validation\Constraint; +use Closure; +use Lcobucci\JWT\Builder; +use Lcobucci\JWT\JwtFacade; +use Lcobucci\JWT\Signer; use Lcobucci\JWT\Token\DataSet; use Lcobucci\JWT\Token\Plain; use Lcobucci\JWT\Token\Signature; +use Lcobucci\JWT\UnencryptedToken; use PHPUnit\Framework\TestCase; abstract class ConstraintTestCase extends TestCase @@ -25,4 +30,13 @@ protected function buildToken( $signature ?? new Signature('sig+hash', 'sig+encoded'), ); } + + protected function issueToken(Signer $signer, Signer\Key $key, ?Closure $customization = null): UnencryptedToken + { + return (new JwtFacade())->issue( + $signer, + $key, + $customization ?? static fn (Builder $builder) => $builder, + ); + } }