Skip to content
Snippets Groups Projects
Commit 07840369 authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Make sure the modifications to $_SERVER in the tests do not go beyond each test.

parent 4aef583b
No related branches found
No related tags found
No related merge requests found
...@@ -100,6 +100,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase ...@@ -100,6 +100,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase
*/ */
public function testGetSelfHost() public function testGetSelfHost()
{ {
$original = $_SERVER;
\SimpleSAML_Configuration::loadFromArray(array( \SimpleSAML_Configuration::loadFromArray(array(
'baseurlpath' => '', 'baseurlpath' => '',
), '[ARRAY]', 'simplesaml'); ), '[ARRAY]', 'simplesaml');
...@@ -107,6 +109,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase ...@@ -107,6 +109,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('localhost', HTTP::getSelfHost()); $this->assertEquals('localhost', HTTP::getSelfHost());
$_SERVER['SERVER_PORT'] = '3030'; $_SERVER['SERVER_PORT'] = '3030';
$this->assertEquals('localhost', HTTP::getSelfHost()); $this->assertEquals('localhost', HTTP::getSelfHost());
$_SERVER = $original;
} }
/** /**
...@@ -114,6 +118,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase ...@@ -114,6 +118,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase
*/ */
public function testGetSelfHostWithPort() public function testGetSelfHostWithPort()
{ {
$original = $_SERVER;
\SimpleSAML_Configuration::loadFromArray(array( \SimpleSAML_Configuration::loadFromArray(array(
'baseurlpath' => '', 'baseurlpath' => '',
), '[ARRAY]', 'simplesaml'); ), '[ARRAY]', 'simplesaml');
...@@ -130,6 +136,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase ...@@ -130,6 +136,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase
$_SERVER['HTTPS'] = 'on'; $_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = '443'; $_SERVER['SERVER_PORT'] = '443';
$this->assertEquals('localhost', HTTP::getSelfHostWithNonStandardPort()); $this->assertEquals('localhost', HTTP::getSelfHostWithNonStandardPort());
$_SERVER = $original;
} }
/** /**
...@@ -137,6 +145,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase ...@@ -137,6 +145,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase
*/ */
public function testCheckURLAllowedWithoutRegex() public function testCheckURLAllowedWithoutRegex()
{ {
$original = $_SERVER;
\SimpleSAML_Configuration::loadFromArray(array( \SimpleSAML_Configuration::loadFromArray(array(
'trusted.url.domains' => array('sp.example.com', 'app.example.com'), 'trusted.url.domains' => array('sp.example.com', 'app.example.com'),
'trusted.url.regex' => false, 'trusted.url.regex' => false,
...@@ -157,6 +167,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase ...@@ -157,6 +167,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase
$this->setExpectedException('SimpleSAML_Error_Exception'); $this->setExpectedException('SimpleSAML_Error_Exception');
HTTP::checkURLAllowed('https://evil.com'); HTTP::checkURLAllowed('https://evil.com');
$_SERVER = $original;
} }
/** /**
...@@ -164,6 +176,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase ...@@ -164,6 +176,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase
*/ */
public function testCheckURLAllowedWithRegex() public function testCheckURLAllowedWithRegex()
{ {
$original = $_SERVER;
\SimpleSAML_Configuration::loadFromArray(array( \SimpleSAML_Configuration::loadFromArray(array(
'trusted.url.domains' => array('.*\.example\.com'), 'trusted.url.domains' => array('.*\.example\.com'),
'trusted.url.regex' => true, 'trusted.url.regex' => true,
...@@ -186,6 +200,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase ...@@ -186,6 +200,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase
$this->setExpectedException('SimpleSAML_Error_Exception'); $this->setExpectedException('SimpleSAML_Error_Exception');
HTTP::checkURLAllowed('https://evil.com'); HTTP::checkURLAllowed('https://evil.com');
$_SERVER = $original;
} }
/** /**
...@@ -194,6 +210,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase ...@@ -194,6 +210,8 @@ class HTTPTest extends \PHPUnit_Framework_TestCase
*/ */
public function testCheckURLAllowedWithRegexWithoutDelimiters() public function testCheckURLAllowedWithRegexWithoutDelimiters()
{ {
$original = $_SERVER;
\SimpleSAML_Configuration::loadFromArray(array( \SimpleSAML_Configuration::loadFromArray(array(
'trusted.url.domains' => array('app\.example\.com'), 'trusted.url.domains' => array('app\.example\.com'),
'trusted.url.regex' => true, 'trusted.url.regex' => true,
...@@ -203,5 +221,7 @@ class HTTPTest extends \PHPUnit_Framework_TestCase ...@@ -203,5 +221,7 @@ class HTTPTest extends \PHPUnit_Framework_TestCase
$this->setExpectedException('SimpleSAML_Error_Exception'); $this->setExpectedException('SimpleSAML_Error_Exception');
HTTP::checkURLAllowed('https://app.example.com.evil.com'); HTTP::checkURLAllowed('https://app.example.com.evil.com');
$_SERVER = $original;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment