diff options
author | Nuno Lopes <nlopess@php.net> | 2006-11-23 17:37:16 +0000 |
---|---|---|
committer | Nuno Lopes <nlopess@php.net> | 2006-11-23 17:37:16 +0000 |
commit | fc24777859af537edb60505eed1340c30184f69e (patch) | |
tree | bed72d43786a9a863f75d448f39780326ca4b3a3 /ext/ftp | |
parent | 577d3dec4c586ef4ef939101b733fbb9d1268d12 (diff) | |
download | php-git-fc24777859af537edb60505eed1340c30184f69e.tar.gz |
MFB
Diffstat (limited to 'ext/ftp')
-rw-r--r-- | ext/ftp/tests/004.phpt | 79 | ||||
-rw-r--r-- | ext/ftp/tests/005.phpt | 86 | ||||
-rw-r--r-- | ext/ftp/tests/server.inc | 19 |
3 files changed, 183 insertions, 1 deletions
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-- +<?php +require 'skipif.inc'; +?> +--FILE-- +<?php +require 'server.inc'; + +$ftp = ftp_connect('127.0.0.1', $port); +if (!$ftp) die("Couldn't connect to the server"); + +var_dump(ftp_login($ftp, 'user', 'pass')); + +var_dump(ftp_systype($ftp)); + +/* some bogus usage */ +var_dump(ftp_alloc($ftp, array())); +var_dump(ftp_cdup($ftp, 0)); +var_dump(ftp_chdir($ftp, array())); +var_dump(ftp_chmod($ftp, 0666)); +var_dump(ftp_get($ftp, 1234,12)); +var_dump(ftp_close()); +var_dump(ftp_connect('sfjkfjaksfjkasjf')); +var_dump(ftp_delete($ftp, array())); +var_dump(ftp_exec($ftp, array())); + +var_dump(ftp_systype($ftp, 0)); +var_dump(ftp_pwd($ftp, array())); + +var_dump(ftp_login($ftp)); +var_dump(ftp_login($ftp, 'user', 'bogus')); + +var_dump(ftp_quit($ftp)); +?> +--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-- +<?php +require 'skipif.inc'; +?> +--FILE-- +<?php +$bogus = 1; +require 'server.inc'; + +$ftp = ftp_connect('127.0.0.1', $port); +if (!$ftp) die("Couldn't connect to the server"); + +var_dump(ftp_login($ftp, 'anonymous', 'mail@example.com')); + +var_dump(ftp_alloc($ftp, 400)); +var_dump(ftp_cdup($ftp)); +var_dump(ftp_chdir($ftp, '~')); +var_dump(ftp_chmod($ftp, 0666, 'x')); +var_dump(ftp_delete($ftp, 'x')); +var_dump(ftp_exec($ftp, 'x')); +var_dump(ftp_fget($ftp, STDOUT, 'x', 0)); +var_dump(ftp_fput($ftp, 'x', fopen(__FILE__, 'r'), 0)); +var_dump(ftp_get($ftp, 'x', 'y', 0)); +var_dump(ftp_mdtm($ftp, 'x')); +var_dump(ftp_mkdir($ftp, 'x')); +var_dump(ftp_nb_continue($ftp)); +var_dump(ftp_nb_fget($ftp, STDOUT, 'x', 0)); +var_dump(ftp_nb_fput($ftp, 'x', fopen(__FILE__, 'r'), 0)); +var_dump(ftp_systype($ftp)); +var_dump(ftp_pwd($ftp)); +var_dump(ftp_size($ftp, '')); +var_dump(ftp_rmdir($ftp, '')); + +?> +--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); |