[openssh-commits] [openssh] 04/04: upstream: Add tests for expansions on UserKnownHostsFile.

git+noreply at mindrot.org git+noreply at mindrot.org
Fri Jul 17 13:53:13 AEST 2020


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit 6736fe680704a3518cb4f3f8f6723b00433bd3dd
Author: dtucker at openbsd.org <dtucker at openbsd.org>
Date:   Fri Jul 17 03:26:58 2020 +0000

    upstream: Add tests for expansions on UserKnownHostsFile.
    
    OpenBSD-Regress-ID: bccf8060306c841bbcceb1392644f906a4d6ca51
---
 regress/percent.sh | 39 +++++++++++++++++++++++++++++----------
 1 file 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

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list