Skip to content

Commit

Permalink
Backwards compat for auth in the config array of HttpSocket::request()
Browse files Browse the repository at this point in the history
Brings functionality back in line with docs as well
  • Loading branch information
cincodenada committed Mar 29, 2013
1 parent 5695d0e commit ece6ac3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Cake/Network/Http/HttpSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ public function request($request = array()) {

if (isset($this->request['uri']['user'], $this->request['uri']['pass'])) {
$this->configAuth('Basic', $this->request['uri']['user'], $this->request['uri']['pass']);
} elseif (isset($this->request['auth'], $this->request['auth']['method'], $this->request['auth']['user'], $this->request['auth']['pass'])) {
$this->configAuth($this->request['auth']['method'], $this->request['auth']['user'], $this->request['auth']['pass']);
}
$this->_setAuth();
$this->request['auth'] = $this->_auth;
Expand Down
13 changes: 13 additions & 0 deletions lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,19 @@ public function testAuth() {
$socket->configAuth('Test', 'mark', 'passwd');
$socket->get('http://example.com/test');
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Test mark.passwd') !== false);

$socket->configAuth(false);
$socket->request(array(
'method' => 'GET',
'uri' => 'http://example.com/test',
'auth' => array(
'method'=>'Basic',
'user' => 'joel',
'pass' => 'hunter2'
)
));
$this->assertEquals($socket->request['auth'],array('Basic' => array('user' => 'joel', 'pass' => 'hunter2')));
$this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic am9lbDpodW50ZXIy') !== false);
}

/**
Expand Down

0 comments on commit ece6ac3

Please sign in to comment.