mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-07 20:08:53 +00:00
Merge branch 'develop-olympus' into develop
* develop-olympus: [ticket/9297] Add network to class name of unit tests. [ticket/9297] Fix typo in localhost. [ticket/9297] Rename test class to reflect its contents. [ticket/9297] Adjust comment - IPv6 is needed for IPv6 connections to work. [ticket/9297] Fix markTestSkipped call in setUpBeforeClass. [ticket/9297] Skip FTP PASV/EPSV test if FTP connection fails. [ticket/9297] Separate ipv4 and ipv6 tests into separate functions. [ticket/9297] Update copyright year of unit test file. [ticket/9297] Make EPSV unit tests work without IPv6. [ticket/9297] Unit tests for ftp_fsock PASV and EPSV. [ticket/9297] Add support for Extended Passive Mode (EPSV) in ftp_fsock class.
This commit is contained in:
commit
5305f6a977
2 changed files with 107 additions and 11 deletions
|
@ -808,23 +808,56 @@ class ftp_fsock extends transfer
|
|||
*/
|
||||
function _open_data_connection()
|
||||
{
|
||||
$this->_send_command('PASV', '', false);
|
||||
|
||||
if (!$ip_port = $this->_check_command(true))
|
||||
// Try to find out whether we have a IPv4 or IPv6 (control) connection
|
||||
if (function_exists('stream_socket_get_name'))
|
||||
{
|
||||
return false;
|
||||
$socket_name = stream_socket_get_name($this->connection, true);
|
||||
$server_ip = substr($socket_name, 0, strrpos($socket_name, ':'));
|
||||
}
|
||||
|
||||
// open the connection to start sending the file
|
||||
if (!preg_match('#[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+#', $ip_port, $temp))
|
||||
if (!isset($server_ip) || preg_match(get_preg_expression('ipv4'), $server_ip))
|
||||
{
|
||||
// bad ip and port
|
||||
return false;
|
||||
// Passive mode
|
||||
$this->_send_command('PASV', '', false);
|
||||
|
||||
if (!$ip_port = $this->_check_command(true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// open the connection to start sending the file
|
||||
if (!preg_match('#[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]{1,3},[0-9]+,[0-9]+#', $ip_port, $temp))
|
||||
{
|
||||
// bad ip and port
|
||||
return false;
|
||||
}
|
||||
|
||||
$temp = explode(',', $temp[0]);
|
||||
$server_ip = $temp[0] . '.' . $temp[1] . '.' . $temp[2] . '.' . $temp[3];
|
||||
$server_port = $temp[4] * 256 + $temp[5];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Extended Passive Mode - RFC2428
|
||||
$this->_send_command('EPSV', '', false);
|
||||
|
||||
if (!$epsv_response = $this->_check_command(true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Response looks like "229 Entering Extended Passive Mode (|||12345|)"
|
||||
// where 12345 is the tcp port for the data connection
|
||||
if (!preg_match('#\(\|\|\|([0-9]+)\|\)#', $epsv_response, $match))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
$server_port = (int) $match[1];
|
||||
|
||||
// fsockopen expects IPv6 address in square brackets
|
||||
$server_ip = "[$server_ip]";
|
||||
}
|
||||
|
||||
$temp = explode(',', $temp[0]);
|
||||
$server_ip = $temp[0] . '.' . $temp[1] . '.' . $temp[2] . '.' . $temp[3];
|
||||
$server_port = $temp[4] * 256 + $temp[5];
|
||||
$errno = 0;
|
||||
$errstr = '';
|
||||
|
||||
|
|
63
tests/network/ftp_fsock_pasv_epsv_test.php
Normal file
63
tests/network/ftp_fsock_pasv_epsv_test.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2011 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_transfer.php';
|
||||
|
||||
/**
|
||||
* @group slow
|
||||
*/
|
||||
class phpbb_network_ftp_fsock_pasv_epsv_test extends phpbb_test_case
|
||||
{
|
||||
static protected $ipv4;
|
||||
|
||||
static public function setUpBeforeClass()
|
||||
{
|
||||
$hostname = 'ftp.debian.org.';
|
||||
self::$ipv4 = gethostbyname($hostname);
|
||||
|
||||
if (self::$ipv4 == $hostname)
|
||||
{
|
||||
self::markTestSkipped("Got no A record back from DNS query for $hostname");
|
||||
}
|
||||
}
|
||||
|
||||
public function test_pasv()
|
||||
{
|
||||
// PASV
|
||||
$this->assert_ls_contains_debian(self::$ipv4);
|
||||
}
|
||||
|
||||
public function test_epsv()
|
||||
{
|
||||
$ipv4 = self::$ipv4;
|
||||
// EPSV
|
||||
$this->assert_ls_contains_debian("[::ffff:$ipv4]");
|
||||
}
|
||||
|
||||
protected function assert_ls_contains_debian($hostname)
|
||||
{
|
||||
$o = $this->get_object($hostname);
|
||||
$result = $o->_init();
|
||||
// This test may fail on IPv6 addresses if IPv6 support is
|
||||
// not available. PHP must be compiled with IPv6 support enabled,
|
||||
// and your operating system must be configured for IPv6 as well.
|
||||
if ($result !== true)
|
||||
{
|
||||
$this->markTestSkipped("Failed to connect to $hostname: $result");
|
||||
}
|
||||
$this->assertContains('debian', $o->_ls());
|
||||
$o->_close();
|
||||
}
|
||||
|
||||
protected function get_object($hostname)
|
||||
{
|
||||
return new ftp_fsock($hostname, 'anonymous', 'anonymous@localhost.tld', '/');
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue