diff --git a/cake/libs/http_socket.php b/cake/libs/http_socket.php index 6686ebbce..5d1198f38 100644 --- a/cake/libs/http_socket.php +++ b/cake/libs/http_socket.php @@ -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']; diff --git a/cake/tests/cases/libs/http_socket.test.php b/cake/tests/cases/libs/http_socket.test.php index d61d654f5..a49222235 100644 --- a/cake/tests/cases/libs/http_socket.test.php +++ b/cake/tests/cases/libs/http_socket.test.php @@ -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 *