Skip to content

Commit

Permalink
Fix new file
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Aug 6, 2019
1 parent 4623b56 commit 0fa5cb0
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions tests/lib/SimpleSAML/SessionHandlerPHPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

class SessionHandlerPHPTest extends ClearStateTestCase
{
/** @var array */
protected $sessionConfig = [
'session.cookie.name' => 'SimpleSAMLSessionID',
'session.cookie.lifetime' => 100,
Expand All @@ -17,8 +18,14 @@ class SessionHandlerPHPTest extends ClearStateTestCase
'session.cookie.secure' => true,
'session.phpsession.cookiename' => 'SimpleSAML',
];

/** @var array */
protected $original;


/**
* @return void
*/
protected function setUp()
{
$this->original = $_SERVER;
Expand All @@ -29,15 +36,21 @@ protected function setUp()
$_SERVER['REQUEST_URI'] = '/simplesaml';
}


/**
* @return void
*/
protected function tearDown()
{
$_SERVER = $this->original;
}


/**
* @covers SimpleSAML\SessionHandlerPHP::__construct()
* @covers SimpleSAML\SessionHandlerPHP::getSessionHandler()
* @covers SimpleSAML\SessionHandler::getSessionHandler()
* @return void
*/
public function testGetSessionHandler()
{
Expand All @@ -46,16 +59,18 @@ public function testGetSessionHandler()
$this->assertInstanceOf('\SimpleSAML\SessionHandlerPHP', $sh);
}


/**
* @covers SimpleSAML\SessionHandlerPHP::setCookie()
* @runInSeparateProcess
* @requires extension xdebug
* @return void
*/
public function testSetCookie()
{
Configuration::loadFromArray($this->sessionConfig, '[ARRAY]', 'simplesaml');
$sh = SessionHandlerPHP::getSessionHandler();
$sh->setCookie('SimpleSAMLSessionID', 1);
$sh->setCookie('SimpleSAMLSessionID', '1');

$headers = xdebug_get_headers();
$this->assertContains('SimpleSAML=1;', $headers[0]);
Expand All @@ -66,14 +81,20 @@ public function testSetCookie()
$this->assertRegExp('/\b[Hh]ttp[Oo]nly(;|$)/', $headers[0]);
}


/**
* @covers SimpleSAML\SessionHandlerPHP::setCookie()
* @runInSeparateProcess
* @requires extension xdebug
* @return void
*/
public function testSetCookieSameSiteNone()
{
Configuration::loadFromArray(array_merge($this->sessionConfig, ['session.cookie.samesite' => 'None']), '[ARRAY]', 'simplesaml');
Configuration::loadFromArray(
array_merge($this->sessionConfig, ['session.cookie.samesite' => 'None']),
'[ARRAY]',
'simplesaml'
);
$sh = SessionHandlerPHP::getSessionHandler();
$sh->setCookie('SimpleSAMLSessionID', 'None');

Expand All @@ -82,14 +103,20 @@ public function testSetCookieSameSiteNone()
$this->assertRegExp('/\b[Ss]ame[Ss]ite=None(;|$)/', $headers[0]);
}


/**
* @covers SimpleSAML\SessionHandlerPHP::setCookie()
* @runInSeparateProcess
* @requires extension xdebug
* @return void
*/
public function testSetCookieSameSiteLax()
{
Configuration::loadFromArray(array_merge($this->sessionConfig, ['session.cookie.samesite' => 'Lax']), '[ARRAY]', 'simplesaml');
Configuration::loadFromArray(
array_merge($this->sessionConfig, ['session.cookie.samesite' => 'Lax']),
'[ARRAY]',
'simplesaml'
);
$sh = SessionHandlerPHP::getSessionHandler();
$sh->setCookie('SimpleSAMLSessionID', 'Lax');

Expand All @@ -98,14 +125,20 @@ public function testSetCookieSameSiteLax()
$this->assertRegExp('/\b[Ss]ame[Ss]ite=Lax(;|$)/', $headers[0]);
}


/**
* @covers SimpleSAML\SessionHandlerPHP::setCookie()
* @runInSeparateProcess
* @requires extension xdebug
* @return void
*/
public function testSetCookieSameSiteStrict()
{
Configuration::loadFromArray(array_merge($this->sessionConfig, ['session.cookie.samesite' => 'Strict']), '[ARRAY]', 'simplesaml');
Configuration::loadFromArray(
array_merge($this->sessionConfig, ['session.cookie.samesite' => 'Strict']),
'[ARRAY]',
'simplesaml'
);
$sh = SessionHandlerPHP::getSessionHandler();
$sh->setCookie('SimpleSAMLSessionID', 'Strict');

Expand All @@ -114,10 +147,12 @@ public function testSetCookieSameSiteStrict()
$this->assertRegExp('/\b[Ss]ame[Ss]ite=Strict(;|$)/', $headers[0]);
}


/**
* @covers SimpleSAML\SessionHandlerPHP::restorePrevious()
* @runInSeparateProcess
* @requires extension xdebug
* @return void
*/
public function testRestorePrevious()
{
Expand All @@ -126,6 +161,7 @@ public function testRestorePrevious()
session_start();

Configuration::loadFromArray($this->sessionConfig, '[ARRAY]', 'simplesaml');
/** @var SessionHandlerPHP $sh */
$sh = SessionHandlerPHP::getSessionHandler();
$sh->setCookie('SimpleSAMLSessionID', 'Restore');
$oldSh = $sh->restorePrevious();
Expand All @@ -137,8 +173,10 @@ public function testRestorePrevious()
$this->assertEquals($headers[0], $headers[2]);
}


/**
* @covers SimpleSAML\SessionHandlerPHP::newSessionId()
* @return void
*/
public function testNewSessionId()
{
Expand Down

0 comments on commit 0fa5cb0

Please sign in to comment.