Skip to content
Snippets Groups Projects
Unverified Commit bc3fd348 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst Committed by GitHub
Browse files

Merge pull request #768 from tvdijen/fix-serverPort

rewrite getServerPort
parents 31502597 effecdc6
No related branches found
No related tags found
No related merge requests found
...@@ -108,15 +108,11 @@ class HTTP ...@@ -108,15 +108,11 @@ class HTTP
*/ */
public static function getServerPort() public static function getServerPort()
{ {
$port = (isset($_SERVER['SERVER_PORT'])) ? $_SERVER['SERVER_PORT'] : '80'; $default_port = self::getServerHTTPS() ? '443' : '80';
if (self::getServerHTTPS()) { $port = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : $default_port;
if ($port !== '443') {
return ':'.$port; if ($port !== $default_port) {
} return ':'.$port;
} else {
if ($port !== '80') {
return ':'.$port;
}
} }
return ''; return '';
} }
......
...@@ -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