1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Make a test-ftp-parser test script and remove the 'built-in' one

This commit is contained in:
Jonas Fonseca 2006-01-03 01:28:44 +01:00 committed by Jonas Fonseca
parent ba5bdfec00
commit 90a1440c03
5 changed files with 127 additions and 81 deletions

View File

@ -3,4 +3,17 @@ include $(top_builddir)/Makefile.config
OBJS = ftp.o parse.o OBJS = ftp.o parse.o
TEST_PROGS = ftp-parser
TESTDEPS = \
$(top_builddir)/src/protocol/ftp/parse.o \
$(top_builddir)/src/protocol/date.o \
$(top_builddir)/src/util/error.o \
$(top_builddir)/src/osdep/stub.o \
$(top_builddir)/src/util/hash.o \
$(top_builddir)/src/util/memdebug.o \
$(top_builddir)/src/util/string.o \
$(top_builddir)/src/util/conv.o \
$(top_builddir)/src/util/memory.o \
$(top_builddir)/src/util/time.o
include $(top_srcdir)/Makefile.lib include $(top_srcdir)/Makefile.lib

View File

@ -1140,24 +1140,9 @@ ftp_process_dirlist(struct cache_entry *cached, off_t *pos,
int *tries, int colorize_dir, unsigned char *dircolor) int *tries, int colorize_dir, unsigned char *dircolor)
{ {
int ret = 0; int ret = 0;
#ifdef DEBUG_FTP_PARSER
static int debug_ftp_parser = 1;
int buflen_orig = buflen;
unsigned char *response_orig = NULL;
if (debug_ftp_parser) {
buffer = get_ftp_debug_parse_responses(buffer, buflen);
buflen = strlen(buffer);
response_orig = buffer;
debug_ftp_parser = 0;
}
#define end_ftp_dirlist_processing() do { mem_free_if(response_orig); } while (0)
#define get_ftp_dirlist_offset(retval) int_min(retval, buflen_orig)
#else
#define end_ftp_dirlist_processing() /* Nothing to free */ #define end_ftp_dirlist_processing() /* Nothing to free */
#define get_ftp_dirlist_offset(retval) (retval) #define get_ftp_dirlist_offset(retval) (retval)
#endif
while (1) { while (1) {
struct ftp_file_info ftp_info = INIT_FTP_FILE_INFO; struct ftp_file_info ftp_info = INIT_FTP_FILE_INFO;

View File

@ -32,6 +32,9 @@
#include "util/time.h" #include "util/time.h"
/* Examples of what the FTP parser is supposed to handle (and not handle) can
* be found in the test-ftp-parser file. */
#define skip_space_end(src, end) \ #define skip_space_end(src, end) \
do { while ((src) < (end) && *(src) == ' ') (src)++; } while (0) do { while ((src) < (end) && *(src) == ' ') (src)++; } while (0)
@ -128,27 +131,6 @@ parse_ftp_eplf_response(struct ftp_file_info *info, unsigned char *src, int len)
/* Parser for UNIX-style listing: */ /* Parser for UNIX-style listing: */
#ifdef DEBUG_FTP_PARSER
static unsigned char ftp_unix_responses[] =
/* ftp.freebsd.org response */
"drwxrwxr-x 3 0 0 512 Apr 17 2003 pub\r\n"
/* UNIX-style listing, without inum and without blocks: */
"-rw-r--r-- 1 root other 531 Jan 29 03:26 README\r\n"
"dr-xr-xr-x 2 root other 512 Apr 8 1994 etc\r\n"
"dr-xr-xr-x 2 root 512 Apr 8 1994 etc\r\n"
"lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin\r\n"
/* Also produced by Microsoft's FTP servers for Windows: */
"---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z\r\n"
"d--------- 1 owner group 0 May 9 19:45 Softlib\r\n"
/* Also WFTPD for MSDOS: */
"-rwxrwxrwx 1 noone nogroup 322 Aug 19 1996 message.ftp\r\n"
/* Also NetWare: */
"d [R----F--] supervisor 512 Jan 16 18:53 login\r\n"
"- [R----F--] rhesus 214059 Oct 20 15:27 cx.exe\r\n"
/* Also NetPresenz for the Mac: */
"-------r-- 326 1391972 1392298 Nov 22 1995 MegaPhone.sit\r\n"
"drwxrwxr-x folder 2 May 10 1996 network\r\n";
#endif
enum ftp_unix { enum ftp_unix {
FTP_UNIX_PERMISSIONS, FTP_UNIX_PERMISSIONS,
@ -429,15 +411,6 @@ parse_ftp_unix_response(struct ftp_file_info *info, unsigned char *src, int len)
/* Parser for VMS-style MultiNet (some spaces removed from examples): */ /* Parser for VMS-style MultiNet (some spaces removed from examples): */
#ifdef DEBUG_FTP_PARSER
static unsigned char ftp_vms_responses[] =
"00README.TXT;1 2 30-DEC-1996 17:44 [SYSTEM] (RWED,RWED,RE,RE)\r\n"
"CORE.DIR;1 1 8-SEP-1996 16:09 [SYSTEM] (RWE,RWE,RE,RE)\r\n"
/* And non-MutliNet VMS: */
"CII-MANUAL.TEX;1 213/216 29-JAN-1996 03:33:12 [ANONYMOU,ANONYMOUS] (RWED,RWED,,)\r\n"
/* A garbage line which should fail: */
"EA95_0PS.GZ;1 No privilege for attempted operation\r\n";
#endif
/* Converts VMS symbolic permissions to number-style ones, e.g. string /* Converts VMS symbolic permissions to number-style ones, e.g. string
* RWED,RWE,RE to 755. "D" (delete) is taken to be equal to "W" (write). * RWED,RWE,RE to 755. "D" (delete) is taken to be equal to "W" (write).
@ -554,12 +527,6 @@ parse_ftp_vms_response(struct ftp_file_info *info, unsigned char *src, int len)
/* Parser for the MSDOS-style format: */ /* Parser for the MSDOS-style format: */
#ifdef DEBUG_FTP_PARSER
static unsigned char ftp_winnt_responses[] =
"04-27-00 09:09PM <DIR> licensed\r\n"
"07-18-00 10:16AM <DIR> pub\r\n"
"04-14-00 03:47PM 589 readme.htm\r\n";
#endif
struct ftp_file_info * struct ftp_file_info *
parse_ftp_winnt_response(struct ftp_file_info *info, unsigned char *src, int len) parse_ftp_winnt_response(struct ftp_file_info *info, unsigned char *src, int len)
@ -639,26 +606,6 @@ parse_ftp_winnt_response(struct ftp_file_info *info, unsigned char *src, int len
return info; return info;
} }
#ifdef DEBUG_FTP_PARSER
unsigned char *
get_ftp_debug_parse_responses(unsigned char *buffer, int buflen)
{
struct string response;
if (!init_string(&response))
return NULL;
add_to_string(&response, ftp_eplf_responses);
add_to_string(&response, ftp_unix_responses);
add_to_string(&response, ftp_vms_responses);
add_to_string(&response, ftp_winnt_responses);
add_bytes_to_string(&response, buffer, buflen);
return response.source;
}
#endif
struct ftp_file_info * struct ftp_file_info *
parse_ftp_file_info(struct ftp_file_info *info, unsigned char *src, int len) parse_ftp_file_info(struct ftp_file_info *info, unsigned char *src, int len)

View File

@ -38,14 +38,4 @@ struct ftp_file_info {
struct ftp_file_info * struct ftp_file_info *
parse_ftp_file_info(struct ftp_file_info *info, unsigned char *src, int len); parse_ftp_file_info(struct ftp_file_info *info, unsigned char *src, int len);
/* Define to feed debug FTP responses into the parser. Then point ELinks to an
* FTP server to run the tests. */
#if 0
#define DEBUG_FTP_PARSER
#endif
#ifdef DEBUG_FTP_PARSER
unsigned char *get_ftp_debug_parse_responses(unsigned char *buffer, int buflen);
#endif
#endif #endif

View File

@ -0,0 +1,111 @@
#!/bin/sh
#
# Copyright (c) 2005 Jonas Fonseca
#
test_description='Test parsing of FTP responses.
It tests responses from several different FTP servers.
'
. "$TEST_LIB"
CRNL="\r\n"
test_ftp_response_expect_success () {
desc="$1"; shift
response="$1"; shift
response="$(echo "$response" | sed -n '2,$p')"
test_expect_success "$desc" \
"ftp-parser --response '$response'"
}
test_ftp_response_expect_failure () {
desc="$1"; shift
response="$1"; shift
response="$(echo "$response" | sed -n '2,$p')"
test_expect_failure "$desc" \
"ftp-parser --response '$response'"
}
#############################################################################
#
# Parser for UNIX-style listing:
#
test_ftp_response_expect_success \
'ftp.freebsd.org response' \
"
drwxrwxr-x 3 0 0 512 Apr 17 2003 pub\r\n"
test_ftp_response_expect_success \
'UNIX-style listing, without inum and without blocks' \
"
-rw-r--r-- 1 root other 531 Jan 29 03:26 README\r\n
dr-xr-xr-x 2 root other 512 Apr 8 1994 etc\r\n
dr-xr-xr-x 2 root 512 Apr 8 1994 etc\r\n
lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin\r\n"
test_ftp_response_expect_success \
"Response produced by Microsoft's FTP servers for Windows" \
"
---------- 1 owner group 1803128 Jul 10 10:18 ls-lR.Z\r\n
d--------- 1 owner group 0 May 9 19:45 Softlib\r\n"
test_ftp_response_expect_success \
'Response from WFTPD for MSDOS' \
"
-rwxrwxrwx 1 noone nogroup 322 Aug 19 1996 message.ftp\r\n"
test_ftp_response_expect_success \
'Response from NetWare' \
"
d[R----F--] supervisor 512 Jan 16 18:53 login\r\n
- [R----F--] rhesus 214059 Oct 20 15:27 cx.exe\r\n"
test_ftp_response_expect_success \
'Response from NetPresenz for the Mac' \
"
-------r-- 326 1391972 1392298 Nov 22 1995 MegaPhone.sit\r\n
drwxrwxr-x folder 2 May 10 1996 network\r\n"
#############################################################################
#
# Parser for VMS-style MultiNet (some spaces removed from examples)
#
test_ftp_response_expect_success \
'Basic VMS responses' \
"
00README.TXT;1 2 30-DEC-1996 17:44 [SYSTEM] (RWED,RWED,RE,RE)\r\n
CORE.DIR;1 1 8-SEP-1996 16:09 [SYSTEM] (RWE,RWE,RE,RE)\r\n"
test_ftp_response_expect_success \
'Response from non-MutliNet VMS' \
"
CII-MANUAL.TEX;1 213/216 29-JAN-1996 03:33:12 [ANONYMOU,ANONYMOUS] (RWED,RWED,,)\r\n"
test_ftp_response_expect_failure \
'A garbage line which should fail' \
"
EA95_0PS.GZ;1 No privilege for attempted operation\r\n"
#############################################################################
#
# Parser for the MSDOS-style format
#
test_ftp_response_expect_success \
'Basic MSDOS-style format' \
"
04-27-00 09:09PM <DIR> licensed\r\n
07-18-00 10:16AM <DIR> pub\r\n
04-14-00 03:47PM 589 readme.htm\r\n"
test_done