upstream: Add tests for expansions on UserKnownHostsFile.

OpenBSD-Regress-ID: bccf8060306c841bbcceb1392644f906a4d6ca51
This commit is contained in:
dtucker@openbsd.org 2020-07-17 03:26:58 +00:00 committed by Damien Miller
parent 287dc6396e
commit 6736fe6807

View File

@ -1,4 +1,4 @@
# $OpenBSD: percent.sh,v 1.7 2020/05/29 04:32:26 dtucker Exp $
# $OpenBSD: percent.sh,v 1.8 2020/07/17 03:26:58 dtucker Exp $
# Placed in the Public Domain.
tid="percent expansions"
@ -25,12 +25,21 @@ trial()
trace "test $opt=$arg $expect"
rm -f $OBJ/actual
got=""
case "$opt" in
localcommand)
${SSH} -F $OBJ/ssh_proxy -o $opt="echo '$arg' >$OBJ/actual" \
somehost true
got=`cat $OBJ/actual`
;;
userknownhostsfile)
# Move the userknownhosts file to what the expansion says,
# make sure ssh works then put it back.
mv "$OBJ/known_hosts" "$OBJ/$expect"
${SSH} -F $OBJ/ssh_proxy -o $opt="$OBJ/$arg" somehost true && \
got="$expect"
mv "$OBJ/$expect" "$OBJ/known_hosts"
;;
matchexec)
(cat $OBJ/ssh_proxy && \
echo "Match Exec \"echo '$arg' >$OBJ/actual\"") \
@ -55,13 +64,18 @@ trial()
}
for i in matchexec localcommand remotecommand controlpath identityagent \
forwardagent localforward remoteforward; do
forwardagent localforward remoteforward userknownhostsfile; do
verbose $tid $i percent
if [ "$i" = "localcommand" ]; then
REMUSER=$USER
case "$i" in
localcommand|userknownhostsfile)
# Any test that's going to actually make a connection needs
# to use the real username.
REMUSER=$USER ;;
*)
REMUSER=remuser ;;
esac
if [ "$i" = "$localcommand" ]; then
trial $i '%T' NONE
else
REMUSER=remuser
fi
# Matches implementation in readconf.c:ssh_connection_hash()
HASH=`printf "${HOSTNAME}127.0.0.1${PORT}$REMUSER" |
@ -70,20 +84,25 @@ for i in matchexec localcommand remotecommand controlpath identityagent \
trial $i '%C' $HASH
trial $i '%i' $USERID
trial $i '%h' 127.0.0.1
trial $i '%d' $HOME
trial $i '%L' $HOST
trial $i '%l' $HOSTNAME
trial $i '%n' somehost
trial $i '%p' $PORT
trial $i '%r' $REMUSER
trial $i '%u' $USER
trial $i '%%/%C/%i/%h/%d/%L/%l/%n/%p/%r/%u' \
"%/$HASH/$USERID/127.0.0.1/$HOME/$HOST/$HOSTNAME/somehost/$PORT/$REMUSER/$USER"
# We can't specify a full path outside the regress dir, so skip tests
# containing %d for UserKnownHostsFile
if [ "$i" != "userknownhostsfile" ]; then
trial $i '%d' $HOME
trial $i '%%/%C/%i/%h/%d/%L/%l/%n/%p/%r/%u' \
"%/$HASH/$USERID/127.0.0.1/$HOME/$HOST/$HOSTNAME/somehost/$PORT/$REMUSER/$USER"
fi
done
# Subset of above since we don't expand shell-style variables on anything that
# runs a command because the shell will expand those.
for i in controlpath identityagent forwardagent localforward remoteforward; do
for i in controlpath identityagent forwardagent localforward remoteforward \
userknownhostsfile; do
verbose $tid $i dollar
FOO=bar
export FOO