| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# Copyright (C) 2014-2026 Free Software Foundation, Inc. |
| 4 |
# |
| 5 |
# This file is part of GNU Inetutils. |
| 6 |
# |
| 7 |
# GNU Inetutils is free software: you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation, either version 3 of the License, or (at |
| 10 |
# your option) any later version. |
| 11 |
# |
| 12 |
# GNU Inetutils is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
# General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program. If not, see `http://www.gnu.org/licenses/'. |
| 19 |
|
| 20 |
# Exercise the internal command interpreter of `ftp', |
| 21 |
# without any networking. Intended for code coverage |
| 22 |
# testing. |
| 23 |
|
| 24 |
set -u |
| 25 |
|
| 26 |
: ${EXEEXT:=} |
| 27 |
|
| 28 |
. ./tools.sh |
| 29 |
|
| 30 |
silence= |
| 31 |
bucket= |
| 32 |
|
| 33 |
# Executable under test. |
| 34 |
# |
| 35 |
FTP=${FTP:-../ftp/ftp$EXEEXT} |
| 36 |
|
| 37 |
if test ! -x "$FTP"; then |
| 38 |
echo >&2 "Missing executable '$FTP'. Skipping test." |
| 39 |
exit 77 |
| 40 |
fi |
| 41 |
|
| 42 |
if test -z "${VERBOSE+set}"; then |
| 43 |
silence=: |
| 44 |
bucket='>/dev/null' |
| 45 |
fi |
| 46 |
|
| 47 |
if test -n "${VERBOSE:-}"; then |
| 48 |
set -x |
| 49 |
$FTP --version | $SED '1q' |
| 50 |
fi |
| 51 |
|
| 52 |
errno=0 |
| 53 |
|
| 54 |
# Check that a client is not connected. |
| 55 |
# |
| 56 |
reply=`echo 'cd /tmp' | $FTP | $GREP -cv 'Not connected\.'` |
| 57 |
test $reply -eq 0 || { errno=1 |
| 58 |
echo >&2 'Failed respond to missing connection.'; } |
| 59 |
|
| 60 |
# Check that help is plentiful. |
| 61 |
# |
| 62 |
reply=`echo help | $FTP | $SED -n '$='` |
| 63 |
test $reply -ge 18 || { errno=1 |
| 64 |
echo >&2 'Unexpectedly short help listing.'; } |
| 65 |
|
| 66 |
# Check change from passive mode to active mode. |
| 67 |
# |
| 68 |
reply=`echo passive | $FTP -p | $GREP -cv 'Passive mode off\.'` |
| 69 |
test $reply -eq 0 || { errno=1 |
| 70 |
echo >&2 'Failed while switching back to active mode.'; } |
| 71 |
|
| 72 |
# Check address mode. |
| 73 |
reply=`echo ipv4 | $FTP --ipv6 | $GREP -cv 'Selecting addresses: IPv4'` |
| 74 |
test $reply -eq 0 || { errno=1 |
| 75 |
echo >&2 'Failed to reset address family by command.'; } |
| 76 |
|
| 77 |
# Step size for hash markers. |
| 78 |
# |
| 79 |
tell='hash 7M |
| 80 |
hash 12k' |
| 81 |
reply=`echo "$tell" | $FTP -v | $EGREP -c '12288|7340032'` |
| 82 |
|
| 83 |
test $reply -eq 2 || { errno=1 |
| 84 |
echo >&2 'Failed to parse step sizes for hash printing.'; } |
| 85 |
|
| 86 |
# A set of mixed commands for the sake of code coverage. |
| 87 |
# |
| 88 |
tell='bell |
| 89 |
case |
| 90 |
hash |
| 91 |
nmap |
| 92 |
proxy nmap |
| 93 |
ntrans |
| 94 |
proxy ntrans |
| 95 |
runique |
| 96 |
sunique |
| 97 |
epsv4 |
| 98 |
lcd /tmp |
| 99 |
lpwd' |
| 100 |
reply=`echo "$tell" | $FTP` |
| 101 |
|
| 102 |
test `echo "$reply" | $SED -n '$='` \ |
| 103 |
-eq `echo "$tell" | $SED -n '$='` \ |
| 104 |
|| { errno=1; echo >&2 'Some command in mixed list produced no response.'; } |
| 105 |
|
| 106 |
# At least Darwin has been known to prepend a directory stem. |
| 107 |
DIR_STEM=`echo "$reply" | $SED -n 's,Local directory now \([^ ]*\)/tmp$,\1,p'` |
| 108 |
|
| 109 |
test -z "$DIR_STEM" \ |
| 110 |
|| $silence echo "This system prepends a directory stem: $DIR_STEM" |
| 111 |
|
| 112 |
test `echo "$reply" | $GREP -c "Local directory is $DIR_STEM/tmp"` -eq 1 \ |
| 113 |
|| { errno=1; echo >&2 'Failed to set local directory.'; } |
| 114 |
|
| 115 |
# File name mappings can be given in several ways. |
| 116 |
# |
| 117 |
# One line giving both patterns. |
| 118 |
tell='nmap a B |
| 119 |
status' |
| 120 |
reply=`echo "$tell" | $FTP` |
| 121 |
test `echo "$reply" | $FGREP -c 'Nmap: (in) a (out) B'` -eq 1 \ |
| 122 |
|| { errno=1; echo >&2 'Failed to set file name mapping using single line.'; } |
| 123 |
|
| 124 |
# One line giving both patterns with tab between arguments to nmap. |
| 125 |
tell='nmap x Y |
| 126 |
status' |
| 127 |
reply=`echo "$tell" | $FTP` |
| 128 |
test `echo "$reply" | $FGREP -c 'Nmap: (in) x (out) Y'` -eq 1 || { errno=1 |
| 129 |
echo >&2 'Failed to set file name mapping using tab between arguments.'; } |
| 130 |
|
| 131 |
# Second pattern on a line of its own. |
| 132 |
tell='nmap A |
| 133 |
b |
| 134 |
status' |
| 135 |
reply=`echo "$tell" | $FTP` |
| 136 |
test `echo "$reply" | $FGREP -c 'Nmap: (in) A (out) b'` -eq 1 \ |
| 137 |
|| { errno=1; echo >&2 'Failed to set file name mapping using two lines.'; } |
| 138 |
|
| 139 |
# The proxy connection also has a file name mapping. |
| 140 |
# |
| 141 |
# One line giving both patterns. |
| 142 |
tell='proxy nmap c D |
| 143 |
proxy status' |
| 144 |
reply=`echo "$tell" | $FTP` |
| 145 |
test `echo "$reply" | $FGREP -c 'Nmap: (in) c (out) D'` -eq 1 || { errno=1 |
| 146 |
echo >&2 'Failed to set proxy file name mapping using single line.'; } |
| 147 |
|
| 148 |
# One line giving both patterns with tab between arguments to nmap. |
| 149 |
tell='proxy nmap X y |
| 150 |
proxy status' |
| 151 |
reply=`echo "$tell" | $FTP` |
| 152 |
test `echo "$reply" | $FGREP -c 'Nmap: (in) X (out) y'` -eq 1 || { errno=1 |
| 153 |
echo >&2 'Failed to set proxy file name mapping (one line, tab b/w args).'; } |
| 154 |
|
| 155 |
# Second pattern on a line of its own. |
| 156 |
tell='proxy nmap C |
| 157 |
d |
| 158 |
proxy status' |
| 159 |
reply=`echo "$tell" | $FTP` |
| 160 |
test `echo "$reply" | $FGREP -c 'Nmap: (in) C (out) d'` -eq 1 || { errno=1 |
| 161 |
echo >&2 'Failed to set proxy file name mapping using two lines.'; } |
| 162 |
|
| 163 |
# Proxy command on a separate line, tabs between arguments of nmap line. |
| 164 |
tell='proxy |
| 165 |
nmap u V |
| 166 |
proxy status' |
| 167 |
reply=`echo "$tell" | $FTP` |
| 168 |
test `echo "$reply" | $FGREP -c 'Nmap: (in) u (out) V'` -eq 1 || { errno=1 |
| 169 |
echo >&2 'Failed to set proxy file name mapping (two lines, tab b/w args).'; } |
| 170 |
|
| 171 |
# Both proxy command and second pattern on a line of its own. |
| 172 |
tell='proxy |
| 173 |
nmap e |
| 174 |
F |
| 175 |
proxy status' |
| 176 |
reply=`echo "$tell" | $FTP` |
| 177 |
test `echo "$reply" | $FGREP -c 'Nmap: (in) e (out) F'` -eq 1 || { errno=1 |
| 178 |
echo >&2 'Failed to set proxy file name mapping using three lines.'; } |
| 179 |
|
| 180 |
# File name translation configuration. |
| 181 |
# |
| 182 |
tell='ntrans a B |
| 183 |
status' |
| 184 |
reply=`echo "$tell" | $FTP` |
| 185 |
test `echo "$reply" | $FGREP -c 'Ntrans: (in) a (out) B'` -eq 1 || { errno=1 |
| 186 |
echo >&2 'Failed to set file name translation (space between arguments).'; } |
| 187 |
|
| 188 |
# Arguments can be separated with space and/or tab characters, so test a tab. |
| 189 |
tell='ntrans A b |
| 190 |
status' |
| 191 |
reply=`echo "$tell" | $FTP` |
| 192 |
test `echo "$reply" | $FGREP -c 'Ntrans: (in) A (out) b'` -eq 1 || { errno=1 |
| 193 |
echo >&2 'Failed to set file name translation (tab between arguments).'; } |
| 194 |
|
| 195 |
# File name translation can be set for the proxy connection. |
| 196 |
tell='proxy ntrans c D |
| 197 |
proxy status' |
| 198 |
reply=`echo "$tell" | $FTP` |
| 199 |
test `echo "$reply" | $FGREP -c 'Ntrans: (in) c (out) D'` -eq 1 || { errno=1 |
| 200 |
echo >&2 'Failed to set proxy file name translation.'; } |
| 201 |
|
| 202 |
# File name translation can be set for the proxy connection (tab b/w arguments). |
| 203 |
tell='proxy ntrans C d |
| 204 |
proxy status' |
| 205 |
reply=`echo "$tell" | $FTP` |
| 206 |
test `echo "$reply" | $FGREP -c 'Ntrans: (in) C (out) d'` -eq 1 || { errno=1 |
| 207 |
echo >&2 'Failed to set proxy file name translation (tab b/w arguments).'; } |
| 208 |
|
| 209 |
# Test nested macro execution. |
| 210 |
# |
| 211 |
tell='macdef A |
| 212 |
$ B |
| 213 |
|
| 214 |
macdef B |
| 215 |
$ C |
| 216 |
|
| 217 |
macdef C |
| 218 |
$ D |
| 219 |
|
| 220 |
macdef D |
| 221 |
hash |
| 222 |
|
| 223 |
$ A' |
| 224 |
reply=`echo "$tell" | $FTP` |
| 225 |
test `echo "$reply" | $FGREP -c 'Hash mark printing on'` -eq 1 || { errno=1 |
| 226 |
echo >&2 'Failed to execute nested macros.'; } |
| 227 |
|
| 228 |
# Summary of work. |
| 229 |
# |
| 230 |
test $errno -ne 0 || $silence echo "Successful testing". |
| 231 |
|
| 232 |
exit $errno |