You are here

public function TokenTest::testThatTokenWithIncorrectSegmentsThrowsException in Auth0 Single Sign On 8.2

Test that a malformed token is rejected.

Return value

void

Throws

CoreException See Auth0\SDK\JWTVerifier::verifyAndDecode().

File

vendor/auth0/auth0-php/tests/API/Helpers/TokenGeneratorTest.php, line 134

Class

TokenTest
Class TokenTest

Namespace

Auth0\Tests\Api\Helpers

Code

public function testThatTokenWithIncorrectSegmentsThrowsException() {
  $verifier = new JWTVerifier([
    'valid_audiences' => [
      uniqid(),
    ],
    'supported_algs' => [
      'HS256',
    ],
    'client_secret' => self::CLIENT_SECRET,
  ]);
  $caught_exception = false;
  try {
    $verifier
      ->verifyAndDecode(uniqid());
  } catch (InvalidTokenException $e) {
    $caught_exception = $this
      ->errorHasString($e, 'Wrong number of segments');
  }
  $this
    ->assertTrue($caught_exception);
  $caught_exception = false;
  try {
    $verifier
      ->verifyAndDecode(uniqid() . '.' . uniqid());
  } catch (InvalidTokenException $e) {
    $caught_exception = $this
      ->errorHasString($e, 'Wrong number of segments');
  }
  $this
    ->assertTrue($caught_exception);
}