From fc24777859af537edb60505eed1340c30184f69e Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Thu, 23 Nov 2006 17:37:16 +0000 Subject: [PATCH] MFB --- ext/ftp/tests/004.phpt | 79 ++++++++++++++++++++++++++++++++++++ ext/ftp/tests/005.phpt | 86 ++++++++++++++++++++++++++++++++++++++++ ext/ftp/tests/server.inc | 19 ++++++++- 3 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 ext/ftp/tests/004.phpt create mode 100644 ext/ftp/tests/005.phpt diff --git a/ext/ftp/tests/004.phpt b/ext/ftp/tests/004.phpt new file mode 100644 index 0000000000..8fc6a862c9 --- /dev/null +++ b/ext/ftp/tests/004.phpt @@ -0,0 +1,79 @@ +--TEST-- +FTP with bogus parameters +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +bool(true) +string(4) "UNIX" + +Warning: ftp_alloc() expects parameter 2 to be long, array given in %s004.php on line 12 +bool(false) + +Warning: ftp_cdup() expects exactly 1 parameter, 2 given in %s004.php on line 13 +NULL + +Warning: ftp_chdir() expects parameter 2 to be string, array given in %s004.php on line 14 +NULL + +Warning: ftp_chmod() expects exactly 3 parameters, 2 given in /cvs/php5/ext/ftp/tests/004.php on line 15 +bool(false) + +Warning: ftp_get() expects at least 4 parameters, 3 given in /cvs/php5/ext/ftp/tests/004.php on line 16 +NULL + +Warning: ftp_close() expects exactly 1 parameter, 0 given in %s004.php on line 17 +NULL + +Warning: ftp_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known in %s004.php on line 18 +bool(false) + +Warning: ftp_delete() expects parameter 2 to be string, array given in %s004.php on line 19 +NULL + +Warning: ftp_exec() expects parameter 2 to be string, array given in %s004.php on line 20 +NULL + +Warning: ftp_systype() expects exactly 1 parameter, 2 given in %s004.php on line 22 +NULL + +Warning: ftp_pwd() expects exactly 1 parameter, 2 given in %s004.php on line 23 +NULL + +Warning: ftp_login() expects exactly 3 parameters, 1 given in %s004.php on line 25 +NULL + +Warning: ftp_login(): Not logged in. in %s004.php on line 26 +bool(false) +bool(true) diff --git a/ext/ftp/tests/005.phpt b/ext/ftp/tests/005.phpt new file mode 100644 index 0000000000..4291c1c1bd --- /dev/null +++ b/ext/ftp/tests/005.phpt @@ -0,0 +1,86 @@ +--TEST-- +FTP with bogus server responses +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +bool(true) +bool(false) + +Warning: ftp_cdup(): Command not implemented (1). in %s005.php on line 11 +bool(false) + +Warning: ftp_chdir(): Command not implemented (2). in %s005.php on line 12 +bool(false) + +Warning: ftp_chmod(): Command not implemented (3). in %s005.php on line 13 +bool(false) + +Warning: ftp_delete(): Command not implemented (4). in %s005.php on line 14 +bool(false) + +Warning: ftp_exec(): Command not implemented (5). in %s005.php on line 15 +bool(false) + +Warning: ftp_fget(): Command not implemented (6). in %s005.php on line 16 +bool(false) + +Warning: ftp_fput(): Command not implemented (7). in %s005.php on line 17 +bool(false) + +Warning: ftp_get(): Command not implemented (8). in %s005.php on line 18 +bool(false) +int(-1) + +Warning: ftp_mkdir(): Command not implemented (10). in %s005.php on line 20 +bool(false) + +Warning: ftp_nb_continue(): no nbronous transfer to continue. in %s005.php on line 21 +int(0) + +Warning: ftp_nb_fget(): Command not implemented (11). in %s005.php on line 22 +int(0) + +Warning: ftp_nb_fput(): Command not implemented (12). in %s005.php on line 23 +int(0) + +Warning: ftp_systype(): Command not implemented (13). in %s005.php on line 24 +bool(false) + +Warning: ftp_pwd(): Command not implemented (14). in %s005.php on line 25 +bool(false) +int(-1) + +Warning: ftp_rmdir(): Command not implemented (16). in %s005.php on line 27 +bool(false) diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc index 034e4b80a6..ca42ef8fda 100644 --- a/ext/ftp/tests/server.inc +++ b/ext/ftp/tests/server.inc @@ -57,6 +57,10 @@ if (!$s) die("Error accepting a new connection\n"); fputs($s, "220----- PHP FTP server 0.3 -----\r\n220 Service ready\r\n"); $buf = fread($s, 2048); + +function user_auth($buf) { + global $user, $s, $ssl; + if (!empty($ssl)) { if ($buf !== "AUTH TLS\r\n") { fputs($s, "500 Syntax error, command unrecognized.\r\n"); @@ -118,12 +122,19 @@ if (anonymous()) { exit; } } +} + +user_auth($buf); $cwd = '/'; +$num_bogus_cmds = 0; while($buf = fread($s, 4098)) { - if ($buf === "HELP\r\n") { + if (!empty($bogus)) { + fputs($s, "502 Command not implemented (".$num_bogus_cmds++.").\r\n"); + + } else if ($buf === "HELP\r\n") { fputs($s, "214-There is help available for the following commands:\r\n"); fputs($s, " USER\r\n"); fputs($s, " HELP\r\n"); @@ -139,6 +150,9 @@ while($buf = fread($s, 4098)) { change_dir('..'); fputs($s, "250 CDUP command successful.\r\n"); + } elseif ($buf === "SYST\r\n") { + fputs($s, "215 UNIX Type: L8.\r\n"); + } elseif ($buf === "QUIT\r\n") { break; @@ -146,6 +160,9 @@ while($buf = fread($s, 4098)) { change_dir($m[1]); fputs($s, "250 CWD command successful.\r\n"); + } else if(preg_match('/^USER /', $buf)) { + user_auth($buf); + } else { fputs($s, "500 Syntax error, command unrecognized.\r\n"); dump_and_exit($buf); -- 2.50.1