mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Fixing setAuthConfig to accept false as param to remove auth config. Tests added.
This commit is contained in:
parent
cd24aca39d
commit
4325e67163
2 changed files with 20 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue