From 30e639ae39266a897fa28dcfcdf98cf746120889 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 18 Feb 2009 15:29:06 -0600 Subject: [PATCH] add a couple unit tests to ftp --- basis/ftp/client/client.factor | 2 +- basis/ftp/ftp.factor | 4 --- basis/ftp/server/server-tests.factor | 50 ++++++++++++++++++++++++++++ basis/ftp/server/server.factor | 4 +-- 4 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 basis/ftp/server/server-tests.factor diff --git a/basis/ftp/client/client.factor b/basis/ftp/client/client.factor index ac21bb8f78..14877110d3 100644 --- a/basis/ftp/client/client.factor +++ b/basis/ftp/client/client.factor @@ -93,7 +93,7 @@ ERROR: ftp-error got expected ; : ensure-login ( url -- url ) dup username>> [ "anonymous" >>username - "ftp-client" >>password + "ftp-client@factorcode.org" >>password ] unless ; : >ftp-url ( url -- url' ) >url ensure-port ensure-login ; diff --git a/basis/ftp/ftp.factor b/basis/ftp/ftp.factor index 27eebc5946..eea98c0172 100644 --- a/basis/ftp/ftp.factor +++ b/basis/ftp/ftp.factor @@ -16,7 +16,3 @@ TUPLE: ftp-response n strings parsed ; over strings>> push ; : ftp-send ( string -- ) write "\r\n" write flush ; - -CONSTANT: ftp-ipv4 1 - -CONSTANT: ftp-ipv6 2 diff --git a/basis/ftp/server/server-tests.factor b/basis/ftp/server/server-tests.factor new file mode 100644 index 0000000000..d7d9d8384d --- /dev/null +++ b/basis/ftp/server/server-tests.factor @@ -0,0 +1,50 @@ +USING: calendar ftp.server io.encodings.ascii io.files +io.files.unique namespaces threads tools.test kernel +io.servers.connection ftp.client accessors urls +io.pathnames io.directories sequences fry ; +IN: ftp.server.tests + +: test-file-contents ( -- string ) + "Files are so boring anymore." ; + +: create-test-file ( -- path ) + test-file-contents + "ftp.server" "test" make-unique-file + [ ascii set-file-contents ] keep canonicalize-path ; + +: test-ftp-server ( quot -- ) + '[ + current-temporary-directory get 0 + + [ start-server* ] + [ + sockets>> first addr>> port>> + + swap >>port + "ftp" >>protocol + "localhost" >>host + create-test-file >>path + _ call + ] + [ stop-server ] tri + ] with-unique-directory drop ; inline + +[ t ] +[ + + [ + unique-directory [ + [ ftp-get ] [ path>> file-name ascii file-contents ] bi + ] with-directory + ] test-ftp-server test-file-contents = +] unit-test + +[ + + [ + "/" >>path + unique-directory [ + [ ftp-get ] [ path>> file-name ascii file-contents ] bi + ] with-directory + ] test-ftp-server test-file-contents = +] must-fail diff --git a/basis/ftp/server/server.factor b/basis/ftp/server/server.factor index ffe16b2f4c..5247b824fa 100644 --- a/basis/ftp/server/server.factor +++ b/basis/ftp/server/server.factor @@ -61,11 +61,9 @@ C: ftp-disconnect normalize-path server get serving-directory>> head? ; : can-serve-directory? ( path -- ? ) - canonicalize-path { [ exists? ] [ file-info directory? ] [ serving? ] } 1&& ; : can-serve-file? ( path -- ? ) - canonicalize-path { [ exists? ] [ file-info type>> +regular-file+ = ] @@ -351,7 +349,7 @@ M: ftp-server handle-client* ( server -- ) : ( directory port -- server ) ftp-server new-threaded-server swap >>insecure - swap >>serving-directory + swap canonicalize-path >>serving-directory "ftp.server" >>name 5 minutes >>timeout latin1 >>encoding ;