1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
<?php
declare(strict_types=1);
namespace Lcobucci\JWT\Tests\Validation\Constraint;
use Lcobucci\JWT\Token;
use Lcobucci\JWT\Token\RegisteredClaims;
use Lcobucci\JWT\Validation\Constraint\IssuedBy;
use Lcobucci\JWT\Validation\ConstraintViolation;
use PHPUnit\Framework\Attributes as PHPUnit;
#[PHPUnit\CoversClass(ConstraintViolation::class)]
#[PHPUnit\CoversClass(IssuedBy::class)]
#[PHPUnit\UsesClass(Token\DataSet::class)]
#[PHPUnit\UsesClass(Token\Plain::class)]
#[PHPUnit\UsesClass(Token\Signature::class)]
final class IssuedByTest extends ConstraintTestCase
{
#[PHPUnit\Test]
public function assertShouldRaiseExceptionWhenIssuerIsNotSet(): void
{
$this->expectException(ConstraintViolation::class);
$this->expectExceptionMessage('The token was not issued by the given issuers');
$constraint = new IssuedBy('test.com', 'test.net');
$constraint->assert($this->buildToken());
}
#[PHPUnit\Test]
public function assertShouldRaiseExceptionWhenIssuerValueDoesNotMatch(): void
{
$this->expectException(ConstraintViolation::class);
$this->expectExceptionMessage('The token was not issued by the given issuers');
$constraint = new IssuedBy('test.com', 'test.net');
$constraint->assert($this->buildToken([RegisteredClaims::ISSUER => 'example.com']));
}
#[PHPUnit\Test]
public function assertShouldRaiseExceptionWhenIssuerTypeValueDoesNotMatch(): void
{
$this->expectException(ConstraintViolation::class);
$this->expectExceptionMessage('The token was not issued by the given issuers');
$constraint = new IssuedBy('test.com', '123');
$constraint->assert($this->buildToken([RegisteredClaims::ISSUER => 123]));
}
#[PHPUnit\Test]
public function assertShouldNotRaiseExceptionWhenIssuerMatches(): void
{
$token = $this->buildToken([RegisteredClaims::ISSUER => 'test.com']);
$constraint = new IssuedBy('test.com', 'test.net');
$constraint->assert($token);
$this->addToAssertionCount(1);
}
}
|