Skip to content

Commit

Permalink
Merge branch '2.6' into 3.0
Browse files Browse the repository at this point in the history
Conflicts:
	app/Config/Schema/db_acl.sql
	lib/Cake/Console/Command/Task/ProjectTask.php
	lib/Cake/Console/Templates/skel/Config/Schema/db_acl.sql
	lib/Cake/Controller/Component/AuthComponent.php
	lib/Cake/Model/Model.php
	lib/Cake/Network/Http/HttpSocket.php
	lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php
	lib/Cake/Test/Case/Network/Http/HttpSocketTest.php
	src/Network/Email/Email.php
	src/Network/Email/SmtpTransport.php
	src/Network/Request.php
	src/Network/Socket.php
	tests/TestCase/Network/Email/SmtpTransportTest.php
  • Loading branch information
ADmad committed Jul 27, 2014
2 parents dc7fcb9 + 9e21d04 commit f14bf3c
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,6 +10,7 @@

# IDE and editor specific files #
#################################
/nbproject
.idea

# OS generated files #
Expand Down
11 changes: 11 additions & 0 deletions src/Console/ConsoleOptionParser.php
Expand Up @@ -412,6 +412,17 @@ public function addSubcommand($name, $options = []) {
return $this;
}

/**
* Remove a subcommand from the option parser.
*
* @param string $name The subcommand name to remove.
* @return $this
*/
public function removeSubcommand($name) {
unset($this->_subcommands[$name]);
return $this;
}

