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 8edf207 commit 7d7bc52c8902ddf8904830582ef615309f243156
Showing with 36 additions and 5 deletions.
  1. +10 −4 cake/libs/http_socket.php
  2. +26 −1 cake/tests/cases/libs/http_socket.test.php
@@ -171,7 +171,12 @@ function request($request = array()) {
if (!isset($request['uri'])) {
$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'];
@@ -180,11 +185,14 @@ function request($request = array()) {
$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)) {
@@ -529,7 +537,6 @@ function configUri($uri = null) {
if (!isset($uri['host'])) {
return false;
}
$config = array(
'request' => array(
'uri' => array_intersect_key($uri, $this->config['request']['uri']),
@@ -978,7 +985,6 @@ function reset($full = true) {
if (empty($initalState)) {
$initalState = get_class_vars(__CLASS__);
}
if ($full == false) {
$this->request = $initalState['request'];
$this->response = $initalState['response'];
@@ -988,4 +994,4 @@ function reset($full = true) {
return true;
}
}
?>
?>
@@ -502,6 +502,31 @@ function testGet() {
$this->RequestSocket->expect('request', a(array('method' => 'GET', 'uri' => 'http://www.google.com/', 'auth' => array('user' => 'foo', 'pass' => 'bar'))));
$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 TestHttpSocket();
$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
*
@@ -1359,4 +1384,4 @@ function testPartialReset() {
$this->assertIdentical($return, true);
}
}
?>
?>

0 comments on commit 7d7bc52

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