Skip to content
Snippets Groups Projects
Unverified Commit effecdc6 authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Add test for getServerPort()

parent a1bf3411
No related branches found
No related tags found
No related merge requests found
...@@ -6,8 +6,6 @@ use SimpleSAML\Utils\HTTP; ...@@ -6,8 +6,6 @@ use SimpleSAML\Utils\HTTP;
class HTTPTest extends TestCase class HTTPTest extends TestCase
{ {
/** /**
* Set up the environment ($_SERVER) populating the typical variables from a given URL. * Set up the environment ($_SERVER) populating the typical variables from a given URL.
* *
...@@ -120,7 +118,6 @@ class HTTPTest extends TestCase ...@@ -120,7 +118,6 @@ class HTTPTest extends TestCase
$_SERVER = $original; $_SERVER = $original;
} }
/** /**
* Test SimpleSAML\Utils\HTTP::getSelfHost() with and without custom port. * Test SimpleSAML\Utils\HTTP::getSelfHost() with and without custom port.
*/ */
...@@ -166,7 +163,6 @@ class HTTPTest extends TestCase ...@@ -166,7 +163,6 @@ class HTTPTest extends TestCase
$_SERVER = $original; $_SERVER = $original;
} }
/** /**
* Test SimpleSAML\Utils\HTTP::getSelfURL(). * Test SimpleSAML\Utils\HTTP::getSelfURL().
*/ */
...@@ -292,7 +288,6 @@ class HTTPTest extends TestCase ...@@ -292,7 +288,6 @@ class HTTPTest extends TestCase
$_SERVER = $original; $_SERVER = $original;
} }
/** /**
* Test SimpleSAML\Utils\HTTP::checkURLAllowed(), without regex. * Test SimpleSAML\Utils\HTTP::checkURLAllowed(), without regex.
*/ */
...@@ -355,6 +350,42 @@ class HTTPTest extends TestCase ...@@ -355,6 +350,42 @@ class HTTPTest extends TestCase
$_SERVER = $original; $_SERVER = $original;
} }
/**
* Test SimpleSAML\Utils\HTTP::getServerPort().
*/
public function testGetServerPort()
{
$original = $_SERVER;
// Test HTTP + non-standard port
$_SERVER['HTTPS'] = 'off';
$_SERVER['SERVER_PORT'] = '3030';
$this->assertEquals(HTTP::getServerPort(), ':3030');
// Test HTTP + standard port
$_SERVER['SERVER_PORT'] = '80';
$this->assertEquals(HTTP::getServerPort(), '');
// Test HTTP + without port
unset($_SERVER['SERVER_PORT']);
$this->assertEquals(HTTP::getServerPort(), '');
// Test HTTPS + non-standard port
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = '3030';
$this->assertEquals(HTTP::getServerPort(), ':3030');
// Test HTTPS + standard port
$_SERVER['SERVER_PORT'] = '443';
$this->assertEquals(HTTP::getServerPort(), '');
// Test HTTPS + without port
unset($_SERVER['SERVER_PORT']);
$this->assertEquals(HTTP::getServerPort(), '');
$_SERVER = $original;
}
/** /**
* Test SimpleSAML\Utils\HTTP::checkURLAllowed(), with the regex as a * Test SimpleSAML\Utils\HTTP::checkURLAllowed(), with the regex as a
* subdomain of an evil domain. * subdomain of an evil domain.
......
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