/**
* Add multiple subcommands at once.
*
Expand Down
23 changes: 13 additions & 10 deletions src/Network/Email/SmtpTransport.php
Expand Up @@ -241,20 +241,23 @@ protected function _connect() {
* @throws \Cake\Network\Error\SocketException
*/
protected function _auth() {
$config = $this->_config;
if (isset($config['username']) && isset($config['password'])) {
$authRequired = $this->_smtpSend('AUTH LOGIN', '334|503');
if ($authRequired == '334') {
if (!$this->_smtpSend(base64_encode($config['username']), '334')) {
if (isset($this->_config['username']) && isset($this->_config['password'])) {
$replyCode = $this->_smtpSend('AUTH LOGIN', '334|500|502|504');
if ($replyCode == '334') {
try {
$this->_smtpSend(base64_encode($this->_config['username']), '334');
} catch (Error\SocketException $e) {
throw new Error\SocketException('SMTP server did not accept the username.');
}
if (!$this->_smtpSend(base64_encode($config['password']), '235')) {
try {
$this->_smtpSend(base64_encode($this->_config['password']), '235');
} catch (Error\SocketException $e) {
throw new Error\SocketException('SMTP server did not accept the password.');
}
} elseif ($authRequired == '504') {
throw new Error\SocketException('SMTP authentication method not allowed, check if SMTP server requires TLS');
} elseif ($authRequired != '503') {
throw new Error\SocketException('SMTP does not require authentication.');
} elseif ($replyCode == '504') {
throw new Error\SocketException('SMTP authentication method not allowed, check if SMTP server requires TLS.');
} else {
throw new Error\SocketException('AUTH command not recognized or not implemented, SMTP server may not require authentication.');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Network/Request.php
Expand Up @@ -275,7 +275,7 @@ protected function _processPost($data) {
* @return void
*/
protected function _processGet($query) {
$unsetUrl = '/' . str_replace('.', '_', urldecode($this->url));
$unsetUrl = '/' . str_replace(array('.', ' '), '_', urldecode($this->url));
unset($query[$unsetUrl]);
unset($query[$this->base . $unsetUrl]);
if (strpos($this->url, '?') !== false) {
Expand Down
9 changes: 3 additions & 6 deletions src/Network/Socket.php
Expand Up @@ -109,10 +109,6 @@ class Socket {
*/
public function __construct(array $config = array()) {
$this->config($config);

if (!is_numeric($this->_config['protocol'])) {
$this->_config['protocol'] = getprotobyname($this->_config['protocol']);
}
}

/**
Expand All @@ -127,8 +123,8 @@ public function connect() {
}

$scheme = null;
if (isset($this->_config['request']['uri']) && $this->_config['request']['uri']['scheme'] === 'https') {
$scheme = 'ssl://';
if (!empty($this->_config['protocol']) && strpos($this->_config['host'], '://') === false) {
$scheme = $this->_config['protocol'] . '://';
}

if (!empty($this->_config['context'])) {
Expand Down Expand Up @@ -381,3 +377,4 @@ public function enableCrypto($type, $clientOrServer = 'client', $enable = true)
}

}

15 changes: 15 additions & 0 deletions tests/TestCase/Console/ConsoleOptionParserTest.php
Expand Up @@ -491,6 +491,21 @@ public function testAddSubcommandObject() {
$this->assertEquals('test', $result['test']->name());
}

/**
* test removeSubcommand with an object.
*
* @return void
*/
public function testRemoveSubcommand() {
$parser = new ConsoleOptionParser('test', false);
$parser->addSubcommand(new ConsoleInputSubcommand('test'));
$result = $parser->subcommands();
$this->assertEquals(1, count($result));
$parser->removeSubcommand('test');
$result = $parser->subcommands();
$this->assertEquals(0, count($result), 'Remove a subcommand does not work');
}

/**
* test adding multiple subcommands
*
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Network/Email/EmailTest.php
Expand Up @@ -198,15 +198,15 @@ public function testTo() {
$list = array(
'root@localhost' => 'root',
'bjørn@hammeröath.com' => 'Bjorn',
'cake@cakephp.org' => 'Cake PHP',
'cake.php@cakephp.org' => 'Cake PHP',
'cake-php@googlegroups.com' => 'Cake Groups',
'root@cakephp.org'
);
$this->CakeEmail->to($list);
$expected = array(
'root@localhost' => 'root',
'bjørn@hammeröath.com' => 'Bjorn',
'cake@cakephp.org' => 'Cake PHP',
'cake.php@cakephp.org' => 'Cake PHP',
'cake-php@googlegroups.com' => 'Cake Groups',
'root@cakephp.org' => 'root@cakephp.org'
);
Expand All @@ -218,7 +218,7 @@ public function testTo() {
$expected = array(
'root@localhost' => 'root',
'bjørn@hammeröath.com' => 'Bjorn',
'cake@cakephp.org' => 'Cake PHP',
'cake.php@cakephp.org' => 'Cake PHP',
'cake-php@googlegroups.com' => 'Cake Groups',
'root@cakephp.org' => 'root@cakephp.org',
'jrbasso@cakephp.org' => 'jrbasso@cakephp.org',
Expand Down
87 changes: 87 additions & 0 deletions tests/TestCase/Network/Email/SmtpTransportTest.php
Expand Up @@ -132,6 +132,7 @@ public function testConnectEhloTls() {
* testConnectEhloTlsOnNonTlsServer method
*
* @expectedException \Cake\Network\Error\SocketException
* @expectedExceptionMessage SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.
* @return void
*/
public function testConnectEhloTlsOnNonTlsServer() {
Expand All @@ -152,6 +153,7 @@ public function testConnectEhloTlsOnNonTlsServer() {
* testConnectEhloNoTlsOnRequiredTlsServer method
*
* @expectedException \Cake\Network\Error\SocketException
* @expectedExceptionMessage SMTP authentication method not allowed, check if SMTP server requires TLS.
* @return void
*/
public function testConnectEhloNoTlsOnRequiredTlsServer() {
Expand Down Expand Up @@ -190,6 +192,7 @@ public function testConnectHelo() {
* testConnectFail method
*
* @expectedException \Cake\Network\Error\SocketException
* @expectedExceptionMessage SMTP server did not accept the connection.
* @return void
*/
public function testConnectFail() {
Expand Down Expand Up @@ -224,6 +227,90 @@ public function testAuth() {
$this->SmtpTransport->auth();
}

/**
* testAuthNotRecognized method
*
* @expectedException Cake\Network\Error\SocketException
* @expectedExceptionMessage AUTH command not recognized or not implemented, SMTP server may not require authentication.
* @return void
*/
public function testAuthNotRecognized() {
$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("500 5.3.3 Unrecognized command\r\n"));
$this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
$this->SmtpTransport->auth();
}

/**
* testAuthNotImplemented method
*
* @expectedException Cake\Network\Error\SocketException
* @expectedExceptionMessage AUTH command not recognized or not implemented, SMTP server may not require authentication.
* @return void
*/
public function testAuthNotImplemented() {
$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("502 5.3.3 Command not implemented\r\n"));
$this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
$this->SmtpTransport->auth();
}

/**
* testAuthBadSequence method
*
* @expectedException Cake\Network\Error\SocketException
* @expectedExceptionMessage SMTP Error: 503 5.5.1 Already authenticated
* @return void
*/
public function testAuthBadSequence() {
$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("503 5.5.1 Already authenticated\r\n"));
$this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
$this->SmtpTransport->auth();
}

/**
* testAuthBadUsername method
*
* @expectedException Cake\Network\Error\SocketException
* @expectedExceptionMessage SMTP server did not accept the username.
* @return void
*/
public function testAuthBadUsername() {
$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("334 Login\r\n"));
$this->socket->expects($this->at(3))->method('write')->with("bWFyaw==\r\n");
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("535 5.7.8 Authentication failed\r\n"));
$this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
$this->SmtpTransport->auth();
}

/**
* testAuthBadPassword method
*
* @expectedException Cake\Network\Error\SocketException
* @expectedExceptionMessage SMTP server did not accept the password.
* @return void
*/
public function testAuthBadPassword() {
$this->socket->expects($this->at(0))->method('write')->with("AUTH LOGIN\r\n");
$this->socket->expects($this->at(1))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(2))->method('read')->will($this->returnValue("334 Login\r\n"));
$this->socket->expects($this->at(3))->method('write')->with("bWFyaw==\r\n");
$this->socket->expects($this->at(4))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(5))->method('read')->will($this->returnValue("334 Pass\r\n"));
$this->socket->expects($this->at(6))->method('write')->with("c3Rvcnk=\r\n");
$this->socket->expects($this->at(7))->method('read')->will($this->returnValue(false));
$this->socket->expects($this->at(8))->method('read')->will($this->returnValue("535 5.7.8 Authentication failed\r\n"));
$this->SmtpTransport->config(array('username' => 'mark', 'password' => 'story'));
$this->SmtpTransport->auth();
}

/**
* testAuthNoAuth method
*
Expand Down
14 changes: 14 additions & 0 deletions tests/TestCase/Network/RequestTest.php
Expand Up @@ -2079,6 +2079,20 @@ public function testHere() {
$this->assertEquals('/posts/base_path/1/value?test=value', $result);
}

/**
* Test the here() with space in URL
*
* @return void
*/
public function testHereWithSpaceInUrl() {
Configure::write('App.base', '');
$_GET = array('/admin/settings/settings/prefix/Access_Control' => '');
$request = new CakeRequest('/admin/settings/settings/prefix/Access%20Control');

$result = $request->here();
$this->assertEquals('/admin/settings/settings/prefix/Access%20Control', $result);
}

/**
* Test the input() method.
*
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Network/SocketTest.php
Expand Up @@ -55,7 +55,7 @@ public function testConstruct() {
$this->assertSame($config, array(
'persistent' => false,
'host' => 'localhost',
'protocol' => getprotobyname('tcp'),
'protocol' => 'tcp',
'port' => 80,
'timeout' => 30
));
Expand All @@ -70,7 +70,7 @@ public function testConstruct() {

$config['host'] = 'www.cakephp.org';
$config['port'] = 23;
$config['protocol'] = 17;
$config['protocol'] = 'udp';

$this->assertSame($this->Socket->config(), $config);
}
Expand Down

0 comments on commit f14bf3c

Please sign in to comment.