浏览代码

Merge branch '2.6' into 3.0

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
ADmad 11 年之前
父节点
当前提交
f14bf3c1f2

+ 1 - 0
.gitignore

@@ -10,6 +10,7 @@
 
 # IDE and editor specific files #
 #################################
+/nbproject
 .idea
 
 # OS generated files #

+ 11 - 0
src/Console/ConsoleOptionParser.php

@@ -413,6 +413,17 @@ class ConsoleOptionParser {
 	}
 
 /**
+ * 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.
  *
  * @param array $commands Array of subcommands.

+ 13 - 10
src/Network/Email/SmtpTransport.php

@@ -241,20 +241,23 @@ class SmtpTransport extends AbstractTransport {
  * @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.');
 			}
 		}
 	}

+ 1 - 1
src/Network/Request.php

@@ -275,7 +275,7 @@ class Request implements \ArrayAccess {
  * @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) {

+ 3 - 6
src/Network/Socket.php

@@ -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']);
-		}
 	}
 
 /**
@@ -127,8 +123,8 @@ class Socket {
 		}
 
 		$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'])) {
@@ -381,3 +377,4 @@ class Socket {
 	}
 
 }
+

+ 15 - 0
tests/TestCase/Console/ConsoleOptionParserTest.php

@@ -492,6 +492,21 @@ class ConsoleOptionParserTest extends TestCase {
 	}
 
 /**
+ * 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
  *
  * @return void

+ 3 - 3
tests/TestCase/Network/Email/EmailTest.php

@@ -198,7 +198,7 @@ class EmailTest extends TestCase {
 		$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'
 		);
@@ -206,7 +206,7 @@ class EmailTest extends TestCase {
 		$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'
 		);
@@ -218,7 +218,7 @@ class EmailTest extends TestCase {
 		$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',

+ 87 - 0
tests/TestCase/Network/Email/SmtpTransportTest.php

@@ -132,6 +132,7 @@ class SmtpTransportTest extends TestCase {
  * 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() {
@@ -152,6 +153,7 @@ class SmtpTransportTest extends TestCase {
  * testConnectEhloNoTlsOnRequiredTlsServer method
  *
  * @expectedException \Cake\Network\Error\SocketException
+ * @expectedExceptionMessage SMTP authentication method not allowed, check if SMTP server requires TLS.
  * @return void
  */
 	public function testConnectEhloNoTlsOnRequiredTlsServer() {
@@ -190,6 +192,7 @@ class SmtpTransportTest extends TestCase {
  * testConnectFail method
  *
  * @expectedException \Cake\Network\Error\SocketException
+ * @expectedExceptionMessage SMTP server did not accept the connection.
  * @return void
  */
 	public function testConnectFail() {
@@ -225,6 +228,90 @@ class SmtpTransportTest extends TestCase {
 	}
 
 /**
+ * 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
  *
  * @return void

+ 14 - 0
tests/TestCase/Network/RequestTest.php

@@ -2080,6 +2080,20 @@ class RequestTest extends TestCase {
 	}
 
 /**
+ * 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.
  *
  * @return void

+ 2 - 2
tests/TestCase/Network/SocketTest.php

@@ -55,7 +55,7 @@ class SocketTest extends TestCase {
 		$this->assertSame($config, array(
 			'persistent'	=> false,
 			'host'			=> 'localhost',
-			'protocol'		=> getprotobyname('tcp'),
+			'protocol'		=> 'tcp',
 			'port'			=> 80,
 			'timeout'		=> 30
 		));
@@ -70,7 +70,7 @@ class SocketTest extends TestCase {
 
 		$config['host'] = 'www.cakephp.org';
 		$config['port'] = 23;
-		$config['protocol'] = 17;
+		$config['protocol'] = 'udp';
 
 		$this->assertSame($this->Socket->config(), $config);
 	}