From 4325e671630a30bb8313d2364c990718a0e2ffcc Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Fri, 3 Dec 2010 01:30:03 -0200 Subject: [PATCH] Fixing setAuthConfig to accept false as param to remove auth config. Tests added. --- cake/libs/http_socket.php | 2 +- cake/tests/cases/libs/http_socket.test.php | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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. *