summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordtucker@openbsd.org <dtucker@openbsd.org>2020-07-17 03:26:58 +0000
committerDamien Miller <djm@mindrot.org>2020-07-17 13:53:04 +1000
commit6736fe680704a3518cb4f3f8f6723b00433bd3dd (patch)
tree52060ea5b5b509d65e5e1d5541148c54f826fad9
parent287dc6396e0f9cb2393f901816dbd7f2a7dfbb5f (diff)
upstream: Add tests for expansions on UserKnownHostsFile.
OpenBSD-Regress-ID: bccf8060306c841bbcceb1392644f906a4d6ca51
-rw-r--r--regress/percent.sh39
1 files changed, 29 insertions, 10 deletions
diff --git a/regress/percent.sh b/regress/percent.sh
index cdcbe183..f569f82c 100644
--- a/regress/percent.sh
+++ b/regress/percent.sh
@@ -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