You are here

class SessionStateHandlerTest in Auth0 Single Sign On 8.2

Class SessionStateHandlerTest

@package Auth0\Tests\Api\Helpers\State

Hierarchy

  • class \Auth0\Tests\Api\Helpers\State\SessionStateHandlerTest extends \Auth0\Tests\Api\Helpers\State\PHPUnit_Framework_TestCase

Expanded class hierarchy of SessionStateHandlerTest

File

vendor/auth0/auth0-php/tests/API/Helpers/State/SessionStateHandlerTest.php, line 12

Namespace

Auth0\Tests\Api\Helpers\State
View source
class SessionStateHandlerTest extends \PHPUnit_Framework_TestCase {

  /**
   * Storage engine to use.
   *
   * @var SessionStore
   */
  private $sessionStore;

  /**
   * State handler to use.
   *
   * @var SessionStateHandler
   */
  private $stateHandler;

  /**
   * SessionStateHandlerTest constructor.
   *
   * @return void
   */
  public function __construct() {
    parent::__construct();
    $this->sessionStore = new SessionStore();
    $this->stateHandler = new SessionStateHandler($this->sessionStore);
  }

  /**
   * Test that state is stored and retrieved properly.
   *
   * @return void
   */
  public function testStateStoredCorrectly() {
    $uniqid = uniqid();

    // Suppressing "headers already sent" warning related to cookies.
    // phpcs:ignore
    @$this->stateHandler
      ->store($uniqid);
    $this
      ->assertEquals($uniqid, $this->sessionStore
      ->get(SessionStateHandler::STATE_NAME));
  }

  /**
   * Test that the state is being issued correctly.
   *
   * @return void
   */
  public function testStateIssuedCorrectly() {
    $state_issued = $this->stateHandler
      ->issue();
    $this
      ->assertEquals($state_issued, $this->sessionStore
      ->get(SessionStateHandler::STATE_NAME));
  }

  /**
   * Test that state validated properly.
   *
   * @return void
   */
  public function testStateValidatesCorrectly() {
    $state_issued = $this->stateHandler
      ->issue();
    $this
      ->assertTrue($this->stateHandler
      ->validate($state_issued));
    $this
      ->assertNull($this->sessionStore
      ->get(SessionStateHandler::STATE_NAME));
  }

  /**
   * Test that state validation fails with an incorrect value.
   *
   * @return void
   */
  public function testStateFailsWithIncorrectValue() {
    $state_issued = $this->stateHandler
      ->issue();
    $this
      ->assertFalse($this->stateHandler
      ->validate($state_issued . 'false'));
    $this
      ->assertNull($this->sessionStore
      ->get(SessionStateHandler::STATE_NAME));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SessionStateHandlerTest::$sessionStore private property Storage engine to use.
SessionStateHandlerTest::$stateHandler private property State handler to use.
SessionStateHandlerTest::testStateFailsWithIncorrectValue public function Test that state validation fails with an incorrect value.
SessionStateHandlerTest::testStateIssuedCorrectly public function Test that the state is being issued correctly.
SessionStateHandlerTest::testStateStoredCorrectly public function Test that state is stored and retrieved properly.
SessionStateHandlerTest::testStateValidatesCorrectly public function Test that state validated properly.
SessionStateHandlerTest::__construct public function SessionStateHandlerTest constructor.