Fixing setAuthConfig to accept false as param to remove auth config. Tests added.

This commit is contained in:
Juan Basso 2010-12-03 01:30:03 -02:00
parent cd24aca39d
commit 4325e67163
2 changed files with 20 additions and 1 deletions

View file

@ -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;

View file

@ -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.
*