Skip to content

Commit 5a98db1

Browse files
authored
Merge pull request #16717 from niden-code/T16668-request-basicauth
T16668 request basicauth
2 parents b1d6923 + 7a03d7f commit 5a98db1

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

CHANGELOG-5.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- Fixed `Phalcon\Filter\Filter` to have the correct docblock for IDE completion
2626
- 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)
2727
- Fixed `Phalcon\Session\Adapter\Stream::gc()` to throw an exception if something is wrong with `glob()` [#16713](https://github.com/phalcon/cphalcon/issues/16713)
28+
- Fixed `Phalcon\Http\Request::getBasicAuth()` to return a `null` password if not defined on the server [#16668](https://github.com/phalcon/cphalcon/issues/16668)
2829

2930
### Removed
3031

phalcon/Http/Request.zep

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class Request extends AbstractInjectionAware implements RequestInterface, Reques
129129
*/
130130
public function getBasicAuth() -> array | null
131131
{
132-
if !this->hasServer("PHP_AUTH_USER") || !this->hasServer("PHP_AUTH_PW") {
132+
if !this->hasServer("PHP_AUTH_USER") {
133133
return null;
134134
}
135135

tests/unit/Http/Request/GetBasicAuthCest.php

+20-11
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class GetBasicAuthCest
2626
*/
2727
public function httpRequestGetBasicAuthEmpty(UnitTester $I)
2828
{
29-
$I->wantToTest('Http\Request - getBasicAuth() - empty');
30-
3129
$request = new Request();
3230

3331
$I->assertNull($request->getBasicAuth());
@@ -41,25 +39,36 @@ public function httpRequestGetBasicAuthEmpty(UnitTester $I)
4139
*/
4240
public function httpRequestGetBasicAuth(UnitTester $I)
4341
{
44-
$I->wantToTest('Http\Request - getBasicAuth()');
42+
$_SERVER['PHP_AUTH_USER'] = 'darth';
43+
$_SERVER['PHP_AUTH_PW'] = 'vader';
44+
45+
$request = new Request();
4546

46-
$store = $_SERVER ?? [];
47-
$time = $_SERVER['REQUEST_TIME_FLOAT'];
48-
$_SERVER = [
49-
'REQUEST_TIME_FLOAT' => $time,
50-
'PHP_AUTH_USER' => 'darth',
51-
'PHP_AUTH_PW' => 'vader',
47+
$expected = [
48+
'username' => 'darth',
49+
'password' => 'vader',
5250
];
51+
$actual = $request->getBasicAuth();
52+
$I->assertSame($expected, $actual);
53+
54+
/**
55+
* @issue 16668
56+
*/
57+
unset($_SERVER['PHP_AUTH_USER']);
58+
unset($_SERVER['PHP_AUTH_PW']);
59+
60+
$_SERVER['PHP_AUTH_USER'] = 'darth';
5361

5462
$request = new Request();
5563

5664
$expected = [
5765
'username' => 'darth',
58-
'password' => 'vader',
66+
'password' => null,
5967
];
6068
$actual = $request->getBasicAuth();
6169
$I->assertSame($expected, $actual);
6270

63-
$_SERVER = $store;
71+
unset($_SERVER['PHP_AUTH_USER']);
72+
unset($_SERVER['PHP_AUTH_PW']);
6473
}
6574
}

0 commit comments

Comments
 (0)