Permalink
Browse files

Merge branch '2.2' into 2.3 (closes #8955)

* 2.2:
  [HttpFoundation] removed extra parenthesis
  [Process][2.2] Fix Process component on windows
  [HttpFoundation] improve perf of previous merge (refs #8882)
  Request->getPort() should prefer HTTP_HOST over SERVER_PORT
  Fixing broken http auth digest in some circumstances (php-fpm + apache).
  fixed typo

Conflicts:
	src/Symfony/Component/Process/Process.php
  • Loading branch information...
2 parents 702e652 + d05ab6b commit 3689849e8b6f80283e6614ae1524cef160c93d33 @fabpot fabpot committed Sep 7, 2013
@@ -295,7 +295,7 @@ public function provideDateFormats()
}
/**
- * This test is to check that the strings '0', '1', '2', '3' are no accepted
+ * This test is to check that the strings '0', '1', '2', '3' are not accepted
* as valid IntlDateFormatter constants for FULL, LONG, MEDIUM or SHORT respectively.
*
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
@@ -905,6 +905,14 @@ public function getPort()
}
}
+ if ($host = $this->headers->get('HOST')) {
+ if (false !== $pos = strrpos($host, ':')) {
+ return intval(substr($host, $pos + 1));
+ }
+
+ return 'https' === $this->getScheme() ? 443 : 80;
+ }
+
return $this->server->get('SERVER_PORT');
}
@@ -1613,7 +1621,7 @@ protected function prepareBaseUrl()
$seg = $segs[$index];
$baseUrl = '/'.$seg.$baseUrl;
++$index;
- } while (($last > $index) && (false !== ($pos = strpos($path, $baseUrl))) && (0 != $pos));
+ } while ($last > $index && (false !== $pos = strpos($path, $baseUrl)) && 0 != $pos);
}
// Does the baseUrl have anything in common with the request_uri?
@@ -1630,7 +1638,7 @@ protected function prepareBaseUrl()
}
$truncatedRequestUri = $requestUri;
- if (($pos = strpos($requestUri, '?')) !== false) {
+ if (false !== $pos = strpos($requestUri, '?')) {
$truncatedRequestUri = substr($requestUri, 0, $pos);
}
@@ -1643,7 +1651,7 @@ protected function prepareBaseUrl()
// If using mod_rewrite or ISAPI_Rewrite strip the script filename
// out of baseUrl. $pos !== 0 makes sure it is not matching a value
// from PATH_INFO or QUERY_STRING
- if ((strlen($requestUri) >= strlen($baseUrl)) && ((false !== ($pos = strpos($requestUri, $baseUrl))) && ($pos !== 0))) {
+ if (strlen($requestUri) >= strlen($baseUrl) && (false !== $pos = strpos($requestUri, $baseUrl)) && $pos !== 0) {
$baseUrl = substr($requestUri, 0, $pos + strlen($baseUrl));
}
@@ -1696,7 +1704,7 @@ protected function preparePathInfo()
$requestUri = substr($requestUri, 0, $pos);
}
- if ((null !== $baseUrl) && (false === ($pathInfo = substr($requestUri, strlen($baseUrl))))) {
+ if (null !== $baseUrl && false === $pathInfo = substr($requestUri, strlen($baseUrl))) {
// If substr() returns false then PATH_INFO is set to an empty string
return '/';
} elseif (null === $baseUrl) {
@@ -64,18 +64,26 @@ public function getHeaders()
$authorizationHeader = $this->parameters['REDIRECT_HTTP_AUTHORIZATION'];
}
- // Decode AUTHORIZATION header into PHP_AUTH_USER and PHP_AUTH_PW when authorization header is basic
- if ((null !== $authorizationHeader) && (0 === stripos($authorizationHeader, 'basic'))) {
- $exploded = explode(':', base64_decode(substr($authorizationHeader, 6)));
- if (count($exploded) == 2) {
- list($headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']) = $exploded;
+ if (null !== $authorizationHeader) {
+ if (0 === stripos($authorizationHeader, 'basic')) {
+ // Decode AUTHORIZATION header into PHP_AUTH_USER and PHP_AUTH_PW when authorization header is basic
+ $exploded = explode(':', base64_decode(substr($authorizationHeader, 6)));
+ if (count($exploded) == 2) {
+ list($headers['PHP_AUTH_USER'], $headers['PHP_AUTH_PW']) = $exploded;
+ }
+ } elseif (empty($this->parameters['PHP_AUTH_DIGEST']) && (0 === stripos($authorizationHeader, 'digest'))) {
+ // In some circumstances PHP_AUTH_DIGEST needs to be set
+ $headers['PHP_AUTH_DIGEST'] = $authorizationHeader;
+ $this->parameters['PHP_AUTH_DIGEST'] = $authorizationHeader;
}
}
}
// PHP_AUTH_USER/PHP_AUTH_PW
if (isset($headers['PHP_AUTH_USER'])) {
$headers['AUTHORIZATION'] = 'Basic '.base64_encode($headers['PHP_AUTH_USER'].':'.$headers['PHP_AUTH_PW']);
+ } elseif (isset($headers['PHP_AUTH_DIGEST'])) {
+ $headers['AUTHORIZATION'] = $headers['PHP_AUTH_DIGEST'];
}
return $headers;
@@ -1526,6 +1526,18 @@ public function testTrustedHosts()
// trusted hosts
$request->headers->set('host', 'trusted.com');
$this->assertEquals('trusted.com', $request->getHost());
+ $this->assertEquals(80, $request->getPort());
+
+ $request->server->set('HTTPS', true);
+ $request->headers->set('host', 'trusted.com');
+ $this->assertEquals('trusted.com', $request->getHost());
+ $this->assertEquals(443, $request->getPort());
+ $request->server->set('HTTPS', false);
+
+ $request->headers->set('host', 'trusted.com:8000');
+ $this->assertEquals('trusted.com', $request->getHost());
+ $this->assertEquals(8000, $request->getPort());
+
$request->headers->set('host', 'subdomain.trusted.com');
$this->assertEquals('subdomain.trusted.com', $request->getHost());
@@ -89,6 +89,28 @@ public function testHttpBasicAuthWithPhpCgiEmptyPassword()
), $bag->getHeaders());
}
+ public function testHttpDigestAuthWithPhpCgi()
+ {
+ $digest = 'Digest username="foo", realm="acme", nonce="'.md5('secret').'", uri="/protected, qop="auth"';
+ $bag = new ServerBag(array('HTTP_AUTHORIZATION' => $digest));
+
+ $this->assertEquals(array(
+ 'AUTHORIZATION' => $digest,
+ 'PHP_AUTH_DIGEST' => $digest,
+ ), $bag->getHeaders());
+ }
+
+ public function testHttpDigestAuthWithPhpCgiRedirect()
+ {
+ $digest = 'Digest username="foo", realm="acme", nonce="'.md5('secret').'", uri="/protected, qop="auth"';
+ $bag = new ServerBag(array('REDIRECT_HTTP_AUTHORIZATION' => $digest));
+
+ $this->assertEquals(array(
+ 'AUTHORIZATION' => $digest,
+ 'PHP_AUTH_DIGEST' => $digest,
+ ), $bag->getHeaders());
+ }
+
public function testOAuthBearerAuth()
{
$headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';
Oops, something went wrong.

0 comments on commit 3689849

Please sign in to comment.