You are here

public function KitchenTest::testBakeData in Bakery Single Sign-On System 8.2

@covers ::bakeData @covers ::tasteData

File

tests/src/Unit/KitchenTest.php, line 245

Class

KitchenTest
@coversDefaultClass \Drupal\bakery\Kitchen

Namespace

Drupal\Tests\bakery\Unit

Code

public function testBakeData() {
  $encoded = 'Mzc0M2RiNTMwMzJkOTE0MDFhMDMxMmVmNjQ2NmYxZGRlODMwZmM1ZjQ3ZDhkNzY5YjAwYTI1YWI3YjFlNGI1ZDYKk5BY7/qPHxsfaqbNRmpYnv5Zt5PdEKDTAaoTps/fYUAfHLHpidALZ3OxG2Nm6tFDXNmMR/SwnZMjICrc0UJgbcqe+VK4sCkHY41UDYhzHKRBHqg3S1hwVQ2727jLoEKHe5bKRpDnXA3DbIAp0p+y+qT7MvxMKPThOWEiZlpc8U3QhthD17aIXyEWgR487C5o4obdDr/w8vYTM+qyQhNMynDGdBhBTIh1mN4gd3vr';
  $cookie = new Gingerbread('tester', 0, 'child.example.com', 123);
  $timestamp = 1634021402;
  $this->request
    ->getCurrentRequest()->server
    ->set('REQUEST_TIME', $timestamp);
  $this
    ->assertEquals($encoded, $this->kitchen
    ->bakeData($cookie));
  $data = $this->kitchen
    ->tasteData($encoded, Gingerbread::getName());
  $this
    ->assertEqualsCanonicalizing([
    'name' => $cookie
      ->getAccountName(),
    'or_email' => $cookie
      ->getOrEmail(),
    'slave' => $cookie
      ->getChild(),
    'uid' => $cookie
      ->getChildUid(),
    'type' => Gingerbread::getName(),
    'timestamp' => $timestamp,
  ], $data);

  // Bad signature fails.
  $this
    ->assertFalse($this->kitchen
    ->tasteData('a' . $encoded, Gingerbread::getName()));

  // Bad cookie name fails.
  $this
    ->assertFalse($this->kitchen
    ->tasteData($encoded, Stroopwafel::getName()));

  // Stale cookies do not taste good.
  $this->request
    ->getCurrentRequest()->server
    ->set('REQUEST_TIME', $timestamp + $this->config
    ->get('bakery_freshness') + 50);
  $this
    ->assertFalse($this->kitchen
    ->tasteData($encoded, Gingerbread::getName()));
}