Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T16668 request basicauth #16717

Merged
merged 14 commits into from
Mar 8, 2025
1 change: 1 addition & 0 deletions CHANGELOG-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Fixed `Phalcon\Filter\Filter` to have the correct docblock for IDE completion
- Fixed `Phalcon\Mvc\Model\Query` to use the lifetime in the "cache" service if none has been supplied by the options [#16696](https://github.com/phalcon/cphalcon/issues/16696)
- Fixed `Phalcon\Session\Adapter\Stream::gc()` to throw an exception if something is wrong with `glob()` [#16713](https://github.com/phalcon/cphalcon/issues/16713)
- Fixed `Phalcon\Http\Request::getBasicAuth()` to return a `null` password if not defined on the server [#16668](https://github.com/phalcon/cphalcon/issues/16668)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion phalcon/Http/Request.zep
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Request extends AbstractInjectionAware implements RequestInterface, Reques
*/
public function getBasicAuth() -> array | null
{
if !this->hasServer("PHP_AUTH_USER") || !this->hasServer("PHP_AUTH_PW") {
if !this->hasServer("PHP_AUTH_USER") {
return null;
}

Expand Down
31 changes: 20 additions & 11 deletions tests/unit/Http/Request/GetBasicAuthCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class GetBasicAuthCest
*/
public function httpRequestGetBasicAuthEmpty(UnitTester $I)
{
$I->wantToTest('Http\Request - getBasicAuth() - empty');

$request = new Request();

$I->assertNull($request->getBasicAuth());
Expand All @@ -41,25 +39,36 @@ public function httpRequestGetBasicAuthEmpty(UnitTester $I)
*/
public function httpRequestGetBasicAuth(UnitTester $I)
{
$I->wantToTest('Http\Request - getBasicAuth()');
$_SERVER['PHP_AUTH_USER'] = 'darth';
$_SERVER['PHP_AUTH_PW'] = 'vader';

$request = new Request();

$store = $_SERVER ?? [];
$time = $_SERVER['REQUEST_TIME_FLOAT'];
$_SERVER = [
'REQUEST_TIME_FLOAT' => $time,
'PHP_AUTH_USER' => 'darth',
'PHP_AUTH_PW' => 'vader',
$expected = [
'username' => 'darth',
'password' => 'vader',
];
$actual = $request->getBasicAuth();
$I->assertSame($expected, $actual);

/**
* @issue 16668
*/
unset($_SERVER['PHP_AUTH_USER']);
unset($_SERVER['PHP_AUTH_PW']);

$_SERVER['PHP_AUTH_USER'] = 'darth';

$request = new Request();

$expected = [
'username' => 'darth',
'password' => 'vader',
'password' => null,
];
$actual = $request->getBasicAuth();
$I->assertSame($expected, $actual);

$_SERVER = $store;
unset($_SERVER['PHP_AUTH_USER']);
unset($_SERVER['PHP_AUTH_PW']);
}
}
Loading