Skip to content

Commit

Permalink
[HttpFoundation] Do not overwrite the Authorization header if it is a…
Browse files Browse the repository at this point in the history
…lready set
  • Loading branch information
jakzal authored and fabpot committed Jan 22, 2016
1 parent 385f23e commit 53ebfda
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpFoundation/ServerBag.php
Expand Up @@ -86,6 +86,10 @@ public function getHeaders()
}
}

if (isset($headers['AUTHORIZATION'])) {
return $headers;
}

// 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']);
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/ServerBagTest.php
Expand Up @@ -151,4 +151,19 @@ public function testOAuthBearerAuthWithRedirect()
'AUTHORIZATION' => $headerContent,
), $bag->getHeaders());
}

/**
* @see https://github.com/symfony/symfony/issues/17345
*/
public function testItDoesNotOverwriteTheAuthorizationHeaderIfItIsAlreadySet()
{
$headerContent = 'Bearer L-yLEOr9zhmUYRkzN1jwwxwQ-PBNiKDc8dgfB4hTfvo';
$bag = new ServerBag(array('PHP_AUTH_USER' => 'foo', 'HTTP_AUTHORIZATION' => $headerContent));

$this->assertEquals(array(
'AUTHORIZATION' => $headerContent,
'PHP_AUTH_USER' => 'foo',
'PHP_AUTH_PW' => '',
), $bag->getHeaders());
}
}

0 comments on commit 53ebfda

Please sign in to comment.