diff --git a/cake/libs/http_socket.php b/cake/libs/http_socket.php index 45abaa079..d5ed518ad 100644 --- a/cake/libs/http_socket.php +++ b/cake/libs/http_socket.php @@ -187,7 +187,7 @@ class HttpSocket extends CakeSocket { * @param string $pass Password for authentication * @return void */ - public function setAuthConfig($method, $user, $pass = null) { + public function setAuthConfig($method, $user = null, $pass = null) { if (empty($method)) { $this->_auth = array(); return; diff --git a/cake/tests/cases/libs/http_socket.test.php b/cake/tests/cases/libs/http_socket.test.php index 99f3f0cdb..06b055928 100644 --- a/cake/tests/cases/libs/http_socket.test.php +++ b/cake/tests/cases/libs/http_socket.test.php @@ -755,6 +755,25 @@ class HttpSocketTest extends CakeTestCase { $this->RequestSocket->get('http://www.google.com/', null, array('auth' => array('user' => 'foo', 'pass' => 'bar'))); } +/** + * Test authentication + * + * @return void + */ + public function testAuth() { + $socket = new MockHttpSocket(); + $socket->get('http://mark:secret@example.com/test'); + $this->assertTrue(strpos($socket->request['header'], 'Authorization: Basic bWFyazpzZWNyZXQ=') !== false); + + $socket->setAuthConfig(false); + $socket->get('http://example.com/test'); + $this->assertFalse(strpos($socket->request['header'], 'Authorization:')); + + $socket->setAuthConfig('Test', 'mark', 'passwd'); + $socket->get('http://example.com/test'); + $this->assertTrue(strpos($socket->request['header'], 'Authorization: Test mark.passwd') !== false); + } + /** * test that two consecutive get() calls reset the authentication credentials. *