summaryrefslogtreecommitdiff
path: root/regress/percent.sh
diff options
context:
space:
mode:
Diffstat (limited to 'regress/percent.sh')
-rw-r--r--regress/percent.sh88
1 files changed, 88 insertions, 0 deletions
diff --git a/regress/percent.sh b/regress/percent.sh
new file mode 100644
index 000000000..2e891f693
--- /dev/null
+++ b/regress/percent.sh
@@ -0,0 +1,88 @@
1# $OpenBSD: percent.sh,v 1.6 2020/04/10 00:54:03 dtucker Exp $
2# Placed in the Public Domain.
3
4tid="percent expansions"
5
6if [ -x "/usr/xpg4/bin/id" ]; then
7 PATH=/usr/xpg4/bin:$PATH
8 export PATH
9fi
10
11USER=`id -u -n`
12USERID=`id -u`
13HOST=`hostname | cut -f1 -d.`
14HOSTNAME=`hostname`
15
16# Localcommand is evaluated after connection because %T is not available
17# until then. Because of this we use a different method of exercising it,
18# and we can't override the remote user otherwise authentication will fail.
19# We also have to explicitly enable it.
20echo "permitlocalcommand yes" >> $OBJ/ssh_proxy
21
22trial()
23{
24 opt="$1"; arg="$2"; expect="$3"
25
26 trace "test $opt=$arg $expect"
27 rm -f $OBJ/actual
28 case "$opt" in
29 localcommand)
30 ${SSH} -F $OBJ/ssh_proxy -o $opt="echo '$arg' >$OBJ/actual" \
31 somehost true
32 got=`cat $OBJ/actual`
33 ;;
34 matchexec)
35 (cat $OBJ/ssh_proxy && \
36 echo "Match Exec \"echo '$arg' >$OBJ/actual\"") \
37 >$OBJ/ssh_proxy_match
38 ${SSH} -F $OBJ/ssh_proxy_match remuser@somehost true || true
39 got=`cat $OBJ/actual`
40 ;;
41 *forward)
42 # LocalForward and RemoteForward take two args and only
43 # operate on Unix domain socket paths
44 got=`${SSH} -F $OBJ/ssh_proxy -o $opt="/$arg /$arg" -G \
45 remuser@somehost | awk '$1=="'$opt'"{print $2" "$3}'`
46 expect="/$expect /$expect"
47 ;;
48 *)
49 got=`${SSH} -F $OBJ/ssh_proxy -o $opt="$arg" -G \
50 remuser@somehost | awk '$1=="'$opt'"{print $2}'`
51 esac
52 if [ "$got" != "$expect" ]; then
53 fail "$opt=$arg expect $expect got $got"
54 fi
55}
56
57for i in matchexec localcommand remotecommand controlpath identityagent \
58 forwardagent localforward remoteforward; do
59 verbose $tid $i
60 if [ "$i" = "localcommand" ]; then
61 REMUSER=$USER
62 trial $i '%T' NONE
63 else
64 REMUSER=remuser
65 fi
66 # Matches implementation in readconf.c:ssh_connection_hash()
67 HASH=`printf "${HOSTNAME}127.0.0.1${PORT}$REMUSER" |
68 openssl sha1 | cut -f2 -d' '`
69 trial $i '%%' '%'
70 trial $i '%C' $HASH
71 trial $i '%i' $USERID
72 trial $i '%h' 127.0.0.1
73 trial $i '%d' $HOME
74 trial $i '%L' $HOST
75 trial $i '%l' $HOSTNAME
76 trial $i '%n' somehost
77 trial $i '%p' $PORT
78 trial $i '%r' $REMUSER
79 trial $i '%u' $USER
80 trial $i '%%/%C/%i/%h/%d/%L/%l/%n/%p/%r/%u' \
81 "%/$HASH/$USERID/127.0.0.1/$HOME/$HOST/$HOSTNAME/somehost/$PORT/$REMUSER/$USER"
82done
83
84# A subset of options support tilde expansion
85for i in controlpath identityagent forwardagent; do
86 trial $i '~' $HOME/
87 trial $i '~/.ssh' $HOME/.ssh
88done