Fixing HttpSocket losing auth credentials when multiple requests are made with the same object. Fixes #893

This commit is contained in:
mark_story 2010-07-06 22:30:48 -04:00
parent 60ab9800e2
commit 103346155f
2 changed files with 33 additions and 4 deletions

View file

@ -196,7 +196,10 @@ class HttpSocket extends CakeSocket {
$request['uri'] = null;
}
$uri = $this->_parseUri($request['uri']);
$hadAuth = false;
if (is_array($uri) && array_key_exists('user', $uri)) {
$hadAuth = true;
}
if (!isset($uri['host'])) {
$host = $this->config['host'];
}
@ -204,11 +207,14 @@ class HttpSocket extends CakeSocket {
$host = $request['host'];
unset($request['host']);
}
$request['uri'] = $this->url($request['uri']);
$request['uri'] = $this->_parseUri($request['uri'], true);
$this->request = Set::merge($this->request, $this->config['request'], $request);
if (!$hadAuth && !empty($this->config['request']['auth']['user'])) {
$this->request['uri']['user'] = $this->config['request']['auth']['user'];
$this->request['uri']['pass'] = $this->config['request']['auth']['pass'];
}
$this->_configUri($this->request['uri']);
if (isset($host)) {
@ -605,7 +611,6 @@ class HttpSocket extends CakeSocket {
if (!isset($uri['host'])) {
return false;
}
$config = array(
'request' => array(
'uri' => array_intersect_key($uri, $this->config['request']['uri']),
@ -1049,7 +1054,6 @@ class HttpSocket extends CakeSocket {
if (empty($initalState)) {
$initalState = get_class_vars(__CLASS__);
}
if ($full == false) {
$this->request = $initalState['request'];
$this->response = $initalState['response'];

View file

@ -638,6 +638,31 @@ class HttpSocketTest extends CakeTestCase {
$this->RequestSocket->get('http://www.google.com/', null, array('auth' => array('user' => 'foo', 'pass' => 'bar')));
}
/**
* test that two consecutive get() calls reset the authentication credentials.
*
* @return void
*/
function testConsecutiveGetResetsAuthCredentials() {
$socket = new MockHttpSocket();
$socket->config['request']['auth'] = array(
'method' => 'Basic',
'user' => 'mark',
'pass' => 'secret'
);
$socket->get('http://mark:secret@example.com/test');
$this->assertEqual($socket->request['uri']['user'], 'mark');
$this->assertEqual($socket->request['uri']['pass'], 'secret');
$socket->get('/test2');
$this->assertEqual($socket->request['auth']['user'], 'mark');
$this->assertEqual($socket->request['auth']['pass'], 'secret');
$socket->get('/test3');
$this->assertEqual($socket->request['auth']['user'], 'mark');
$this->assertEqual($socket->request['auth']['pass'], 'secret');
}
/**
* testPostPutDelete method
*