Skip to content

Commit ece6ac3

Browse files
committed
Backwards compat for auth in the config array of HttpSocket::request()
Brings functionality back in line with docs as well
1 parent 5695d0e commit ece6ac3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/Cake/Network/Http/HttpSocket.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ public function request($request = array()) {
323323

324324
if (isset($this->request['uri']['user'], $this->request['uri']['pass'])) {
325325
$this->configAuth('Basic', $this->request['uri']['user'], $this->request['uri']['pass']);
326+
} elseif (isset($this->request['auth'], $this->request['auth']['method'], $this->request['auth']['user'], $this->request['auth']['pass'])) {
327+
$this->configAuth($this->request['auth']['method'], $this->request['auth']['user'], $this->request['auth']['pass']);
326328
}
327329
$this->_setAuth();
328330
$this->request['auth'] = $this->_auth;

lib/Cake/Test/Case/Network/Http/HttpSocketTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,19 @@ public function testAuth() {
10651065
$socket->configAuth('Test', 'mark', 'passwd');
10661066
$socket->get('http://example.com/test');
10671067
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Test mark.passwd') !== false);
1068+
1069+
$socket->configAuth(false);
1070+
$socket->request(array(
1071+
'method' => 'GET',
1072+
'uri' => 'http://example.com/test',
1073+
'auth' => array(
1074+
'method'=>'Basic',
1075+
'user' => 'joel',
1076+
'pass' => 'hunter2'
1077+
)
1078+
));
1079+
$this->assertEquals($socket->request['auth'],array('Basic' => array('user' => 'joel', 'pass' => 'hunter2')));
1080+
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic am9lbDpodW50ZXIy') !== false);
10681081
}
10691082

10701083
/**

0 commit comments

Comments
 (0)