Skip to content
Permalink
Browse files

Fixing HttpSocket losing auth credentials when multiple requests are …

…made with the same object. Fixes #893
  • Loading branch information...
markstory committed Jul 7, 2010
1 parent 60ab980 commit 103346155fe2730f52171f96fd9bf778c205f803
Showing with 33 additions and 4 deletions.
  1. +8 −4 cake/libs/http_socket.php
  2. +25 −0 cake/tests/cases/libs/http_socket.test.php
@@ -196,19 +196,25 @@ function request($request = array()) {
$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'];
}
if (isset($request['host'])) {
$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 @@ function _configUri($uri = null) {
if (!isset($uri['host'])) {
return false;
}
$config = array(
'request' => array(
'uri' => array_intersect_key($uri, $this->config['request']['uri']),
@@ -1049,7 +1054,6 @@ function reset($full = true) {
if (empty($initalState)) {
$initalState = get_class_vars(__CLASS__);
}
if ($full == false) {
$this->request = $initalState['request'];
$this->response = $initalState['response'];
@@ -638,6 +638,31 @@ function testGet() {
$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
*

0 comments on commit 1033461

Please sign in to comment.
You can’t perform that action at this time.