From 8f7f2c2fb2edeeccd18136ca8e5a6deb39427e9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Cobucci?= Date: Thu, 18 Aug 2022 01:25:33 +0200 Subject: [PATCH] Track constraint on violations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This provides more information to users, which is useful when debugging a violations list. Signed-off-by: Luís Cobucci --- .../Constraint/HasClaimWithValue.php | 9 ++++--- src/Validation/Constraint/IdentifiedBy.php | 5 ++-- src/Validation/Constraint/IssuedBy.php | 5 ++-- src/Validation/Constraint/LooseValidAt.php | 6 ++--- src/Validation/Constraint/PermittedFor.php | 5 ++-- src/Validation/Constraint/RelatedTo.php | 5 ++-- src/Validation/Constraint/SignedWith.php | 6 ++--- src/Validation/Constraint/StrictValidAt.php | 14 +++++----- src/Validation/ConstraintViolation.php | 15 +++++++++++ test/functional/ES512TokenTest.php | 1 + test/functional/EcdsaTokenTest.php | 3 +-- test/functional/EddsaTokenTest.php | 1 + test/functional/HmacTokenTest.php | 1 + .../MaliciousTamperingPreventionTest.php | 1 + test/functional/RsaTokenTest.php | 1 + test/functional/TimeFractionPrecisionTest.php | 1 + test/functional/UnsignedTokenTest.php | 1 + test/unit/JwtFacadeTest.php | 1 + .../Constraint/HasClaimWithValueTest.php | 3 +++ .../Constraint/IdentifiedByTest.php | 3 +++ .../Validation/Constraint/IssuedByTest.php | 3 +++ .../Constraint/PermittedForTest.php | 3 +++ .../Validation/Constraint/RelatedToTest.php | 2 ++ .../Validation/Constraint/SignedWithTest.php | 3 +++ .../Constraint/StrictValidAtTest.php | 4 +++ .../Validation/Constraint/ValidAtTest.php | 1 + .../Validation/Constraint/ValidAtTestCase.php | 3 +++ .../Validation/ConstraintViolationTest.php | 27 +++++++++++++++++++ 28 files changed, 107 insertions(+), 26 deletions(-) create mode 100644 test/unit/Validation/ConstraintViolationTest.php diff --git a/src/Validation/Constraint/HasClaimWithValue.php b/src/Validation/Constraint/HasClaimWithValue.php index b54fe209..614c38db 100644 --- a/src/Validation/Constraint/HasClaimWithValue.php +++ b/src/Validation/Constraint/HasClaimWithValue.php @@ -31,17 +31,20 @@ public function __construct(string $claim, $expectedValue) public function assert(Token $token): void { if (! $token instanceof UnencryptedToken) { - throw new ConstraintViolation('You should pass a plain token'); + throw ConstraintViolation::error('You should pass a plain token', $this); } $claims = $token->claims(); if (! $claims->has($this->claim)) { - throw new ConstraintViolation('The token does not have the claim "' . $this->claim . '"'); + throw ConstraintViolation::error('The token does not have the claim "' . $this->claim . '"', $this); } if ($claims->get($this->claim) !== $this->expectedValue) { - throw new ConstraintViolation('The claim "' . $this->claim . '" does not have the expected value'); + throw ConstraintViolation::error( + 'The claim "' . $this->claim . '" does not have the expected value', + $this + ); } } } diff --git a/src/Validation/Constraint/IdentifiedBy.php b/src/Validation/Constraint/IdentifiedBy.php index 0d3a1940..c0ad8a01 100644 --- a/src/Validation/Constraint/IdentifiedBy.php +++ b/src/Validation/Constraint/IdentifiedBy.php @@ -19,8 +19,9 @@ public function __construct(string $id) public function assert(Token $token): void { if (! $token->isIdentifiedBy($this->id)) { - throw new ConstraintViolation( - 'The token is not identified with the expected ID' + throw ConstraintViolation::error( + 'The token is not identified with the expected ID', + $this ); } } diff --git a/src/Validation/Constraint/IssuedBy.php b/src/Validation/Constraint/IssuedBy.php index 5f5346e3..c4628150 100644 --- a/src/Validation/Constraint/IssuedBy.php +++ b/src/Validation/Constraint/IssuedBy.php @@ -20,8 +20,9 @@ public function __construct(string ...$issuers) public function assert(Token $token): void { if (! $token->hasBeenIssuedBy(...$this->issuers)) { - throw new ConstraintViolation( - 'The token was not issued by the given issuers' + throw ConstraintViolation::error( + 'The token was not issued by the given issuers', + $this ); } } diff --git a/src/Validation/Constraint/LooseValidAt.php b/src/Validation/Constraint/LooseValidAt.php index af16135d..22e0930d 100644 --- a/src/Validation/Constraint/LooseValidAt.php +++ b/src/Validation/Constraint/LooseValidAt.php @@ -47,7 +47,7 @@ public function assert(Token $token): void private function assertExpiration(Token $token, DateTimeInterface $now): void { if ($token->isExpired($now)) { - throw new ConstraintViolation('The token is expired'); + throw ConstraintViolation::error('The token is expired', $this); } } @@ -55,7 +55,7 @@ private function assertExpiration(Token $token, DateTimeInterface $now): void private function assertMinimumTime(Token $token, DateTimeInterface $now): void { if (! $token->isMinimumTimeBefore($now)) { - throw new ConstraintViolation('The token cannot be used yet'); + throw ConstraintViolation::error('The token cannot be used yet', $this); } } @@ -63,7 +63,7 @@ private function assertMinimumTime(Token $token, DateTimeInterface $now): void private function assertIssueTime(Token $token, DateTimeInterface $now): void { if (! $token->hasBeenIssuedBefore($now)) { - throw new ConstraintViolation('The token was issued in the future'); + throw ConstraintViolation::error('The token was issued in the future', $this); } } } diff --git a/src/Validation/Constraint/PermittedFor.php b/src/Validation/Constraint/PermittedFor.php index 1155697a..ed2ce8ee 100644 --- a/src/Validation/Constraint/PermittedFor.php +++ b/src/Validation/Constraint/PermittedFor.php @@ -19,8 +19,9 @@ public function __construct(string $audience) public function assert(Token $token): void { if (! $token->isPermittedFor($this->audience)) { - throw new ConstraintViolation( - 'The token is not allowed to be used by this audience' + throw ConstraintViolation::error( + 'The token is not allowed to be used by this audience', + $this ); } } diff --git a/src/Validation/Constraint/RelatedTo.php b/src/Validation/Constraint/RelatedTo.php index 8beecd70..dc2461a2 100644 --- a/src/Validation/Constraint/RelatedTo.php +++ b/src/Validation/Constraint/RelatedTo.php @@ -19,8 +19,9 @@ public function __construct(string $subject) public function assert(Token $token): void { if (! $token->isRelatedTo($this->subject)) { - throw new ConstraintViolation( - 'The token is not related to the expected subject' + throw ConstraintViolation::error( + 'The token is not related to the expected subject', + $this ); } } diff --git a/src/Validation/Constraint/SignedWith.php b/src/Validation/Constraint/SignedWith.php index d645be12..150b6a38 100644 --- a/src/Validation/Constraint/SignedWith.php +++ b/src/Validation/Constraint/SignedWith.php @@ -23,15 +23,15 @@ public function __construct(Signer $signer, Signer\Key $key) public function assert(Token $token): void { if (! $token instanceof UnencryptedToken) { - throw new ConstraintViolation('You should pass a plain token'); + throw ConstraintViolation::error('You should pass a plain token', $this); } if ($token->headers()->get('alg') !== $this->signer->algorithmId()) { - throw new ConstraintViolation('Token signer mismatch'); + throw ConstraintViolation::error('Token signer mismatch', $this); } if (! $this->signer->verify($token->signature()->hash(), $token->payload(), $this->key)) { - throw new ConstraintViolation('Token signature mismatch'); + throw ConstraintViolation::error('Token signature mismatch', $this); } } } diff --git a/src/Validation/Constraint/StrictValidAt.php b/src/Validation/Constraint/StrictValidAt.php index cf159a4c..5a1738a1 100644 --- a/src/Validation/Constraint/StrictValidAt.php +++ b/src/Validation/Constraint/StrictValidAt.php @@ -38,7 +38,7 @@ private function guardLeeway(?DateInterval $leeway): DateInterval public function assert(Token $token): void { if (! $token instanceof UnencryptedToken) { - throw new ConstraintViolation('You should pass a plain token'); + throw ConstraintViolation::error('You should pass a plain token', $this); } $now = $this->clock->now(); @@ -52,11 +52,11 @@ public function assert(Token $token): void private function assertExpiration(UnencryptedToken $token, DateTimeInterface $now): void { if (! $token->claims()->has(Token\RegisteredClaims::EXPIRATION_TIME)) { - throw new ConstraintViolation('"Expiration Time" claim missing'); + throw ConstraintViolation::error('"Expiration Time" claim missing', $this); } if ($token->isExpired($now)) { - throw new ConstraintViolation('The token is expired'); + throw ConstraintViolation::error('The token is expired', $this); } } @@ -64,11 +64,11 @@ private function assertExpiration(UnencryptedToken $token, DateTimeInterface $no private function assertMinimumTime(UnencryptedToken $token, DateTimeInterface $now): void { if (! $token->claims()->has(Token\RegisteredClaims::NOT_BEFORE)) { - throw new ConstraintViolation('"Not Before" claim missing'); + throw ConstraintViolation::error('"Not Before" claim missing', $this); } if (! $token->isMinimumTimeBefore($now)) { - throw new ConstraintViolation('The token cannot be used yet'); + throw ConstraintViolation::error('The token cannot be used yet', $this); } } @@ -76,11 +76,11 @@ private function assertMinimumTime(UnencryptedToken $token, DateTimeInterface $n private function assertIssueTime(UnencryptedToken $token, DateTimeInterface $now): void { if (! $token->claims()->has(Token\RegisteredClaims::ISSUED_AT)) { - throw new ConstraintViolation('"Issued At" claim missing'); + throw ConstraintViolation::error('"Issued At" claim missing', $this); } if (! $token->hasBeenIssuedBefore($now)) { - throw new ConstraintViolation('The token was issued in the future'); + throw ConstraintViolation::error('The token was issued in the future', $this); } } } diff --git a/src/Validation/ConstraintViolation.php b/src/Validation/ConstraintViolation.php index 39a56edc..cb1abeb7 100644 --- a/src/Validation/ConstraintViolation.php +++ b/src/Validation/ConstraintViolation.php @@ -6,6 +6,21 @@ use Lcobucci\JWT\Exception; use RuntimeException; +use function get_class; + final class ConstraintViolation extends RuntimeException implements Exception { + /** + * @readonly + * @var class-string|null + */ + public ?string $constraint = null; + + public static function error(string $message, Constraint $constraint): self + { + $exception = new self($message); + $exception->constraint = get_class($constraint); + + return $exception; + } } diff --git a/test/functional/ES512TokenTest.php b/test/functional/ES512TokenTest.php index 6105de72..34206ed1 100644 --- a/test/functional/ES512TokenTest.php +++ b/test/functional/ES512TokenTest.php @@ -37,6 +37,7 @@ * @covers \Lcobucci\JWT\Signer\OpenSSL * @covers \Lcobucci\JWT\SodiumBase64Polyfill * @covers \Lcobucci\JWT\Validation\Validator + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * @covers \Lcobucci\JWT\Validation\RequiredConstraintsViolated * @covers \Lcobucci\JWT\Validation\Constraint\SignedWith */ diff --git a/test/functional/EcdsaTokenTest.php b/test/functional/EcdsaTokenTest.php index 4f553392..6e0a8252 100644 --- a/test/functional/EcdsaTokenTest.php +++ b/test/functional/EcdsaTokenTest.php @@ -39,10 +39,9 @@ * @covers \Lcobucci\JWT\Signer\OpenSSL * @covers \Lcobucci\JWT\SodiumBase64Polyfill * @covers \Lcobucci\JWT\Validation\Validator + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * @covers \Lcobucci\JWT\Validation\Constraint\SignedWith - * @covers \Lcobucci\JWT\Validation\Validator * @covers \Lcobucci\JWT\Validation\RequiredConstraintsViolated - * @covers \Lcobucci\JWT\Validation\Constraint\SignedWith */ class EcdsaTokenTest extends TestCase { diff --git a/test/functional/EddsaTokenTest.php b/test/functional/EddsaTokenTest.php index 54b77af1..e2741050 100644 --- a/test/functional/EddsaTokenTest.php +++ b/test/functional/EddsaTokenTest.php @@ -35,6 +35,7 @@ * @covers \Lcobucci\JWT\Validation\Validator * @covers \Lcobucci\JWT\Validation\Constraint\SignedWith * @covers \Lcobucci\JWT\Validation\Validator + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * @covers \Lcobucci\JWT\Validation\RequiredConstraintsViolated * @covers \Lcobucci\JWT\Validation\Constraint\SignedWith */ diff --git a/test/functional/HmacTokenTest.php b/test/functional/HmacTokenTest.php index 8020f4f1..d92fcc0d 100644 --- a/test/functional/HmacTokenTest.php +++ b/test/functional/HmacTokenTest.php @@ -37,6 +37,7 @@ * @covers \Lcobucci\JWT\Signer\Hmac\UnsafeSha256 * @covers \Lcobucci\JWT\SodiumBase64Polyfill * @covers \Lcobucci\JWT\Validation\Validator + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * @covers \Lcobucci\JWT\Validation\RequiredConstraintsViolated * @covers \Lcobucci\JWT\Validation\Constraint\SignedWith */ diff --git a/test/functional/MaliciousTamperingPreventionTest.php b/test/functional/MaliciousTamperingPreventionTest.php index 598901ef..2f6cf369 100644 --- a/test/functional/MaliciousTamperingPreventionTest.php +++ b/test/functional/MaliciousTamperingPreventionTest.php @@ -61,6 +61,7 @@ public function createConfiguration(): void * @covers \Lcobucci\JWT\Signer\Hmac\Sha256 * @covers \Lcobucci\JWT\Signer\Hmac\Sha512 * @covers \Lcobucci\JWT\SodiumBase64Polyfill + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * @covers \Lcobucci\JWT\Validation\Constraint\SignedWith * @covers \Lcobucci\JWT\Validation\Validator */ diff --git a/test/functional/RsaTokenTest.php b/test/functional/RsaTokenTest.php index 969e9748..9b4fac4e 100644 --- a/test/functional/RsaTokenTest.php +++ b/test/functional/RsaTokenTest.php @@ -36,6 +36,7 @@ * @covers \Lcobucci\JWT\Signer\Rsa\Sha512 * @covers \Lcobucci\JWT\SodiumBase64Polyfill * @covers \Lcobucci\JWT\Validation\Validator + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * @covers \Lcobucci\JWT\Validation\RequiredConstraintsViolated * @covers \Lcobucci\JWT\Validation\Constraint\SignedWith */ diff --git a/test/functional/TimeFractionPrecisionTest.php b/test/functional/TimeFractionPrecisionTest.php index 4e197c5c..57792fd6 100644 --- a/test/functional/TimeFractionPrecisionTest.php +++ b/test/functional/TimeFractionPrecisionTest.php @@ -23,6 +23,7 @@ * @covers \Lcobucci\JWT\Signer\Key\InMemory * @covers \Lcobucci\JWT\Signer\None * @covers \Lcobucci\JWT\Validation\Validator + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * @covers \Lcobucci\JWT\Validation\RequiredConstraintsViolated * @covers \Lcobucci\JWT\Validation\Constraint\SignedWith */ diff --git a/test/functional/UnsignedTokenTest.php b/test/functional/UnsignedTokenTest.php index 23bfa5d7..65b9374f 100644 --- a/test/functional/UnsignedTokenTest.php +++ b/test/functional/UnsignedTokenTest.php @@ -32,6 +32,7 @@ * @covers \Lcobucci\JWT\Signer\None * @covers \Lcobucci\JWT\Signer\Key\InMemory * @covers \Lcobucci\JWT\SodiumBase64Polyfill + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * @covers \Lcobucci\JWT\Validation\RequiredConstraintsViolated * @covers \Lcobucci\JWT\Validation\Validator * @covers \Lcobucci\JWT\Validation\Constraint\IssuedBy diff --git a/test/unit/JwtFacadeTest.php b/test/unit/JwtFacadeTest.php index 01bad3e1..6581d9e6 100644 --- a/test/unit/JwtFacadeTest.php +++ b/test/unit/JwtFacadeTest.php @@ -38,6 +38,7 @@ * @uses \Lcobucci\JWT\Validation\Constraint\IssuedBy * @uses \Lcobucci\JWT\Validation\Constraint\SignedWith * @uses \Lcobucci\JWT\Validation\Constraint\StrictValidAt + * @uses \Lcobucci\JWT\Validation\ConstraintViolation * @uses \Lcobucci\JWT\Validation\RequiredConstraintsViolated */ final class JwtFacadeTest extends TestCase diff --git a/test/unit/Validation/Constraint/HasClaimWithValueTest.php b/test/unit/Validation/Constraint/HasClaimWithValueTest.php index 3e4e9864..bfc9905e 100644 --- a/test/unit/Validation/Constraint/HasClaimWithValueTest.php +++ b/test/unit/Validation/Constraint/HasClaimWithValueTest.php @@ -39,6 +39,7 @@ public function registeredClaims(): iterable * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -58,6 +59,7 @@ public function assertShouldRaiseExceptionWhenClaimIsNotSet(): void * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -77,6 +79,7 @@ public function assertShouldRaiseExceptionWhenClaimValueDoesNotMatch(): void * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain diff --git a/test/unit/Validation/Constraint/IdentifiedByTest.php b/test/unit/Validation/Constraint/IdentifiedByTest.php index c41f4d93..88e8b10d 100644 --- a/test/unit/Validation/Constraint/IdentifiedByTest.php +++ b/test/unit/Validation/Constraint/IdentifiedByTest.php @@ -14,6 +14,7 @@ final class IdentifiedByTest extends ConstraintTestCase * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -33,6 +34,7 @@ public function assertShouldRaiseExceptionWhenIdIsNotSet(): void * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -52,6 +54,7 @@ public function assertShouldRaiseExceptionWhenIdDoesNotMatch(): void * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain diff --git a/test/unit/Validation/Constraint/IssuedByTest.php b/test/unit/Validation/Constraint/IssuedByTest.php index cb62eaa4..e36c3d76 100644 --- a/test/unit/Validation/Constraint/IssuedByTest.php +++ b/test/unit/Validation/Constraint/IssuedByTest.php @@ -14,6 +14,7 @@ final class IssuedByTest extends ConstraintTestCase * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -33,6 +34,7 @@ public function assertShouldRaiseExceptionWhenIssuerIsNotSet(): void * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -52,6 +54,7 @@ public function assertShouldRaiseExceptionWhenIssuerValueDoesNotMatch(): void * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain diff --git a/test/unit/Validation/Constraint/PermittedForTest.php b/test/unit/Validation/Constraint/PermittedForTest.php index 95c2932a..b99f0cf8 100644 --- a/test/unit/Validation/Constraint/PermittedForTest.php +++ b/test/unit/Validation/Constraint/PermittedForTest.php @@ -14,6 +14,7 @@ final class PermittedForTest extends ConstraintTestCase * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -33,6 +34,7 @@ public function assertShouldRaiseExceptionWhenAudienceIsNotSet(): void * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -52,6 +54,7 @@ public function assertShouldRaiseExceptionWhenAudienceValueDoesNotMatch(): void * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain diff --git a/test/unit/Validation/Constraint/RelatedToTest.php b/test/unit/Validation/Constraint/RelatedToTest.php index a5fe626d..30c5470b 100644 --- a/test/unit/Validation/Constraint/RelatedToTest.php +++ b/test/unit/Validation/Constraint/RelatedToTest.php @@ -14,6 +14,7 @@ final class RelatedToTest extends ConstraintTestCase * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -33,6 +34,7 @@ public function assertShouldRaiseExceptionWhenSubjectIsNotSet(): void * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain diff --git a/test/unit/Validation/Constraint/SignedWithTest.php b/test/unit/Validation/Constraint/SignedWithTest.php index a045142d..f2ab5195 100644 --- a/test/unit/Validation/Constraint/SignedWithTest.php +++ b/test/unit/Validation/Constraint/SignedWithTest.php @@ -32,6 +32,7 @@ public function createDependencies(): void * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Signer\Key\InMemory * @uses \Lcobucci\JWT\Token\DataSet @@ -52,6 +53,7 @@ public function assertShouldRaiseExceptionWhenTokenIsNotAPlainToken(): void * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Signer\Key\InMemory * @uses \Lcobucci\JWT\Token\DataSet @@ -76,6 +78,7 @@ public function assertShouldRaiseExceptionWhenSignerIsNotTheSame(): void * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Signer\Key\InMemory * @uses \Lcobucci\JWT\Token\DataSet diff --git a/test/unit/Validation/Constraint/StrictValidAtTest.php b/test/unit/Validation/Constraint/StrictValidAtTest.php index fb41bd28..a58fea5f 100644 --- a/test/unit/Validation/Constraint/StrictValidAtTest.php +++ b/test/unit/Validation/Constraint/StrictValidAtTest.php @@ -24,6 +24,7 @@ protected function buildValidAtConstraint(Clock $clock, ?DateInterval $leeway = * @covers ::__construct * @covers ::assert * @covers ::guardLeeway + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -45,6 +46,7 @@ public function assertShouldRaiseExceptionWhenTokenIsNotAPlainToken(): void * @covers ::assert * @covers ::guardLeeway * @covers ::assertIssueTime + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -67,6 +69,7 @@ public function assertShouldRaiseExceptionWhenIatClaimIsMissing(): void * @covers ::guardLeeway * @covers ::assertIssueTime * @covers ::assertMinimumTime + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -94,6 +97,7 @@ public function assertShouldRaiseExceptionWhenNbfClaimIsMissing(): void * @covers ::guardLeeway * @covers ::assertIssueTime * @covers ::assertMinimumTime + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * @covers ::assertExpiration * * @uses \Lcobucci\JWT\Token\DataSet diff --git a/test/unit/Validation/Constraint/ValidAtTest.php b/test/unit/Validation/Constraint/ValidAtTest.php index 321a4840..bd5997b7 100644 --- a/test/unit/Validation/Constraint/ValidAtTest.php +++ b/test/unit/Validation/Constraint/ValidAtTest.php @@ -17,6 +17,7 @@ final class ValidAtTest extends ConstraintTestCase * * @covers ::__construct * @covers ::assert + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain diff --git a/test/unit/Validation/Constraint/ValidAtTestCase.php b/test/unit/Validation/Constraint/ValidAtTestCase.php index 81053e36..70f49227 100644 --- a/test/unit/Validation/Constraint/ValidAtTestCase.php +++ b/test/unit/Validation/Constraint/ValidAtTestCase.php @@ -50,6 +50,7 @@ final public function constructShouldRaiseExceptionOnNegativeLeeway(): void * @covers ::assertExpiration * @covers ::assertIssueTime * @covers ::assertMinimumTime + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -80,6 +81,7 @@ final public function assertShouldRaiseExceptionWhenTokenIsExpired(): void * @covers ::assert * @covers ::assertIssueTime * @covers ::assertMinimumTime + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain @@ -109,6 +111,7 @@ final public function assertShouldRaiseExceptionWhenMinimumTimeIsNotMet(): void * @covers ::guardLeeway * @covers ::assert * @covers ::assertIssueTime + * @covers \Lcobucci\JWT\Validation\ConstraintViolation * * @uses \Lcobucci\JWT\Token\DataSet * @uses \Lcobucci\JWT\Token\Plain diff --git a/test/unit/Validation/ConstraintViolationTest.php b/test/unit/Validation/ConstraintViolationTest.php new file mode 100644 index 00000000..9edbf96d --- /dev/null +++ b/test/unit/Validation/ConstraintViolationTest.php @@ -0,0 +1,27 @@ +getMessage()); + self::assertSame(IdentifiedBy::class, $violation->constraint); + } +}