]> granicus.if.org Git - php/commitdiff
Increase ext/ftp coverage
authorGabriel Caruso <carusogabriel34@gmail.com>
Sat, 3 Feb 2018 06:56:03 +0000 (07:56 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Tue, 6 Feb 2018 15:28:42 +0000 (16:28 +0100)
ext/ftp/tests/ftp_get_basic.phpt
ext/ftp/tests/ftp_site_basic.phpt [new file with mode: 0644]
ext/ftp/tests/server.inc

index 2fd8c7914919febb06804ef725e6f4b6bb8d28d9..60f1b1de79bc5606f89b7159bc557645ae69eac3 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-FTP ftp_get file for both binary and ASCII transfer modes 
+FTP ftp_get file for both binary and ASCII transfer modes
 --CREDITS--
 Nathaniel McHugh
 --SKIPIF--
@@ -27,8 +27,11 @@ var_dump(ftp_get($ftp, $tmpfname, 'binary data.bin', FTP_BINARY));
 var_dump(urlencode(file_get_contents($tmpfname)));
 unlink($tmpfname);
 
-//test non-existent file request 
+//test non-existent file request
 ftp_get($ftp, $tmpfname ,'a warning.txt', FTP_ASCII);
+
+//test invalid ftp_get params
+var_dump(ftp_get('foo', 'bar', 'baz'));
 ?>
 --EXPECTF--
 bool(true)
@@ -38,3 +41,6 @@ bool(true)
 string(21) "BINARYFoo%00Bar%0D%0A"
 
 Warning: ftp_get(): a warning: No such file or directory  in %sftp_get_basic.php on line %d
+
+Warning: ftp_get() expects parameter 1 to be resource, string given in %s on line %d
+NULL
diff --git a/ext/ftp/tests/ftp_site_basic.phpt b/ext/ftp/tests/ftp_site_basic.phpt
new file mode 100644 (file)
index 0000000..7dfaf1a
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+ftp_site function basic functionality
+--CREDITS--
+Gabriel Caruso (carusogabriel34@gmail.com)
+--SKIPIF--
+<?php require 'skipif.inc'; ?>
+--FILE--
+<?php
+require 'server.inc';
+
+$ftp = ftp_connect('127.0.0.1', $port);
+$ftp or die("Couldn't connect to the server");
+
+ftp_login($ftp, 'user', 'pass') or die("Couldn't login into the server");
+
+var_dump(ftp_site($ftp, 'CHMOD 0600 file'));
+var_dump(ftp_site($ftp, 'foo bar baz'));
+?>
+--EXPECTF--
+bool(true)
+
+Warning: ftp_site(): Syntax error, command unrecognized. in %s on line %d
+bool(false)
index 0b161de221b984d3cfebf4fff9f2ce13eb59854d..d94844b218d9ac6dcc2d5392c892f79456d32c8f 100644 (file)
@@ -19,13 +19,8 @@ if (!$socket) {
        die("could not start/bind the ftp server\n");
 }
 
-
-
-
 $pid = pcntl_fork();
 
-
-
 function pasv_listen($action){
        global $pasv_port, $tmp_file;
        $tmp_file = 'nm2.php';
@@ -56,8 +51,6 @@ function pasv_listen($action){
        }
 }
 
-
-
 if ($pid) {
 
        function dump_and_exit($buf)
@@ -524,8 +517,9 @@ if ($pid) {
 
                        fputs($s, "226 Closing data Connection.\r\n");
                        fclose($fs);
-               }else {
+               }elseif (preg_match("/^SITE/", $buf)) {
                        fputs($s, "500 Syntax error, command unrecognized.\r\n");
+               }else {
                        dump_and_exit($buf);
                }
        }